
Display an error when the OrgName and OrgId flags are both passed in. Only one or the other is allowed. closes https://github.com/influxdata/influx-cli/issues/371
164 lines
4.0 KiB
Go
164 lines
4.0 KiB
Go
package main
|
|
|
|
import (
|
|
"github.com/influxdata/influx-cli/v2/clients/user"
|
|
"github.com/influxdata/influx-cli/v2/pkg/cli/middleware"
|
|
"github.com/urfave/cli"
|
|
)
|
|
|
|
func newUserCmd() cli.Command {
|
|
return cli.Command{
|
|
Name: "user",
|
|
Usage: "User management commands",
|
|
Before: middleware.NoArgs,
|
|
Subcommands: []cli.Command{
|
|
newUserCreateCmd(),
|
|
newUserDeleteCmd(),
|
|
newUserListCmd(),
|
|
newUserUpdateCmd(),
|
|
newUserSetPasswordCmd(),
|
|
},
|
|
}
|
|
}
|
|
|
|
func newUserCreateCmd() cli.Command {
|
|
var params user.CreateParams
|
|
return cli.Command{
|
|
Name: "create",
|
|
Usage: "Create user",
|
|
Flags: append(
|
|
append(commonFlags(), getOrgFlags(¶ms.OrgParams)...),
|
|
&cli.StringFlag{
|
|
Name: "name, n",
|
|
Usage: "The user name",
|
|
EnvVar: "INFLUX_NAME",
|
|
Required: true,
|
|
Destination: ¶ms.Name,
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "password, p",
|
|
Usage: "The user password",
|
|
Destination: ¶ms.Password,
|
|
},
|
|
),
|
|
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
|
Action: func(ctx *cli.Context) error {
|
|
if err := checkOrgFlags(¶ms.OrgParams); err != nil {
|
|
return err
|
|
}
|
|
api := getAPI(ctx)
|
|
client := user.Client{
|
|
CLI: getCLI(ctx),
|
|
UsersApi: api.UsersApi,
|
|
OrganizationsApi: api.OrganizationsApi,
|
|
}
|
|
return client.Create(getContext(ctx), ¶ms)
|
|
},
|
|
}
|
|
}
|
|
|
|
func newUserDeleteCmd() cli.Command {
|
|
var id string
|
|
return cli.Command{
|
|
Name: "delete",
|
|
Usage: "Delete user",
|
|
Flags: append(
|
|
commonFlags(),
|
|
&cli.StringFlag{
|
|
Name: "id, i",
|
|
Usage: "The user ID",
|
|
Required: true,
|
|
Destination: &id,
|
|
},
|
|
),
|
|
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
|
Action: func(ctx *cli.Context) error {
|
|
client := user.Client{CLI: getCLI(ctx), UsersApi: getAPI(ctx).UsersApi}
|
|
return client.Delete(getContext(ctx), id)
|
|
},
|
|
}
|
|
}
|
|
|
|
func newUserListCmd() cli.Command {
|
|
var params user.ListParams
|
|
return cli.Command{
|
|
Name: "list",
|
|
Aliases: []string{"find", "ls"},
|
|
Usage: "List users",
|
|
Flags: append(
|
|
commonFlags(),
|
|
&cli.StringFlag{
|
|
Name: "id, i",
|
|
Usage: "The user ID",
|
|
Destination: ¶ms.Id,
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "name, n",
|
|
Usage: "The user name",
|
|
Destination: ¶ms.Name,
|
|
},
|
|
),
|
|
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
|
Action: func(ctx *cli.Context) error {
|
|
client := user.Client{CLI: getCLI(ctx), UsersApi: getAPI(ctx).UsersApi}
|
|
return client.List(getContext(ctx), ¶ms)
|
|
},
|
|
}
|
|
}
|
|
|
|
func newUserUpdateCmd() cli.Command {
|
|
var params user.UpdateParams
|
|
return cli.Command{
|
|
Name: "update",
|
|
Flags: append(
|
|
commonFlags(),
|
|
&cli.StringFlag{
|
|
Name: "id, i",
|
|
Usage: "The user ID",
|
|
Required: true,
|
|
Destination: ¶ms.Id,
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "name, n",
|
|
Usage: "The user name",
|
|
Destination: ¶ms.Name,
|
|
},
|
|
),
|
|
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
|
Action: func(ctx *cli.Context) error {
|
|
client := user.Client{CLI: getCLI(ctx), UsersApi: getAPI(ctx).UsersApi}
|
|
return client.Update(getContext(ctx), ¶ms)
|
|
},
|
|
}
|
|
}
|
|
|
|
func newUserSetPasswordCmd() cli.Command {
|
|
var params user.SetPasswordParams
|
|
return cli.Command{
|
|
Name: "password",
|
|
Flags: append(
|
|
commonFlagsNoPrint(),
|
|
&cli.StringFlag{
|
|
Name: "id, i",
|
|
Usage: "The user ID",
|
|
Destination: ¶ms.Id,
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "name, n",
|
|
Usage: "The user name",
|
|
Destination: ¶ms.Name,
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "password, p",
|
|
Usage: "Password to set on the user",
|
|
Destination: ¶ms.Password,
|
|
},
|
|
),
|
|
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
|
Action: func(ctx *cli.Context) error {
|
|
client := user.Client{CLI: getCLI(ctx), UsersApi: getAPI(ctx).UsersApi}
|
|
return client.SetPassword(getContext(ctx), ¶ms)
|
|
},
|
|
}
|
|
}
|