Ash Wilson | 1f11051 | 2014-10-02 15:43:47 -0400 | [diff] [blame] | 1 | package tokens |
| 2 | |
Jon Perritt | a3302e1 | 2016-03-07 03:48:59 -0600 | [diff] [blame] | 3 | import "github.com/gophercloud/gophercloud" |
Ash Wilson | 1f11051 | 2014-10-02 15:43:47 -0400 | [diff] [blame] | 4 | |
Ash Wilson | 40095f0 | 2014-10-07 15:46:40 -0400 | [diff] [blame] | 5 | // AuthOptionsBuilder describes any argument that may be passed to the Create call. |
| 6 | type AuthOptionsBuilder interface { |
Ash Wilson | 40095f0 | 2014-10-07 15:46:40 -0400 | [diff] [blame] | 7 | // ToTokenCreateMap assembles the Create request body, returning an error if parameters are |
| 8 | // missing or inconsistent. |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame^] | 9 | ToTokenV2CreateMap() (map[string]interface{}, error) |
Ash Wilson | 40095f0 | 2014-10-07 15:46:40 -0400 | [diff] [blame] | 10 | } |
| 11 | |
| 12 | // Create authenticates to the identity service and attempts to acquire a Token. |
| 13 | // If successful, the CreateResult |
| 14 | // Generally, rather than interact with this call directly, end users should call openstack.AuthenticatedClient(), |
| 15 | // which abstracts all of the gory details about navigating service catalogs and such. |
| 16 | func Create(client *gophercloud.ServiceClient, auth AuthOptionsBuilder) CreateResult { |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame^] | 17 | var r CreateResult |
| 18 | b, err := auth.ToTokenV2CreateMap() |
Ash Wilson | 40095f0 | 2014-10-07 15:46:40 -0400 | [diff] [blame] | 19 | if err != nil { |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame^] | 20 | r.Err = err |
| 21 | return r |
Ash Wilson | 40095f0 | 2014-10-07 15:46:40 -0400 | [diff] [blame] | 22 | } |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame^] | 23 | _, r.Err = client.Post(CreateURL(client), b, &r.Body, &gophercloud.RequestOpts{ |
Jamie Hannaford | 562a7d5 | 2015-03-24 16:20:16 +0100 | [diff] [blame] | 24 | OkCodes: []int{200, 203}, |
Ash Wilson | 1f11051 | 2014-10-02 15:43:47 -0400 | [diff] [blame] | 25 | }) |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame^] | 26 | return r |
Ash Wilson | 1f11051 | 2014-10-02 15:43:47 -0400 | [diff] [blame] | 27 | } |
hzlouchao | f6e2926 | 2015-10-27 12:51:08 +0800 | [diff] [blame] | 28 | |
Jon Perritt | a3302e1 | 2016-03-07 03:48:59 -0600 | [diff] [blame] | 29 | // Get validates and retrieves information for user's token. |
hzlouchao | f6e2926 | 2015-10-27 12:51:08 +0800 | [diff] [blame] | 30 | func Get(client *gophercloud.ServiceClient, token string) GetResult { |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame^] | 31 | var r GetResult |
| 32 | _, r.Err = client.Get(GetURL(client, token), &r.Body, &gophercloud.RequestOpts{ |
hzlouchao | b764089 | 2015-11-04 21:37:20 +0800 | [diff] [blame] | 33 | OkCodes: []int{200, 203}, |
| 34 | }) |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame^] | 35 | return r |
hzlouchao | b764089 | 2015-11-04 21:37:20 +0800 | [diff] [blame] | 36 | } |