blob: 55d3b989f5f3e8fe2a6741d240e03010574cb1b9 [file] [log] [blame]
Ash Wilson6425a412014-08-29 12:30:35 -04001package gophercloud
2
3import "strings"
4
5// ServiceClient stores details required to interact with a specific service API implemented by a provider.
6// Generally, you'll acquire these by calling the appropriate `New` method on a ProviderClient.
7type ServiceClient struct {
Ash Wilsonc6372fe2014-09-03 11:24:52 -04008 // Provider is a reference to the provider that implements this service.
9 Provider *ProviderClient
Ash Wilson6425a412014-08-29 12:30:35 -040010
11 // Endpoint is the base URL of the service's API, acquired from a service catalog.
Ash Wilsoned6a1d82014-09-03 12:01:00 -040012 // It MUST end with a /.
Ash Wilson6425a412014-08-29 12:30:35 -040013 Endpoint string
Ash Wilson42380322014-10-06 14:21:46 -040014
15 // ResourceBase is the base URL shared by the resources within a service's API. It should include
16 // the API version and, like Endpoint, MUST end with a / if set. If not set, the Endpoint is used
17 // as-is, instead.
18 ResourceBase string
19}
20
21// ResourceBaseURL returns the base URL of any resources used by this service. It MUST end with a /.
22func (client *ServiceClient) ResourceBaseURL() string {
23 if client.ResourceBase != "" {
24 return client.ResourceBase
25 }
26 return client.Endpoint
Ash Wilson6425a412014-08-29 12:30:35 -040027}
28
29// ServiceURL constructs a URL for a resource belonging to this provider.
30func (client *ServiceClient) ServiceURL(parts ...string) string {
Ash Wilson42380322014-10-06 14:21:46 -040031 return client.ResourceBaseURL() + strings.Join(parts, "/")
32}
33
34// AuthenticatedHeaders returns a collection of HTTP request headers that mark a request as
35// belonging to the currently authenticated user.
36func (client *ServiceClient) AuthenticatedHeaders() map[string]string {
37 return client.Provider.AuthenticatedHeaders()
Ash Wilson6425a412014-08-29 12:30:35 -040038}