blob: 9887947f615d4a6e40ff78e4aeb0c51af7a3159a [file] [log] [blame]
Ash Wilsonb8401a72014-09-08 17:07:49 -04001package gophercloud
2
Ash Wilson8c3bc8b2014-10-31 11:40:15 -04003// Availability indicates to whom a specific service endpoint is accessible:
4// the internet at large, internal networks only, or only to administrators.
5// Different identity services use different terminology for these. Identity v2
6// lists them as different kinds of URLs within the service catalog ("adminURL",
7// "internalURL", and "publicURL"), while v3 lists them as "Interfaces" in an
Ash Wilsonaa88fd92014-10-31 16:11:57 -04008// endpoint's response.
Ash Wilsonefac18b2014-09-10 14:44:42 -04009type Availability string
Ash Wilson0747d7e2014-09-09 14:27:35 -040010
11const (
Ash Wilsonaa88fd92014-10-31 16:11:57 -040012 // AvailabilityAdmin indicates that an endpoint is only available to
13 // administrators.
Ash Wilsonefac18b2014-09-10 14:44:42 -040014 AvailabilityAdmin Availability = "admin"
Ash Wilson0747d7e2014-09-09 14:27:35 -040015
Ash Wilsonaa88fd92014-10-31 16:11:57 -040016 // AvailabilityPublic indicates that an endpoint is available to everyone on
17 // the internet.
Ash Wilsonefac18b2014-09-10 14:44:42 -040018 AvailabilityPublic Availability = "public"
Ash Wilson0747d7e2014-09-09 14:27:35 -040019
Ash Wilson8c3bc8b2014-10-31 11:40:15 -040020 // AvailabilityInternal indicates that an endpoint is only available within
21 // the cluster's internal network.
Ash Wilsonefac18b2014-09-10 14:44:42 -040022 AvailabilityInternal Availability = "internal"
Ash Wilson0747d7e2014-09-09 14:27:35 -040023)
24
Ash Wilsonaa88fd92014-10-31 16:11:57 -040025// EndpointOpts specifies search criteria used by queries against an
Ash Wilson8c3bc8b2014-10-31 11:40:15 -040026// OpenStack service catalog. The options must contain enough information to
27// unambiguously identify one, and only one, endpoint within the catalog.
28//
29// Usually, these are passed to service client factory functions in a provider
30// package, like "rackspace.NewComputeV2()".
Ash Wilsonb8401a72014-09-08 17:07:49 -040031type EndpointOpts struct {
Ash Wilson8c3bc8b2014-10-31 11:40:15 -040032 // Type [required] is the service type for the client (e.g., "compute",
33 // "object-store"). Generally, this will be supplied by the service client
34 // function, but a user-given value will be honored if provided.
Ash Wilsonb8401a72014-09-08 17:07:49 -040035 Type string
36
Ash Wilson8c3bc8b2014-10-31 11:40:15 -040037 // Name [optional] is the service name for the client (e.g., "nova") as it
38 // appears in the service catalog. Services can have the same Type but a
39 // different Name, which is why both Type and Name are sometimes needed.
Ash Wilsonb8401a72014-09-08 17:07:49 -040040 Name string
41
Ash Wilson8c3bc8b2014-10-31 11:40:15 -040042 // Region [required] is the geographic region in which the endpoint resides,
43 // generally specifying which datacenter should house your resources.
44 // Required only for services that span multiple regions.
Ash Wilsonb8401a72014-09-08 17:07:49 -040045 Region string
46
Ash Wilson8c3bc8b2014-10-31 11:40:15 -040047 // Availability [optional] is the visibility of the endpoint to be returned.
48 // Valid types include the constants AvailabilityPublic, AvailabilityInternal,
49 // or AvailabilityAdmin from this package.
50 //
51 // Availability is not required, and defaults to AvailabilityPublic. Not all
52 // providers or services offer all Availability options.
Ash Wilsonefac18b2014-09-10 14:44:42 -040053 Availability Availability
Ash Wilsonb8401a72014-09-08 17:07:49 -040054}
55
Ash Wilson93fb5a32014-10-31 15:27:58 -040056/*
57EndpointLocator is an internal function to be used by provider implementations.
58
59It provides an implementation that locates a single endpoint from a service
60catalog for a specific ProviderClient based on user-provided EndpointOpts. The
61provider then uses it to discover related ServiceClients.
62*/
Ash Wilsonb8401a72014-09-08 17:07:49 -040063type EndpointLocator func(EndpointOpts) (string, error)
Jon Perritt509fbb62014-09-10 13:29:56 -050064
Ash Wilson93fb5a32014-10-31 15:27:58 -040065// ApplyDefaults is an internal method to be used by provider implementations.
66//
67// It sets EndpointOpts fields if not already set, including a default type.
68// Currently, EndpointOpts.Availability defaults to the public endpoint.
Jon Perritt509fbb62014-09-10 13:29:56 -050069func (eo *EndpointOpts) ApplyDefaults(t string) {
70 if eo.Type == "" {
71 eo.Type = t
72 }
73 if eo.Availability == "" {
74 eo.Availability = AvailabilityPublic
75 }
76}