Samuel A. Falvo II | 2e2b877 | 2013-07-04 15:40:15 -0700 | [diff] [blame^] | 1 | package gophercloud |
| 2 | |
| 3 | // globalContext is the, well, "global context." |
| 4 | // Most of this SDK is written in a manner to facilitate easier testing, |
| 5 | // which doesn't require all the configuration a real-world application would require. |
| 6 | // However, for real-world deployments, applications should be able to rely on a consistent configuration of providers, etc. |
| 7 | var globalContext *Context |
| 8 | |
| 9 | // providers is the set of supported providers. |
| 10 | var providers = map[string]Provider{ |
| 11 | "rackspace-us": Provider{ |
| 12 | AuthEndpoint: "https://identity.api.rackspacecloud.com/v2.0/tokens", |
| 13 | }, |
| 14 | "rackspace-uk": Provider{ |
| 15 | AuthEndpoint: "https://lon.identity.api.rackspacecloud.com/v2.0/tokens", |
| 16 | }, |
| 17 | } |
| 18 | |
| 19 | // Initialize the global context to sane configuration. |
| 20 | // The Go runtime ensures this function is called before main(), |
| 21 | // thus guaranteeing proper configuration before your application ever runs. |
| 22 | func init() { |
| 23 | globalContext = TestContext() |
| 24 | for name, descriptor := range providers { |
| 25 | globalContext.RegisterProvider(name, descriptor) |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | // Authenticate() grants access to the OpenStack-compatible provider API. |
| 30 | // |
| 31 | // Providers are identified through a unique key string. |
| 32 | // Specifying an unsupported provider will result in an ErrProvider error. |
| 33 | // |
| 34 | // The supplied AuthOptions instance allows the client to specify only those credentials |
| 35 | // relevant for the authentication request. At present, support exists for OpenStack |
| 36 | // Identity V2 API only; support for V3 will become available as soon as documentation for it |
| 37 | // becomes readily available. |
| 38 | // |
| 39 | // For Identity V2 API requirements, you must provide at least the Username and Password |
| 40 | // options. The TenantId field is optional, and defaults to "". |
| 41 | func Authenticate(provider string, options AuthOptions) (*Access, error) { |
| 42 | return globalContext.Authenticate(provider, options) |
| 43 | } |
| 44 | |
| 45 | // Instantiates a Cloud Servers object for the provider given. |
| 46 | func ComputeApi(acc AccessProvider, criteria ApiCriteria) (ComputeProvider, error) { |
| 47 | return globalContext.ComputeApi(acc, criteria) |
| 48 | } |