feat: support username-password in config update (#447)

This commit is contained in:
Jeffrey Smith II
2022-10-14 07:56:39 -04:00
committed by GitHub
parent 188c393034
commit 6142b7a4a3
4 changed files with 139 additions and 43 deletions

View File

@ -174,6 +174,7 @@ https://docs.influxdata.com/influxdb/latest/reference/cli/influx/config/rm/
func newConfigUpdateCmd() cli.Command {
var cfg config.Config
var userpass string
return cli.Command{
Name: "set",
Aliases: []string{"update"},
@ -213,6 +214,11 @@ https://docs.influxdata.com/influxdb/latest/reference/cli/influx/config/set/
Usage: "New auth token to set on the config",
Destination: &cfg.Token,
},
&cli.StringFlag{
Name: "username-password, p",
Usage: "Username (and optionally password) to use for authentication. Only supported in OSS",
Destination: &userpass,
},
&cli.StringFlag{
Name: "org, o",
Usage: "New default organization to set on the config",
@ -225,7 +231,13 @@ https://docs.influxdata.com/influxdb/latest/reference/cli/influx/config/set/
},
),
Action: func(ctx *cli.Context) error {
if cfg.Token != "" && userpass != "" {
return fmt.Errorf("cannot specify `--token` and `--username-password` together, please choose one")
}
client := cmd.Client{CLI: getCLI(ctx)}
if userpass != "" {
return client.UpdateWithUserPass(cfg, userpass)
}
return client.Update(cfg)
},
}