entity

package
v1.26.2 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 23 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Unmarshal

func Unmarshal(e *entityv1alpha1.Entity, out Entity) error

Types

type AttrCache

type AttrCache struct {
	// contains filtered or unexported fields
}

func (*AttrCache) String

func (c *AttrCache) String(ctx context.Context, eid eid.EID, attr string) string

String obtains a cached string attribute for an entity. Attributes like names do not change that often, so they are cached in memory. If the attribute does not exist for an entity or there is an error, an empty string is returned

An error is logged if there was an issue reaching the Authz service.

type BatchGetInput

type BatchGetInput struct {
	EIDs []eid.EID
	// UseCache will try and retrieve entities from
	// the client cache if it's present.
	//
	// If all entities are cached, no API call will be made.
	UseCache bool
}

type BatchGetOutput

type BatchGetOutput = entityv1alpha1.BatchGetResponse

type BatchPutJSONInput

type BatchPutJSONInput struct {
	Entities []EntityJSON
}

type BatchUpdateInput

type BatchUpdateInput struct {
	// Put is a slice of entities to be upserted to the entity store.
	Put []Entity
	// PutChildren is a slice of parent/child relationships to be added to the entity store.
	PutChildren []ChildRelation
	// Archive is a slice of EIDs of entities to be archived.
	// When an entity is archived it will no longer appear in the List API calls by default.
	Archive []eid.EID
	// Unarchive is a slice of EIDs of entities to be made active again.
	Unarchive []eid.EID
	// Unarchive is a slice of EIDs of entities to be deleted from the entity store.
	Delete []eid.EID
	// DeleteChildren is a slice of parent/child relations to be removed from the entity store.
	DeleteChildren []ChildRelation
}

type BatchUpdateOutput

type BatchUpdateOutput = entityv1alpha1.BatchUpdateResponse

type ChildRelation

type ChildRelation struct {
	Parent eid.EID
	Child  eid.EID
}

func (ChildRelation) ToAPI

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(opts Opts) Client

func NewFromConfig

func NewFromConfig(cfg *config.Context) Client

func (*Client) All added in v1.12.2

func (c *Client) All(ctx context.Context, input ListInput) (out []*entityv1alpha1.Entity, err error)

All returns all results from a paginated API

func (*Client) AttrCache

func (c *Client) AttrCache() *AttrCache

AttrCache returns a cach for looking up entity attributes. This cache should ONLY be used for attributes not related to authorization decisions, such as displaying names, email addresses and labels.

func (*Client) BatchGet

func (c *Client) BatchGet(ctx context.Context, input BatchGetInput) (*BatchGetOutput, error)

func (*Client) BatchPutJSON

func (c *Client) BatchPutJSON(ctx context.Context, input BatchPutJSONInput) (*BatchUpdateOutput, error)

func (*Client) BatchUpdate

func (c *Client) BatchUpdate(ctx context.Context, input BatchUpdateInput) (*BatchUpdateOutput, error)

func (*Client) GetEntity

func (c *Client) GetEntity(ctx context.Context, input GetInput) (*entityv1alpha1.GetResponse, error)

func (*Client) GetNamed

func (c *Client) GetNamed(ctx context.Context, eid eid.EID) *accessv1alpha1.NamedEID

GetNamed hydrates a resource with the 'name' attribute from the cache. This may result in additional API calls to the authz service if the entity is not present in the client cache.

func (*Client) GetUser

func (c *Client) GetUser(ctx context.Context, eid eid.EID) *accessv1alpha1.User

GetUser hydrates a resource with the 'name' and 'email' attribute from the cache. This may result in additional API calls to the authz service if the entity is not present in the client cache.

func (*Client) List

func (c *Client) List(ctx context.Context, input ListInput) (*ListOutput, error)

func (*Client) ListChildren

func (c *Client) ListChildren(ctx context.Context, input ListChildrenInput) (ListChildrenOutput, error)

func (*Client) ListChildrenRequest

func (c *Client) ListChildrenRequest(input ListChildrenInput) *listChildrenRequestCall

func (*Client) ListParents

func (c *Client) ListParents(ctx context.Context, input ListParentsInput) (ListParentsOutput, error)

func (*Client) ListParentsRequest

func (c *Client) ListParentsRequest(input ListParentsInput) *listParentsRequestCall

func (*Client) ListRequest

func (c *Client) ListRequest(input ListInput) *listEntitiesRequestCall

FilterEntitiesRequest returns a request with filterEntitiesRequestCall.Pages() that will pull all pages of results, invoking the callback for each page I based this pattern off the google cloud SDK, I found it to be pretty neat, not set on the naming I think a good API here will have the option to do a single API call or a Pages call in the google API it would be filterEntitiesRequestCall.Do() to make a single request they also use a chained builder pattern

func (*Client) Put

func (c *Client) Put(ctx context.Context, input PutInput) (*BatchUpdateOutput, error)

PutEntity just currently calls the BatchUpdate API with a single entity.

func (*Client) RawClient

RawClient returns the underlying Buf Connect client.

type Entity

type Entity interface {
	EID() eid.EID
}

Entities are objects that can be stored in the authz database.

type EntityJSON

type EntityJSON struct {
	EID     eid.EID        `json:"eid"`
	Attrs   map[string]any `json:"attrs"`
	Parents []eid.EID      `json:"parents"`
}

EntityJSON is a JSON representation of entities. It matches the Cedar Rust SDK JSON format.

type GetInput

type GetInput struct {
	EID eid.EID
	// UseCache will try and retrieve entities from
	// the client cache if it's present.
	//
	// If all entities are cached, no API call will be made.
	UseCache bool
}

type ListChildrenInput

type ListChildrenInput struct {
	Parent    eid.EID
	PageToken string
}

type ListChildrenOutput

type ListChildrenOutput struct {
	Children      []eid.EID
	NextPageToken string
}

type ListInput

type ListInput struct {
	Type            string
	PageToken       string
	IncludeArchived bool
	OrderDescending bool
}

type ListOutput

type ListOutput = entityv1alpha1.ListResponse

type ListParentsInput

type ListParentsInput struct {
	Child     eid.EID
	PageToken string
}

type ListParentsOutput

type ListParentsOutput struct {
	Parents       []eid.EID
	NextPageToken string
}

type Opts

type Opts struct {
	HTTPClient    connect.HTTPClient
	BaseURL       string
	ClientOptions []connect.ClientOption
	// AttrCacheExpiration defaults to 24h if not provided
	AttrCacheExpiration time.Duration
	// AttrCleanupInterval defaults to 48h if not provided
	AttrCleanupInterval time.Duration
}

type Parenter

type Parenter interface {
	Parents() []eid.EID
}

Implementing the parent interface allows an entity to provide parents based on its attributes.

type PutInput

type PutInput struct {
	Entity Entity
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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