blob: 12c0f17515530d3d6a075048c211bc9a79e1db42 [file] [log] [blame]
Ash Wilson1f110512014-10-02 15:43:47 -04001package tokens
2
Jon Perritta3302e12016-03-07 03:48:59 -06003import "github.com/gophercloud/gophercloud"
Ash Wilson1f110512014-10-02 15:43:47 -04004
Ash Wilson40095f02014-10-07 15:46:40 -04005// AuthOptionsBuilder describes any argument that may be passed to the Create call.
6type AuthOptionsBuilder interface {
Ash Wilson40095f02014-10-07 15:46:40 -04007 // ToTokenCreateMap assembles the Create request body, returning an error if parameters are
8 // missing or inconsistent.
Jon Perrittdb0ae142016-03-13 00:33:41 -06009 ToTokenV2CreateMap() (map[string]interface{}, error)
Ash Wilson40095f02014-10-07 15:46:40 -040010}
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.
Jon Perritt2be387a2016-03-31 09:31:58 -050016func Create(client *gophercloud.ServiceClient, auth AuthOptionsBuilder) (r CreateResult) {
Jon Perrittdb0ae142016-03-13 00:33:41 -060017 b, err := auth.ToTokenV2CreateMap()
Ash Wilson40095f02014-10-07 15:46:40 -040018 if err != nil {
Jon Perrittdb0ae142016-03-13 00:33:41 -060019 r.Err = err
Jon Perritt2be387a2016-03-31 09:31:58 -050020 return
Ash Wilson40095f02014-10-07 15:46:40 -040021 }
Jon Perrittdb0ae142016-03-13 00:33:41 -060022 _, r.Err = client.Post(CreateURL(client), b, &r.Body, &gophercloud.RequestOpts{
Jamie Hannaford562a7d52015-03-24 16:20:16 +010023 OkCodes: []int{200, 203},
Ash Wilson1f110512014-10-02 15:43:47 -040024 })
Ash Wilson1f110512014-10-02 15:43:47 -040025}
hzlouchaof6e29262015-10-27 12:51:08 +080026
Jon Perritta3302e12016-03-07 03:48:59 -060027// Get validates and retrieves information for user's token.
Jon Perritt2be387a2016-03-31 09:31:58 -050028func Get(client *gophercloud.ServiceClient, token string) (r GetResult) {
Jon Perrittdb0ae142016-03-13 00:33:41 -060029 _, r.Err = client.Get(GetURL(client, token), &r.Body, &gophercloud.RequestOpts{
hzlouchaob7640892015-11-04 21:37:20 +080030 OkCodes: []int{200, 203},
31 })
hzlouchaob7640892015-11-04 21:37:20 +080032}