group

package
v0.0.0-...-6b846f9 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilDatabase            = errors.New("data is nil")
	ErrNoParent               = errors.New("no parent group")
	ErrNilGroupID             = errors.New("role group id is zero")
	ErrZeroRoleID             = errors.New("role id is zero")
	ErrZeroID                 = errors.New("id is zero")
	ErrNonZeroID              = errors.New("id is not zero")
	ErrNilAssetID             = errors.New("asset id is zero")
	ErrInvalidAssetKind       = errors.New("asset kind is invalid")
	ErrNilStore               = errors.New("group store is nil")
	ErrRelationNotFound       = errors.New("relation not found")
	ErrGroupAlreadyRegistered = errors.New("group is already registered")
	ErrEmptyKey               = errors.New("empty group key")
	ErrEmptyGroupName         = errors.New("empty group name")
	ErrDuplicateGroup         = errors.New("duplicate group")
	ErrDuplicateParent        = errors.New("duplicate parent")
	ErrDuplicateRelation      = errors.New("duplicate relation")
	ErrAssetNotEligible       = errors.New("asset is not eligible for this operation")
	ErrGroupKindMismatch      = errors.New("group kinds mismatch")
	ErrInvalidKind            = errors.New("invalid group kind")
	ErrNotAsset               = errors.New("asset is not a asset")
	ErrAlreadyAsset           = errors.New("already a asset")
	ErrCircuitedParent        = errors.New("circuited parenting")
	ErrCircuitCheckTimeout    = errors.New("circuit check timed out")
	ErrNilManager             = errors.New("group manager is nil")
	ErrGroupNotFound          = errors.New("group not found")
	ErrGroupKeyTaken          = errors.New("group key is already taken")
	ErrUnknownKind            = errors.New("unknown group kind")
	ErrInvalidGroupKey        = errors.New("invalid group key")
	ErrInvalidGroupName       = errors.New("invalid group name")
	ErrEmptyGroupKey          = errors.New("group key is empty")
	ErrAmbiguousKind          = errors.New("group kind is ambiguous")
)

errors

Functions

func FlagDictionary

func FlagDictionary() map[uint32]string

FlagDictionary returns a map of property flag values to their respective names

Types

type Asset

type Asset struct {
	Kind AssetKind
	ID   uuid.UUID
}

func NewAsset

func NewAsset(k AssetKind, id uuid.UUID) Asset

func UserAsset

func UserAsset(id uuid.UUID) Asset

type AssetKind

type AssetKind uint8
const (
	AKUser AssetKind = iota
)

func (*AssetKind) Scan

func (ak *AssetKind) Scan(data []byte) error

func (AssetKind) String

func (ak AssetKind) String() string

func (AssetKind) Value

func (ak AssetKind) Value() (driver.Value, error)

type CassandraStore

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

func (CassandraStore) CreateRelation

func (c CassandraStore) CreateRelation(ctx context.Context, rel Relation) error

func (CassandraStore) DeleteByID

func (c CassandraStore) DeleteByID(ctx context.Context, groupID uuid.UUID) error

func (CassandraStore) DeleteRelation

func (c CassandraStore) DeleteRelation(ctx context.Context, rel Relation) error

func (CassandraStore) FetchAllGroups

func (c CassandraStore) FetchAllGroups(ctx context.Context) (gs []Group, err error)

func (CassandraStore) FetchAllRelations

func (c CassandraStore) FetchAllRelations(ctx context.Context) ([]Relation, error)

func (CassandraStore) FetchGroupByID

func (c CassandraStore) FetchGroupByID(ctx context.Context, groupID uuid.UUID) (g Group, err error)

func (CassandraStore) FetchGroupByKey

func (c CassandraStore) FetchGroupByKey(ctx context.Context, key string) (g Group, err error)

func (CassandraStore) FetchGroupByName

func (c CassandraStore) FetchGroupByName(ctx context.Context, name string) (g Group, err error)

func (CassandraStore) FetchGroupRelations

func (c CassandraStore) FetchGroupRelations(ctx context.Context, groupID uuid.UUID) ([]Relation, error)

func (CassandraStore) FetchGroupsByName

func (c CassandraStore) FetchGroupsByName(ctx context.Context, isPartial bool, name string) (gs []Group, err error)

func (CassandraStore) HasRelation

func (c CassandraStore) HasRelation(ctx context.Context, rel Relation) (bool, error)

func (CassandraStore) UpsertGroup

func (c CassandraStore) UpsertGroup(ctx context.Context, g Group) (Group, error)

type Flags

type Flags uint8

Flags designates whether a group is enabled, default, a role or a standard group

const (
	FEnabled Flags = 1 << iota
	FDefault
	FGroup
	FRole
	FAllGroups = FGroup | FRole

	// this flag is used for group flags without translation
	APUnrecognizedFlag = "unrecognized group flag"
)

