Turn v2 EndpointURL into a ServiceCatalog method.
diff --git a/openstack/client.go b/openstack/client.go
index a2a9e91..64f22d9 100644
--- a/openstack/client.go
+++ b/openstack/client.go
@@ -111,51 +111,11 @@
}
client.TokenID = token.ID
- client.EndpointLocator = func(opts gophercloud.EndpointOpts) (string, error) {
- return v2endpointLocator(catalog, opts)
- }
+ client.EndpointLocator = catalog.EndpointURL
return nil
}
-func v2endpointLocator(catalog *tokens2.ServiceCatalog, opts gophercloud.EndpointOpts) (string, error) {
- // Extract Endpoints from the catalog entries that match the requested Type, Name if provided, and Region if provided.
- var endpoints = make([]tokens2.Endpoint, 0, 1)
- for _, entry := range catalog.Entries {
- if (entry.Type == opts.Type) && (opts.Name == "" || entry.Name == opts.Name) {
- for _, endpoint := range entry.Endpoints {
- if opts.Region == "" || endpoint.Region == opts.Region {
- endpoints = append(endpoints, endpoint)
- }
- }
- }
- }
-
- // Report an error if the options were ambiguous.
- if len(endpoints) == 0 {
- return "", gophercloud.ErrEndpointNotFound
- }
- if len(endpoints) > 1 {
- return "", fmt.Errorf("Discovered %d matching endpoints: %#v", len(endpoints), endpoints)
- }
-
- // Extract the appropriate URL from the matching Endpoint.
- for _, endpoint := range endpoints {
- switch opts.Availability {
- case gophercloud.AvailabilityPublic:
- return normalizeURL(endpoint.PublicURL), nil
- case gophercloud.AvailabilityInternal:
- return normalizeURL(endpoint.InternalURL), nil
- case gophercloud.AvailabilityAdmin:
- return normalizeURL(endpoint.AdminURL), nil
- default:
- return "", fmt.Errorf("Unexpected availability in endpoint query: %s", opts.Availability)
- }
- }
-
- return "", gophercloud.ErrEndpointNotFound
-}
-
// AuthenticateV3 explicitly authenticates against the identity v3 service.
func AuthenticateV3(client *gophercloud.ProviderClient, options gophercloud.AuthOptions) error {
return v3auth(client, "", options)
diff --git a/openstack/identity/v2/tokens/results.go b/openstack/identity/v2/tokens/results.go
index 5c95506..d5ad8c5 100644
--- a/openstack/identity/v2/tokens/results.go
+++ b/openstack/identity/v2/tokens/results.go
@@ -133,11 +133,11 @@
return CreateResult{gophercloud.CommonResult{Err: err}}
}
-// LocateEndpointURL discovers the endpoint URL for a specific service from a ServiceCatalog acquired
-// from a Create request. The specified EndpointOpts are used to identify a unique, unambiguous
-// endpoint to return. The minimum that can be specified is a Type, but you will also often need
-// to specify a Name and/or a Region depending on what's available on your OpenStack deployment.
-func LocateEndpointURL(catalog *ServiceCatalog, opts gophercloud.EndpointOpts) (string, error) {
+// EndpointURL discovers the endpoint URL for a specific service with a ServiceCatalog. The
+// specified EndpointOpts are used to identify a unique, unambiguous endpoint to return. The minimum
+// that can be specified is a Type, but you will also often need to specify a Name and/or a Region
+// depending on what's available on your OpenStack deployment.
+func (catalog *ServiceCatalog) EndpointURL(opts gophercloud.EndpointOpts) (string, error) {
// Extract Endpoints from the catalog entries that match the requested Type, Name if provided, and Region if provided.
var endpoints = make([]Endpoint, 0, 1)
for _, entry := range catalog.Entries {