Complete setup with fleetctl preview (#167)

- Run the `fleetctl setup` command to set up the Fleet server with
  default username ('admin') and password ('admin123#').
- Configures fleetctl if it has not yet been configured.

Closes #152
This commit is contained in:
Zach Wasserman 2021-01-04 17:11:10 -08:00 committed by GitHub
parent cf9146eea2
commit d52f850702
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 4 deletions

View File

@ -39,7 +39,7 @@ func configFlag() cli.Flag {
Name: "config",
Value: defaultConfigPath,
EnvVar: "CONFIG",
Usage: "Path to the Fleet config file",
Usage: "Path to the fleetctl config file",
}
}
@ -48,7 +48,7 @@ func contextFlag() cli.Flag {
Name: "context",
Value: "default",
EnvVar: "CONTEXT",
Usage: "Name of Fleet config context to use",
Usage: "Name of fleetctl config context to use",
}
}

View File

@ -15,6 +15,7 @@ import (
"time"
"github.com/cenkalti/backoff/v4"
"github.com/fleetdm/fleet/server/service"
"github.com/pkg/errors"
"github.com/urfave/cli"
)
@ -32,9 +33,13 @@ func previewCommand() cli.Command {
This command will create a directory fleet-preview in the current working directory. Configurations can be modified in that directory.`,
Subcommands: []cli.Command{},
Flags: []cli.Flag{
configFlag(),
contextFlag(),
},
Action: func(c *cli.Context) error {
if _, err := exec.LookPath("docker-compose"); err != nil {
return errors.New("Please install Docker (https://docs.docker.com/get-docker/).")
return errors.New("Docker is required for the fleetctl preview experience.\n\nPlease install Docker (https://docs.docker.com/get-docker/).")
}
// Download files if necessary
@ -59,12 +64,60 @@ This command will create a directory fleet-preview in the current working direct
}
fmt.Println("Waiting for server to start up...")
fmt.Println("Note: You can safely ignore the browser warning \"Your connection is not private\". Click through this warning using the \"Advanced\" option.")
if err := waitStartup(); err != nil {
return errors.Wrap(err, "wait for server startup")
}
fmt.Println("Initializing server...")
const (
address = "https://localhost:8412"
username = "admin"
password = "admin123#"
)
fleet, err := service.NewClient(address, true, "", "")
if err != nil {
return errors.Wrap(err, "Error creating Fleet API client handler")
}
token, err := fleet.Setup(username, username, password, "Fleet Preview")
if err != nil {
return errors.Wrap(err, "Error setting up Fleet")
}
val, err := getConfigValue(c, "address")
if err != nil {
return errors.Wrap(err, "Error checking config")
}
if v, ok := val.(string); ok && v != "" {
fmt.Println("Skipped fleetctl setup because there is an existing fleetctl config.")
fmt.Println("Fleet is now available at https://localhost:8412.")
fmt.Println("Username:", username)
fmt.Println("Password:", password)
fmt.Println("Note: You can safely ignore the browser warning \"Your connection is not private\". Click through this warning using the \"Advanced\" option.")
return nil
}
if err := setConfigValue(c, "email", username); err != nil {
return errors.Wrap(err, "Error setting username")
}
if err := setConfigValue(c, "token", token); err != nil {
return errors.Wrap(err, "Error setting token")
}
if err := setConfigValue(c, "tls-skip-verify", "true"); err != nil {
return errors.Wrap(err, "Error setting tls-skip-verify")
}
if err := setConfigValue(c, "address", address); err != nil {
return errors.Wrap(err, "error setting address")
}
fmt.Println("Fleet is now available at https://localhost:8412.")
fmt.Println("Username:", username)
fmt.Println("Password:", password)
fmt.Println("Note: You can safely ignore the browser warning \"Your connection is not private\". Click through this warning using the \"Advanced\" option.")
return nil
},