endpoint_search.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package gophercloud
  2. // Availability indicates to whom a specific service endpoint is accessible:
  3. // the internet at large, internal networks only, or only to administrators.
  4. // Different identity services use different terminology for these. Identity v2
  5. // lists them as different kinds of URLs within the service catalog ("adminURL",
  6. // "internalURL", and "publicURL"), while v3 lists them as "Interfaces" in an
  7. // endpoint's response.
  8. type Availability string
  9. const (
  10. // AvailabilityAdmin indicates that an endpoint is only available to
  11. // administrators.
  12. AvailabilityAdmin Availability = "admin"
  13. // AvailabilityPublic indicates that an endpoint is available to everyone on
  14. // the internet.
  15. AvailabilityPublic Availability = "public"
  16. // AvailabilityInternal indicates that an endpoint is only available within
  17. // the cluster's internal network.
  18. AvailabilityInternal Availability = "internal"
  19. )
  20. // EndpointOpts specifies search criteria used by queries against an
  21. // OpenStack service catalog. The options must contain enough information to
  22. // unambiguously identify one, and only one, endpoint within the catalog.
  23. //
  24. // Usually, these are passed to service client factory functions in a provider
  25. // package, like "openstack.NewComputeV2()".
  26. type EndpointOpts struct {
  27. // Type [required] is the service type for the client (e.g., "compute",
  28. // "object-store"). Generally, this will be supplied by the service client
  29. // function, but a user-given value will be honored if provided.
  30. Type string
  31. // Name [optional] is the service name for the client (e.g., "nova") as it
  32. // appears in the service catalog. Services can have the same Type but a
  33. // different Name, which is why both Type and Name are sometimes needed.
  34. Name string
  35. // Region [required] is the geographic region in which the endpoint resides,
  36. // generally specifying which datacenter should house your resources.
  37. // Required only for services that span multiple regions.
  38. Region string
  39. // Availability [optional] is the visibility of the endpoint to be returned.
  40. // Valid types include the constants AvailabilityPublic, AvailabilityInternal,
  41. // or AvailabilityAdmin from this package.
  42. //
  43. // Availability is not required, and defaults to AvailabilityPublic. Not all
  44. // providers or services offer all Availability options.
  45. Availability Availability
  46. }
  47. /*
  48. EndpointLocator is an internal function to be used by provider implementations.
  49. It provides an implementation that locates a single endpoint from a service
  50. catalog for a specific ProviderClient based on user-provided EndpointOpts. The
  51. provider then uses it to discover related ServiceClients.
  52. */
  53. type EndpointLocator func(EndpointOpts) (string, error)
  54. // ApplyDefaults is an internal method to be used by provider implementations.
  55. //
  56. // It sets EndpointOpts fields if not already set, including a default type.
  57. // Currently, EndpointOpts.Availability defaults to the public endpoint.
  58. func (eo *EndpointOpts) ApplyDefaults(t string) {
  59. if eo.Type == "" {
  60. eo.Type = t
  61. }
  62. if eo.Availability == "" {
  63. eo.Availability = AvailabilityPublic
  64. }
  65. }