blob: f64efb235ef781e71471be8dd1a599f7033ad3aa [file] [log] [blame]
Ash Wilsonb8401a72014-09-08 17:07:49 -04001package gophercloud
2
3import "errors"
4
5var (
Ash Wilson8c3bc8b2014-10-31 11:40:15 -04006 // 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 Wilson1cd3e692014-09-09 11:01:47 -040010 ErrServiceNotFound = errors.New("No suitable service could be found in the service catalog.")
11
Ash Wilson8c3bc8b2014-10-31 11:40:15 -040012 // 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 Wilsonb8401a72014-09-08 17:07:49 -040016 ErrEndpointNotFound = errors.New("No suitable endpoint could be found in the service catalog.")
17)
18
Ash Wilson8c3bc8b2014-10-31 11:40:15 -040019// 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 Wilsonefac18b2014-09-10 14:44:42 -040025type Availability string
Ash Wilson0747d7e2014-09-09 14:27:35 -040026
27const (
Ash Wilson8c3bc8b2014-10-31 11:40:15 -040028 // AvailabilityAdmin indicates that an endpoint only available to administrators.
Ash Wilsonefac18b2014-09-10 14:44:42 -040029 AvailabilityAdmin Availability = "admin"
Ash Wilson0747d7e2014-09-09 14:27:35 -040030
Ash Wilson8c3bc8b2014-10-31 11:40:15 -040031 // AvailabilityPublic indicates that an endpoint available to everyone on the
32 // internet.
Ash Wilsonefac18b2014-09-10 14:44:42 -040033 AvailabilityPublic Availability = "public"
Ash Wilson0747d7e2014-09-09 14:27:35 -040034
Ash Wilson8c3bc8b2014-10-31 11:40:15 -040035 // AvailabilityInternal indicates that an endpoint is only available within
36 // the cluster's internal network.
Ash Wilsonefac18b2014-09-10 14:44:42 -040037 AvailabilityInternal Availability = "internal"
Ash Wilson0747d7e2014-09-09 14:27:35 -040038)
39
Ash Wilson8c3bc8b2014-10-31 11:40:15 -040040// 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 Wilsonb8401a72014-09-08 17:07:49 -040046type EndpointOpts struct {
Ash Wilson8c3bc8b2014-10-31 11:40:15 -040047 // 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 Wilsonb8401a72014-09-08 17:07:49 -040050 Type string
51
Ash Wilson8c3bc8b2014-10-31 11:40:15 -040052 // 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 Wilsonb8401a72014-09-08 17:07:49 -040055 Name string
56
Ash Wilson8c3bc8b2014-10-31 11:40:15 -040057 // 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 Wilsonb8401a72014-09-08 17:07:49 -040060 Region string
61
Ash Wilson8c3bc8b2014-10-31 11:40:15 -040062 // 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 Wilsonefac18b2014-09-10 14:44:42 -040068 Availability Availability
Ash Wilsonb8401a72014-09-08 17:07:49 -040069}
70
Jamie Hannafordb280dea2014-10-24 15:14:06 +020071// EndpointLocator is a function that describes how to locate a single endpoint
72// from a service catalog for a specific ProviderClient. It should be set
Ash Wilson8c3bc8b2014-10-31 11:40:15 -040073// during ProviderClient authentication and used to discover related
74// ServiceClients.
Ash Wilsonb8401a72014-09-08 17:07:49 -040075type EndpointLocator func(EndpointOpts) (string, error)
Jon Perritt509fbb62014-09-10 13:29:56 -050076
Jamie Hannafordb280dea2014-10-24 15:14:06 +020077// ApplyDefaults sets EndpointOpts fields if not already set. Currently,
78// EndpointOpts.Availability defaults to the public endpoint.
Jon Perritt509fbb62014-09-10 13:29:56 -050079func (eo *EndpointOpts) ApplyDefaults(t string) {
80 if eo.Type == "" {
81 eo.Type = t
82 }
83 if eo.Availability == "" {
84 eo.Availability = AvailabilityPublic
85 }
86}