github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/identity/v3/federation/mappings/requests.go (about) 1 package mappings 2 3 import ( 4 golangsdk "github.com/opentelekomcloud/gophertelekomcloud" 5 "github.com/opentelekomcloud/gophertelekomcloud/pagination" 6 ) 7 8 // List enumerates the Groups to which the current token has access. 9 func List(client *golangsdk.ServiceClient) pagination.Pager { 10 url := listURL(client) 11 12 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 13 return MappingPage{pagination.LinkedPageBase{PageResult: r}} 14 }) 15 } 16 17 // Get retrieves details on a single Mapping, by ID. 18 func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { 19 _, r.Err = client.Get(mappingURL(client, id), &r.Body, nil) 20 return 21 } 22 23 // CreateOptsBuilder allows extensions to add additional parameters to 24 // the Create request. 25 type CreateOptsBuilder interface { 26 ToMappingCreateMap() (map[string]interface{}, error) 27 } 28 29 // CreateOpts provides options used to create a mapping. 30 type CreateOpts struct { 31 // Rules used to map federated users to local users. 32 Rules []RuleOpts `json:"rules" required:"true"` 33 } 34 35 type RuleOpts struct { 36 Local []LocalRuleOpts `json:"local" required:"true"` 37 Remote []RemoteRuleOpts `json:"remote" required:"true"` 38 } 39 40 type LocalRuleOpts struct { 41 User *UserOpts `json:"user,omitempty"` 42 Group *GroupOpts `json:"group,omitempty"` 43 Groups string `json:"groups,omitempty"` 44 } 45 46 type UserOpts struct { 47 Name string `json:"name" required:"true"` 48 } 49 50 type GroupOpts struct { 51 Name string `json:"name" required:"true"` 52 Domain *Domain `json:"domain,omitempty"` 53 } 54 55 type Domain struct { 56 Name string `json:"name,omitempty"` 57 ID string `json:"id,omitempty"` 58 } 59 60 type RemoteRuleOpts struct { 61 Type string `json:"type" required:"true"` 62 NotAnyOf []string `json:"not_any_of,omitempty"` 63 AnyOneOf []string `json:"any_one_of,omitempty"` 64 Regex *bool `json:"regex,omitempty"` 65 } 66 67 // ToMappingCreateMap formats a CreateOpts into a create request. 68 func (opts CreateOpts) ToMappingCreateMap() (map[string]interface{}, error) { 69 b, err := golangsdk.BuildRequestBody(opts, "mapping") 70 if err != nil { 71 return nil, err 72 } 73 74 return b, nil 75 } 76 77 // Create creates a new Mapping, by ID. 78 func Create(client *golangsdk.ServiceClient, mappingID string, opts CreateOptsBuilder) (r CreateResult) { 79 b, err := opts.ToMappingCreateMap() 80 if err != nil { 81 r.Err = err 82 return 83 } 84 _, r.Err = client.Put(mappingURL(client, mappingID), &b, &r.Body, &golangsdk.RequestOpts{ 85 OkCodes: []int{201}, 86 }) 87 return 88 } 89 90 // UpdateOptsBuilder allows extensions to add additional parameters to 91 // the Update request. 92 type UpdateOptsBuilder interface { 93 ToMappingUpdateMap() (map[string]interface{}, error) 94 } 95 96 // UpdateOpts provides options for updating a mapping. 97 type UpdateOpts struct { 98 // Rules used to map federated users to local users. 99 Rules []RuleOpts `json:"rules" required:"true"` 100 } 101 102 // ToMappingUpdateMap formats a UpdateOpts into an update request. 103 func (opts UpdateOpts) ToMappingUpdateMap() (map[string]interface{}, error) { 104 b, err := golangsdk.BuildRequestBody(opts, "mapping") 105 if err != nil { 106 return nil, err 107 } 108 109 return b, nil 110 } 111 112 // Update updates an existing Mapping, by ID. 113 func Update(client *golangsdk.ServiceClient, mappingID string, opts UpdateOptsBuilder) (r UpdateResult) { 114 b, err := opts.ToMappingUpdateMap() 115 if err != nil { 116 r.Err = err 117 return 118 } 119 _, r.Err = client.Patch(mappingURL(client, mappingID), &b, &r.Body, &golangsdk.RequestOpts{ 120 OkCodes: []int{200}, 121 }) 122 return 123 } 124 125 // Delete deletes a mapping, by ID. 126 func Delete(client *golangsdk.ServiceClient, mappingID string) (r DeleteResult) { 127 _, r.Err = client.Delete(mappingURL(client, mappingID), nil) 128 return 129 }