Ash Wilson | 85d8265 | 2014-08-28 13:57:46 -0400 | [diff] [blame] | 1 | package v3 |
| 2 | |
Ash Wilson | 8a85a91 | 2014-08-28 15:09:58 -0400 | [diff] [blame] | 3 | import ( |
| 4 | "github.com/rackspace/gophercloud" |
| 5 | "github.com/rackspace/gophercloud/openstack/identity/v3/tokens" |
| 6 | ) |
Ash Wilson | 85d8265 | 2014-08-28 13:57:46 -0400 | [diff] [blame] | 7 | |
| 8 | // Client abstracts the connection information necessary to make API calls to Identity v3 |
| 9 | // resources. |
Ash Wilson | 8a85a91 | 2014-08-28 15:09:58 -0400 | [diff] [blame] | 10 | type Client gophercloud.ServiceClient |
Ash Wilson | 85d8265 | 2014-08-28 13:57:46 -0400 | [diff] [blame] | 11 | |
| 12 | var ( |
| 13 | nilClient = Client{} |
| 14 | ) |
| 15 | |
| 16 | // NewClient attempts to authenticate to the v3 identity endpoint. Returns a populated |
| 17 | // IdentityV3Client on success or an error on failure. |
| 18 | func NewClient(authOptions gophercloud.AuthOptions) (*Client, error) { |
Ash Wilson | 8a85a91 | 2014-08-28 15:09:58 -0400 | [diff] [blame] | 19 | client := Client{Options: authOptions} |
| 20 | |
| 21 | result, err := tokens.Create(&client, nil) |
| 22 | if err != nil { |
| 23 | return nil, err |
| 24 | } |
| 25 | |
| 26 | // Assign the token and return. |
| 27 | client.TokenID = result.TokenID() |
| 28 | return &client, nil |
Ash Wilson | 85d8265 | 2014-08-28 13:57:46 -0400 | [diff] [blame] | 29 | } |