Samuel A. Falvo II | 8a549ef | 2014-01-24 15:20:54 -0800 | [diff] [blame] | 1 | package identity |
| 2 | |
| 3 | import ( |
| 4 | "github.com/mitchellh/mapstructure" |
| 5 | ) |
| 6 | |
| 7 | type TenantDesc struct { |
| 8 | Id string |
| 9 | Name string |
| 10 | } |
| 11 | |
| 12 | type TokenDesc struct { |
| 13 | Id_ string `mapstructure:"Id"` |
| 14 | Expires_ string `mapstructure:"Expires"` |
| 15 | Tenant TenantDesc |
| 16 | } |
| 17 | |
| 18 | func Token(m AuthResults) (*TokenDesc, error) { |
| 19 | accessMap := m["access"].(map[string]interface{}) |
| 20 | tokenMap := accessMap["token"].(map[string]interface{}) |
| 21 | td := &TokenDesc{} |
| 22 | err := mapstructure.Decode(tokenMap, td) |
| 23 | if err != nil { |
| 24 | return nil, err |
| 25 | } |
| 26 | return td, nil |
| 27 | } |
| 28 | |
| 29 | func (td *TokenDesc) Id() string { |
| 30 | return td.Id_ |
| 31 | } |
| 32 | |
| 33 | func (td *TokenDesc) Expires() string { |
| 34 | return td.Expires_ |
| 35 | } |
| 36 | |
| 37 | func (td *TokenDesc) TenantId() string { |
| 38 | return td.Tenant.Id |
| 39 | } |
| 40 | |
| 41 | func (td *TokenDesc) TenantName() string { |
| 42 | return td.Tenant.Name |
| 43 | } |