Ash Wilson | 54b0382 | 2014-10-07 14:18:41 -0400 | [diff] [blame] | 1 | package rackspace |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | |
| 6 | "github.com/rackspace/gophercloud" |
| 7 | os "github.com/rackspace/gophercloud/openstack" |
| 8 | ) |
| 9 | |
| 10 | const ( |
| 11 | // RackspaceUSIdentity is an identity endpoint located in the United States. |
| 12 | RackspaceUSIdentity = "https://identity.api.rackspacecloud.com/v2.0/" |
| 13 | |
| 14 | // RackspaceUKIdentity is an identity endpoint located in the UK. |
| 15 | RackspaceUKIdentity = "https://lon.identity.api.rackspacecloud.com/v2.0/" |
| 16 | ) |
| 17 | |
| 18 | // NewClient creates a client that's prepared to communicate with the Rackspace API, but is not |
| 19 | // yet authenticated. Most users will probably prefer using the AuthenticatedClient function |
| 20 | // instead. |
| 21 | // |
| 22 | // Provide the base URL of the identity endpoint you wish to authenticate against as "endpoint". |
| 23 | // Often, this will be either RackspaceUSIdentity or RackspaceUKIdentity. |
| 24 | func NewClient(endpoint string) (*gophercloud.ProviderClient, error) { |
| 25 | return os.NewClient(endpoint) |
| 26 | } |
| 27 | |
| 28 | // AuthenticatedClient logs in to Rackspace with the provided credentials and constructs a |
| 29 | // ProviderClient that's ready to operate. |
| 30 | // |
| 31 | // If the provided AuthOptions does not specify an explicit IdentityEndpoint, it will default to |
| 32 | // the canonical, production Rackspace US identity endpoint. |
| 33 | func AuthenticatedClient(options gophercloud.AuthOptions) (*gophercloud.ProviderClient, error) { |
| 34 | if options.IdentityEndpoint == "" { |
| 35 | options.IdentityEndpoint = RackspaceUSIdentity |
| 36 | } |
| 37 | |
| 38 | _, err := NewClient(options.IdentityEndpoint) |
| 39 | if err != nil { |
| 40 | return nil, err |
| 41 | } |
| 42 | |
| 43 | return nil, errors.New("Incomplete") |
| 44 | } |