aboutsummaryrefslogtreecommitdiff
path: root/account.go
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2018-02-19 20:51:16 +0100
committerStefan Majewsky <majewsky@gmx.net>2018-02-19 20:51:16 +0100
commit8f777460661bbbcbe42730979140f525b382110e (patch)
treef6360dc2f4c7ce9342de38c88cde247fa70a4467 /account.go
parent46081e2068aeea62783863515ab116bb6af20661 (diff)
downloadgo-schwift-8f777460661bbbcbe42730979140f525b382110e.tar.gz
introduce Client interface
Diffstat (limited to 'account.go')
-rw-r--r--account.go32
1 files changed, 19 insertions, 13 deletions
diff --git a/account.go b/account.go
index bbca9c5..6abfaf3 100644
--- a/account.go
+++ b/account.go
@@ -27,7 +27,7 @@ import (
//Account represents a Swift account.
type Account struct {
- client *gophercloud.ServiceClient
+ client Client
//URL parts
baseURL string
name string
@@ -37,13 +37,13 @@ type Account struct {
var endpointURLRegexp = regexp.MustCompile(`^(.*/)v1/(.*)/$`)
-//AccountFromClient takes a gophercloud.ServiceClient which wraps a Swift
-//endpoint, and returns the Account instance corresponding to the account or
-//project that this client is connected to.
-func AccountFromClient(client *gophercloud.ServiceClient) (*Account, error) {
- match := endpointURLRegexp.FindStringSubmatch(client.Endpoint)
+//AccountFromClient takes something that implements the Client interface, and
+//returns the Account instance corresponding to the account/project that this
+//client is connected to.
+func AccountFromClient(client Client) (*Account, error) {
+ match := endpointURLRegexp.FindStringSubmatch(client.EndpointURL())
if match == nil {
- return nil, fmt.Errorf(`schwift.AccountFromClient(): invalid Swift endpoint URL: cannot find "/v1/" in %q`, client.Endpoint)
+ return nil, fmt.Errorf(`schwift.AccountFromClient(): invalid Swift endpoint URL: cannot find "/v1/" in %q`, client.EndpointURL())
}
return &Account{
client: client,
@@ -52,6 +52,13 @@ func AccountFromClient(client *gophercloud.ServiceClient) (*Account, error) {
}, nil
}
+//AccountFromGophercloud takes a gophercloud.ServiceClient which wraps a Swift
+//endpoint, and returns the Account instance corresponding to the account or
+//project that this client is connected to.
+func AccountFromGophercloud(client *gophercloud.ServiceClient) (*Account, error) {
+ return AccountFromClient(&gophercloudClient{client})
+}
+
//SwitchAccount returns a handle on a different account on the same server. Note
//that you need reseller permissions to access accounts other than that where
//you originally authenticated. This method does not check whether the account
@@ -60,10 +67,9 @@ func AccountFromClient(client *gophercloud.ServiceClient) (*Account, error) {
//The account name is usually the project name with an additional "AUTH_"
//prefix.
func (a *Account) SwitchAccount(accountName string) *Account {
- clonedClient := *a.client
- clonedClient.Endpoint = a.baseURL + "v1/" + accountName + "/"
+ newEndpointURL := a.baseURL + "v1/" + accountName + "/"
return &Account{
- client: &clonedClient,
+ client: a.client.Clone(newEndpointURL),
baseURL: a.baseURL,
name: accountName,
}
@@ -75,9 +81,9 @@ func (a *Account) Name() string {
return a.name
}
-//Client returns the gophercloud.ServiceClient which is used to make requests
-//against this account.
-func (a *Account) Client() *gophercloud.ServiceClient {
+//Client returns the Client which is used to make requests against this
+//account.
+func (a *Account) Client() Client {
return a.client
}