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
|
package osinherit
import "github.com/gophercloud/gophercloud"
// AssignOpts provides options to assign an inherited role
type AssignOpts struct {
// UserID is the ID of a user to assign an inherited role
// Note: exactly one of UserID or GroupID must be provided
UserID string `xor:"GroupID"`
// GroupID is the ID of a group to assign an inherited role
// Note: exactly one of UserID or GroupID must be provided
GroupID string `xor:"UserID"`
// ProjectID is the ID of a project to assign an inherited role on
// Note: exactly one of ProjectID or DomainID must be provided
ProjectID string `xor:"DomainID"`
// DomainID is the ID of a domain to assign an inherited role on
// Note: exactly one of ProjectID or DomainID must be provided
DomainID string `xor:"ProjectID"`
}
// ValidateOpts provides options to which role to validate
type ValidateOpts struct {
// UserID is the ID of a user to validate an inherited role
// Note: exactly one of UserID or GroupID must be provided
UserID string `xor:"GroupID"`
// GroupID is the ID of a group to validate an inherited role
// Note: exactly one of UserID or GroupID must be provided
GroupID string `xor:"UserID"`
// ProjectID is the ID of a project to validate an inherited role on
// Note: exactly one of ProjectID or DomainID must be provided
ProjectID string `xor:"DomainID"`
// DomainID is the ID of a domain to validate an inherited role on
// Note: exactly one of ProjectID or DomainID must be provided
DomainID string `xor:"ProjectID"`
}
// UnassignOpts provides options to unassign an inherited role
type UnassignOpts struct {
// UserID is the ID of a user to unassign an inherited role
// Note: exactly one of UserID or GroupID must be provided
UserID string `xor:"GroupID"`
// GroupID is the ID of a group to unassign an inherited role
// Note: exactly one of UserID or GroupID must be provided
GroupID string `xor:"UserID"`
// ProjectID is the ID of a project to assign an inherited role on
// Note: exactly one of ProjectID or DomainID must be provided
ProjectID string `xor:"DomainID"`
// DomainID is the ID of a domain to assign an inherited role on
// Note: exactly one of ProjectID or DomainID must be provided
DomainID string `xor:"ProjectID"`
}
// Assign is the operation responsible for assigning an inherited role
// to a user/group on a project/domain.
func Assign(client *gophercloud.ServiceClient, roleID string, opts AssignOpts) (r AssignmentResult) {
// Check xor conditions
_, err := gophercloud.BuildRequestBody(opts, "")
if err != nil {
r.Err = err
return
}
// Get corresponding URL
var targetID string
var targetType string
if opts.ProjectID != "" {
targetID = opts.ProjectID
targetType = "projects"
} else {
targetID = opts.DomainID
targetType = "domains"
}
var actorID string
var actorType string
if opts.UserID != "" {
actorID = opts.UserID
actorType = "users"
} else {
actorID = opts.GroupID
actorType = "groups"
}
resp, err := client.Put(assignURL(client, targetType, targetID, actorType, actorID, roleID), nil, nil, &gophercloud.RequestOpts{
OkCodes: []int{204},
})
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
// Validate is the operation responsible for validating an inherited role
// of a user/group on a project/domain.
func Validate(client *gophercloud.ServiceClient, roleID string, opts ValidateOpts) (r ValidateResult) {
// Check xor conditions
_, err := gophercloud.BuildRequestBody(opts, "")
if err != nil {
r.Err = err
return
}
// Get corresponding URL
var targetID string
var targetType string
if opts.ProjectID != "" {
targetID = opts.ProjectID
targetType = "projects"
} else {
targetID = opts.DomainID
targetType = "domains"
}
var actorID string
var actorType string
if opts.UserID != "" {
actorID = opts.UserID
actorType = "users"
} else {
actorID = opts.GroupID
actorType = "groups"
}
resp, err := client.Head(assignURL(client, targetType, targetID, actorType, actorID, roleID), &gophercloud.RequestOpts{
OkCodes: []int{204},
})
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
// Unassign is the operation responsible for unassigning an inherited
// role to a user/group on a project/domain.
func Unassign(client *gophercloud.ServiceClient, roleID string, opts UnassignOpts) (r UnassignmentResult) {
// Check xor conditions
_, err := gophercloud.BuildRequestBody(opts, "")
if err != nil {
r.Err = err
return
}
// Get corresponding URL
var targetID string
var targetType string
if opts.ProjectID != "" {
targetID = opts.ProjectID
targetType = "projects"
} else {
targetID = opts.DomainID
targetType = "domains"
}
var actorID string
var actorType string
if opts.UserID != "" {
actorID = opts.UserID
actorType = "users"
} else {
actorID = opts.GroupID
actorType = "groups"
}
resp, err := client.Delete(assignURL(client, targetType, targetID, actorType, actorID, roleID), &gophercloud.RequestOpts{
OkCodes: []int{204},
})
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
|