func (Flags) String

func (flags Flags) String() string

AccessExplained returns a human-readable conjunction of comma-separated accesspolicy names for this given context namespace

func (Flags) Translate

func (flags Flags) Translate() string

func (Flags) Value

func (flags Flags) Value() (driver.Value, error)

type Group

type Group struct {
	DisplayName string    `db:"name" json:"name"`
	Key         string    `db:"key" json:"key" valid:"required,ascii"`
	ID          uuid.UUID `db:"id" json:"id"`
	ParentID    uuid.UUID `db:"parent_id" json:"parent_id"`
	Flags       Flags     `db:"kind" json:"kind"`
	// contains filtered or unexported fields
}

Group represents a asset group TODO: replace Flags and IsDefault with a Flags bitmask TODO: work out a simple Flags bit layout

func NewGroup

func NewGroup(flags Flags, parentID uuid.UUID, key string, name string) (g Group, err error)

NewGroup initializing new group

func (Group) IsDefault

func (g Group) IsDefault() bool

func (Group) IsEnabled

func (g Group) IsEnabled() bool

func (Group) IsGroup

func (g Group) IsGroup() bool

func (Group) IsRole

func (g Group) IsRole() bool

func (*Group) Validate

func (g *Group) Validate() (err error)

Validate validates itself

type List

type List []Group

Registry is a typed slice of groups to make sorting easier

type Manager

type Manager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Manager is a group manager TODO: add default groups which need not to be assigned explicitly

func NewManager

func NewManager(ctx context.Context, s Store) (m *Manager, err error)

NewManager initializing a new group manager

func (*Manager) Create

func (m *Manager) Create(ctx context.Context, flags Flags, parentID uuid.UUID, key string, name string) (g Group, err error)

Upsert creates new group

func (*Manager) CreateRelation

func (m *Manager) CreateRelation(ctx context.Context, rel Relation) (err error)

CreateRelation adding asset to a group NOTE: storing relation only if group has a store set is implicit and should at least log/print about the occurrence

func (*Manager) DeleteGroup

func (m *Manager) DeleteGroup(ctx context.Context, groupID uuid.UUID) (err error)

DeletePolicy returns an accesspolicy policy by its ObjectID NOTE: also deletes all relations and nested groups (should asset have sufficient accesspolicy rights to do that) TODO: implement recursive deletion

func (*Manager) DeleteRelation

func (m *Manager) DeleteRelation(ctx context.Context, rel Relation) (err error)

DeleteRelation removes asset from a group

func (*Manager) GroupByID

func (m *Manager) GroupByID(ctx context.Context, id uuid.UUID) (g Group, err error)

GroupByID returns a group by ActorID

func (*Manager) GroupByKey

func (m *Manager) GroupByKey(ctx context.Context, key string) (g Group, err error)

PolicyByKey returns a group by name

func (*Manager) GroupByName

func (m *Manager) GroupByName(ctx context.Context, name string) (g Group, err error)

GroupByName returns an accesspolicy policy by its key TODO: add expirable caching

func (*Manager) Groups

func (m *Manager) Groups(ctx context.Context, mask Flags) []Group

Groups to which the asset belongs

func (*Manager) GroupsByAssetID

func (m *Manager) GroupsByAssetID(ctx context.Context, mask Flags, asset Asset) (gs []Group)

GroupsByAssetID returns a slice of groups to which a given asset belongs

func (*Manager) Init

func (m *Manager) Init(ctx context.Context) error

Init initializes group manager

func (*Manager) Invite

func (m *Manager) Invite(ctx context.Context, groupID uuid.UUID, asset Asset) (err error)

Invite an existing user to become a asset of the group NOTE: this is optional and often can be disabled for better control TODO: requires careful planning

func (*Manager) IsAsset

func (m *Manager) IsAsset(ctx context.Context, groupID uuid.UUID, asset Asset) bool

IsAsset tests whether a given asset belongs to a given group

func (*Manager) IsCircuited

func (m *Manager) IsCircuited(ctx context.Context, groupID uuid.UUID) (bool, error)

IsCircuited tests whether the parents trace back to a nil

func (*Manager) LinkAsset

func (m *Manager) LinkAsset(ctx context.Context, groupID uuid.UUID, asset Asset) (err error)

LinkAsset adds a asset to the group assets NOTE: does not affect the store

func (*Manager) List

func (m *Manager) List(kind Flags) (gs []Group)

Registry returns all groups inside a manager

func (*Manager) Logger

func (m *Manager) Logger() *zap.Logger

Logger returns primary logger if is set, otherwise initializing and returning

func (*Manager) Lookup

func (m *Manager) Lookup(ctx context.Context, groupID uuid.UUID) (g Group, err error)

