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