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:
Zachary Wasserman 2019-01-02 15:27:37 -08:00 committed by GitHub
parent b752073d05
commit 0f99b454a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View file

@ -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:

View file

@ -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,
},