diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0978174..8800948 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -58,7 +58,6 @@ jobs: mkdir $COVERDIR GOCOVERDIR=$COVERDIR ./ctfd-setup go tool covdata textfmt -i=$COVERDIR -o cov.out - cat cov.out env: CTFD_URL: http://localhost:8000 diff --git a/cmd/ctfd-setup/main.go b/cmd/ctfd-setup/main.go index 250c004..6d5d077 100644 --- a/cmd/ctfd-setup/main.go +++ b/cmd/ctfd-setup/main.go @@ -2,16 +2,16 @@ package main import ( "context" - "fmt" "log" "os" "os/signal" "syscall" + ctfdsetup "github.com/ctfer-io/ctfd-setup" "github.com/ctfer-io/go-ctfd/api" - ctfdsetup "github.com/pandatix/ctfd-setup" "github.com/pkg/errors" "github.com/urfave/cli/v2" + "go.uber.org/zap" "gopkg.in/yaml.v3" ) @@ -67,10 +67,13 @@ func main() { } func run(ctx *cli.Context) error { + log := ctfdsetup.Log() + // Read and unmarshal setup config file raw := []byte(ctfdsetup.DefaultConf) if ctx.IsSet("file") { f := ctx.String("file") + log.Info("getting configuration file", zap.String("file", f)) b, err := os.ReadFile(f) if err != nil { return errors.Wrapf(err, "reading file %s", f) @@ -82,10 +85,10 @@ func run(ctx *cli.Context) error { if err := yaml.Unmarshal(raw, &conf); err != nil { return errors.Wrap(err, "unmarshalling configuration") } - fmt.Printf("conf: %+v\n", conf) // Connect to CTFd url := ctx.String("url") + log.Info("setting up CTFd instance", zap.String("url", url)) nonce, session, err := api.GetNonceAndSession(url, api.WithContext(ctx.Context)) if err != nil { return errors.Wrap(err, "getting CTFd nonce and session") diff --git a/go.mod b/go.mod index cc7fc55..fd06190 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/pandatix/ctfd-setup +module github.com/ctfer-io/ctfd-setup go 1.22.1 @@ -6,6 +6,7 @@ require ( github.com/ctfer-io/go-ctfd v0.4.0 github.com/pkg/errors v0.9.1 github.com/urfave/cli/v2 v2.27.1 + go.uber.org/zap v1.27.0 gopkg.in/yaml.v3 v3.0.1 ) @@ -14,4 +15,5 @@ require ( github.com/gorilla/schema v1.2.1 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect + go.uber.org/multierr v1.10.0 // indirect ) diff --git a/go.sum b/go.sum index 8a70827..9a44995 100644 --- a/go.sum +++ b/go.sum @@ -18,6 +18,12 @@ github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho= github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ= +go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= +go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= +go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/logger.go b/logger.go new file mode 100644 index 0000000..3c97036 --- /dev/null +++ b/logger.go @@ -0,0 +1,19 @@ +package ctfdsetup + +import ( + "sync" + + "go.uber.org/zap" +) + +var ( + logSync sync.Once + logger *zap.Logger +) + +func Log() *zap.Logger { + logSync.Do(func() { + logger, _ = zap.NewProduction() + }) + return logger +}