Rename ServiceClient to ProviderClient.
Rather than store state within service-level Clients, we really want that
at the provider level. Service-level clients should be stateless.
diff --git a/openstack/identity/v3/tokens/requests.go b/openstack/identity/v3/tokens/requests.go
index ab84d81..115737e 100644
--- a/openstack/identity/v3/tokens/requests.go
+++ b/openstack/identity/v3/tokens/requests.go
@@ -13,14 +13,14 @@
DomainName string
}
-func subjectTokenHeaders(c *gophercloud.ServiceClient, subjectToken string) map[string]string {
+func subjectTokenHeaders(c *gophercloud.ProviderClient, subjectToken string) map[string]string {
h := c.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.ProviderClient, scope *Scope) (gophercloud.AuthResults, error) {
type domainReq struct {
ID *string `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
@@ -251,7 +251,7 @@
}
// Info validates and retrieves information about another token.
-func Info(c *gophercloud.ServiceClient, token string) (*TokenCreateResult, error) {
+func Info(c *gophercloud.ProviderClient, token string) (*TokenCreateResult, error) {
var result TokenCreateResult
response, err := perigee.Request("GET", getTokenURL(c), perigee.Options{
@@ -271,7 +271,7 @@
}
// Validate determines if a specified token is valid or not.
-func Validate(c *gophercloud.ServiceClient, token string) (bool, error) {
+func Validate(c *gophercloud.ProviderClient, token string) (bool, error) {
response, err := perigee.Request("HEAD", getTokenURL(c), perigee.Options{
MoreHeaders: subjectTokenHeaders(c, token),
OkCodes: []int{204, 404},
@@ -284,7 +284,7 @@
}
// Revoke immediately makes specified token invalid.
-func Revoke(c *gophercloud.ServiceClient, token string) error {
+func Revoke(c *gophercloud.ProviderClient, token string) error {
_, err := perigee.Request("DELETE", getTokenURL(c), perigee.Options{
MoreHeaders: subjectTokenHeaders(c, token),
OkCodes: []int{204},
diff --git a/openstack/identity/v3/tokens/requests_test.go b/openstack/identity/v3/tokens/requests_test.go
index 77b49f3..e1b845f 100644
--- a/openstack/identity/v3/tokens/requests_test.go
+++ b/openstack/identity/v3/tokens/requests_test.go
@@ -15,7 +15,7 @@
testhelper.SetupHTTP()
defer testhelper.TeardownHTTP()
- client := gophercloud.ServiceClient{
+ client := gophercloud.ProviderClient{
Endpoint: testhelper.Endpoint(),
Options: options,
TokenID: "12345abcdef",
@@ -41,7 +41,7 @@
testhelper.SetupHTTP()
defer testhelper.TeardownHTTP()
- client := gophercloud.ServiceClient{
+ client := gophercloud.ProviderClient{
Endpoint: testhelper.Endpoint(),
Options: options,
}
@@ -240,7 +240,7 @@
testhelper.SetupHTTP()
defer testhelper.TeardownHTTP()
- client := gophercloud.ServiceClient{
+ client := gophercloud.ProviderClient{
Endpoint: testhelper.Endpoint(),
Options: gophercloud.AuthOptions{UserID: "me", Password: "shhh"},
}
@@ -391,7 +391,7 @@
testhelper.SetupHTTP()
defer testhelper.TeardownHTTP()
- client := gophercloud.ServiceClient{
+ client := gophercloud.ProviderClient{
Endpoint: testhelper.Endpoint(),
TokenID: "12345abcdef",
}
@@ -425,8 +425,8 @@
}
}
-func prepareAuthTokenHandler(t *testing.T, expectedMethod string, status int) gophercloud.ServiceClient {
- client := gophercloud.ServiceClient{
+func prepareAuthTokenHandler(t *testing.T, expectedMethod string, status int) gophercloud.ProviderClient {
+ client := gophercloud.ProviderClient{
Endpoint: testhelper.Endpoint(),
TokenID: "12345abcdef",
}
diff --git a/openstack/identity/v3/tokens/urls.go b/openstack/identity/v3/tokens/urls.go
index 5b47c02..ac5a19f 100644
--- a/openstack/identity/v3/tokens/urls.go
+++ b/openstack/identity/v3/tokens/urls.go
@@ -2,6 +2,6 @@
import "github.com/rackspace/gophercloud"
-func getTokenURL(c *gophercloud.ServiceClient) string {
+func getTokenURL(c *gophercloud.ProviderClient) string {
return c.ServiceURL("auth", "tokens")
}
diff --git a/openstack/identity/v3/tokens/urls_test.go b/openstack/identity/v3/tokens/urls_test.go
index 5ff8bc6..5007b3d 100644
--- a/openstack/identity/v3/tokens/urls_test.go
+++ b/openstack/identity/v3/tokens/urls_test.go
@@ -11,7 +11,7 @@
testhelper.SetupHTTP()
defer testhelper.TeardownHTTP()
- client := gophercloud.ServiceClient{Endpoint: testhelper.Endpoint()}
+ client := gophercloud.ProviderClient{Endpoint: testhelper.Endpoint()}
expected := testhelper.Endpoint() + "auth/tokens"
actual := getTokenURL(&client)
diff --git a/provider_client.go b/provider_client.go
new file mode 100644
index 0000000..0f26e53
--- /dev/null
+++ b/provider_client.go
@@ -0,0 +1,32 @@
+package gophercloud
+
+import "strings"
+
+// ProviderClient stores details that are required to interact with any services within a specific provider's API.
+//
+// Generally, you acquire a ProviderClient by calling the `NewClient()` method in the appropriate provider's child package,
+// providing whatever authentication credentials are required.
+type ProviderClient struct {
+ // Authority caches results of the most recent authentication.
+ Authority AuthResults
+
+ // Options remembers the original authentication parameters, if reauthentication is enabled.
+ Options AuthOptions
+
+ // Endpoint is the base URL of the relevant API.
+ Endpoint string
+
+ // TokenID is the most recently valid token issued.
+ TokenID string
+}
+
+// ServiceURL constructs a URL for a resource belonging to this client.
+func (client *ProviderClient) ServiceURL(parts ...string) string {
+ return client.Endpoint + strings.Join(parts, "/")
+}
+
+// AuthenticatedHeaders returns a map of HTTP headers that are common for all authenticated service
+// requests.
+func (client *ProviderClient) AuthenticatedHeaders() map[string]string {
+ return map[string]string{"X-Auth-Token": client.TokenID}
+}
diff --git a/service_client.go b/service_client.go
deleted file mode 100644
index feed758..0000000
--- a/service_client.go
+++ /dev/null
@@ -1,35 +0,0 @@
-package gophercloud
-
-import (
- "strings"
-)
-
-// ServiceClient stores details about a specific service that are necessary for further interactions with that service API, as well
-// as utility methods for service implementation.
-//
-// Generally, you will acquire a ServiceClient by calling the NewClient() function in the appropriate service package.
-type ServiceClient struct {
-
- // Authority caches results of the most recent authentication.
- Authority AuthResults
-
- // Options remembers the original authentication parameters, if reauthentication is enabled.
- Options AuthOptions
-
- // Endpoint is the base URL of the relevant API.
- Endpoint string
-
- // TokenID is the most recently valid token issued.
- TokenID string
-}
-
-// ServiceURL constructs a URL for a resource belonging to this client.
-func (client *ServiceClient) ServiceURL(parts ...string) string {
- return client.Endpoint + strings.Join(parts, "/")
-}
-
-// AuthenticatedHeaders returns a map of HTTP headers that are common for all authenticated service
-// requests.
-func (client *ServiceClient) AuthenticatedHeaders() map[string]string {
- return map[string]string{"X-Auth-Token": client.TokenID}
-}