Skip to content

Commit

Permalink
chore: fix multiple issues
Browse files Browse the repository at this point in the history
  • Loading branch information
pandatix committed Apr 7, 2024
1 parent f4fc7d8 commit a1245f4
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 6 additions & 3 deletions cmd/ctfd-setup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand All @@ -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")
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module github.com/pandatix/ctfd-setup
module github.com/ctfer-io/ctfd-setup

go 1.22.1

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
)

Expand All @@ -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
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
19 changes: 19 additions & 0 deletions logger.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit a1245f4

Please sign in to comment.