Ash Wilson | b8401a7 | 2014-09-08 17:07:49 -0400 | [diff] [blame] | 1 | package gophercloud |
| 2 | |
| 3 | import "errors" |
| 4 | |
| 5 | var ( |
Ash Wilson | 8c3bc8b | 2014-10-31 11:40:15 -0400 | [diff] [blame] | 6 | // ErrServiceNotFound is returned when no service in a service catalog matches |
| 7 | // the provided EndpointOpts. This is generally returned by provider service |
| 8 | // factory methods like "NewComputeV2()" and can mean that a service is not |
| 9 | // enabled for your account. |
Ash Wilson | 1cd3e69 | 2014-09-09 11:01:47 -0400 | [diff] [blame] | 10 | ErrServiceNotFound = errors.New("No suitable service could be found in the service catalog.") |
| 11 | |
Ash Wilson | 8c3bc8b | 2014-10-31 11:40:15 -0400 | [diff] [blame] | 12 | // ErrEndpointNotFound is returned when no available endpoints match the |
| 13 | // provided EndpointOpts. This is also generally returned by provider service |
| 14 | // factory methods, and usually indicates that a region was specified |
| 15 | // incorrectly. |
Ash Wilson | b8401a7 | 2014-09-08 17:07:49 -0400 | [diff] [blame] | 16 | ErrEndpointNotFound = errors.New("No suitable endpoint could be found in the service catalog.") |
| 17 | ) |
| 18 | |
Ash Wilson | 8c3bc8b | 2014-10-31 11:40:15 -0400 | [diff] [blame] | 19 | // Availability indicates to whom a specific service endpoint is accessible: |
| 20 | // the internet at large, internal networks only, or only to administrators. |
| 21 | // Different identity services use different terminology for these. Identity v2 |
| 22 | // lists them as different kinds of URLs within the service catalog ("adminURL", |
| 23 | // "internalURL", and "publicURL"), while v3 lists them as "Interfaces" in an |
| 24 | // endpoints response. |
Ash Wilson | efac18b | 2014-09-10 14:44:42 -0400 | [diff] [blame] | 25 | type Availability string |
Ash Wilson | 0747d7e | 2014-09-09 14:27:35 -0400 | [diff] [blame] | 26 | |
| 27 | const ( |
Ash Wilson | 8c3bc8b | 2014-10-31 11:40:15 -0400 | [diff] [blame] | 28 | // AvailabilityAdmin indicates that an endpoint only available to administrators. |
Ash Wilson | efac18b | 2014-09-10 14:44:42 -0400 | [diff] [blame] | 29 | AvailabilityAdmin Availability = "admin" |
Ash Wilson | 0747d7e | 2014-09-09 14:27:35 -0400 | [diff] [blame] | 30 | |
Ash Wilson | 8c3bc8b | 2014-10-31 11:40:15 -0400 | [diff] [blame] | 31 | // AvailabilityPublic indicates that an endpoint available to everyone on the |
| 32 | // internet. |
Ash Wilson | efac18b | 2014-09-10 14:44:42 -0400 | [diff] [blame] | 33 | AvailabilityPublic Availability = "public" |
Ash Wilson | 0747d7e | 2014-09-09 14:27:35 -0400 | [diff] [blame] | 34 | |
Ash Wilson | 8c3bc8b | 2014-10-31 11:40:15 -0400 | [diff] [blame] | 35 | // AvailabilityInternal indicates that an endpoint is only available within |
| 36 | // the cluster's internal network. |
Ash Wilson | efac18b | 2014-09-10 14:44:42 -0400 | [diff] [blame] | 37 | AvailabilityInternal Availability = "internal" |
Ash Wilson | 0747d7e | 2014-09-09 14:27:35 -0400 | [diff] [blame] | 38 | ) |
| 39 | |
Ash Wilson | 8c3bc8b | 2014-10-31 11:40:15 -0400 | [diff] [blame] | 40 | // EndpointOpts specifies search criteria used to by queries against an |
| 41 | // OpenStack service catalog. The options must contain enough information to |
| 42 | // unambiguously identify one, and only one, endpoint within the catalog. |
| 43 | // |
| 44 | // Usually, these are passed to service client factory functions in a provider |
| 45 | // package, like "rackspace.NewComputeV2()". |
Ash Wilson | b8401a7 | 2014-09-08 17:07:49 -0400 | [diff] [blame] | 46 | type EndpointOpts struct { |
Ash Wilson | 8c3bc8b | 2014-10-31 11:40:15 -0400 | [diff] [blame] | 47 | // Type [required] is the service type for the client (e.g., "compute", |
| 48 | // "object-store"). Generally, this will be supplied by the service client |
| 49 | // function, but a user-given value will be honored if provided. |
Ash Wilson | b8401a7 | 2014-09-08 17:07:49 -0400 | [diff] [blame] | 50 | Type string |
| 51 | |
Ash Wilson | 8c3bc8b | 2014-10-31 11:40:15 -0400 | [diff] [blame] | 52 | // Name [optional] is the service name for the client (e.g., "nova") as it |
| 53 | // appears in the service catalog. Services can have the same Type but a |
| 54 | // different Name, which is why both Type and Name are sometimes needed. |
Ash Wilson | b8401a7 | 2014-09-08 17:07:49 -0400 | [diff] [blame] | 55 | Name string |
| 56 | |
Ash Wilson | 8c3bc8b | 2014-10-31 11:40:15 -0400 | [diff] [blame] | 57 | // Region [required] is the geographic region in which the endpoint resides, |
| 58 | // generally specifying which datacenter should house your resources. |
| 59 | // Required only for services that span multiple regions. |
Ash Wilson | b8401a7 | 2014-09-08 17:07:49 -0400 | [diff] [blame] | 60 | Region string |
| 61 | |
Ash Wilson | 8c3bc8b | 2014-10-31 11:40:15 -0400 | [diff] [blame] | 62 | // Availability [optional] is the visibility of the endpoint to be returned. |
| 63 | // Valid types include the constants AvailabilityPublic, AvailabilityInternal, |
| 64 | // or AvailabilityAdmin from this package. |
| 65 | // |
| 66 | // Availability is not required, and defaults to AvailabilityPublic. Not all |
| 67 | // providers or services offer all Availability options. |
Ash Wilson | efac18b | 2014-09-10 14:44:42 -0400 | [diff] [blame] | 68 | Availability Availability |
Ash Wilson | b8401a7 | 2014-09-08 17:07:49 -0400 | [diff] [blame] | 69 | } |
| 70 | |
Ash Wilson | 93fb5a3 | 2014-10-31 15:27:58 -0400 | [diff] [blame] | 71 | /* |
| 72 | EndpointLocator is an internal function to be used by provider implementations. |
| 73 | |
| 74 | It provides an implementation that locates a single endpoint from a service |
| 75 | catalog for a specific ProviderClient based on user-provided EndpointOpts. The |
| 76 | provider then uses it to discover related ServiceClients. |
| 77 | */ |
Ash Wilson | b8401a7 | 2014-09-08 17:07:49 -0400 | [diff] [blame] | 78 | type EndpointLocator func(EndpointOpts) (string, error) |
Jon Perritt | 509fbb6 | 2014-09-10 13:29:56 -0500 | [diff] [blame] | 79 | |
Ash Wilson | 93fb5a3 | 2014-10-31 15:27:58 -0400 | [diff] [blame] | 80 | // ApplyDefaults is an internal method to be used by provider implementations. |
| 81 | // |
| 82 | // It sets EndpointOpts fields if not already set, including a default type. |
| 83 | // Currently, EndpointOpts.Availability defaults to the public endpoint. |
Jon Perritt | 509fbb6 | 2014-09-10 13:29:56 -0500 | [diff] [blame] | 84 | func (eo *EndpointOpts) ApplyDefaults(t string) { |
| 85 | if eo.Type == "" { |
| 86 | eo.Type = t |
| 87 | } |
| 88 | if eo.Availability == "" { |
| 89 | eo.Availability = AvailabilityPublic |
| 90 | } |
| 91 | } |