Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add ExtractProject() to identity/v3/tokens
Add the ability to extract project information out of a scoped
v3 token.
  • Loading branch information
kaccardi committed May 2, 2016
commit 2b8f8ef8edd7bd80eb0365273775a13a3686cd59
26 changes: 26 additions & 0 deletions openstack/identity/v3/tokens/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ type ServiceCatalog struct {
Entries []CatalogEntry
}

// Project contains project information extracted from a scoped token.
type Project struct {
ID string `mapstructure:"id"`
Name string `mapstructure:"name"`
}

// commonResult is the deferred result of a Create or a Get call.
type commonResult struct {
gophercloud.Result
Expand Down Expand Up @@ -118,6 +124,26 @@ func createErr(err error) CreateResult {
}
}

// ExtractProject returns project information from a GET token request.
func (result GetResult) ExtractProject() (*Project, error) {
if result.Err != nil {
return nil, result.Err
}

var response struct {
Token struct {
ValidProject Project `mapstructure:"project"`
} `mapstructure:"token"`
}

err := mapstructure.Decode(result.Body, &response)
if err != nil {
return nil, err
}

return &response.Token.ValidProject, nil
}

// GetResult is the deferred response from a Get call.
type GetResult struct {
commonResult
Expand Down