Merge pull request #55 from rackspace/tech-debt-reduction
Refactor common initialization sequences.
diff --git a/acceptance/libargs.go b/acceptance/libargs.go
index 67858f1..5daea21 100644
--- a/acceptance/libargs.go
+++ b/acceptance/libargs.go
@@ -127,4 +127,37 @@
// than what aSuitableFlavor() returns. If none could be found, this function will panic.
func findAlternativeFlavor() string {
return "3" // 1GB image, up from 512MB image
-}
\ No newline at end of file
+}
+
+// withIdentity authenticates the user against the provider's identity service, and provides an
+// accessor for additional services.
+func withIdentity(f func(gophercloud.AccessProvider)) {
+ provider, username, password := getCredentials()
+ acc, err := gophercloud.Authenticate(
+ provider,
+ gophercloud.AuthOptions{
+ Username: username,
+ Password: password,
+ },
+ )
+ 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{
+ Name: "cloudServersOpenStack",
+ Region: "DFW",
+ VersionId: "2",
+ UrlChoice: gophercloud.PublicURL,
+ })
+ if err != nil {
+ panic(err)
+ }
+
+ f(api)
+}