Documentation
¶
Index ¶
- Constants
- Variables
- type Context
- func AsRequestContext(echoCtx *echo.Context) (Context, error)
- func CloneRequestContext(ctx Context) Context
- func CloneWithInner(ctx Context, inner context.Context) Context
- func NewRequestContext(ctx context.Context) Context
- func NewRequestContextF(ctx context.Context, moduleName string, domainConstraints dmodel.DynamicFields) Context
- func NewRequestContextM(ctx context.Context, moduleName string) Context
- type ContextPermissions
- type Principal
- type PrincipalKind
- type RequestContext
- func (this RequestContext) GetDbTranx() db.DbTransaction
- func (this RequestContext) GetDomainConstraints() dmodel.DynamicFields
- func (this RequestContext) GetLogger() logging.LoggerService
- func (this RequestContext) GetModuleName() string
- func (this RequestContext) GetPermissions() ContextPermissions
- func (this RequestContext) GetUser() dmodel.DynamicFields
- func (this RequestContext) InnerContext() context.Context
- func (this *RequestContext) SetDbTranx(trx db.DbTransaction)
- func (this *RequestContext) SetDomainConstraints(constraints dmodel.DynamicFields)
- func (this *RequestContext) SetLogger(logger logging.LoggerService)
- func (this *RequestContext) SetPermissions(permissions ContextPermissions)
- func (this *RequestContext) SetUser(user dmodel.DynamicFields)
- func (this *RequestContext) Value(key any) any
- func (this *RequestContext) WithValue(key, val any)
Constants ¶
const ( // PrincipalKindUser is a person acting through a client. PrincipalKindUser = PrincipalKind("user") // PrincipalKindService is a workload acting on the system's behalf: a scheduled job, a // message consumer, a device. It authorizes exactly like a user, on entitlements it was // granted - never by virtue of being internal. PrincipalKindService = PrincipalKind("service") // PrincipalKindSystem is reserved for future platform-level operations. It deliberately // carries NO bypass behaviour; treat it as unauthorized until that is designed. PrincipalKindSystem = PrincipalKind("system") )
Variables ¶
var CtxKeyDomainConstraints = contextKey{"domain_constraints"}
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context interface {
context.Context
InnerContext() context.Context
GetLogger() logging.LoggerService
SetLogger(logger logging.LoggerService)
GetDbTranx() db.DbTransaction
SetDbTranx(trx db.DbTransaction)
GetDomainConstraints() dmodel.DynamicFields
SetDomainConstraints(constraints dmodel.DynamicFields)
GetModuleName() string
GetPermissions() ContextPermissions
SetPermissions(permissions ContextPermissions)
GetUser() dmodel.DynamicFields
SetUser(user dmodel.DynamicFields)
// Replace current inner context with a new one that has the given key and value.
WithValue(key, val any)
}
func AsRequestContext ¶
Returns pointer to an instance of RequestContext if it exists, otherwise returns an error.
func CloneRequestContext ¶
CloneRequestContext returns a copy of ctx that can be given a different transaction without disturbing the original. Use it to derive a scoped context from a live request; the New* constructors above build an empty one, for code with no caller behind it.
It copies every field the copy might be used with, the caller's identity above all: basemodel stamps created_by/updated_by from GetPermissions().UserId, so a clone that dropped permissions would write those columns null and report nothing. Domain constraints live in the inner context's values, so copying Context carries them along.
A field added to RequestContext must be added here too.
func CloneWithInner ¶
CloneWithInner is CloneRequestContext with the inner context replaced, for a caller that has derived a cancellation or deadline from the request's own context and needs the identity, logger and transaction to travel with it. Passing the bare inner context instead would drop all of those; mutating the original would impose the deadline on the caller's remaining work.
func NewRequestContext ¶
func NewRequestContextF ¶
func NewRequestContextF(ctx context.Context, moduleName string, domainConstraints dmodel.DynamicFields) Context
NewRequestContextF builds an empty context carrying domain constraints.
The constraints go through SetDomainConstraints rather than a struct field: GetDomainConstraints reads them back off the inner context's values, so a field set here would never be read.
type ContextPermissions ¶
type ContextPermissions struct {
IsOwner bool
Entitlements ds.Set[string]
UserId model.Id `json:"user_id"`
// The actor executing this request: a user, or a service acting for the system.
Principal Principal `json:"principal"`
// The orgs that user belongs to (if any)
UserOrgIds ds.Set[model.Id] `json:"user_org_ids"`
// The org unit that user belongs to (if any)
OrgUnitId *model.Id `json:"org_unit_id"`
// The org that the org unit belongs to (if user belongs to an org unit)
OrgUnitOrgId *model.Id `json:"org_unit_org_id"`
}
type Principal ¶
type Principal struct {
Kind PrincipalKind `json:"kind"`
Id model.Id `json:"id"`
// OrgId is the single org a service principal acts within. A service holds no org
// membership, so this is what org-scoped work is checked against; nil for a user, whose
// reach comes from UserOrgIds instead.
OrgId *model.Id `json:"org_id"`
// DisplayName is for audit and logs only. Never make a security decision from it.
DisplayName string `json:"display_name"`
}
Principal is the authenticated actor behind the current execution.
A zero Principal means "nobody was authenticated". Authorization must fail closed on it rather than reading absence as permission - see requestguard.AssertPermission.
type PrincipalKind ¶
type PrincipalKind string
PrincipalKind says what sort of actor is executing, so that a job or a consumer is distinguishable from an unauthenticated caller rather than looking identical to one.
This is not IAM's PrincipalType (`nikkiuser` | `custom`), which describes where a login credential came from - a different axis, and in a module core cannot import.
type RequestContext ¶
func (RequestContext) GetDbTranx ¶
func (this RequestContext) GetDbTranx() db.DbTransaction
func (RequestContext) GetDomainConstraints ¶
func (this RequestContext) GetDomainConstraints() dmodel.DynamicFields
func (RequestContext) GetLogger ¶
func (this RequestContext) GetLogger() logging.LoggerService
func (RequestContext) GetModuleName ¶
func (this RequestContext) GetModuleName() string
func (RequestContext) GetPermissions ¶
func (this RequestContext) GetPermissions() ContextPermissions
func (RequestContext) GetUser ¶
func (this RequestContext) GetUser() dmodel.DynamicFields
func (RequestContext) InnerContext ¶
func (this RequestContext) InnerContext() context.Context
func (*RequestContext) SetDbTranx ¶
func (this *RequestContext) SetDbTranx(trx db.DbTransaction)
func (*RequestContext) SetDomainConstraints ¶
func (this *RequestContext) SetDomainConstraints(constraints dmodel.DynamicFields)
func (*RequestContext) SetLogger ¶
func (this *RequestContext) SetLogger(logger logging.LoggerService)
func (*RequestContext) SetPermissions ¶
func (this *RequestContext) SetPermissions(permissions ContextPermissions)
func (*RequestContext) SetUser ¶
func (this *RequestContext) SetUser(user dmodel.DynamicFields)
func (*RequestContext) Value ¶
func (this *RequestContext) Value(key any) any
func (*RequestContext) WithValue ¶
func (this *RequestContext) WithValue(key, val any)
Replace current inner context with a new one that has the given key and value.