Use general (Provider|Service)Client structs.
diff --git a/openstack/identity/v3/tokens/requests.go b/openstack/identity/v3/tokens/requests.go
index ab84d81..7bdb548 100644
--- a/openstack/identity/v3/tokens/requests.go
+++ b/openstack/identity/v3/tokens/requests.go
@@ -14,13 +14,13 @@
}
func subjectTokenHeaders(c *gophercloud.ServiceClient, subjectToken string) map[string]string {
- h := c.AuthenticatedHeaders()
+ h := c.Provider.AuthenticatedHeaders()
h["X-Subject-Token"] = subjectToken
return h
}
// Create authenticates and either generates a new token, or changes the Scope of an existing token.
-func Create(c *gophercloud.ServiceClient, scope *Scope) (gophercloud.AuthResults, error) {
+func Create(c *gophercloud.ServiceClient, options gophercloud.AuthOptions, scope *Scope) (gophercloud.AuthResults, error) {
type domainReq struct {
ID *string `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
@@ -67,44 +67,42 @@
Auth authReq `json:"auth"`
}
- ao := c.Options
-
// Populate the request structure based on the provided arguments. Create and return an error
// if insufficient or incompatible information is present.
var req request
// Test first for unrecognized arguments.
- if ao.APIKey != "" {
+ if options.APIKey != "" {
return nil, ErrAPIKeyProvided
}
- if ao.TenantID != "" {
+ if options.TenantID != "" {
return nil, ErrTenantIDProvided
}
- if ao.TenantName != "" {
+ if options.TenantName != "" {
return nil, ErrTenantNameProvided
}
- if ao.Password == "" {
- if c.TokenID != "" {
+ if options.Password == "" {
+ if c.Provider.TokenID != "" {
// Because we aren't using password authentication, it's an error to also provide any of the user-based authentication
// parameters.
- if ao.Username != "" {
+ if options.Username != "" {
return nil, ErrUsernameWithToken
}
- if ao.UserID != "" {
+ if options.UserID != "" {
return nil, ErrUserIDWithToken
}
- if ao.DomainID != "" {
+ if options.DomainID != "" {
return nil, ErrDomainIDWithToken
}
- if ao.DomainName != "" {
+ if options.DomainName != "" {
return nil, ErrDomainNameWithToken
}
// Configure the request for Token authentication.
req.Auth.Identity.Methods = []string{"token"}
req.Auth.Identity.Token = &tokenReq{
- ID: c.TokenID,
+ ID: c.Provider.TokenID,
}
} else {
// If no password or token ID are available, authentication can't continue.
@@ -115,60 +113,60 @@
req.Auth.Identity.Methods = []string{"password"}
// At least one of Username and UserID must be specified.
- if ao.Username == "" && ao.UserID == "" {
+ if options.Username == "" && options.UserID == "" {
return nil, ErrUsernameOrUserID
}
- if ao.Username != "" {
+ if options.Username != "" {
// If Username is provided, UserID may not be provided.
- if ao.UserID != "" {
+ if options.UserID != "" {
return nil, ErrUsernameOrUserID
}
// Either DomainID or DomainName must also be specified.
- if ao.DomainID == "" && ao.DomainName == "" {
+ if options.DomainID == "" && options.DomainName == "" {
return nil, ErrDomainIDOrDomainName
}
- if ao.DomainID != "" {
- if ao.DomainName != "" {
+ if options.DomainID != "" {
+ if options.DomainName != "" {
return nil, ErrDomainIDOrDomainName
}
// Configure the request for Username and Password authentication with a DomainID.
req.Auth.Identity.Password = &passwordReq{
User: userReq{
- Name: &ao.Username,
- Password: ao.Password,
- Domain: &domainReq{ID: &ao.DomainID},
+ Name: &options.Username,
+ Password: options.Password,
+ Domain: &domainReq{ID: &options.DomainID},
},
}
}
- if ao.DomainName != "" {
+ if options.DomainName != "" {
// Configure the request for Username and Password authentication with a DomainName.
req.Auth.Identity.Password = &passwordReq{
User: userReq{
- Name: &ao.Username,
- Password: ao.Password,
- Domain: &domainReq{Name: &ao.DomainName},
+ Name: &options.Username,
+ Password: options.Password,
+ Domain: &domainReq{Name: &options.DomainName},
},
}
}
}
- if ao.UserID != "" {
+ if options.UserID != "" {
// If UserID is specified, neither DomainID nor DomainName may be.
- if ao.DomainID != "" {
+ if options.DomainID != "" {
return nil, ErrDomainIDWithUserID
}
- if ao.DomainName != "" {
+ if options.DomainName != "" {
return nil, ErrDomainNameWithUserID
}
// Configure the request for UserID and Password authentication.
req.Auth.Identity.Password = &passwordReq{
- User: userReq{ID: &ao.UserID, Password: ao.Password},
+ User: userReq{ID: &options.UserID, Password: options.Password},
}
}
}
diff --git a/openstack/identity/v3/tokens/requests_test.go b/openstack/identity/v3/tokens/requests_test.go
index 243a32f..97690a6 100644
--- a/openstack/identity/v3/tokens/requests_test.go
+++ b/openstack/identity/v3/tokens/requests_test.go
@@ -16,8 +16,7 @@
defer testhelper.TeardownHTTP()
client := gophercloud.ServiceClient{
- ProviderClient: gophercloud.ProviderClient{
- Options: options,
+ Provider: &gophercloud.ProviderClient{
TokenID: "12345abcdef",
},
Endpoint: testhelper.Endpoint(),
@@ -33,7 +32,7 @@
fmt.Fprintf(w, `{}`)
})
- _, err := Create(&client, scope)
+ _, err := Create(&client, options, scope)
if err != nil {
t.Errorf("Create returned an error: %v", err)
}
@@ -44,16 +43,14 @@
defer testhelper.TeardownHTTP()
client := gophercloud.ServiceClient{
- ProviderClient: gophercloud.ProviderClient{
- Options: options,
- },
+ Provider: &gophercloud.ProviderClient{},
Endpoint: testhelper.Endpoint(),
}
if includeToken {
- client.TokenID = "abcdef123456"
+ client.Provider.TokenID = "abcdef123456"
}
- _, err := Create(&client, scope)
+ _, err := Create(&client, options, scope)
if err == nil {
t.Errorf("Create did NOT return an error")
}
@@ -245,9 +242,7 @@
defer testhelper.TeardownHTTP()
client := gophercloud.ServiceClient{
- ProviderClient: gophercloud.ProviderClient{
- Options: gophercloud.AuthOptions{UserID: "me", Password: "shhh"},
- },
+ Provider: &gophercloud.ProviderClient{},
Endpoint: testhelper.Endpoint(),
}
@@ -258,7 +253,8 @@
fmt.Fprintf(w, `{}`)
})
- result, err := Create(&client, nil)
+ options := gophercloud.AuthOptions{UserID: "me", Password: "shhh"}
+ result, err := Create(&client, options, nil)
if err != nil {
t.Errorf("Create returned an error: %v", err)
}
@@ -398,7 +394,7 @@
defer testhelper.TeardownHTTP()
client := gophercloud.ServiceClient{
- ProviderClient: gophercloud.ProviderClient{
+ Provider: &gophercloud.ProviderClient{
TokenID: "12345abcdef",
},
Endpoint: testhelper.Endpoint(),
@@ -435,7 +431,7 @@
func prepareAuthTokenHandler(t *testing.T, expectedMethod string, status int) gophercloud.ServiceClient {
client := gophercloud.ServiceClient{
- ProviderClient: gophercloud.ProviderClient{
+ Provider: &gophercloud.ProviderClient{
TokenID: "12345abcdef",
},
Endpoint: testhelper.Endpoint(),