| package gophercloud |
| |
| // globalContext is the, well, "global context." |
| // Most of this SDK is written in a manner to facilitate easier testing, |
| // which doesn't require all the configuration a real-world application would require. |
| // However, for real-world deployments, applications should be able to rely on a consistent configuration of providers, etc. |
| var globalContext *Context |
| |
| // providers is the set of supported providers. |
| var providers = map[string]Provider{ |
| "rackspace-us": Provider{ |
| AuthEndpoint: "https://identity.api.rackspacecloud.com/v2.0/tokens", |
| }, |
| "rackspace-uk": Provider{ |
| AuthEndpoint: "https://lon.identity.api.rackspacecloud.com/v2.0/tokens", |
| }, |
| } |
| |
| // Initialize the global context to sane configuration. |
| // The Go runtime ensures this function is called before main(), |
| // thus guaranteeing proper configuration before your application ever runs. |
| func init() { |
| globalContext = TestContext() |
| for name, descriptor := range providers { |
| globalContext.RegisterProvider(name, descriptor) |
| } |
| } |
| |
| // Authenticate() grants access to the OpenStack-compatible provider API. |
| // |
| // Providers are identified through a unique key string. |
| // Specifying an unsupported provider will result in an ErrProvider error. |
| // |
| // The supplied AuthOptions instance allows the client to specify only those credentials |
| // relevant for the authentication request. At present, support exists for OpenStack |
| // Identity V2 API only; support for V3 will become available as soon as documentation for it |
| // becomes readily available. |
| // |
| // For Identity V2 API requirements, you must provide at least the Username and Password |
| // options. The TenantId field is optional, and defaults to "". |
| func Authenticate(provider string, options AuthOptions) (*Access, error) { |
| return globalContext.Authenticate(provider, options) |
| } |
| |
| // Instantiates a Cloud Servers object for the provider given. |
| func ServersApi(acc AccessProvider, criteria ApiCriteria) (CloudServersProvider, error) { |
| return globalContext.ServersApi(acc, criteria) |
| } |