fix auth v2 unit tests
diff --git a/auth_options.go b/auth_options.go
index 5102f09..922a279 100644
--- a/auth_options.go
+++ b/auth_options.go
@@ -48,3 +48,36 @@
// authentication token ID.
TokenID string
}
+
+// ToTokenV2CreateMap allows AuthOptions to satisfy the AuthOptionsBuilder
+// interface in the v2 tokens package
+func (opts AuthOptions) ToTokenV2CreateMap() (map[string]interface{}, error) {
+ // Populate the request map.
+ authMap := make(map[string]interface{})
+
+ if opts.Username != "" {
+ if opts.Password != "" {
+ authMap["passwordCredentials"] = map[string]interface{}{
+ "username": opts.Username,
+ "password": opts.Password,
+ }
+ } else {
+ return nil, ErrMissingInput{Argument: "Password"}
+ }
+ } else if opts.TokenID != "" {
+ authMap["token"] = map[string]interface{}{
+ "id": opts.TokenID,
+ }
+ } else {
+ return nil, ErrMissingInput{Argument: "Username"}
+ }
+
+ if opts.TenantID != "" {
+ authMap["tenantId"] = opts.TenantID
+ }
+ if opts.TenantName != "" {
+ authMap["tenantName"] = opts.TenantName
+ }
+
+ return map[string]interface{}{"auth": authMap}, nil
+}
diff --git a/openstack/client.go b/openstack/client.go
index 9858efb..2fa4750 100644
--- a/openstack/client.go
+++ b/openstack/client.go
@@ -99,7 +99,17 @@
v2Client.Endpoint = endpoint
}
- result := tokens2.Create(v2Client, tokens2.AuthOptions{AuthOptions: options})
+ v2Opts := tokens2.AuthOptions{
+ IdentityEndpoint: options.IdentityEndpoint,
+ Username: options.Username,
+ Password: options.Password,
+ TenantID: options.TenantID,
+ TenantName: options.TenantName,
+ AllowReauth: options.AllowReauth,
+ TokenID: options.TokenID,
+ }
+
+ result := tokens2.Create(v2Client, v2Opts)
token, err := result.ExtractToken()
if err != nil {
diff --git a/openstack/identity/v2/tokens/requests.go b/openstack/identity/v2/tokens/requests.go
index 73e0b91..1c4ba7c 100644
--- a/openstack/identity/v2/tokens/requests.go
+++ b/openstack/identity/v2/tokens/requests.go
@@ -35,10 +35,16 @@
ToTokenV2CreateMap() (map[string]interface{}, error)
}
-// AuthOptions wraps a gophercloud AuthOptions in order to adhere to the AuthOptionsBuilder
-// interface.
+// AuthOptions are the valid options for Openstack Identity v2 authentication.
+// For field descriptions, see gophercloud.AuthOptions.
type AuthOptions struct {
- gophercloud.AuthOptions
+ IdentityEndpoint string `json:"-"`
+ Username string `json:"username,omitempty"`
+ Password string `json:"password,omitempty"`
+ TenantID string `json:"tenantId,omitempty"`
+ TenantName string `json:"tenantName,omitempty"`
+ AllowReauth bool `json:"-"`
+ TokenID string
}
// ToTokenV2CreateMap allows AuthOptions to satisfy the AuthOptionsBuilder
diff --git a/openstack/identity/v2/tokens/requests_test.go b/openstack/identity/v2/tokens/requests_test.go
index 0cbb00c..a6d16f3 100644
--- a/openstack/identity/v2/tokens/requests_test.go
+++ b/openstack/identity/v2/tokens/requests_test.go
@@ -13,7 +13,7 @@
defer th.TeardownHTTP()
HandleTokenPost(t, requestJSON)
- return Create(client.ServiceClient(), AuthOptions{options})
+ return Create(client.ServiceClient(), options)
}
func tokenPostErr(t *testing.T, options gophercloud.AuthOptions, expectedErr error) {
@@ -21,7 +21,7 @@
defer th.TeardownHTTP()
HandleTokenPost(t, "")
- actualErr := Create(client.ServiceClient(), AuthOptions{options}).Err
+ actualErr := Create(client.ServiceClient(), options).Err
th.CheckDeepEquals(t, expectedErr, actualErr)
}