Use general (Provider|Service)Client structs.
diff --git a/openstack/identity/v3/client.go b/openstack/identity/v3/client.go
deleted file mode 100644
index 96e6f5d..0000000
--- a/openstack/identity/v3/client.go
+++ /dev/null
@@ -1,52 +0,0 @@
-package v3
-
-import (
- "time"
-
- "github.com/rackspace/gophercloud"
- "github.com/rackspace/gophercloud/openstack/identity/v3/tokens"
-)
-
-// Client abstracts the connection information necessary to make API calls to Identity v3 resources.
-// It exists mainly to adhere to the IdentityService interface.
-type Client struct {
- gophercloud.ServiceClient
-}
-
-// Token models a token acquired from the tokens/ API resource.
-type Token struct {
- ID string
- ExpiresAt time.Time
-}
-
-// NewClient creates a new client associated with the v3 identity service of a provider.
-func NewClient(provider *gophercloud.ProviderClient, endpoint string) *Client {
- return &Client{
- ServiceClient: gophercloud.ServiceClient{
- ProviderClient: *provider,
- Endpoint: endpoint,
- },
- }
-}
-
-// GetToken provides the supplied credentials to an identity v3 endpoint and attempts to acquire a token.
-func (c *Client) GetToken(authOptions gophercloud.AuthOptions) (*Token, error) {
- c.ServiceClient.ProviderClient.Options = authOptions
-
- result, err := tokens.Create(&c.ServiceClient, nil)
- if err != nil {
- return nil, err
- }
-
- tokenID, err := result.TokenID()
- if err != nil {
- return nil, err
- }
-
- expiresAt, err := result.ExpiresAt()
- if err != nil {
- return nil, err
- }
-
- return &Token{ID: tokenID, ExpiresAt: expiresAt}, nil
-}
diff --git a/openstack/identity/v3/client_test.go b/openstack/identity/v3/client_test.go
deleted file mode 100644
index d549f09..0000000
--- a/openstack/identity/v3/client_test.go
+++ /dev/null
@@ -1,55 +0,0 @@
-package v3
-
-import (
- "fmt"
- "net/http"
- "testing"
- "time"
-
- "github.com/rackspace/gophercloud"
- "github.com/rackspace/gophercloud/openstack/identity/v3/tokens"
- "github.com/rackspace/gophercloud/testhelper"
-)
-
-func TestNewClient(t *testing.T) {
- testhelper.SetupHTTP()
- defer testhelper.TeardownHTTP()
-
- provider := &gophercloud.ProviderClient{}
- client := NewClient(provider, testhelper.Endpoint()+"v3/")
-
- expected := testhelper.Endpoint() + "v3/"
- if client.Endpoint != expected {
- t.Errorf("Expected endpoint to be %s, but was %s", expected, client.Endpoint)
- }
-}
-
-func TestGetToken(t *testing.T) {
- testhelper.SetupHTTP()
- defer testhelper.TeardownHTTP()
- const ID = "aaaa1111"
-
- testhelper.Mux.HandleFunc("/v3/auth/tokens", func(w http.ResponseWriter, r *http.Request) {
- w.Header().Add("X-Subject-Token", ID)
-
- w.WriteHeader(http.StatusCreated)
- fmt.Fprintf(w, `{ "token": { "expires_at": "2013-02-02T18:30:59.000000Z" } }`)
- })
-
- provider := &gophercloud.ProviderClient{}
- client := NewClient(provider, testhelper.Endpoint()+"v3/")
-
- token, err := client.GetToken(gophercloud.AuthOptions{UserID: "me", Password: "swordfish"})
- if err != nil {
- t.Errorf("Unexpected error from authentication: %v", err)
- }
-
- if token.ID != ID {
- t.Errorf("Expected token ID [%s], but got [%s]", ID, token.ID)
- }
-
- expectedExpiration, _ := time.Parse(tokens.RFC3339Milli, "2013-02-02T18:30:59.000000Z")
- if token.ExpiresAt != expectedExpiration {
- t.Errorf("Expected token expiration [%v], but got [%v]", expectedExpiration, token.ExpiresAt)
- }
-}
diff --git a/openstack/identity/v3/doc.go b/openstack/identity/v3/doc.go
deleted file mode 100644
index 8a9335a..0000000
--- a/openstack/identity/v3/doc.go
+++ /dev/null
@@ -1,4 +0,0 @@
-/*
-Package v3 implements v3 of the OpenStack identity API.
-*/
-package v3
diff --git a/openstack/identity/v3/services/requests.go b/openstack/identity/v3/services/requests.go
index a752d57..e9384e1 100644
--- a/openstack/identity/v3/services/requests.go
+++ b/openstack/identity/v3/services/requests.go
@@ -19,7 +19,7 @@
var resp response
_, err := perigee.Request("POST", getListURL(client), perigee.Options{
- MoreHeaders: client.AuthenticatedHeaders(),
+ MoreHeaders: client.Provider.AuthenticatedHeaders(),
ReqBody: &req,
Results: &resp,
OkCodes: []int{201},
diff --git a/openstack/identity/v3/services/requests_test.go b/openstack/identity/v3/services/requests_test.go
index d2637c4..6592fc6 100644
--- a/openstack/identity/v3/services/requests_test.go
+++ b/openstack/identity/v3/services/requests_test.go
@@ -31,7 +31,7 @@
})
client := gophercloud.ServiceClient{
- ProviderClient: gophercloud.ProviderClient{
+ Provider: &gophercloud.ProviderClient{
TokenID: "1111",
},
Endpoint: testhelper.Endpoint(),
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(),