github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/identity/v3/federation/requests.go (about)

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