mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
018e10ea66
``` $ fleetctl config set address https://localhost:8080 [+] Set the "address" config key to "https://localhost:8080" in the "default" context $ fleetctl config set ignore_tls true [+] Set the "ignore_tls" config key to "true" in the "default" context $ fleetctl setup --email mike@arpaia.co --password "abc123" [+] Fleet setup successful and context configured! $ cat ~/.fleet/config contexts: default: address: https://localhost:8080 email: mike@arpaia.co ignore_tls: true token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzZXNzaW9uX2tleSI6IlUvdm05Vk9wSG0xUlA4SUtjQnBhb2ovWlo1TXppSEVXcFRCNFNPb2tHQnNLUFpDQXFieVpWWnpJb0UvczQzcWkyd1pHZXJOa29SNFVIQ2hNZUc0K09RPT0ifQ.rHawSN8JvD4jjWAPTYX2Ep9ZpMt3u4mSIQcu920C-_s $ fleetctl logout [+] Fleet logout successful and local token cleared! $ cat ~/.fleet/config contexts: default: address: https://localhost:8080 email: mike@arpaia.co ignore_tls: true token: "" ```
75 lines
1.7 KiB
Go
75 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/kolide/fleet/server/service"
|
|
"github.com/pkg/errors"
|
|
"github.com/urfave/cli"
|
|
)
|
|
|
|
func setupCommand() cli.Command {
|
|
var (
|
|
flEmail string
|
|
flPassword string
|
|
flOrgName string
|
|
)
|
|
return cli.Command{
|
|
Name: "setup",
|
|
Usage: "Setup a Kolide Fleet instance",
|
|
UsageText: `fleetctl config login [options]`,
|
|
Flags: []cli.Flag{
|
|
configFlag(),
|
|
contextFlag(),
|
|
cli.StringFlag{
|
|
Name: "email",
|
|
EnvVar: "EMAIL",
|
|
Value: "",
|
|
Destination: &flEmail,
|
|
Usage: "The email of the admin user to create",
|
|
},
|
|
cli.StringFlag{
|
|
Name: "password",
|
|
EnvVar: "PASSWORD",
|
|
Value: "",
|
|
Destination: &flPassword,
|
|
Usage: "The password for the admin user",
|
|
},
|
|
cli.StringFlag{
|
|
Name: "org-name",
|
|
EnvVar: "ORG_NAME",
|
|
Value: "",
|
|
Destination: &flOrgName,
|
|
Usage: "The name of the organization",
|
|
},
|
|
},
|
|
Action: func(c *cli.Context) error {
|
|
fleet, err := clientFromCLI(c)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
token, err := fleet.Setup(flEmail, flPassword, flOrgName)
|
|
if err != nil {
|
|
switch err.(type) {
|
|
case service.SetupAlreadyErr:
|
|
return err
|
|
}
|
|
return errors.Wrap(err, "error setting up Fleet")
|
|
}
|
|
|
|
if err := setConfigValue(c, "email", flEmail); err != nil {
|
|
return errors.Wrap(err, "error setting email for the current context")
|
|
}
|
|
|
|
if err := setConfigValue(c, "token", token); err != nil {
|
|
return errors.Wrap(err, "error setting token for the current context")
|
|
}
|
|
|
|
fmt.Printf("[+] Fleet setup successful and context configured!\n")
|
|
|
|
return nil
|
|
},
|
|
}
|
|
}
|