public
import "github.com/prescriptoo/prescriptoo-api/services/authorization/public"Package public exposes authorization DTOs and narrow service capabilities. Callers authenticate identities before permission checks. Resource services retain lifecycle checks and supply trusted ownership facts.
Index
- Variables
- func IsAdminResourceOwner(input AdminResourceOwnershipInput) bool
- func IsOrganizationResourceOwner(input OrganizationResourceOwnershipInput) bool
- type Actor
- type AdminPermissionChecker
- type AdminResourceOwnershipInput
- type AssignRoleInput
- type CreateRoleInput
- type DeleteRoleInput
- type Effect
- type EffectivePermission
- type HasAdminPermissionInput
- type HasOrganizationPermissionInput
- type MemberAuthorization
- type MemberAuthorizationReader
- type MemberPermissionRemover
- type MemberPermissionSetter
- type MemberQuery
- type Membership
- type MembershipReader
- type OrganizationPermissionChecker
- type OrganizationPermissionTransactions
- type OrganizationResourceOwnershipInput
- type Permission
- type PermissionGrant
- type PermissionKey
- type PermissionLister
- type PermissionOverride
- type Query
- type RemoveMemberPermissionInput
- type ResourceAccess
- type RevokeRoleInput
- type Role
- type RoleAssigner
- type RoleCreator
- type RoleDeleter
- type RoleEditor
- type RoleLister
- type RolePermissionSetter
- type RoleQuery
- type RoleReader
- type RoleRevoker
- type Scope
- type ScopeType
- type SetMemberPermissionInput
- type SetRolePermissionsInput
- type UpdateRoleInput
Variables
var (
// ErrInvalidInput identifies malformed authorization input.
ErrInvalidInput = errors.New("invalid authorization input")
// ErrInvalidPermission identifies an unknown permission or unsupported access restriction.
ErrInvalidPermission = errors.New("unsupported permission")
// ErrForbidden indicates the actor lacks required authority.
ErrForbidden = errors.New("authorization denied")
// ErrNotFound indicates a resource is absent from the requested scope.
ErrNotFound = errors.New("authorization resource not found")
// ErrConflict identifies an outdated version or conflicting definition.
ErrConflict = errors.New("authorization version conflict")
// ErrProtectedRole protects owner-designated authority from grant-management edits.
ErrProtectedRole = errors.New("protected authorization role")
// ErrUnavailable indicates a required authorization dependency failed.
ErrUnavailable = errors.New("authorization service unavailable")
)2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
func IsAdminResourceOwner
func IsAdminResourceOwner(input AdminResourceOwnershipInput) boolIsAdminResourceOwner compares ownership of a platform resource. An organization resource must use IsOrganizationResourceOwner instead.
func IsOrganizationResourceOwner
func IsOrganizationResourceOwner(input OrganizationResourceOwnershipInput) boolIsOrganizationResourceOwner proves equality within one organization. It does not authenticate, verify membership, or grant a permission.
type Actor
Actor must contain an identity verified by the consuming service.
type Actor struct {
UserID string
}2
3
type AdminPermissionChecker
AdminPermissionChecker exposes only platform-admin grant evaluation.
type AdminPermissionChecker interface {
HasAdminPermission(context.Context, HasAdminPermissionInput) (bool, error)
}2
3
type AdminResourceOwnershipInput
AdminResourceOwnershipInput carries trusted identity user IDs for a platform resource.
type AdminResourceOwnershipInput struct {
UserID string
OwnerUserID string
}2
3
4
type AssignRoleInput
AssignRoleInput adds a role at the expected member-authorization version.
type AssignRoleInput struct {
MemberQuery
RoleID string
ExpectedVersion int64
}2
3
4
5
type CreateRoleInput
CreateRoleInput defines a custom role and its initial permission bundle.
type CreateRoleInput struct {
Query
Name string
Slug string
Description string
Permissions []PermissionGrant
}2
3
4
5
6
7
type DeleteRoleInput
DeleteRoleInput deletes a role and its assignments at the expected role version.
type DeleteRoleInput struct {
RoleQuery
ExpectedVersion int64
}2
3
4
type Effect
Effect determines whether a direct override allows or denies access.
type Effect stringSupported direct override effects.
const (
EffectAllow Effect = "allow"
EffectDeny Effect = "deny"
)2
3
4
type EffectivePermission
EffectivePermission is contextual: own and any decisions can differ.
type EffectivePermission struct {
Permission PermissionKey `json:"permission"`
Own bool `json:"own"`
Any bool `json:"any"`
}2
3
4
5
type HasAdminPermissionInput
HasAdminPermissionInput requests a grant check within platform administration.
type HasAdminPermissionInput struct {
UserID string
Permission PermissionKey
Access ResourceAccess
}2
3
4
5
type HasOrganizationPermissionInput
HasOrganizationPermissionInput requests a grant check within one organization. Access defaults to any. Own must be requested only after the ownership helper succeeds against a server-loaded resource. Any grants also match own checks; own grants never match any checks. Matching explicit denials override allows. For record actions, select Own for owners even when an Any grant exists; otherwise an Own denial cannot be evaluated for that record.
type HasOrganizationPermissionInput struct {
UserID string
OrganizationID string
Permission PermissionKey
Access ResourceAccess
}2
3
4
5
6
type MemberAuthorization
MemberAuthorization returns role assignments, overrides, versions and contextual decisions.
type MemberAuthorization struct {
UserID string `json:"user_id"`
Scope Scope `json:"scope"`
Version int64 `json:"version"`
Roles []Role `json:"roles"`
Overrides []PermissionOverride `json:"overrides"`
EffectivePermissions []EffectivePermission `json:"effective_permissions"`
}2
3
4
5
6
7
8
type MemberAuthorizationReader
MemberAuthorizationReader inspects a member's scoped authorization state.
type MemberAuthorizationReader interface {
GetMemberAuthorization(context.Context, MemberQuery) (*MemberAuthorization, error)
}2
3
type MemberPermissionRemover
MemberPermissionRemover removes a direct override to restore inheritance.
type MemberPermissionRemover interface {
RemoveMemberPermission(context.Context, RemoveMemberPermissionInput) (*MemberAuthorization, error)
}2
3
type MemberPermissionSetter
MemberPermissionSetter sets a direct scoped allow or deny override.
type MemberPermissionSetter interface {
SetMemberPermission(context.Context, SetMemberPermissionInput) (*MemberAuthorization, error)
}2
3
type MemberQuery
MemberQuery identifies the target identity within one membership scope.
type MemberQuery struct {
Query
TargetUserID string
}2
3
4
type Membership
Membership is a live owner-provided grant eligibility record. ID must identify this membership incarnation so deletion/recreation cannot resurrect old grants.
type Membership struct {
ID string
Active bool
// IsOwner is reserved for owner-designated platform super admins / org admins.
// Custom authorization roles cannot create this authority.
IsOwner bool
}2
3
4
5
6
7
type MembershipReader
MembershipReader performs pure membership queries without authorization callbacks. This avoids recursion when Admin/Organization consume this service.
type MembershipReader interface {
GetAuthorizationMembership(context.Context, Scope, string) (Membership, error)
}2
3
type OrganizationPermissionChecker
OrganizationPermissionChecker exposes only organization grant evaluation.
type OrganizationPermissionChecker interface {
HasOrganizationPermission(context.Context, HasOrganizationPermissionInput) (bool, error)
}2
3
type OrganizationPermissionTransactions
OrganizationPermissionTransactions reads current grants in the caller's transaction. Callers must first lock Organization and derive the live membership through its capability.
type OrganizationPermissionTransactions interface {
HasOrganizationPermissionInTransaction(context.Context, pgx.Tx, HasOrganizationPermissionInput, Membership) (bool, error)
}2
3
type OrganizationResourceOwnershipInput
OrganizationResourceOwnershipInput contains trusted, server-loaded identities. OwnerUserID is the resource's defined owner, not necessarily its creator.
type OrganizationResourceOwnershipInput struct {
UserID string
OrganizationID string
ResourceOrganizationID string
OwnerUserID string
}2
3
4
5
6
type Permission
Permission is an application-defined catalog entry, never user-created code.
type Permission struct {
Key PermissionKey `json:"key"`
ScopeType ScopeType `json:"scope_type"`
Resource string `json:"resource"`
Action string `json:"action"`
SupportsOwn bool `json:"supports_own"`
}2
3
4
5
6
7
func Catalog
func Catalog() []PermissionCatalog returns a copy of the supported application permission definitions. Adding a new key requires application enforcement and a database migration.
func FindPermission
func FindPermission(key PermissionKey) (Permission, bool)FindPermission finds a supported permission without accepting arbitrary keys.
type PermissionGrant
PermissionGrant grants one supported permission with an ownership restriction.
type PermissionGrant struct {
Permission PermissionKey `json:"permission" minLength:"1"`
Access ResourceAccess `json:"access" enum:"any,own"`
}2
3
4
type PermissionKey
PermissionKey identifies an application-defined resource/action.
type PermissionKey stringtype PermissionLister
PermissionLister exposes the supported permission catalog for an authorized actor.
type PermissionLister interface {
ListPermissions(context.Context, Query) ([]Permission, error)
}2
3
type PermissionOverride
PermissionOverride adds an explicit allow or deny for one member.
type PermissionOverride struct {
PermissionGrant
Effect Effect `json:"effect" enum:"allow,deny"`
}2
3
4
type Query
Query carries a verified actor and an explicit authorization scope.
type Query struct {
Audit audit.OperationContext `json:"-"`
Actor Actor
Scope Scope
}2
3
4
5
type RemoveMemberPermissionInput
RemoveMemberPermissionInput removes an override and restores role inheritance.
type RemoveMemberPermissionInput struct {
MemberQuery
Permission PermissionKey
Access ResourceAccess
ExpectedVersion int64
}2
3
4
5
6
type ResourceAccess
ResourceAccess selects an ownership relationship within the current scope.
type ResourceAccess stringSupported resource ownership relationships.
const (
AccessAny ResourceAccess = "any"
AccessOwn ResourceAccess = "own"
)2
3
4
type RevokeRoleInput
RevokeRoleInput removes a role at the expected member-authorization version.
type RevokeRoleInput = AssignRoleInputtype Role
Role is a versioned permission bundle within one scope.
type Role struct {
ID string `json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
Description string `json:"description"`
Protected bool `json:"protected"`
Version int64 `json:"version"`
Permissions []PermissionGrant `json:"permissions"`
}2
3
4
5
6
7
8
9
type RoleAssigner
RoleAssigner assigns a role without exceeding the actor's delegation authority.
type RoleAssigner interface {
AssignRole(context.Context, AssignRoleInput) (*MemberAuthorization, error)
}2
3
type RoleCreator
RoleCreator creates a role after validating delegation authority.
type RoleCreator interface {
CreateRole(context.Context, CreateRoleInput) (*Role, error)
}2
3
type RoleDeleter
RoleDeleter atomically removes a role and its assignments.
type RoleDeleter interface {
DeleteRole(context.Context, DeleteRoleInput) error
}2
3
type RoleEditor
RoleEditor replaces versioned role metadata.
type RoleEditor interface {
UpdateRole(context.Context, UpdateRoleInput) (*Role, error)
}2
3
type RoleLister
RoleLister lists role definitions within one authorized scope.
type RoleLister interface {
ListRoles(context.Context, Query) ([]Role, error)
}2
3
type RolePermissionSetter
RolePermissionSetter replaces a role bundle after validating old and new grants.
type RolePermissionSetter interface {
SetRolePermissions(context.Context, SetRolePermissionsInput) (*Role, error)
}2
3
type RoleQuery
RoleQuery identifies a role within the actor's requested scope.
type RoleQuery struct {
Query
RoleID string
}2
3
4
type RoleReader
RoleReader reads one role definition within its scope.
type RoleReader interface {
GetRole(context.Context, RoleQuery) (*Role, error)
}2
3
type RoleRevoker
RoleRevoker revokes one member role assignment.
type RoleRevoker interface {
RevokeRole(context.Context, RevokeRoleInput) (*MemberAuthorization, error)
}2
3
type Scope
Scope selects the platform or exactly one organization.
type Scope struct {
Type ScopeType `json:"type" enum:"admin,organization"`
OrganizationID string `json:"organization_id,omitempty"`
}2
3
4
type ScopeType
ScopeType identifies the platform or organization permission domain.
type ScopeType stringSupported authorization scope domains.
const (
ScopeAdmin ScopeType = "admin"
ScopeOrganization ScopeType = "organization"
)2
3
4
type SetMemberPermissionInput
SetMemberPermissionInput sets a version-checked direct member override.
type SetMemberPermissionInput struct {
MemberQuery
Override PermissionOverride
ExpectedVersion int64
}2
3
4
5
type SetRolePermissionsInput
SetRolePermissionsInput replaces a complete permission bundle at its expected version.
type SetRolePermissionsInput struct {
RoleQuery
Permissions []PermissionGrant
ExpectedVersion int64
}2
3
4
5
type UpdateRoleInput
UpdateRoleInput replaces role metadata when the expected version matches.
type UpdateRoleInput struct {
RoleQuery
Name string
Description string
ExpectedVersion int64
}2
3
4
5
6
Generated by gomarkdoc