Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 1 | package gophercloud |
| 2 | |
| 3 | // ScopeOptsV3 allows a created token to be limited to a specific domain or project. |
| 4 | type ScopeOptsV3 struct { |
| 5 | ProjectID string `json:"scope.project.id,omitempty" not:"ProjectName,DomainID,DomainName"` |
| 6 | ProjectName string `json:"scope.project.name,omitempty"` |
| 7 | DomainID string `json:"scope.project.id,omitempty" not:"ProjectName,ProjectID,DomainName"` |
| 8 | DomainName string `json:"scope.project.id,omitempty"` |
| 9 | } |
| 10 | |
| 11 | type ScopeDomainV3 struct { |
| 12 | ID string `json:"id,omitempty"` |
| 13 | Name string `json:"name,omitempty"` |
| 14 | } |
| 15 | |
| 16 | type ScopeProjectDomainV3 struct { |
| 17 | ID string `json:"id,omitempty"` |
| 18 | Name string `json:"name,omitempty"` |
| 19 | } |
| 20 | |
| 21 | type ScopeProjectV3 struct { |
| 22 | Domain *ScopeProjectDomainV3 `json:"domain,omitempty"` |
| 23 | Name string `json:"name,omitempty"` |
| 24 | ID string `json:"id,omitempty"` |
| 25 | } |
| 26 | |
| 27 | type ScopeV3 struct { |
| 28 | Domain *ScopeDomainV3 `json:"domain,omitempty"` |
| 29 | Project *ScopeProjectV3 `json:"project,omitempty"` |
| 30 | } |
| 31 | |
| 32 | type DomainV3 struct { |
| 33 | ID string `json:"id,omitempty" xor:"Name"` |
| 34 | Name string `json:"name,omitempty" xor:"ID"` |
| 35 | } |
| 36 | |
| 37 | type UserV3 struct { |
| 38 | ID string `json:"id,omitempty" xor:"Name"` |
| 39 | Name string `json:"name,omitempty" xor:"ID"` |
| 40 | Password string `json:"password" required:"true"` |
| 41 | Domain *DomainV3 `json:"domain,omitempty" not:"Domain.ID,Domain.Name"` |
| 42 | } |
| 43 | |
| 44 | type PasswordCredentialsV3 struct { |
| 45 | User *UserV3 `json:"user" required:"true"` |
| 46 | } |
| 47 | |
| 48 | type TokenCredentialsV3 struct { |
| 49 | ID string `json:"id" required:"true"` |
| 50 | } |
| 51 | |
| 52 | type IdentityCredentialsV3 struct { |
| 53 | Methods []string `json:"methods" required:"true"` |
| 54 | PasswordCredentials *PasswordCredentialsV3 `json:"password,omitempty" xor:"TokenCredentials"` |
| 55 | TokenCredentials *TokenCredentialsV3 `json:"token,omitempty" xor:"PasswordCredentials"` |
| 56 | } |
| 57 | |
| 58 | type AuthOptionsV3 struct { |
| 59 | Identity *IdentityCredentialsV3 `json:"identity" required:"true"` |
| 60 | Scope *ScopeV3 `json:"scope,omitempty"` |
| 61 | } |
| 62 | |
| 63 | func (opts AuthOptionsV3) ToTokenV3CreateMap(scope *ScopeOptsV3) (map[string]interface{}, error) { |
| 64 | if scope != nil { |
| 65 | opts.Scope = &ScopeV3{ |
| 66 | Domain: &ScopeDomainV3{ |
| 67 | ID: scope.DomainID, |
| 68 | Name: scope.DomainName, |
| 69 | }, |
| 70 | Project: &ScopeProjectV3{ |
| 71 | Domain: &ScopeProjectDomainV3{ |
| 72 | ID: scope.DomainID, |
| 73 | Name: scope.DomainName, |
| 74 | }, |
| 75 | ID: scope.ProjectID, |
| 76 | Name: scope.ProjectName, |
| 77 | }, |
| 78 | } |
| 79 | } |
| 80 | return BuildRequestBody(opts, "auth") |
| 81 | } |