Merge pull request #31 from rackspace/service-catalog-search
Implement Access.FirstEndpointUrlByCriteria
The FirstEndpointUrlByCriteria method is a key enabler for writing API
provider interface constructors. A simple, albeit incomplete, use-case
for Cloud Servers API demonstrates how it's used internally.
In order to list servers, we need access to a cloud server API. This is
the job of the ComputeApi() function.
ComputeApi(), in turn, tries hard not to contrain the user in choosing
an endpoint, while still offering an interface optimized for the common
case of using an existing service provider's endpoints. Otherwise, the
user will end up having to use nested functions and bizarre predicate
sequences like this:
func(ce *CatalogEntry, ee *EntryEndpoint) bool {
if ce != nil {
return ce.Name == "cloudComputeOpenStack"
}
if ee != nil {
return ee.Region == "DFW" && ee.VersionId == "2"
}
return false
}
The current interface just encapsulates this kind of logic into a simple
structure, taking 66% fewer lines, and zero chance for error:
ApiCriteria{
Name: "cloudComputeOpenStack",
Region: "DFW",
VersionId: "2",
}
FindFirstEndpointByConstraint() is invoked (via
AccessProvider.FirstEndpointUrlByConstraint()) to actually look for a
matching endpoint in the provider's service catalog. This interprets
the ApiCriteria structure settings, except for UrlChoice. If it finds a
candidate endpoint, the user may select public or private endpoints via
the ApiCriteria.UrlChoice setting (which the
FirstEndpointUrlByCriteria() function interprets). If nothing is found,
an ErrEndpoint error will be returned to the caller. Of course, this
being a brand new implementation, it just returns the default of
"nothing found" for all queries anyway.
If not specified, a criteria's UrlChoice defaults to PublicURL.