policies

package
v0.0.0-...-08576c7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 2, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

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()
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]interface{}{
		"description": "policy for foobar_user",
	},
}

policy, err := policies.Create(identityClient, createOpts).Extract()
if err != nil {
	panic(err)
}

Example to Get a Policy

policyID := "0fe36e73809d46aeae6705c39077b1b3"
policy, err := policies.Get(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]interface{}{
		"description": "policy for foobar_user",
	},
}

policy, err := policies.Update(identityClient, policyID, updateOpts).Extract()
if err != nil {
	panic(err)
}

fmt.Printf("%+v\n", policy)

Example to Delete a Policy

policyID := "0fe36e73809d46aeae6705c39077b1b3"
err := policies.Delete(identityClient, policyID).ExtractErr()
if err != nil {
	panic(err)
}

Index

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]interface{} `json:"-"`
}

CreateOpts provides options used to create a policy.

func (CreateOpts) ToPolicyCreateMap

func (opts CreateOpts) ToPolicyCreateMap() (map[string]interface{}, error)

ToPolicyCreateMap formats a CreateOpts into a create request.

type CreateOptsBuilder

type CreateOptsBuilder interface {
	ToPolicyCreateMap() (map[string]interface{}, error)
}

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(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult)

Create creates a new Policy.

func (CreateResult) Extract

func (r CreateResult) Extract() (*Policy, error)

Extract interprets any policyResults as a 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.

func Delete

func Delete(client *gophercloud.ServiceClient, policyID string) (r DeleteResult)

Delete deletes a policy.

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.

func Get

func Get(client *gophercloud.ServiceClient, policyID string) (r GetResult)

Get retrieves details on a single policy, by ID.

func (GetResult) Extract

func (r GetResult) Extract() (*Policy, error)

Extract interprets any policyResults 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

func (opts ListOpts) ToPolicyListQuery() (string, error)

ToPolicyListQuery formats a ListOpts into a query string.

type ListOptsBuilder

type ListOptsBuilder interface {
	ToPolicyListQuery() (string, error)
}

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]interface{} `json:"links"`

	// Extra is a collection of miscellaneous key/values.
	Extra map[string]interface{} `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

func (r *Policy) UnmarshalJSON(b []byte) error

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

type StringFieldLengthExceedsLimit struct {
	Field string
	Limit int
}

StringFieldLengthExceedsLimit is returned by the ToPolicyCreateMap/ToPolicyUpdateMap methods when validation of a type does not pass

func (StringFieldLengthExceedsLimit) Error

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]interface{} `json:"-"`
}

UpdateOpts provides options for updating a policy.

func (UpdateOpts) ToPolicyUpdateMap

func (opts UpdateOpts) ToPolicyUpdateMap() (map[string]interface{}, error)

ToPolicyUpdateMap formats a UpdateOpts into an update request.

type UpdateOptsBuilder

type UpdateOptsBuilder interface {
	ToPolicyUpdateMap() (map[string]interface{}, error)
}

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(client *gophercloud.ServiceClient, policyID string, opts UpdateOptsBuilder) (r UpdateResult)

Update updates an existing Role.

func (UpdateResult) Extract

func (r UpdateResult) Extract() (*Policy, error)

Extract interprets any policyResults as a Policy.

Directories

Path Synopsis
Package testing contains policies unit tests
Package testing contains policies unit tests

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL