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