blob: 5a3b16221f0d0c2bb86fa77db7c971247df4e762 [file] [log] [blame]
Samuel A. Falvo II2e2b8772013-07-04 15:40:15 -07001package gophercloud
2
Samuel A. Falvo II2d0f6da2013-07-15 16:41:52 -07003import (
4 "github.com/racker/perigee"
5)
6
Samuel A. Falvo II2e2b8772013-07-04 15:40:15 -07007// globalContext is the, well, "global context."
8// Most of this SDK is written in a manner to facilitate easier testing,
9// which doesn't require all the configuration a real-world application would require.
10// However, for real-world deployments, applications should be able to rely on a consistent configuration of providers, etc.
11var globalContext *Context
12
13// providers is the set of supported providers.
14var providers = map[string]Provider{
15 "rackspace-us": Provider{
16 AuthEndpoint: "https://identity.api.rackspacecloud.com/v2.0/tokens",
17 },
18 "rackspace-uk": Provider{
19 AuthEndpoint: "https://lon.identity.api.rackspacecloud.com/v2.0/tokens",
20 },
21}
22
23// Initialize the global context to sane configuration.
24// The Go runtime ensures this function is called before main(),
25// thus guaranteeing proper configuration before your application ever runs.
26func init() {
27 globalContext = TestContext()
28 for name, descriptor := range providers {
29 globalContext.RegisterProvider(name, descriptor)
30 }
31}
32
33// Authenticate() grants access to the OpenStack-compatible provider API.
34//
35// Providers are identified through a unique key string.
36// Specifying an unsupported provider will result in an ErrProvider error.
37//
38// The supplied AuthOptions instance allows the client to specify only those credentials
39// relevant for the authentication request. At present, support exists for OpenStack
40// Identity V2 API only; support for V3 will become available as soon as documentation for it
41// becomes readily available.
42//
43// For Identity V2 API requirements, you must provide at least the Username and Password
44// options. The TenantId field is optional, and defaults to "".
45func Authenticate(provider string, options AuthOptions) (*Access, error) {
46 return globalContext.Authenticate(provider, options)
47}
48
49// Instantiates a Cloud Servers object for the provider given.
Samuel A. Falvo II1dd740a2013-07-08 15:48:40 -070050func ServersApi(acc AccessProvider, criteria ApiCriteria) (CloudServersProvider, error) {
51 return globalContext.ServersApi(acc, criteria)
Samuel A. Falvo II2e2b8772013-07-04 15:40:15 -070052}
Samuel A. Falvo II2d0f6da2013-07-15 16:41:52 -070053
54// ActualResponseCode inspects a returned error, and discovers the actual response actual
55// response code that caused the error to be raised.
56func ActualResponseCode(e error) (int, error) {
57 err, ok := e.(*perigee.UnexpectedResponseCodeError)
58 if !ok {
59 return 0, ErrError
60 }
61 return err.Actual, nil
Samuel A. Falvo II20f1aa42013-07-31 14:32:03 -070062}