blob: feed758859728fadc99da31a4da7463eb25d0597 [file] [log] [blame]
Ash Wilson70dfe0c2014-08-28 13:57:09 -04001package gophercloud
2
3import (
4 "strings"
5)
6
Ash Wilsond5f2f2d2014-08-28 14:28:28 -04007// ServiceClient stores details about a specific service that are necessary for further interactions with that service API, as well
8// as utility methods for service implementation.
Ash Wilson70dfe0c2014-08-28 13:57:09 -04009//
Ash Wilsond5f2f2d2014-08-28 14:28:28 -040010// Generally, you will acquire a ServiceClient by calling the NewClient() function in the appropriate service package.
Ash Wilson70dfe0c2014-08-28 13:57:09 -040011type ServiceClient struct {
Ash Wilsond5f2f2d2014-08-28 14:28:28 -040012
13 // Authority caches results of the most recent authentication.
14 Authority AuthResults
15
16 // Options remembers the original authentication parameters, if reauthentication is enabled.
17 Options AuthOptions
18
19 // Endpoint is the base URL of the relevant API.
20 Endpoint string
21
22 // TokenID is the most recently valid token issued.
23 TokenID string
Ash Wilson70dfe0c2014-08-28 13:57:09 -040024}
25
26// ServiceURL constructs a URL for a resource belonging to this client.
27func (client *ServiceClient) ServiceURL(parts ...string) string {
Ash Wilsond5f2f2d2014-08-28 14:28:28 -040028 return client.Endpoint + strings.Join(parts, "/")
Ash Wilson70dfe0c2014-08-28 13:57:09 -040029}
30
31// AuthenticatedHeaders returns a map of HTTP headers that are common for all authenticated service
32// requests.
33func (client *ServiceClient) AuthenticatedHeaders() map[string]string {
Ash Wilsond5f2f2d2014-08-28 14:28:28 -040034 return map[string]string{"X-Auth-Token": client.TokenID}
Ash Wilson70dfe0c2014-08-28 13:57:09 -040035}