Skip to content

Commit

Permalink
feat: add captcha secret flag to start cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
ingvaar committed May 18, 2022
1 parent 369a45e commit f0aa7fe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
10 changes: 7 additions & 3 deletions cmd/start.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cmd

import (
"os"

"okp4/cosmos-faucet/internal/server"
"okp4/cosmos-faucet/pkg/client"

Expand All @@ -9,9 +11,10 @@ import (
)

const (
FlagAddress = "address"
FlagMetrics = "metrics"
FlagHealth = "health"
FlagAddress = "address"
FlagMetrics = "metrics"
FlagHealth = "health"
FlagCaptchaSecret = "captcha-secret"
)

var serverConfig server.Config
Expand Down Expand Up @@ -42,6 +45,7 @@ func NewStartCommand() *cobra.Command {
startCmd.Flags().StringVar(&addr, FlagAddress, ":8080", "rest api address")
startCmd.Flags().BoolVar(&serverConfig.EnableMetrics, FlagMetrics, false, "enable metrics endpoint")
startCmd.Flags().BoolVar(&serverConfig.EnableHealth, FlagHealth, false, "enable health endpoint")
startCmd.Flags().StringVar(&serverConfig.CaptchaSecret, FlagCaptchaSecret, os.Getenv("CAPTCHA_SECRET"), "Set Captcha secret (default from env: CAPTCHA_SECRET)")

return startCmd
}
Expand Down
16 changes: 5 additions & 11 deletions internal/server/server.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package server

import (
"net/http"
"net/http"
"okp4/cosmos-faucet/pkg/client"

"okp4/cosmos-faucet/pkg/client"
"os"

"github.com/gorilla/mux"
"github.com/rs/zerolog/log"
"github.com/gorilla/mux"
"github.com/rs/zerolog/log"
)

// Config holds config of the http server.
Expand All @@ -33,11 +31,7 @@ func NewServer(config Config) HTTPServer {
router: mux.NewRouter().StrictSlash(true),
}
if config.CaptchaSecret == "" {
log.Info().Msgf("Captcha secret not set, checking ENV")
config.CaptchaSecret = os.Getenv("CAPTCHA_SECRET")
if config.CaptchaSecret == "" {
log.Fatal().Msg("Captcha secret not found in ENV")
}
log.Fatal().Msg("Required Captcha secret not set")
}
server.createRoutes(config)
return server
Expand Down

0 comments on commit f0aa7fe

Please sign in to comment.