Merge pull request #166 from maxlinc/flexible_auth
Allow acceptance tests to run with an API key or alternate authentication endpoint.
diff --git a/acceptance/libargs.go b/acceptance/libargs.go
index a9bb92f..cf234e7 100644
--- a/acceptance/libargs.go
+++ b/acceptance/libargs.go
@@ -19,6 +19,7 @@
username = os.Getenv("SDK_USERNAME")
password = os.Getenv("SDK_PASSWORD")
apiKey = os.Getenv("SDK_API_KEY")
+ var authURL = os.Getenv("OS_AUTH_URL")
if (provider == "") || (username == "") || (password == "") {
fmt.Fprintf(os.Stderr, "One or more of the following environment variables aren't set:\n")
@@ -28,6 +29,10 @@
os.Exit(1)
}
+ if strings.Contains(provider, "rackspace") && (authURL != "") {
+ provider = authURL + "/v2.0/tokens"
+ }
+
return
}
@@ -143,6 +148,15 @@
// withIdentity authenticates the user against the provider's identity service, and provides an
// accessor for additional services.
func withIdentity(ar bool, f func(gophercloud.AccessProvider)) {
+ _, _, _, apiKey := getCredentials()
+ if len(apiKey) == 0 {
+ withPasswordIdentity(ar, f)
+ } else {
+ withAPIKeyIdentity(ar, f)
+ }
+}
+
+func withPasswordIdentity(ar bool, f func(gophercloud.AccessProvider)) {
provider, username, password, _ := getCredentials()
acc, err := gophercloud.Authenticate(
provider,
@@ -159,6 +173,23 @@
f(acc)
}
+func withAPIKeyIdentity(ar bool, f func(gophercloud.AccessProvider)) {
+ provider, username, _, apiKey := getCredentials()
+ acc, err := gophercloud.Authenticate(
+ provider,
+ gophercloud.AuthOptions{
+ Username: username,
+ ApiKey: apiKey,
+ AllowReauth: ar,
+ },
+ )
+ if err != nil {
+ panic(err)
+ }
+
+ f(acc)
+}
+
// withServerApi acquires the cloud servers API.
func withServerApi(acc gophercloud.AccessProvider, f func(gophercloud.CloudServersProvider)) {
api, err := gophercloud.ServersApi(acc, gophercloud.ApiCriteria{