mirror of
https://github.com/zitadel/zitadel.git
synced 2025-05-05 13:00:47 +00:00
fix(backend): respect start flags in all commands (#6621)
* fix(backend): respect start flags in all commands Currently flags like --externalDomain do only work in the last registered command which currently is start-from-setup. This creates the flags globally in the init function in uses them for all start commands. * fix(backend): remove viper defaults in start flags At this point viper is not yet initialized so this defaults would have not effect either. * Remove flag name variables and run go mod tidy --------- Co-authored-by: Tim Möhlmann <tim+github@zitadel.com>
This commit is contained in:
parent
1d6dfadad8
commit
ffdde825ec
@ -2,34 +2,31 @@ package start
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/pflag"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
|
"github.com/zitadel/logging"
|
||||||
|
|
||||||
"github.com/zitadel/zitadel/cmd/key"
|
"github.com/zitadel/zitadel/cmd/key"
|
||||||
"github.com/zitadel/zitadel/cmd/tls"
|
"github.com/zitadel/zitadel/cmd/tls"
|
||||||
)
|
)
|
||||||
|
|
||||||
var tlsMode *string
|
var (
|
||||||
|
startFlagSet = &pflag.FlagSet{}
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
startFlagSet.Uint16("port", 0, "port to run ZITADEL on")
|
||||||
|
startFlagSet.String("externalDomain", "", "domain ZITADEL will be exposed on")
|
||||||
|
startFlagSet.String("externalPort", "", "port ZITADEL will be exposed on")
|
||||||
|
}
|
||||||
|
|
||||||
func startFlags(cmd *cobra.Command) {
|
func startFlags(cmd *cobra.Command) {
|
||||||
bindUint16Flag(cmd, "port", "port to run ZITADEL on")
|
cmd.Flags().AddFlagSet(startFlagSet)
|
||||||
bindStringFlag(cmd, "externalDomain", "domain ZITADEL will be exposed on")
|
logging.OnError(
|
||||||
bindStringFlag(cmd, "externalPort", "port ZITADEL will be exposed on")
|
viper.BindPFlags(startFlagSet),
|
||||||
|
).Fatal("start flags")
|
||||||
|
|
||||||
tls.AddTLSModeFlag(cmd)
|
tls.AddTLSModeFlag(cmd)
|
||||||
key.AddMasterKeyFlag(cmd)
|
key.AddMasterKeyFlag(cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func bindStringFlag(cmd *cobra.Command, name, description string) {
|
|
||||||
cmd.PersistentFlags().String(name, viper.GetString(name), description)
|
|
||||||
viper.BindPFlag(name, cmd.PersistentFlags().Lookup(name))
|
|
||||||
}
|
|
||||||
|
|
||||||
func bindUint16Flag(cmd *cobra.Command, name, description string) {
|
|
||||||
cmd.PersistentFlags().Uint16(name, uint16(viper.GetUint(name)), description)
|
|
||||||
viper.BindPFlag(name, cmd.PersistentFlags().Lookup(name))
|
|
||||||
}
|
|
||||||
|
|
||||||
func bindBoolFlag(cmd *cobra.Command, name, description string) {
|
|
||||||
cmd.PersistentFlags().Bool(name, viper.GetBool(name), description)
|
|
||||||
viper.BindPFlag(name, cmd.PersistentFlags().Lookup(name))
|
|
||||||
}
|
|
||||||
|
2
go.mod
2
go.mod
@ -194,7 +194,7 @@ require (
|
|||||||
github.com/sirupsen/logrus v1.9.3
|
github.com/sirupsen/logrus v1.9.3
|
||||||
github.com/spf13/afero v1.11.0 // indirect
|
github.com/spf13/afero v1.11.0 // indirect
|
||||||
github.com/spf13/cast v1.6.0 // indirect
|
github.com/spf13/cast v1.6.0 // indirect
|
||||||
github.com/spf13/pflag v1.0.5 // indirect
|
github.com/spf13/pflag v1.0.5
|
||||||
github.com/subosito/gotenv v1.6.0 // indirect
|
github.com/subosito/gotenv v1.6.0 // indirect
|
||||||
github.com/ttacon/builder v0.0.0-20170518171403-c099f663e1c2 // indirect
|
github.com/ttacon/builder v0.0.0-20170518171403-c099f663e1c2 // indirect
|
||||||
github.com/x448/float16 v0.8.4 // indirect
|
github.com/x448/float16 v0.8.4 // indirect
|
||||||
|
Loading…
x
Reference in New Issue
Block a user