refactor: initial commit for major rewrite
This commit is contained in:
parent
3253cb8bbb
commit
bfd83f35a3
45 changed files with 439 additions and 1733 deletions
67
cmd/serve.go
67
cmd/serve.go
|
|
@ -1,67 +0,0 @@
|
|||
//go:build server || all
|
||||
// +build server all
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/OpenCHAMI/configurator/pkg/server"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var serveCmd = &cobra.Command{
|
||||
Use: "serve",
|
||||
Short: "Start configurator as a server and listen for requests",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
// make sure that we have a token present before trying to make request
|
||||
if conf.AccessToken == "" {
|
||||
// check if ACCESS_TOKEN env var is set if no access token is provided and use that instead
|
||||
accessToken := os.Getenv("ACCESS_TOKEN")
|
||||
if accessToken != "" {
|
||||
conf.AccessToken = accessToken
|
||||
} else {
|
||||
if verbose {
|
||||
log.Warn().Msg("No token found. Continuing without one...\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// show config as JSON and generators if verbose
|
||||
if verbose {
|
||||
b, err := json.MarshalIndent(conf, "", "\t")
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("failed to marshal config")
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("%v\n", string(b))
|
||||
}
|
||||
|
||||
// start listening with the server
|
||||
var (
|
||||
s *server.Server = server.New(&conf)
|
||||
err error = s.Serve()
|
||||
)
|
||||
if errors.Is(err, http.ErrServerClosed) {
|
||||
if verbose {
|
||||
log.Info().Msg("server closed")
|
||||
}
|
||||
} else if err != nil {
|
||||
log.Error().Err(err).Msg("failed to start server")
|
||||
os.Exit(1)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
serveCmd.Flags().StringVar(&conf.Server.Host, "host", conf.Server.Host, "set the server host and port")
|
||||
// serveCmd.Flags().StringVar(&pluginPath, "plugin", "", "set the generator plugins directory path")
|
||||
serveCmd.Flags().StringVar(&conf.Server.Jwks.Uri, "jwks-uri", conf.Server.Jwks.Uri, "set the JWKS url to fetch public key")
|
||||
serveCmd.Flags().IntVar(&conf.Server.Jwks.Retries, "jwks-fetch-retries", conf.Server.Jwks.Retries, "set the JWKS fetch retry count")
|
||||
rootCmd.AddCommand(serveCmd)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue