Documentation
¶
Overview ¶
Package access provides a component-reusable access guard that combines principal lookup, authorization checks, and audit recording.
Business modules should depend on *access.Guard instead of directly wiring authz.Authorizer and audit.Recorder in every component. The guard is still provider-neutral: Casdoor/Casbin is only one possible implementation behind the authz/audit interfaces.
Index ¶
- Constants
- type Check
- type Event
- type Guard
- func (g *Guard) Can(ctx context.Context, check Check) (bool, error)
- func (g *Guard) Principal(ctx context.Context) (*principal.Principal, error)
- func (g *Guard) Record(ctx context.Context, ev Event) error
- func (g *Guard) Require(ctx context.Context, check Check) (*principal.Principal, error)
- func (g *Guard) RequireAndAudit(ctx context.Context, check Check, ev Event) (*principal.Principal, error)
- type Options
Constants ¶
const ( ResultSuccess = audit.ResultSuccess ResultFailed = audit.ResultFailed )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct {
Name string
Action string
Resource string
Result string
Message string
RequestID string
TraceID string
ClientIP string
UserAgent string
Method string
URI string
Operation string
StatusCode int
Component string
OrgID string
ProjectID string
StartedAt time.Time
FinishedAt time.Time
Metadata map[string]string
}
Event is the business-facing audit event shape. It intentionally mirrors audit.Event for common fields but keeps this package as the standard entry point for usecases.
type Guard ¶
type Guard struct {
// contains filtered or unexported fields
}
Guard is the reusable access-control facade for all AI Sphere services.
func (*Guard) RequireAndAudit ¶
func (g *Guard) RequireAndAudit(ctx context.Context, check Check, ev Event) (*principal.Principal, error)
RequireAndAudit performs an authorization check and records the result. It is useful for admin/debug operations and simple CRUD handlers where deny/success audit semantics are identical.