Skip to content

Commit

Permalink
fix(auth/basic): bind pflags to viper only when required
Browse files Browse the repository at this point in the history
Binding pflags to Viper too early will generate a faulty configuration
file for falcoctl. This commit ensures binding is done only when the
basic authentication command is called.

Signed-off-by: Aldo Lacuku <[email protected]>
  • Loading branch information
alacuku authored and poiana committed Aug 26, 2024
1 parent 7e6b79e commit e0d71e7
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions cmd/registry/auth/basic/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ Example - Login with username and password in an interactive prompt:
`,
Args: cobra.ExactArgs(1),
PreRunE: func(cmd *cobra.Command, args []string) error {
_ = viper.BindPFlag("registry.auth.basic.username", cmd.Flags().Lookup("username"))
_ = viper.BindPFlag("registry.auth.basic.password", cmd.Flags().Lookup("password"))
_ = viper.BindPFlag("registry.auth.basic.password_stdin", cmd.Flags().Lookup("password-stdin"))

o.username = viper.GetString("registry.auth.basic.username")
o.password = viper.GetString("registry.auth.basic.password")
o.passwordFromStdin = viper.GetBool("registry.auth.basic.password_stdin")
Expand All @@ -84,13 +88,6 @@ Example - Login with username and password in an interactive prompt:
cmd.Flags().StringVarP(&o.password, "password", "p", "", "registry password")
cmd.Flags().BoolVar(&o.passwordFromStdin, "password-stdin", false, "read password from stdin")

_ = viper.BindPFlag("registry.auth.basic.username", cmd.Flags().Lookup("username"))
_ = viper.BindPFlag("registry.auth.basic.password", cmd.Flags().Lookup("password"))
_ = viper.BindPFlag("registry.auth.basic.password_stdin", cmd.Flags().Lookup("password-stdin"))

// Bind to environment variables.
viper.AutomaticEnv()

return cmd
}

Expand Down

0 comments on commit e0d71e7

Please sign in to comment.