types

package
v0.0.0-...-8b55f26 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: EUPL-1.2 Imports: 6 Imported by: 1

Documentation

Overview

Package types contains generic definitions for working with policies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MapFromAttributes

func MapFromAttributes(in AttributeSet) map[string]any

MapFromAttributes returns a standard map from the given attribute set.

Types

type Attribute

type Attribute struct {
	Key   string
	Value any
}

Attribute is a convenience type to represent a single attribute.

func NewAttribute

func NewAttribute(key string, value any) *Attribute

NewAttribute instantiates a new attribute.

type AttributeIterator

type AttributeIterator func(key string, value any)

AttributeIterator is the function prototype to iterate through a set of attributes.

type AttributeSet

type AttributeSet interface {
	AddAttribute(key string, value any)    // add or replace an attribute.
	GetAttribute(key string) any           // retrieve an attribute.
	RemoveAttribute(key string)            // remove an attribute.
	IterateAttributes(f AttributeIterator) // iterate through all attributes.
	MergeAttributes(in ...AttributeSet)    // merge the given attribute sets into this one.
}

AttributeSet represents the interface to work with a set of attributes.

An implementation must take care to protect against simultaneous use from concurrent go-routines.

func NewAttributeSet

func NewAttributeSet(in ...any) AttributeSet

NewAttributeSet instantiates a new set of attributes.

It matches the AttributesBuilder function signature.

The given attribute sets will be copied into the returned new attribute set. Duplicate keys from an input set will overwrite the previous value. E.g. only the last value with the duplicate key will be retained.

type AttributesBuilder

type AttributesBuilder func(in ...any) AttributeSet

AttributesBuilder is the function prototype for creating a new set of attributes.

type EntitiesBuilder

type EntitiesBuilder func(in ...any) EntitySet

EntitiesBuilder is the function prototype for creating a new set of entities.

type Entity

type Entity interface {
	UID() string              // retrieve the Unique ID (UID) of the entity.
	Type() string             // retrieve the Type of the entity (e,g, name-space).
	ID() string               // retrieve the ID of the entity (unique ID within the name-space).
	Attributes() AttributeSet // retrieve attributes of the entity.
	Parents() []string        // retrieve unique identifiers (UID) of parent entities.
}

Entity represents the interface to work with the details of an entity.

An Entity is a read-only object and does not require protection against simultaneous use from concurrent go-routines.

func NewEntity

func NewEntity(ns, id string, attrs AttributeSet, parents ...string) Entity

NewEntity instanties a new standard entity.

type EntityIterator

type EntityIterator func(entity Entity)

EntityIterator is the function prototype to iterate through a set of entities.

type EntitySet

type EntitySet interface {
	AddEntity(entity Entity)          // add or replace an entity.
	GetEntity(uid string) Entity      // retrieve an entity.
	RemoveEntity(uid string)          // remove an entity.
	IterateEntities(f EntityIterator) // iterate through all entities.
	MergeEntities(in ...EntitySet)    // merge the given entity sets into this one.
}

EntitySet represents the interface to work with a set of entities.

An implementation must take care to protect against simultaneous use from concurrent go-routines.

func NewEntitySet

func NewEntitySet(in ...any) EntitySet

NewEntitySet instantiates a new standard set of attributes.

It matches the EntitiesBuilder function signature.

Input parameters should be of type Entity or EntitySet! Other types of parameters are ignored.

The given entities and/or entity-sets will be copied into the returned new attribute-set. Duplicate keys from an input set will overwrite the previous value. E.g. only the last value with the duplicate key will be retained.

type Format

type Format uint8

Format represents the format for policy files.

const (
	XML Format = iota + 1
	RDFXML
	Turtle
	N3
	JSONLD
	JSON
	YAML
	FreeFormat
)

ListAllKeys of supported policy file formats.

Note that the policy language (Language) limits the choices for the file format of a policy.

func FormatFromString

func FormatFromString(in string) Format

FormatFromString returns the corresponding Format type from the given input.

func (Format) String

func (f Format) String() string

String implements the Stringer interface.

type Language

type Language uint8

Language represents a policy language.

const (
	XACML Language = iota + 1
	ODRL
	REGO
	CEDAR
	CERBOS
)

List of supported policy languages.

func LanguageFromString

func LanguageFromString(in string) Language

LanguageFromString returns the corresponding Language type from the given input.

func (Language) String

func (l Language) String() string

String implements the Stringer interface.

type Request

type Request struct {
	UID         *uuid.UUID          `json:"uid,omitempty"`
	URL         *url.URL            `json:"url,omitempty"`
	Method      string              `json:"method,omitempty"`
	RequestTime *time.Time          `json:"requestTime,omitempty"`
	Headers     map[string][]string `json:"headers,omitempty"`
	Body        []byte              `json:"body,omitempty"`
	Attributes  map[string]any      `json:"attributes,omitempty"`
}

Request contains the details of an HTTP request required for access control.

type Response

type Response struct {
	Allowed    bool           `json:"allowed,omitempty"`
	Message    string         `json:"message,omitempty"`
	NewURL     *url.URL       `json:"newURL,omitempty"`
	NewBody    []byte         `json:"newBody,omitempty"`
	Attributes map[string]any `json:"attributes,omitempty"`
	PolicyKey  string         `json:"policyKey,omitempty"`
	PolicyHash string         `json:"policyHash,omitempty"`
}

Response contains the result of an access control request.

Jump to

Keyboard shortcuts

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