Change RAX_ to RS_ and accept OS_.
diff --git a/rackspace/auth_env.go b/rackspace/auth_env.go
index 1706cc4..5852c3c 100644
--- a/rackspace/auth_env.go
+++ b/rackspace/auth_env.go
@@ -10,21 +10,29 @@
var nilOptions = gophercloud.AuthOptions{}
// ErrNoAuthUrl, ErrNoUsername, and ErrNoPassword errors indicate of the
-// required RAX_AUTH_URL, RAX_USERNAME, or RAX_PASSWORD environment variables,
+// required RS_AUTH_URL, RS_USERNAME, or RS_PASSWORD environment variables,
// respectively, remain undefined. See the AuthOptions() function for more details.
var (
- ErrNoAuthURL = fmt.Errorf("Environment variable RAX_AUTH_URL needs to be set.")
- ErrNoUsername = fmt.Errorf("Environment variable RAX_USERNAME needs to be set.")
- ErrNoPassword = fmt.Errorf("Environment variable RAX_API_KEY or RAX_PASSWORD needs to be set.")
+ ErrNoAuthURL = fmt.Errorf("Environment variable RS_AUTH_URL or OS_AUTH_URL need to be set.")
+ ErrNoUsername = fmt.Errorf("Environment variable RS_USERNAME or OS_USERNAME need to be set.")
+ ErrNoPassword = fmt.Errorf("Environment variable RS_API_KEY or RS_PASSWORD needs to be set.")
)
+func prefixedEnv(base string) string {
+ value := os.Getenv("RS_" + base)
+ if value == "" {
+ value = os.Getenv("OS_" + base)
+ }
+ return value
+}
+
// AuthOptionsFromEnv fills out an identity.AuthOptions structure with the
-// settings found on the various Rackspace RAX_* environment variables.
+// settings found on the various Rackspace RS_* environment variables.
func AuthOptionsFromEnv() (gophercloud.AuthOptions, error) {
- authURL := os.Getenv("RAX_AUTH_URL")
- username := os.Getenv("RAX_USERNAME")
- password := os.Getenv("RAX_PASSWORD")
- apiKey := os.Getenv("RAX_API_KEY")
+ authURL := prefixedEnv("AUTH_URL")
+ username := prefixedEnv("USERNAME")
+ password := prefixedEnv("PASSWORD")
+ apiKey := prefixedEnv("API_KEY")
if authURL == "" {
return nilOptions, ErrNoAuthURL