Skip to content

Commit

Permalink
fallback to json default cfg path if yaml does not exist
Browse files Browse the repository at this point in the history
Signed-off-by: Janine Olear <pninak@web.de>
  • Loading branch information
miyunari committed Oct 4, 2024
1 parent c07462d commit 53fc3e7
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions cmd/app/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ import (
"google.golang.org/grpc/keepalive"
)

const serveCmdEnvPrefix = "FULCIO_SERVE"
const (
serveCmdEnvPrefix = "FULCIO_SERVE"
defaultConfigPath string = "/etc/fulcio-config/config.yaml"
)

var serveCmdConfigFilePath string

Expand All @@ -88,7 +91,7 @@ func newServeCmd() *cobra.Command {
cmd.Flags().String("hsm-caroot-id", "", "HSM ID for Root CA (only used with --ca pkcs11ca)")
cmd.Flags().String("ct-log-url", "http://localhost:6962/test", "host and path (with log prefix at the end) to the ct log")
cmd.Flags().String("ct-log-public-key-path", "", "Path to a PEM-encoded public key of the CT log, used to verify SCTs")
cmd.Flags().String("config-path", "/etc/fulcio-config/config.yaml", "path to fulcio config yaml")
cmd.Flags().String("config-path", defaultConfigPath, "path to fulcio config yaml")
cmd.Flags().String("pkcs11-config-path", "config/crypto11.conf", "path to fulcio pkcs11 config file")
cmd.Flags().String("fileca-cert", "", "Path to CA certificate")
cmd.Flags().String("fileca-key", "", "Path to CA encrypted private key")
Expand Down Expand Up @@ -212,6 +215,13 @@ func runServeCmd(cmd *cobra.Command, args []string) { //nolint: revive
_ = flag.CommandLine.Parse([]string{})

cp := viper.GetString("config-path")
if cp == defaultConfigPath {
if _, err := os.Stat(cp); os.IsNotExist(err) {
log.Logger.Warnf("warn loading --config-path=%s: %v, fall back to json", cp, err)
cp = strings.TrimSuffix(cp, ".yaml") + ".json"
}
}

cfg, err := config.Load(cp)
if err != nil {
log.Logger.Fatalf("error loading --config-path=%s: %v", cp, err)
Expand Down

0 comments on commit 53fc3e7

Please sign in to comment.