Skip to content

Commit

Permalink
allow auth with token
Browse files Browse the repository at this point in the history
  • Loading branch information
jrperritt committed Jul 29, 2015
1 parent d274d31 commit e8f3018
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
31 changes: 25 additions & 6 deletions auth/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,30 @@ func Credentials(c *cli.Context, logger *logrus.Logger) (*gophercloud.AuthOption
}
}

var ao *gophercloud.AuthOptions

if _, ok := have["username"]; !ok {
need := map[string]string{
"tenant-id": "",
"auth-token": "",
}
commandoptions.CLIopts(c, have, need)
if len(need) != 0 {
return nil, "", fmt.Errorf("You must provide either username/api-key or tenant-id/auth-token values.")
}
delete(have, "username")
delete(have, "api-key")
ao = &gophercloud.AuthOptions{
TenantID: have["tenant-id"].Value,
Token: have["auth-token"].Value,
}
} else {
ao = &gophercloud.AuthOptions{
Username: have["username"].Value,
APIKey: have["apikey"].Value,
}
}

// if the user didn't provide an auth URL, default to the Rackspace US endpoint
if _, ok := have["authurl"]; !ok || have["authurl"].Value == "" {
have["authurl"] = commandoptions.Cred{Value: rackspace.RackspaceUSIdentity, From: "default value"}
Expand Down Expand Up @@ -173,16 +197,11 @@ func Credentials(c *cli.Context, logger *logrus.Logger) (*gophercloud.AuthOption
logger.Infof("Authentication Credentials:\n%s\n", haveString)
}

ao := &gophercloud.AuthOptions{
Username: have["username"].Value,
APIKey: have["apikey"].Value,
IdentityEndpoint: have["authurl"].Value,
}

// upper-case the region
region := strings.ToUpper(have["region"].Value)
// allow Gophercloud to re-authenticate
ao.AllowReauth = true
ao.IdentityEndpoint = have["authurl"].Value

return ao, region, nil
}
Expand Down
8 changes: 8 additions & 0 deletions commandoptions/globalflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ func GlobalFlags() []cli.Flag {
Name: "apikey",
Usage: "The API key with which to authenticate.",
},
cli.StringFlag{
Name: "tenant-id",
Usage: "The tenant ID of the user to authenticate as.",
},
cli.StringFlag{
Name: "auth-token",
Usage: "The authentication token of the user to authenticate as. This must be used with the `tenant-id` flag.",
},
cli.StringFlag{
Name: "authurl",
Usage: "The endpoint to which authenticate.",
Expand Down

0 comments on commit e8f3018

Please sign in to comment.