blob: 06474715121aa2d2162e0d2f51d3a4eaf647e8d4 [file] [log] [blame]
Ash Wilson85d82652014-08-28 13:57:46 -04001package v3
2
Ash Wilson8a85a912014-08-28 15:09:58 -04003import (
4 "github.com/rackspace/gophercloud"
5 "github.com/rackspace/gophercloud/openstack/identity/v3/tokens"
6)
Ash Wilson85d82652014-08-28 13:57:46 -04007
8// Client abstracts the connection information necessary to make API calls to Identity v3
9// resources.
Ash Wilson8a85a912014-08-28 15:09:58 -040010type Client gophercloud.ServiceClient
Ash Wilson85d82652014-08-28 13:57:46 -040011
12var (
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.
18func NewClient(authOptions gophercloud.AuthOptions) (*Client, error) {
Ash Wilson8a85a912014-08-28 15:09:58 -040019 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 Wilson85d82652014-08-28 13:57:46 -040029}