github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/identity/v3/federation/mappings/results.go (about)

     1  package mappings
     2  
     3  import (
     4  	golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/pagination"
     6  )
     7  
     8  // Mapping helps manage mapping rules.
     9  type Mapping struct {
    10  	// ID is the unique ID of the mapping.
    11  	ID string `json:"id"`
    12  
    13  	// Resource Links of mappings.
    14  	Links map[string]interface{} `json:"links"`
    15  
    16  	// Rules used to map federated users to local users
    17  	Rules []Rule `json:"rules"`
    18  }
    19  
    20  type Rule struct {
    21  	Local  []LocalRuleOpts `json:"local"`
    22  	Remote []RemoteRule    `json:"remote"`
    23  }
    24  
    25  type RemoteRule struct {
    26  	Type     string   `json:"type"`
    27  	NotAnyOf []string `json:"not_any_of,omitempty"`
    28  	AnyOneOf []string `json:"any_one_of,omitempty"`
    29  	Regex    bool     `json:"regex,omitempty"`
    30  }
    31  
    32  type mappingResult struct {
    33  	golangsdk.Result
    34  }
    35  
    36  // GetResult is the response from a Get operation. Call its Extract method
    37  // to interpret it as a Mapping.
    38  type GetResult struct {
    39  	mappingResult
    40  }
    41  
    42  // CreateResult is the response from a Create operation. Call its Extract method
    43  // to interpret it as a Mapping.
    44  type CreateResult struct {
    45  	mappingResult
    46  }
    47  
    48  // UpdateResult is the response from an Update operation. Call its Extract
    49  // method to interpret it as a Mapping.
    50  type UpdateResult struct {
    51  	mappingResult
    52  }
    53  
    54  // DeleteResult is the response from a Delete operation. Call its ExtractErr to
    55  // determine if the request succeeded or failed.
    56  type DeleteResult struct {
    57  	golangsdk.ErrResult
    58  }
    59  
    60  // MappingPage is a single page of Mapping results.
    61  type MappingPage struct {
    62  	pagination.LinkedPageBase
    63  }
    64  
    65  // IsEmpty determines whether or not a page of Mappings contains any results.
    66  func (r MappingPage) IsEmpty() (bool, error) {
    67  	mappings, err := ExtractMappings(r)
    68  	return len(mappings) == 0, err
    69  }
    70  
    71  // ExtractMappings returns a slice of Mappings contained in a linked page of results.
    72  func ExtractMappings(r pagination.Page) ([]Mapping, error) {
    73  	var s []Mapping
    74  	err := (r.(MappingPage)).ExtractIntoSlicePtr(&s, "mappings")
    75  	return s, err
    76  }
    77  
    78  // Extract interprets any group results as a Mapping.
    79  func (r mappingResult) Extract() (*Mapping, error) {
    80  	s := new(Mapping)
    81  	err := r.ExtractIntoStructPtr(s, "mapping")
    82  	return s, err
    83  }