Documentation ¶
Overview ¶
Package policies provides information and interaction with the policies API resource for the OpenStack Identity service.
Example to List Policies
listOpts := policies.ListOpts{ Type: "application/json", } allPages, err := policies.List(identityClient, listOpts).AllPages(context.TODO()) if err != nil { panic(err) } allPolicies, err := policies.ExtractPolicies(allPages) if err != nil { panic(err) } for _, policy := range allPolicies { fmt.Printf("%+v\n", policy) }
Example to Create a Policy
createOpts := policies.CreateOpts{ Type: "application/json", Blob: []byte("{'foobar_user': 'role:compute-user'}"), Extra: map[string]any{ "description": "policy for foobar_user", }, } policy, err := policies.Create(context.TODO(), identityClient, createOpts).Extract() if err != nil { panic(err) }
Example to Get a Policy
policyID := "0fe36e73809d46aeae6705c39077b1b3" policy, err := policies.Get(context.TODO(), identityClient, policyID).Extract() if err != nil { panic(err) } fmt.Printf("%+v\n", policy)
Example to Update a Policy
policyID := "0fe36e73809d46aeae6705c39077b1b3" updateOpts := policies.UpdateOpts{ Type: "application/json", Blob: []byte("{'foobar_user': 'role:compute-user'}"), Extra: map[string]any{ "description": "policy for foobar_user", }, } policy, err := policies.Update(context.TODO(), identityClient, policyID, updateOpts).Extract() if err != nil { panic(err) } fmt.Printf("%+v\n", policy)
Example to Delete a Policy
policyID := "0fe36e73809d46aeae6705c39077b1b3" err := policies.Delete(context.TODO(), identityClient, policyID).ExtractErr() if err != nil { panic(err) }
Index ¶
- func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager
- type CreateOpts
- type CreateOptsBuilder
- type CreateResult
- type DeleteResult
- type GetResult
- type InvalidListFilter
- type ListOpts
- type ListOptsBuilder
- type Policy
- type PolicyPage
- type StringFieldLengthExceedsLimit
- type UpdateOpts
- type UpdateOptsBuilder
- type UpdateResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func List ¶
func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager
List enumerates the policies to which the current token has access.
Types ¶
type CreateOpts ¶
type CreateOpts struct { // Type is the MIME media type of the serialized policy blob. Type string `json:"type" required:"true"` // Blob is the policy rule as a serialized blob. Blob []byte `json:"-" required:"true"` // Extra is free-form extra key/value pairs to describe the policy. Extra map[string]any `json:"-"` }
CreateOpts provides options used to create a policy.
func (CreateOpts) ToPolicyCreateMap ¶
func (opts CreateOpts) ToPolicyCreateMap() (map[string]any, error)
ToPolicyCreateMap formats a CreateOpts into a create request.
type CreateOptsBuilder ¶
CreateOptsBuilder allows extensions to add additional parameters to the Create request.
type CreateResult ¶
type CreateResult struct {
// contains filtered or unexported fields
}
CreateResult is the response from a Create operation. Call its Extract method to interpret it as a Policy
func Create ¶
func Create(ctx context.Context, client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult)
Create creates a new Policy.
type DeleteResult ¶
type DeleteResult struct {
gophercloud.ErrResult
}
DeleteResult is the response from a Delete operation. Call its ExtractErr to determine if the request succeeded or failed.
type GetResult ¶
type GetResult struct {
// contains filtered or unexported fields
}
GetResult is the response from a Get operation. Call its Extract method to interpret it as a Policy.
type InvalidListFilter ¶
type InvalidListFilter struct {
FilterName string
}
InvalidListFilter is returned by the ToPolicyListQuery method when validation of a filter does not pass
func (InvalidListFilter) Error ¶
func (e InvalidListFilter) Error() string
type ListOpts ¶
type ListOpts struct { // Type filters the response by MIME media type // of the serialized policy blob. Type string `q:"type"` // Filters filters the response by custom filters such as // 'type__contains=foo' Filters map[string]string `q:"-"` }
ListOpts provides options to filter the List results.
func (ListOpts) ToPolicyListQuery ¶
ToPolicyListQuery formats a ListOpts into a query string.
type ListOptsBuilder ¶
ListOptsBuilder allows extensions to add additional parameters to the List request
type Policy ¶
type Policy struct { // ID is the unique ID of the policy. ID string `json:"id"` // Blob is the policy rule as a serialized blob. Blob string `json:"blob"` // Type is the MIME media type of the serialized policy blob. Type string `json:"type"` // Links contains referencing links to the policy. Links map[string]any `json:"links"` // Extra is a collection of miscellaneous key/values. Extra map[string]any `json:"-"` }
Policy is an arbitrarily serialized policy engine rule set to be consumed by a remote service.
func ExtractPolicies ¶
func ExtractPolicies(r pagination.Page) ([]Policy, error)
ExtractPolicies returns a slice of Policies contained in a single page of results.
func (*Policy) UnmarshalJSON ¶
type PolicyPage ¶
type PolicyPage struct {
pagination.LinkedPageBase
}
PolicyPage is a single page of Policy results.
func (PolicyPage) IsEmpty ¶
func (r PolicyPage) IsEmpty() (bool, error)
IsEmpty determines whether or not a page of Policies contains any results.
func (PolicyPage) NextPageURL ¶
func (r PolicyPage) NextPageURL() (string, error)
NextPageURL extracts the "next" link from the links section of the result.
type StringFieldLengthExceedsLimit ¶
StringFieldLengthExceedsLimit is returned by the ToPolicyCreateMap/ToPolicyUpdateMap methods when validation of a type does not pass
func (StringFieldLengthExceedsLimit) Error ¶
func (e StringFieldLengthExceedsLimit) Error() string
type UpdateOpts ¶
type UpdateOpts struct { // Type is the MIME media type of the serialized policy blob. Type string `json:"type,omitempty"` // Blob is the policy rule as a serialized blob. Blob []byte `json:"-"` // Extra is free-form extra key/value pairs to describe the policy. Extra map[string]any `json:"-"` }
UpdateOpts provides options for updating a policy.
func (UpdateOpts) ToPolicyUpdateMap ¶
func (opts UpdateOpts) ToPolicyUpdateMap() (map[string]any, error)
ToPolicyUpdateMap formats a UpdateOpts into an update request.
type UpdateOptsBuilder ¶
UpdateOptsBuilder allows extensions to add additional parameters to the Update request.
type UpdateResult ¶
type UpdateResult struct {
// contains filtered or unexported fields
}
UpdateResult is the response from an Update operation. Call its Extract method to interpret it as a Policy.
func Update ¶
func Update(ctx context.Context, client *gophercloud.ServiceClient, policyID string, opts UpdateOptsBuilder) (r UpdateResult)
Update updates an existing Role.