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.
See squashed commit history below for more detailed rationale behind the
API design.
Squashed commit of the following:
commit 625c31f754dcdcd2d348cf4cf5499a03ba6b2de1
Author: Samuel A. Falvo II <sam.falvo@rackspace.com>
Date: Tue Jul 2 18:21:36 2013 -0700
Fix service name typo
commit c6abcbe20bfe31a8c9399e78c186dca64d050140
Author: Samuel A. Falvo II <sam.falvo@rackspace.com>
Date: Tue Jul 2 18:15:41 2013 -0700
Added decision logic to FFEBC function.
commit bccf7178464c5071a81d63ef16fd20d7a241146f
Author: Samuel A. Falvo II <sam.falvo@rackspace.com>
Date: Tue Jul 2 17:18:14 2013 -0700
Added ListServers and its dependencies.
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.
commit 9549f0b30e0736962dad55f3f38f88124e076fb9
Author: Samuel A. Falvo II <sam.falvo@rackspace.com>
Date: Tue Jul 2 17:10:14 2013 -0700
Removed VIM temp swap file
commit 8e00ad5ac3466cbec3c539e8b21bea6d23ab37f7
Author: Samuel A. Falvo II <sam.falvo@rackspace.com>
Date: Tue Jul 2 16:20:22 2013 -0700
Add ApiCriteria to API
commit 6f3b41929a496c6a0734221bf12ef27035b71e39
Author: Samuel A. Falvo II <sam.falvo@rackspace.com>
Date: Tue Jul 2 16:18:49 2013 -0700
Add acceptance test for list servers
diff --git a/errors.go b/errors.go
index 58a898c..f113446 100644
--- a/errors.go
+++ b/errors.go
@@ -25,3 +25,8 @@
// for authentication; if this endpoint isn't specified, you may receive
// this error when attempting to register it against a context.
var ErrConfiguration = fmt.Errorf("Missing or incomplete configuration")
+
+// ErrEndpoint errors happen when no endpoint with the desired characteristics
+// exists in the service catalog. This can also happen if your tenant lacks
+// adequate permissions to access a given endpoint.
+var ErrEndpoint = fmt.Errorf("Missing endpoint, or insufficient privileges to access endpoint")