github.com/gophercloud/gophercloud@v1.11.0/openstack/identity/v3/extensions/federation/requests.go (about) 1 package federation 2 3 import ( 4 "github.com/gophercloud/gophercloud" 5 "github.com/gophercloud/gophercloud/pagination" 6 ) 7 8 // ListMappings enumerates the mappings. 9 func ListMappings(client *gophercloud.ServiceClient) pagination.Pager { 10 return pagination.NewPager(client, mappingsRootURL(client), func(r pagination.PageResult) pagination.Page { 11 return MappingsPage{pagination.LinkedPageBase{PageResult: r}} 12 }) 13 } 14 15 // CreateMappingOptsBuilder allows extensions to add additional parameters to 16 // the Create request. 17 type CreateMappingOptsBuilder interface { 18 ToMappingCreateMap() (map[string]interface{}, error) 19 } 20 21 // UpdateMappingOpts provides options for creating a mapping. 22 type CreateMappingOpts struct { 23 // The list of rules used to map remote users into local users 24 Rules []MappingRule `json:"rules"` 25 } 26 27 // ToMappingCreateMap formats a CreateMappingOpts into a create request. 28 func (opts CreateMappingOpts) ToMappingCreateMap() (map[string]interface{}, error) { 29 return gophercloud.BuildRequestBody(opts, "mapping") 30 } 31 32 // CreateMapping creates a new Mapping. 33 func CreateMapping(client *gophercloud.ServiceClient, mappingID string, opts CreateMappingOptsBuilder) (r CreateMappingResult) { 34 b, err := opts.ToMappingCreateMap() 35 if err != nil { 36 r.Err = err 37 return 38 } 39 resp, err := client.Put(mappingsResourceURL(client, mappingID), &b, &r.Body, &gophercloud.RequestOpts{ 40 OkCodes: []int{201}, 41 }) 42 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 43 return 44 } 45 46 // GetMapping retrieves details on a single mapping, by ID. 47 func GetMapping(client *gophercloud.ServiceClient, mappingID string) (r GetMappingResult) { 48 resp, err := client.Get(mappingsResourceURL(client, mappingID), &r.Body, nil) 49 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 50 return 51 } 52 53 // UpdateMappingOptsBuilder allows extensions to add additional parameters to 54 // the Update request. 55 type UpdateMappingOptsBuilder interface { 56 ToMappingUpdateMap() (map[string]interface{}, error) 57 } 58 59 // UpdateMappingOpts provides options for updating a mapping. 60 type UpdateMappingOpts struct { 61 // The list of rules used to map remote users into local users 62 Rules []MappingRule `json:"rules"` 63 } 64 65 // ToMappingUpdateMap formats a UpdateOpts into an update request. 66 func (opts UpdateMappingOpts) ToMappingUpdateMap() (map[string]interface{}, error) { 67 return gophercloud.BuildRequestBody(opts, "mapping") 68 } 69 70 // UpdateMapping updates an existing mapping. 71 func UpdateMapping(client *gophercloud.ServiceClient, mappingID string, opts UpdateMappingOptsBuilder) (r UpdateMappingResult) { 72 b, err := opts.ToMappingUpdateMap() 73 if err != nil { 74 r.Err = err 75 return 76 } 77 resp, err := client.Patch(mappingsResourceURL(client, mappingID), &b, &r.Body, &gophercloud.RequestOpts{ 78 OkCodes: []int{200}, 79 }) 80 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 81 return 82 } 83 84 // DeleteMapping deletes a mapping. 85 func DeleteMapping(client *gophercloud.ServiceClient, mappingID string) (r DeleteMappingResult) { 86 resp, err := client.Delete(mappingsResourceURL(client, mappingID), nil) 87 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 88 return 89 }