Improve error message when client is not logged in (#1867)

This commit is contained in:
Zachary Wasserman
2018-07-16 09:35:21 -07:00
committed by GitHub
parent 626cda2d4f
commit e62d2f57df
3 changed files with 16 additions and 3 deletions
+14 -1
View File
@@ -8,7 +8,7 @@ import (
"github.com/urfave/cli"
)
func clientFromCLI(c *cli.Context) (*service.Client, error) {
func unauthenticatedClientFromCLI(c *cli.Context) (*service.Client, error) {
if err := makeConfigIfNotExists(c.String("config")); err != nil {
return nil, errors.Wrapf(err, "error verifying that config exists at %s", c.String("config"))
}
@@ -32,12 +32,25 @@ func clientFromCLI(c *cli.Context) (*service.Client, error) {
return nil, errors.Wrap(err, "error creating Fleet API client handler")
}
return fleet, nil
}
func clientFromCLI(c *cli.Context) (*service.Client, error) {
fleet, err := unauthenticatedClientFromCLI(c)
if err != nil {
return nil, err
}
// Add authentication token
t, err := getConfigValue(c, "token")
if err != nil {
return nil, errors.Wrap(err, "error getting token from the config")
}
if token, ok := t.(string); ok {
if token == "" {
return nil, errors.New("Please log in with: fleetctl login")
}
fleet.SetToken(token)
} else {
return nil, errors.Errorf("token config value was not a string: %+v", t)
+1 -1
View File
@@ -42,7 +42,7 @@ Interactively prompts for email and password if not specified in the flags or en
},
},
Action: func(c *cli.Context) error {
fleet, err := clientFromCLI(c)
fleet, err := unauthenticatedClientFromCLI(c)
if err != nil {
return err
}
+1 -1
View File
@@ -46,7 +46,7 @@ func setupCommand() cli.Command {
},
},
Action: func(c *cli.Context) error {
fleet, err := clientFromCLI(c)
fleet, err := unauthenticatedClientFromCLI(c)
if err != nil {
return err
}