lookup looks up in cache and returns a group if found

func (*Manager) Parent

func (m *Manager) Parent(ctx context.Context, g Group) (p Group, err error)

Parent returns a parent of a given group

func (*Manager) Put

func (m *Manager) Put(ctx context.Context, g Group) error

put adds group to the manager

func (*Manager) Remove

func (m *Manager) Remove(ctx context.Context, groupID uuid.UUID) error

Remove removing group from the manager

func (*Manager) SetLogger

func (m *Manager) SetLogger(logger *zap.Logger) error

SetLogger assigns a logger for this manager

func (*Manager) SetParent

func (m *Manager) SetParent(ctx context.Context, groupID, newParentID uuid.UUID) (err error)

SetParent assigns a new parent ActorID

func (*Manager) Store

func (m *Manager) Store() (Store, error)

Store returns store if set

func (*Manager) UnlinkAsset

func (m *Manager) UnlinkAsset(ctx context.Context, groupID uuid.UUID, asset Asset) (err error)

UnlinkAsset removes a asset from the group assets NOTE: does not affect the store

func (*Manager) Validate

func (m *Manager) Validate(ctx context.Context, groupID uuid.UUID) (err error)

Validate performs an integrity check on a given group

type PostgreSQLStore

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

func (*PostgreSQLStore) CreateRelation

func (s *PostgreSQLStore) CreateRelation(ctx context.Context, rel Relation) (err error)

func (*PostgreSQLStore) DeleteByID

func (s *PostgreSQLStore) DeleteByID(ctx context.Context, groupID uuid.UUID) (err error)

func (*PostgreSQLStore) DeleteRelation

func (s *PostgreSQLStore) DeleteRelation(ctx context.Context, rel Relation) (err error)

func (*PostgreSQLStore) FetchAllGroups

func (s *PostgreSQLStore) FetchAllGroups(ctx context.Context) (gs []Group, err error)

func (*PostgreSQLStore) FetchAllRelations

func (s *PostgreSQLStore) FetchAllRelations(ctx context.Context) (relations []Relation, err error)

func (*PostgreSQLStore) FetchGroupByID

func (s *PostgreSQLStore) FetchGroupByID(ctx context.Context, groupID uuid.UUID) (Group, error)

func (*PostgreSQLStore) FetchGroupByKey

func (s *PostgreSQLStore) FetchGroupByKey(ctx context.Context, key string) (Group, error)

func (*PostgreSQLStore) FetchGroupByName

func (s *PostgreSQLStore) FetchGroupByName(ctx context.Context, name string) (g Group, err error)

func (*PostgreSQLStore) FetchGroupRelations

func (s *PostgreSQLStore) FetchGroupRelations(ctx context.Context, groupID uuid.UUID) ([]Relation, error)

func (*PostgreSQLStore) FetchGroupsByName

func (s *PostgreSQLStore) FetchGroupsByName(ctx context.Context, isPartial bool, name string) (gs []Group, err error)

func (*PostgreSQLStore) HasRelation

func (s *PostgreSQLStore) HasRelation(ctx context.Context, rel Relation) (bool, error)

func (*PostgreSQLStore) UpsertGroup

func (s *PostgreSQLStore) UpsertGroup(ctx context.Context, g Group) (Group, error)

type Relation

type Relation struct {
	GroupID uuid.UUID
	Asset   Asset
}

func NewRelation

func NewRelation(gid uuid.UUID, k AssetKind, aid uuid.UUID) Relation

type Store

type Store interface {
	UpsertGroup(ctx context.Context, g Group) (Group, error)
	CreateRelation(ctx context.Context, rel Relation) error
	FetchGroupByID(ctx context.Context, groupID uuid.UUID) (g Group, err error)
	FetchGroupByKey(ctx context.Context, key string) (g Group, err error)
	FetchGroupByName(ctx context.Context, name string) (g Group, err error)
	FetchGroupsByName(ctx context.Context, isPartial bool, name string) (gs []Group, err error)
	HasRelation(ctx context.Context, rel Relation) (bool, error)
	FetchAllGroups(ctx context.Context) (gs []Group, err error)
	FetchAllRelations(ctx context.Context) ([]Relation, error)
	FetchGroupRelations(ctx context.Context, groupID uuid.UUID) ([]Relation, error)
	DeleteByID(ctx context.Context, groupID uuid.UUID) error
	DeleteRelation(ctx context.Context, rel Relation) error
}

Store describes a storage contract for groups specifically

func NewPostgreSQLStore

func NewPostgreSQLStore(db *pgx.Conn) (Store, error)

type Team

type Team struct {
}

Team represents a lesser group of assets TODO: consider combined accounts or team authentication

Jump to

Keyboard shortcuts

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