Skip to content

Commit

Permalink
use UUID for admin token
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmenendez committed Oct 26, 2023
1 parent c1ed7ec commit be13fa3
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions cmd/census3/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (
"syscall"
"time"

"github.com/google/uuid"
flag "github.com/spf13/pflag"
"github.com/spf13/viper"
"github.com/vocdoni/census3/api"
"github.com/vocdoni/census3/db"
"github.com/vocdoni/census3/service"
"github.com/vocdoni/census3/state"
"go.vocdoni.io/dvote/log"
"go.vocdoni.io/dvote/util"
)

type Census3Config struct {
Expand All @@ -39,7 +39,7 @@ func main() {
flag.StringVar(&config.logLevel, "logLevel", "info", "log level (debug, info, warn, error)")
flag.IntVar(&config.port, "port", 7788, "HTTP port for the API")
flag.StringVar(&config.connectKey, "connectKey", "", "connect group key for IPFS connect")
flag.StringVar(&config.adminToken, "adminToken", "", "the admin token for the API")
flag.StringVar(&config.adminToken, "adminToken", "", "the admin UUID token for the API")
var strWeb3Providers string
flag.StringVar(&strWeb3Providers, "web3Providers", "", "the list of URL's of available web3 providers")
flag.Parse()
Expand Down Expand Up @@ -101,8 +101,13 @@ func main() {
log.Fatal(err)
}
// if the admin token is not defined, generate a random one
if config.adminToken == "" {
config.adminToken = util.RandomHex(20)

if config.adminToken != "" {
if _, err := uuid.Parse(config.adminToken); err != nil {
log.Fatal("bad admin token format, it must be a valid UUID")
}
} else {
config.adminToken = uuid.New().String()
log.Infof("no admin token defined, using a random one: %s", config.adminToken)
}
// start the API
Expand Down

0 comments on commit be13fa3

Please sign in to comment.