session

package
v0.0.0-...-5745a54 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2023 License: ISC Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ID

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

keeps the sortability of ulid and the randomness of uuid

func New

func New() ID

func Parse

func Parse(b []byte) (ID, error)

func (*ID) MarshalText

func (s *ID) MarshalText() ([]byte, error)

func (ID) String

func (s ID) String() string

func (*ID) UnmarshalText

func (s *ID) UnmarshalText(b []byte) error

type Permission

type Permission string

Permission represents a permission prefix; it is used to check if a user has the permission to do something. It might be suffixed with a resource ID to check if the user has the permission to do something on a specific resource.

const (
	// PermRoot has all permissions
	PermRoot Permission = "perm"

	// PermUserCreate is the permission to create a user
	PermUserCreate Permission = "perm:users:create"
	PermUserRead   Permission = "perm:users:read"
	PermUserDelete Permission = "perm:users:delete"

	// PermSensorRead is the permission to read a sensor
	PermSensorRead   Permission = "perm:sensors:read"
	PermSensorUpdate Permission = "perm:sensors:update"
	PermSensorDelete Permission = "perm:sensors:delete"

	// PermAlertsRead is the permission to read alerts
	PermAlertsRead Permission = "perm:alerts:read"

	// PermSensorsStateUpdate is the permission to update a sensor state
	PermSensorsStateUpdate Permission = "perm:sensors:state:update"
)

func (Permission) Customize

func (p Permission) Customize(resourceID string) Permission

type Permissions

type Permissions []Permission

Permissions is a list of permissions

func FromString

func FromString(s ...string) Permissions

func (Permissions) Can

func (p Permissions) Can(permission ...Permission) error

func (Permissions) Has

func (p Permissions) Has(permission ...Permission) bool

func (Permissions) Strings

func (p Permissions) Strings() []string

type Session

type Session struct {
	ID          ID
	UserID      ulid.ULID
	Permissions Permissions
}

func FromContext

func FromContext(ctx context.Context) *Session

func (*Session) Context

func (s *Session) Context(ctx context.Context) context.Context

Jump to

Keyboard shortcuts

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