Ash Wilson | 89466cc | 2014-08-29 11:27:39 -0400 | [diff] [blame^] | 1 | package gophercloud |
| 2 | |
| 3 | import "strings" |
| 4 | |
| 5 | // ProviderClient stores details that are required to interact with any services within a specific provider's API. |
| 6 | // |
| 7 | // Generally, you acquire a ProviderClient by calling the `NewClient()` method in the appropriate provider's child package, |
| 8 | // providing whatever authentication credentials are required. |
| 9 | type ProviderClient struct { |
| 10 | // Authority caches results of the most recent authentication. |
| 11 | Authority AuthResults |
| 12 | |
| 13 | // Options remembers the original authentication parameters, if reauthentication is enabled. |
| 14 | Options AuthOptions |
| 15 | |
| 16 | // Endpoint is the base URL of the relevant API. |
| 17 | Endpoint string |
| 18 | |
| 19 | // TokenID is the most recently valid token issued. |
| 20 | TokenID string |
| 21 | } |
| 22 | |
| 23 | // ServiceURL constructs a URL for a resource belonging to this client. |
| 24 | func (client *ProviderClient) ServiceURL(parts ...string) string { |
| 25 | return client.Endpoint + strings.Join(parts, "/") |
| 26 | } |
| 27 | |
| 28 | // AuthenticatedHeaders returns a map of HTTP headers that are common for all authenticated service |
| 29 | // requests. |
| 30 | func (client *ProviderClient) AuthenticatedHeaders() map[string]string { |
| 31 | return map[string]string{"X-Auth-Token": client.TokenID} |
| 32 | } |