Extrapolate OS_ env vars for other auth options.
diff --git a/openstack/utils/utils.go b/openstack/utils/utils.go
index 99b0977..f97f3d1 100644
--- a/openstack/utils/utils.go
+++ b/openstack/utils/utils.go
@@ -1,18 +1,19 @@
-// This package contains utilities which eases working with Gophercloud's OpenStack APIs.
+// Package utils contains utilities which eases working with Gophercloud's OpenStack APIs.
package utils
import (
"fmt"
- identity "github.com/rackspace/gophercloud/openstack/identity/v2"
"os"
+
+ "github.com/rackspace/gophercloud"
)
-var nilOptions = identity.AuthOptions{}
+var nilOptions = gophercloud.AuthOptions{}
// ErrNoAuthUrl, ErrNoUsername, and ErrNoPassword errors indicate of the required OS_AUTH_URL, OS_USERNAME, or OS_PASSWORD
// environment variables, respectively, remain undefined. See the AuthOptions() function for more details.
var (
- ErrNoAuthUrl = fmt.Errorf("Environment variable OS_AUTH_URL needs to be set.")
+ ErrNoAuthURL = fmt.Errorf("Environment variable OS_AUTH_URL needs to be set.")
ErrNoUsername = fmt.Errorf("Environment variable OS_USERNAME needs to be set.")
ErrNoPassword = fmt.Errorf("Environment variable OS_PASSWORD needs to be set.")
)
@@ -21,18 +22,21 @@
// OS_* environment variables. The following variables provide sources of truth: OS_AUTH_URL, OS_USERNAME,
// OS_PASSWORD, OS_TENANT_ID, and OS_TENANT_NAME. Of these, OS_USERNAME, OS_PASSWORD, and OS_AUTH_URL must
// have settings, or an error will result. OS_TENANT_ID and OS_TENANT_NAME are optional.
-func AuthOptions() (identity.AuthOptions, error) {
- authUrl := os.Getenv("OS_AUTH_URL")
+func AuthOptions() (gophercloud.AuthOptions, error) {
+ authURL := os.Getenv("OS_AUTH_URL")
username := os.Getenv("OS_USERNAME")
+ userID := os.Getenv("OS_USERID")
password := os.Getenv("OS_PASSWORD")
- tenantId := os.Getenv("OS_TENANT_ID")
+ tenantID := os.Getenv("OS_TENANT_ID")
tenantName := os.Getenv("OS_TENANT_NAME")
+ domainID := os.Getenv("OS_DOMAIN_ID")
+ domainName := os.Getenv("OS_DOMAIN_NAME")
- if authUrl == "" {
- return nilOptions, ErrNoAuthUrl
+ if authURL == "" {
+ return nilOptions, ErrNoAuthURL
}
- if username == "" {
+ if username == "" && userID == "" {
return nilOptions, ErrNoUsername
}
@@ -40,17 +44,21 @@
return nilOptions, ErrNoPassword
}
- ao := identity.AuthOptions{
- Endpoint: authUrl,
- Username: username,
- Password: password,
- TenantId: tenantId,
- TenantName: tenantName,
+ ao := gophercloud.AuthOptions{
+ IdentityEndpoint: authURL,
+ UserID: userID,
+ Username: username,
+ Password: password,
+ TenantID: tenantID,
+ TenantName: tenantName,
+ DomainID: domainID,
+ DomainName: domainName,
}
return ao, nil
}
+// BuildQuery constructs the query section of a URI from a map.
func BuildQuery(params map[string]string) string {
query := "?"
for k, v := range params {