mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 13:37:30 +00:00
Add username support to fleetctl setup (#1971)
Username continues to default to email if not specified in the options. Closes #1970
This commit is contained in:
parent
b752073d05
commit
0f99b454a0
2 changed files with 16 additions and 4 deletions
|
|
@ -13,13 +13,14 @@ import (
|
|||
func setupCommand() cli.Command {
|
||||
var (
|
||||
flEmail string
|
||||
flUsername string
|
||||
flPassword string
|
||||
flOrgName string
|
||||
)
|
||||
return cli.Command{
|
||||
Name: "setup",
|
||||
Usage: "Setup a Kolide Fleet instance",
|
||||
UsageText: `fleetctl config login [options]`,
|
||||
UsageText: `fleetctl setup [options]`,
|
||||
Flags: []cli.Flag{
|
||||
configFlag(),
|
||||
contextFlag(),
|
||||
|
|
@ -30,6 +31,13 @@ func setupCommand() cli.Command {
|
|||
Destination: &flEmail,
|
||||
Usage: "Email of the admin user to create",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "username",
|
||||
EnvVar: "USERNAME",
|
||||
Value: "",
|
||||
Destination: &flUsername,
|
||||
Usage: "Username of the admin user to create",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "password",
|
||||
EnvVar: "PASSWORD",
|
||||
|
|
@ -54,6 +62,10 @@ func setupCommand() cli.Command {
|
|||
if flEmail == "" {
|
||||
return errors.Errorf("Email of the admin user to create must be provided")
|
||||
}
|
||||
if flUsername == "" {
|
||||
fmt.Println("No username supplied, using email as username")
|
||||
flUsername = flEmail
|
||||
}
|
||||
if flPassword == "" {
|
||||
fmt.Print("Password: ")
|
||||
passBytes, err := terminal.ReadPassword(int(os.Stdin.Fd()))
|
||||
|
|
@ -75,7 +87,7 @@ func setupCommand() cli.Command {
|
|||
|
||||
}
|
||||
|
||||
token, err := fleet.Setup(flEmail, flPassword, flOrgName)
|
||||
token, err := fleet.Setup(flEmail, flUsername, flPassword, flOrgName)
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
case service.SetupAlreadyErr:
|
||||
|
|
|
|||
|
|
@ -10,12 +10,12 @@ import (
|
|||
|
||||
// Setup attempts to setup the current Fleet instance. If setup is successful,
|
||||
// an auth token is returned.
|
||||
func (c *Client) Setup(email, password, org string) (string, error) {
|
||||
func (c *Client) Setup(email, username, password, org string) (string, error) {
|
||||
t := true
|
||||
params := setupRequest{
|
||||
Admin: &kolide.UserPayload{
|
||||
Admin: &t,
|
||||
Username: &email,
|
||||
Username: &username,
|
||||
Email: &email,
|
||||
Password: &password,
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue