github.com/gophercloud/gophercloud@v1.11.0/openstack/identity/v3/extensions/federation/results.go (about) 1 package federation 2 3 import ( 4 "github.com/gophercloud/gophercloud" 5 "github.com/gophercloud/gophercloud/pagination" 6 ) 7 8 type UserType string 9 10 const ( 11 UserTypeEphemeral UserType = "ephemeral" 12 UserTypeLocal UserType = "local" 13 ) 14 15 // Mapping a set of rules to map federation protocol attributes to 16 // Identity API objects. 17 type Mapping struct { 18 // The Federation Mapping unique ID 19 ID string `json:"id"` 20 21 // Links contains referencing links to the limit. 22 Links map[string]interface{} `json:"links"` 23 24 // The list of rules used to map remote users into local users 25 Rules []MappingRule `json:"rules"` 26 } 27 28 type MappingRule struct { 29 // References a local Identity API resource, such as a group or user to which the remote attributes will be mapped. 30 Local []RuleLocal `json:"local"` 31 32 // Each object contains a rule for mapping remote attributes to Identity API concepts. 33 Remote []RuleRemote `json:"remote"` 34 } 35 36 type RuleRemote struct { 37 // Type represents an assertion type keyword. 38 Type string `json:"type"` 39 40 // If true, then each string will be evaluated as a regular expression search against the remote attribute type. 41 Regex *bool `json:"regex,omitempty"` 42 43 // The rule is matched only if any of the specified strings appear in the remote attribute type. 44 // This is mutually exclusive with NotAnyOf. 45 AnyOneOf []string `json:"any_one_of,omitempty"` 46 47 // The rule is not matched if any of the specified strings appear in the remote attribute type. 48 // This is mutually exclusive with AnyOneOf. 49 NotAnyOf []string `json:"not_any_of,omitempty"` 50 51 // The rule works as a filter, removing any specified strings that are listed there from the remote attribute type. 52 // This is mutually exclusive with Whitelist. 53 Blacklist []string `json:"blacklist,omitempty"` 54 55 // The rule works as a filter, allowing only the specified strings in the remote attribute type to be passed ahead. 56 // This is mutually exclusive with Blacklist. 57 Whitelist []string `json:"whitelist,omitempty"` 58 } 59 60 type RuleLocal struct { 61 // Domain to which the remote attributes will be matched. 62 Domain *Domain `json:"domain,omitempty"` 63 64 // Group to which the remote attributes will be matched. 65 Group *Group `json:"group,omitempty"` 66 67 // Group IDs to which the remote attributes will be matched. 68 GroupIDs string `json:"group_ids,omitempty"` 69 70 // Groups to which the remote attributes will be matched. 71 Groups string `json:"groups,omitempty"` 72 73 // Projects to which the remote attributes will be matched. 74 Projects []RuleProject `json:"projects,omitempty"` 75 76 // User to which the remote attributes will be matched. 77 User *RuleUser `json:"user,omitempty"` 78 } 79 80 type Domain struct { 81 // Domain ID 82 // This is mutually exclusive with Name. 83 ID string `json:"id,omitempty"` 84 85 // Domain Name 86 // This is mutually exclusive with ID. 87 Name string `json:"name,omitempty"` 88 } 89 90 type Group struct { 91 // Group ID to which the rule should match. 92 // This is mutually exclusive with Name and Domain. 93 ID string `json:"id,omitempty"` 94 95 // Group Name to which the rule should match. 96 // This is mutually exclusive with ID. 97 Name string `json:"name,omitempty"` 98 99 // Group Domain to which the rule should match. 100 // This is mutually exclusive with ID. 101 Domain *Domain `json:"domain,omitempty"` 102 } 103 104 type RuleProject struct { 105 // Project name 106 Name string `json:"name,omitempty"` 107 108 // Project roles 109 Roles []RuleProjectRole `json:"roles,omitempty"` 110 } 111 112 type RuleProjectRole struct { 113 // Role name 114 Name string `json:"name,omitempty"` 115 } 116 117 type RuleUser struct { 118 // User domain 119 Domain *Domain `json:"domain,omitempty"` 120 121 // User email 122 Email string `json:"email,omitempty"` 123 124 // User ID 125 ID string `json:"id,omitempty"` 126 127 // User name 128 Name string `json:"name,omitempty"` 129 130 // User type 131 Type *UserType `json:"type,omitempty"` 132 } 133 134 type mappingResult struct { 135 gophercloud.Result 136 } 137 138 // Extract interprets any mappingResult as a Mapping. 139 func (c mappingResult) Extract() (*Mapping, error) { 140 var s struct { 141 Mapping *Mapping `json:"mapping"` 142 } 143 err := c.ExtractInto(&s) 144 return s.Mapping, err 145 } 146 147 // CreateMappingResult is the response from a CreateMapping operation. 148 // Call its Extract method to interpret it as a Mapping. 149 type CreateMappingResult struct { 150 mappingResult 151 } 152 153 // GetMappingResult is the response from a GetMapping operation. 154 // Call its Extract method to interpret it as a Mapping. 155 type GetMappingResult struct { 156 mappingResult 157 } 158 159 // UpdateMappingResult is the response from a UpdateMapping operation. 160 // Call its Extract method to interpret it as a Mapping. 161 type UpdateMappingResult struct { 162 mappingResult 163 } 164 165 // DeleteMappingResult is the response from a DeleteMapping operation. 166 // Call its ExtractErr to determine if the request succeeded or failed. 167 type DeleteMappingResult struct { 168 gophercloud.ErrResult 169 } 170 171 // MappingsPage is a single page of Mapping results. 172 type MappingsPage struct { 173 pagination.LinkedPageBase 174 } 175 176 // IsEmpty determines whether or not a page of Mappings contains any results. 177 func (c MappingsPage) IsEmpty() (bool, error) { 178 if c.StatusCode == 204 { 179 return true, nil 180 } 181 182 mappings, err := ExtractMappings(c) 183 return len(mappings) == 0, err 184 } 185 186 // NextPageURL extracts the "next" link from the links section of the result. 187 func (c MappingsPage) NextPageURL() (string, error) { 188 var s struct { 189 Links struct { 190 Next string `json:"next"` 191 Previous string `json:"previous"` 192 } `json:"links"` 193 } 194 err := c.ExtractInto(&s) 195 if err != nil { 196 return "", err 197 } 198 return s.Links.Next, err 199 } 200 201 // ExtractMappings returns a slice of Mappings contained in a single page of 202 // results. 203 func ExtractMappings(r pagination.Page) ([]Mapping, error) { 204 var s struct { 205 Mappings []Mapping `json:"mappings"` 206 } 207 err := (r.(MappingsPage)).ExtractInto(&s) 208 return s.Mappings, err 209 }