blob: 470e495805d3d10225cdfe57be364f6ddf48eecd [file] [log] [blame]
Jon Perrittdb0ae142016-03-13 00:33:41 -06001package gophercloud
2
3// ScopeOptsV3 allows a created token to be limited to a specific domain or project.
4type 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
11type ScopeDomainV3 struct {
12 ID string `json:"id,omitempty"`
13 Name string `json:"name,omitempty"`
14}
15
16type ScopeProjectDomainV3 struct {
17 ID string `json:"id,omitempty"`
18 Name string `json:"name,omitempty"`
19}
20
21type ScopeProjectV3 struct {
22 Domain *ScopeProjectDomainV3 `json:"domain,omitempty"`
23 Name string `json:"name,omitempty"`
24 ID string `json:"id,omitempty"`
25}
26
27type ScopeV3 struct {
28 Domain *ScopeDomainV3 `json:"domain,omitempty"`
29 Project *ScopeProjectV3 `json:"project,omitempty"`
30}
31
32type DomainV3 struct {
33 ID string `json:"id,omitempty" xor:"Name"`
34 Name string `json:"name,omitempty" xor:"ID"`
35}
36
37type 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
44type PasswordCredentialsV3 struct {
45 User *UserV3 `json:"user" required:"true"`
46}
47
48type TokenCredentialsV3 struct {
49 ID string `json:"id" required:"true"`
50}
51
52type 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
58type AuthOptionsV3 struct {
59 Identity *IdentityCredentialsV3 `json:"identity" required:"true"`
60 Scope *ScopeV3 `json:"scope,omitempty"`
61}
62
63func (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}