identity

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: May 23, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPrincipalMissing = errors.New("identity: principal missing")

Functions

func WithPrincipal

func WithPrincipal(ctx context.Context, principal Principal) context.Context

Types

type Principal

type Principal struct {
	ID       string            `json:"id"`
	Type     PrincipalType     `json:"type"`
	Scope    Scope             `json:"scope"`
	Roles    []Role            `json:"roles,omitempty"`
	Metadata map[string]string `json:"metadata,omitempty"`
}

func PrincipalFromContext

func PrincipalFromContext(ctx context.Context) (Principal, bool)

func RequirePrincipal

func RequirePrincipal(ctx context.Context) (Principal, error)

func (Principal) HasAnyRole

func (p Principal) HasAnyRole(roles ...Role) bool

func (Principal) HasRole

func (p Principal) HasRole(role Role) bool

func (Principal) Validate

func (p Principal) Validate() error

type PrincipalType

type PrincipalType string
const (
	PrincipalUser    PrincipalType = "user"
	PrincipalService PrincipalType = "service"
	PrincipalSystem  PrincipalType = "system"
)

type Role

type Role string
const (
	RoleAdmin    Role = "admin"
	RoleOperator Role = "operator"
	RoleViewer   Role = "viewer"
	RoleApprover Role = "approver"
	RoleService  Role = "service"
)

type Scope

type Scope struct {
	TenantID    string `json:"tenant_id,omitempty"`
	WorkspaceID string `json:"workspace_id,omitempty"`
	ProjectID   string `json:"project_id,omitempty"`
}

Jump to

Keyboard shortcuts

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