From 0f99b454a0847ece670eb38b35cdd6cb3a11b918 Mon Sep 17 00:00:00 2001 From: Zachary Wasserman Date: Wed, 2 Jan 2019 15:27:37 -0800 Subject: [PATCH] Add username support to fleetctl setup (#1971) Username continues to default to email if not specified in the options. Closes #1970 --- cmd/fleetctl/setup.go | 16 ++++++++++++++-- server/service/client_setup.go | 4 ++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/cmd/fleetctl/setup.go b/cmd/fleetctl/setup.go index 5bd38c7ace..cd69357c25 100644 --- a/cmd/fleetctl/setup.go +++ b/cmd/fleetctl/setup.go @@ -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: diff --git a/server/service/client_setup.go b/server/service/client_setup.go index f6e3166588..816bead910 100644 --- a/server/service/client_setup.go +++ b/server/service/client_setup.go @@ -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, },