This repository has been archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
requests.go
102 lines (83 loc) · 3.13 KB
/
requests.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package agency
import (
"github.com/huaweicloud/golangsdk"
)
type CreateOpts struct {
Name string `json:"name" required:"true"`
DomainID string `json:"domain_id" required:"true"`
DelegatedDomain string `json:"trust_domain_name" required:"true"`
Description string `json:"description,omitempty"`
Duration string `json:"duration,omitempty"`
}
type CreateOptsBuilder interface {
ToAgencyCreateMap() (map[string]interface{}, error)
}
func (opts CreateOpts) ToAgencyCreateMap() (map[string]interface{}, error) {
return golangsdk.BuildRequestBody(opts, "agency")
}
func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
b, err := opts.ToAgencyCreateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = c.Post(rootURL(c), b, &r.Body, nil)
return
}
type UpdateOpts struct {
DelegatedDomain string `json:"trust_domain_name,omitempty"`
Description string `json:"description,omitempty"`
Duration string `json:"duration,omitempty"`
}
type UpdateOptsBuilder interface {
ToAgencyUpdateMap() (map[string]interface{}, error)
}
func (opts UpdateOpts) ToAgencyUpdateMap() (map[string]interface{}, error) {
return golangsdk.BuildRequestBody(opts, "agency")
}
func Update(c *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
b, err := opts.ToAgencyUpdateMap()
if err != nil {
r.Err = err
return
}
reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}}
_, r.Err = c.Put(resourceURL(c, id), b, &r.Body, reqOpt)
return
}
func Get(c *golangsdk.ServiceClient, id string) (r GetResult) {
_, r.Err = c.Get(resourceURL(c, id), &r.Body, nil)
return
}
func Delete(c *golangsdk.ServiceClient, id string) (r ErrResult) {
_, r.Err = c.Delete(resourceURL(c, id), nil)
return
}
func AttachRoleByProject(c *golangsdk.ServiceClient, agencyID, projectID, roleID string) (r ErrResult) {
reqOpt := &golangsdk.RequestOpts{OkCodes: []int{204}}
_, r.Err = c.Put(roleURL(c, "projects", projectID, agencyID, roleID), nil, nil, reqOpt)
return
}
func AttachRoleByDomain(c *golangsdk.ServiceClient, agencyID, domainID, roleID string) (r ErrResult) {
reqOpt := &golangsdk.RequestOpts{OkCodes: []int{204}}
_, r.Err = c.Put(roleURL(c, "domains", domainID, agencyID, roleID), nil, nil, reqOpt)
return
}
func DetachRoleByProject(c *golangsdk.ServiceClient, agencyID, projectID, roleID string) (r ErrResult) {
reqOpt := &golangsdk.RequestOpts{OkCodes: []int{204}}
_, r.Err = c.Delete(roleURL(c, "projects", projectID, agencyID, roleID), reqOpt)
return
}
func DetachRoleByDomain(c *golangsdk.ServiceClient, agencyID, domainID, roleID string) (r ErrResult) {
reqOpt := &golangsdk.RequestOpts{OkCodes: []int{204}}
_, r.Err = c.Delete(roleURL(c, "domains", domainID, agencyID, roleID), reqOpt)
return
}
func ListRolesAttachedOnProject(c *golangsdk.ServiceClient, agencyID, projectID string) (r ListRolesResult) {
_, r.Err = c.Get(listRolesURL(c, "projects", projectID, agencyID), &r.Body, nil)
return
}
func ListRolesAttachedOnDomain(c *golangsdk.ServiceClient, agencyID, domainID string) (r ListRolesResult) {
_, r.Err = c.Get(listRolesURL(c, "domains", domainID, agencyID), &r.Body, nil)
return
}