Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 3d6ab64

Browse files
committed
Fill TokenID from OS_TOKEN environment variable.
1 parent bb30330 commit 3d6ab64

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

openstack/auth_env.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ var nilOptions = gophercloud.AuthOptions{}
1313
// environment variables, respectively, remain undefined. See the AuthOptions() function for more details.
1414
var (
1515
ErrNoAuthURL = fmt.Errorf("Environment variable OS_AUTH_URL needs to be set.")
16-
ErrNoUsername = fmt.Errorf("Environment variable OS_USERNAME needs to be set.")
17-
ErrNoPassword = fmt.Errorf("Environment variable OS_PASSWORD needs to be set.")
16+
ErrNoUsername = fmt.Errorf("Environment variable OS_USERNAME, OS_USERID, or OS_TOKEN needs to be set.")
17+
ErrNoPassword = fmt.Errorf("Environment variable OS_PASSWORD or OS_TOKEN needs to be set.")
1818
)
1919

20-
// AuthOptions fills out an identity.AuthOptions structure with the settings found on the various OpenStack
21-
// OS_* environment variables. The following variables provide sources of truth: OS_AUTH_URL, OS_USERNAME,
22-
// OS_PASSWORD, OS_TENANT_ID, and OS_TENANT_NAME. Of these, OS_USERNAME, OS_PASSWORD, and OS_AUTH_URL must
23-
// have settings, or an error will result. OS_TENANT_ID and OS_TENANT_NAME are optional.
20+
// AuthOptionsFromEnv fills out an AuthOptions structure from the environment
21+
// variables: OS_AUTH_URL, OS_USERNAME, OS_USERID, OS_PASSWORD, OS_TENANT_ID,
22+
// OS_TENANT_NAME, OS_DOMAIN_ID, OS_DOMAIN_NAME, OS_TOKEN. It checks that
23+
// (1) OS_AUTH_URL is set, (2) OS_USERNAME, OS_USERID, or OS_TOKEN is set,
24+
// (3) OS_PASSWORD or OS_TOKEN is set.
2425
func AuthOptionsFromEnv() (gophercloud.AuthOptions, error) {
2526
authURL := os.Getenv("OS_AUTH_URL")
2627
username := os.Getenv("OS_USERNAME")
@@ -30,16 +31,17 @@ func AuthOptionsFromEnv() (gophercloud.AuthOptions, error) {
3031
tenantName := os.Getenv("OS_TENANT_NAME")
3132
domainID := os.Getenv("OS_DOMAIN_ID")
3233
domainName := os.Getenv("OS_DOMAIN_NAME")
34+
tokenID := os.Getenv("OS_TOKEN")
3335

3436
if authURL == "" {
3537
return nilOptions, ErrNoAuthURL
3638
}
3739

38-
if username == "" && userID == "" {
40+
if username == "" && userID == "" && tokenID == "" {
3941
return nilOptions, ErrNoUsername
4042
}
4143

42-
if password == "" {
44+
if password == "" && tokenID == "" {
4345
return nilOptions, ErrNoPassword
4446
}
4547

@@ -52,6 +54,7 @@ func AuthOptionsFromEnv() (gophercloud.AuthOptions, error) {
5254
TenantName: tenantName,
5355
DomainID: domainID,
5456
DomainName: domainName,
57+
TokenID: tokenID,
5558
}
5659

5760
return ao, nil

0 commit comments

Comments
 (0)