Documentation
ΒΆ
Index ΒΆ
- Constants
- type CacheConfig
- type Config
- type EngineConfig
- type Handler
- func (h *Handler) CreateAction(c forge.Context) error
- func (h *Handler) CreateNamespace(c forge.Context) error
- func (h *Handler) CreatePolicy(c forge.Context) error
- func (h *Handler) CreateResource(c forge.Context) error
- func (h *Handler) DeleteAction(c forge.Context) error
- func (h *Handler) DeleteNamespace(c forge.Context) error
- func (h *Handler) DeletePolicy(c forge.Context) error
- func (h *Handler) DeleteResource(c forge.Context) error
- func (h *Handler) Evaluate(c forge.Context) error
- func (h *Handler) EvaluateBatch(c forge.Context) error
- func (h *Handler) GetAnalytics(c forge.Context) error
- func (h *Handler) GetAuditLog(c forge.Context) error
- func (h *Handler) GetMigrationStatus(c forge.Context) error
- func (h *Handler) GetNamespace(c forge.Context) error
- func (h *Handler) GetPolicy(c forge.Context) error
- func (h *Handler) GetResource(c forge.Context) error
- func (h *Handler) GetTemplate(c forge.Context) error
- func (h *Handler) InstantiateTemplate(c forge.Context) error
- func (h *Handler) ListActions(c forge.Context) error
- func (h *Handler) ListNamespaces(c forge.Context) error
- func (h *Handler) ListPolicies(c forge.Context) error
- func (h *Handler) ListResources(c forge.Context) error
- func (h *Handler) ListTemplates(c forge.Context) error
- func (h *Handler) MigrateFromRBAC(c forge.Context) error
- func (h *Handler) TestPolicy(c forge.Context) error
- func (h *Handler) UpdateNamespace(c forge.Context) error
- func (h *Handler) UpdatePolicy(c forge.Context) error
- func (h *Handler) ValidatePolicy(c forge.Context) error
- type MessageResponse
- type MigrationConfig
- type OrgConfig
- type PerformanceConfig
- type PermissionMiddleware
- type PermissionMiddlewareConfig
- type PermissionMiddlewareFunc
- type Plugin
- func (p *Plugin) AttributeResolver() *engine.AttributeResolver
- func (p *Plugin) CheckPermission(c forge.Context, resourceType, action, resourceID string) (bool, error)
- func (p *Plugin) Description() string
- func (p *Plugin) Health(ctx context.Context) error
- func (p *Plugin) ID() string
- func (p *Plugin) Init(authInst core.Authsome) error
- func (p *Plugin) Migrate() error
- func (p *Plugin) MigrationService() *migration.RBACMigrationService
- func (p *Plugin) Name() string
- func (p *Plugin) RegisterHooks(hookRegistry *hooks.HookRegistry) error
- func (p *Plugin) RegisterResourceLoader(resourceType string, loader providers.ResourceLoader)
- func (p *Plugin) RegisterResourceLoaderFunc(resourceType string, fn providers.ResourceLoaderFunc)
- func (p *Plugin) RegisterRoutes(router forge.Router) error
- func (p *Plugin) RegisterServiceDecorators(services *registry.ServiceRegistry) error
- func (p *Plugin) RequireAdmin(resourceType string) PermissionMiddlewareFunc
- func (p *Plugin) RequireDelete(resourceType string) PermissionMiddlewareFunc
- func (p *Plugin) RequireOwnership(resourceType, resourceIDParam string) PermissionMiddlewareFunc
- func (p *Plugin) RequirePermission(resourceType, action string) PermissionMiddlewareFunc
- func (p *Plugin) RequirePermissionWithConfig(config PermissionMiddlewareConfig) PermissionMiddlewareFunc
- func (p *Plugin) RequirePermissionWithID(resourceType, action, resourceIDParam string) PermissionMiddlewareFunc
- func (p *Plugin) RequireRead(resourceType string) PermissionMiddlewareFunc
- func (p *Plugin) RequireWrite(resourceType string) PermissionMiddlewareFunc
- func (p *Plugin) ResourceRegistry() *providers.ResourceProviderRegistry
- func (p *Plugin) Service() *Service
- func (p *Plugin) Shutdown(ctx context.Context) error
- func (p *Plugin) Version() string
- func (p *Plugin) WireFromAuthsome() error
- func (p *Plugin) WireMigrationService(rbacAdapter *migration.RBACServiceAdapter) error
- func (p *Plugin) WireUserAttributeProvider(cfg providers.AuthsomeUserProviderConfig) error
- type PluginOption
- func WithCacheBackend(backend string) PluginOption
- func WithCacheEnabled(enabled bool) PluginOption
- func WithDefaultConfig(cfg *Config) PluginOption
- func WithMaxPoliciesPerOrg(max int) PluginOption
- func WithMetricsEnabled(enabled bool) PluginOption
- func WithMode(mode string) PluginOption
- func WithParallelEvaluation(enabled bool) PluginOption
- type Service
- func (s *Service) CreateAction(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, ...) (*core.ActionDefinition, error)
- func (s *Service) CreateDefaultNamespace(ctx context.Context, appID, envID xid.ID, orgID *xid.ID) error
- func (s *Service) CreateNamespace(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, userID xid.ID, ...) (*core.Namespace, error)
- func (s *Service) CreatePolicy(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, userID xid.ID, ...) (*core.Policy, error)
- func (s *Service) CreateResource(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, ...) (*core.ResourceDefinition, error)
- func (s *Service) DeleteAction(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, actionID xid.ID) error
- func (s *Service) DeleteNamespace(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, namespaceID xid.ID) error
- func (s *Service) DeletePolicy(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, policyID xid.ID) error
- func (s *Service) DeleteResource(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, resourceID xid.ID) error
- func (s *Service) Evaluate(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, userID xid.ID, ...) (*engine.Decision, error)
- func (s *Service) EvaluateBatch(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, userID xid.ID, ...) ([]*handlers.BatchEvaluationResult, error)
- func (s *Service) GetAnalytics(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, ...) (*handlers.AnalyticsSummary, error)
- func (s *Service) GetMigrationStatus(ctx context.Context, appID, envID xid.ID, orgID *xid.ID) (*core.MigrationStatus, error)
- func (s *Service) GetNamespace(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, namespaceID xid.ID) (*core.Namespace, error)
- func (s *Service) GetPolicy(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, policyID xid.ID) (*core.Policy, error)
- func (s *Service) GetResource(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, resourceID xid.ID) (*core.ResourceDefinition, error)
- func (s *Service) GetTemplate(ctx context.Context, templateID string) (*core.PolicyTemplate, error)
- func (s *Service) Health(ctx context.Context) error
- func (s *Service) InstantiateTemplate(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, userID xid.ID, ...) (*core.Policy, error)
- func (s *Service) InvalidateAppCache(ctx context.Context, appID xid.ID) error
- func (s *Service) InvalidateEnvironmentCache(ctx context.Context, appID, envID xid.ID) error
- func (s *Service) InvalidateOrganizationCache(ctx context.Context, appID, envID, orgID xid.ID) error
- func (s *Service) InvalidateUserCache(ctx context.Context, userID xid.ID) error
- func (s *Service) ListActions(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, namespaceID xid.ID) ([]*core.ActionDefinition, error)
- func (s *Service) ListAuditEvents(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, ...) ([]*core.AuditEvent, int, error)
- func (s *Service) ListNamespaces(ctx context.Context, appID, envID xid.ID, orgID *xid.ID) ([]*core.Namespace, error)
- func (s *Service) ListPolicies(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, ...) ([]*core.Policy, int, error)
- func (s *Service) ListResources(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, namespaceID xid.ID) ([]*core.ResourceDefinition, error)
- func (s *Service) ListTemplates(ctx context.Context) ([]*core.PolicyTemplate, error)
- func (s *Service) Migrate(ctx context.Context) error
- func (s *Service) MigrateFromRBAC(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, ...) (*core.MigrationStatus, error)
- func (s *Service) SetMigrationService(svc *migration.RBACMigrationService)
- func (s *Service) Shutdown(ctx context.Context) error
- func (s *Service) TestPolicy(ctx context.Context, req *handlers.TestPolicyRequest) (*handlers.TestPolicyResponse, error)
- func (s *Service) UpdateNamespace(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, namespaceID xid.ID, ...) (*core.Namespace, error)
- func (s *Service) UpdatePolicy(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, userID xid.ID, ...) (*core.Policy, error)
- func (s *Service) ValidatePolicy(ctx context.Context, req *handlers.ValidatePolicyRequest) (*handlers.ValidatePolicyResponse, error)
- func (s *Service) WarmCache(ctx context.Context, appID, envID xid.ID, orgID *xid.ID) error
- func (s *Service) WarmCacheForAllApps(ctx context.Context) error
- type StatusResponse
Constants ΒΆ
const ( PluginID = "permissions" PluginName = "Advanced Permissions" PluginVersion = "1.0.0" )
Variables ΒΆ
This section is empty.
Functions ΒΆ
This section is empty.
Types ΒΆ
type CacheConfig ΒΆ
type CacheConfig struct {
// Enabled controls whether caching is active
// Default: true
Enabled bool `json:"enabled" yaml:"enabled"`
// Backend specifies the cache backend
// Options: "memory", "redis", "hybrid"
// Default: "hybrid"
Backend string `json:"backend" yaml:"backend"`
// LocalCacheSize is the size of the in-memory LRU cache
// Default: 10000
LocalCacheSize int `json:"localCacheSize" yaml:"localCacheSize"`
// LocalCacheTTL is the TTL for local cache entries
// Default: 5 minutes
LocalCacheTTL time.Duration `json:"localCacheTTL" yaml:"localCacheTTL"`
// RedisTTL is the TTL for Redis cache entries
// Default: 15 minutes
RedisTTL time.Duration `json:"redisTTL" yaml:"redisTTL"`
// WarmupOnStart pre-loads policies on startup
// Default: true
WarmupOnStart bool `json:"warmupOnStart" yaml:"warmupOnStart"`
// InvalidateOnChange immediately invalidates cache on policy changes
// Default: true
InvalidateOnChange bool `json:"invalidateOnChange" yaml:"invalidateOnChange"`
}
CacheConfig controls caching behavior
type Config ΒΆ
type Config struct {
// Enabled controls whether the permissions system is active
Enabled bool `json:"enabled" yaml:"enabled"`
// Mode determines the evaluation mode
// - "strict": Only use permissions system (RBAC disabled)
// - "hybrid": Try permissions first, fallback to RBAC
// - "rbac-primary": Try RBAC first, fallback to permissions
Mode string `json:"mode" yaml:"mode"`
// Engine configuration
Engine EngineConfig `json:"engine" yaml:"engine"`
// Cache configuration
Cache CacheConfig `json:"cache" yaml:"cache"`
// Performance tuning
Performance PerformanceConfig `json:"performance" yaml:"performance"`
// Migration settings
Migration MigrationConfig `json:"migration" yaml:"migration"`
// Organization-specific overrides
Organizations map[string]*OrgConfig `json:"organizations" yaml:"organizations"`
}
Config represents the permissions plugin configuration
func LoadConfig ΒΆ
func LoadConfig(configManager forge.ConfigManager) (*Config, error)
LoadConfig loads configuration from Forge config manager
func (*Config) GetOrgConfig ΒΆ
GetOrgConfig returns the effective configuration for an organization
func (*Config) MergeOrgConfig ΒΆ
MergeOrgConfig merges organization-specific settings
type EngineConfig ΒΆ
type EngineConfig struct {
// MaxPolicyComplexity limits the number of operations in a policy
// Default: 100
MaxPolicyComplexity int `json:"maxPolicyComplexity" yaml:"maxPolicyComplexity"`
// EvaluationTimeout is the maximum time for policy evaluation
// Default: 10ms
EvaluationTimeout time.Duration `json:"evaluationTimeout" yaml:"evaluationTimeout"`
// MaxPoliciesPerOrg limits policies per organization
// Default: 10000
MaxPoliciesPerOrg int `json:"maxPoliciesPerOrg" yaml:"maxPoliciesPerOrg"`
// ParallelEvaluation enables concurrent policy evaluation
// Default: true
ParallelEvaluation bool `json:"parallelEvaluation" yaml:"parallelEvaluation"`
// MaxParallelEvaluations controls concurrency level
// Default: 4
MaxParallelEvaluations int `json:"maxParallelEvaluations" yaml:"maxParallelEvaluations"`
// EnableAttributeCaching caches attribute lookups
// Default: true
EnableAttributeCaching bool `json:"enableAttributeCaching" yaml:"enableAttributeCaching"`
// AttributeCacheTTL is the TTL for attribute cache
// Default: 5 minutes
AttributeCacheTTL time.Duration `json:"attributeCacheTTL" yaml:"attributeCacheTTL"`
}
EngineConfig controls the policy evaluation engine
type Handler ΒΆ
type Handler struct {
// contains filtered or unexported fields
}
Handler handles HTTP requests for the permissions plugin V2 Architecture: App β Environment β Organization
func NewHandler ΒΆ
NewHandler creates a new handler instance
func (*Handler) CreateAction ΒΆ
CreateAction handles POST /permissions/actions
func (*Handler) CreateNamespace ΒΆ
CreateNamespace handles POST /permissions/namespaces
func (*Handler) CreatePolicy ΒΆ
CreatePolicy handles POST /permissions/policies
func (*Handler) CreateResource ΒΆ
CreateResource handles POST /permissions/resources
func (*Handler) DeleteAction ΒΆ
DeleteAction handles DELETE /permissions/actions/:id
func (*Handler) DeleteNamespace ΒΆ
DeleteNamespace handles DELETE /permissions/namespaces/:id
func (*Handler) DeletePolicy ΒΆ
DeletePolicy handles DELETE /permissions/policies/:id
func (*Handler) DeleteResource ΒΆ
DeleteResource handles DELETE /permissions/resources/:id
func (*Handler) EvaluateBatch ΒΆ
EvaluateBatch handles POST /permissions/evaluate/batch
func (*Handler) GetAnalytics ΒΆ
GetAnalytics handles GET /permissions/analytics
func (*Handler) GetAuditLog ΒΆ
GetAuditLog handles GET /permissions/audit
func (*Handler) GetMigrationStatus ΒΆ
GetMigrationStatus handles GET /permissions/migrate/rbac/status
func (*Handler) GetNamespace ΒΆ
GetNamespace handles GET /permissions/namespaces/:id
func (*Handler) GetResource ΒΆ
GetResource handles GET /permissions/resources/:id
func (*Handler) GetTemplate ΒΆ
GetTemplate handles GET /permissions/templates/:id
func (*Handler) InstantiateTemplate ΒΆ
InstantiateTemplate handles POST /permissions/templates/:id/instantiate
func (*Handler) ListActions ΒΆ
ListActions handles GET /permissions/actions
func (*Handler) ListNamespaces ΒΆ
ListNamespaces handles GET /permissions/namespaces
func (*Handler) ListPolicies ΒΆ
ListPolicies handles GET /permissions/policies
func (*Handler) ListResources ΒΆ
ListResources handles GET /permissions/resources
func (*Handler) ListTemplates ΒΆ
ListTemplates handles GET /permissions/templates
func (*Handler) MigrateFromRBAC ΒΆ
MigrateFromRBAC handles POST /permissions/migrate/rbac
func (*Handler) TestPolicy ΒΆ
TestPolicy handles POST /permissions/policies/test
func (*Handler) UpdateNamespace ΒΆ
UpdateNamespace handles PUT /permissions/namespaces/:id
func (*Handler) UpdatePolicy ΒΆ
UpdatePolicy handles PUT /permissions/policies/:id
type MessageResponse ΒΆ
type MessageResponse = handlers.MessageResponse
Response types - use from handlers package
type MigrationConfig ΒΆ
type MigrationConfig struct {
// AutoMigrate automatically converts RBAC policies
// Default: false (requires manual migration)
AutoMigrate bool `json:"autoMigrate" yaml:"autoMigrate"`
// ValidateEquivalence checks that migrated policies match RBAC
// Default: true
ValidateEquivalence bool `json:"validateEquivalence" yaml:"validateEquivalence"`
// KeepRBACPolicies retains RBAC policies after migration
// Default: true (safe to delete after validation)
KeepRBACPolicies bool `json:"keepRBACPolicies" yaml:"keepRBACPolicies"`
// DryRun simulates migration without making changes
// Default: false
DryRun bool `json:"dryRun" yaml:"dryRun"`
}
MigrationConfig controls RBAC β Permissions migration
type OrgConfig ΒΆ
type OrgConfig struct {
// Enabled controls if permissions are enabled for this org
Enabled *bool `json:"enabled,omitempty" yaml:"enabled,omitempty"`
// MaxPolicies overrides the global limit for this org
MaxPolicies *int `json:"maxPolicies,omitempty" yaml:"maxPolicies,omitempty"`
// CustomResources defines org-specific resource types
CustomResources []string `json:"customResources,omitempty" yaml:"customResources,omitempty"`
// CustomActions defines org-specific actions
CustomActions []string `json:"customActions,omitempty" yaml:"customActions,omitempty"`
// TemplateID specifies which platform template to inherit
TemplateID *string `json:"templateId,omitempty" yaml:"templateId,omitempty"`
// InheritPlatform controls platform policy inheritance
InheritPlatform *bool `json:"inheritPlatform,omitempty" yaml:"inheritPlatform,omitempty"`
}
OrgConfig allows organization-specific overrides
type PerformanceConfig ΒΆ
type PerformanceConfig struct {
// EnableMetrics enables Prometheus metrics
// Default: true
EnableMetrics bool `json:"enableMetrics" yaml:"enableMetrics"`
// EnableTracing enables OpenTelemetry tracing
// Default: false (enable in production)
EnableTracing bool `json:"enableTracing" yaml:"enableTracing"`
// TraceSamplingRate is the percentage of requests to trace
// Default: 0.01 (1%)
TraceSamplingRate float64 `json:"traceSamplingRate" yaml:"traceSamplingRate"`
// SlowQueryThreshold logs queries slower than this
// Default: 5ms
SlowQueryThreshold time.Duration `json:"slowQueryThreshold" yaml:"slowQueryThreshold"`
// EnableProfiling enables pprof endpoints
// Default: false (enable for debugging)
EnableProfiling bool `json:"enableProfiling" yaml:"enableProfiling"`
}
PerformanceConfig controls performance tuning
type PermissionMiddleware ΒΆ added in v0.0.3
type PermissionMiddleware struct {
// contains filtered or unexported fields
}
PermissionMiddleware provides middleware for automatic permission checking on routes
func NewPermissionMiddleware ΒΆ added in v0.0.3
func NewPermissionMiddleware(service *Service, config PermissionMiddlewareConfig, logger forge.Logger) *PermissionMiddleware
NewPermissionMiddleware creates a new permission middleware
func (*PermissionMiddleware) Middleware ΒΆ added in v0.0.3
func (m *PermissionMiddleware) Middleware() func(next forge.Handler) forge.Handler
Middleware returns the forge middleware function
type PermissionMiddlewareConfig ΒΆ added in v0.0.3
type PermissionMiddlewareConfig struct {
// ResourceType is the type of resource being protected (e.g., "document", "project")
ResourceType string
// Action is the action being performed (e.g., "read", "write", "delete")
Action string
// ResourceIDParam is the URL parameter name containing the resource ID (e.g., "id", "documentId")
// If empty, the middleware checks access at the resource type level without a specific resource
ResourceIDParam string
// DenyHandler is an optional custom handler for denied requests
// If nil, a default 403 response is returned
DenyHandler forge.Handler
// AllowAnonymous allows unauthenticated requests to proceed (useful with other conditions)
AllowAnonymous bool
// SkipIfNoUser skips permission check if no user is in context (useful for optional auth routes)
SkipIfNoUser bool
// CustomContext provides additional context for the permission check
CustomContext map[string]interface{}
}
PermissionMiddlewareConfig configures the permission middleware behavior
type PermissionMiddlewareFunc ΒΆ added in v0.0.3
PermissionMiddlewareFunc is the middleware function type
type Plugin ΒΆ
type Plugin struct {
// contains filtered or unexported fields
}
Plugin implements the AuthSome plugin interface for advanced permissions V2 Architecture: App β Environment β Organization
func NewPlugin ΒΆ
func NewPlugin(opts ...PluginOption) *Plugin
NewPlugin creates a new permissions plugin instance
func (*Plugin) AttributeResolver ΒΆ added in v0.0.3
func (p *Plugin) AttributeResolver() *engine.AttributeResolver
AttributeResolver returns the attribute resolver for registering custom providers
func (*Plugin) CheckPermission ΒΆ added in v0.0.3
func (p *Plugin) CheckPermission(c forge.Context, resourceType, action, resourceID string) (bool, error)
CheckPermission is a helper that evaluates a permission check inline without middleware Useful for conditional permission checks within handlers
func (*Plugin) Description ΒΆ
Description returns the plugin description
func (*Plugin) MigrationService ΒΆ added in v0.0.3
func (p *Plugin) MigrationService() *migration.RBACMigrationService
MigrationService returns the RBAC migration service (for programmatic access)
func (*Plugin) RegisterHooks ΒΆ
func (p *Plugin) RegisterHooks(hookRegistry *hooks.HookRegistry) error
RegisterHooks registers lifecycle hooks
func (*Plugin) RegisterResourceLoader ΒΆ added in v0.0.3
func (p *Plugin) RegisterResourceLoader(resourceType string, loader providers.ResourceLoader)
RegisterResourceLoader registers a resource loader for a specific resource type This allows external code to provide resource data for policy evaluation
func (*Plugin) RegisterResourceLoaderFunc ΒΆ added in v0.0.3
func (p *Plugin) RegisterResourceLoaderFunc(resourceType string, fn providers.ResourceLoaderFunc)
RegisterResourceLoaderFunc registers a function as a resource loader
func (*Plugin) RegisterRoutes ΒΆ
RegisterRoutes registers HTTP routes for the plugin
func (*Plugin) RegisterServiceDecorators ΒΆ added in v0.0.3
func (p *Plugin) RegisterServiceDecorators(services *registry.ServiceRegistry) error
RegisterServiceDecorators allows plugins to replace core services with decorated versions This is called automatically by AuthSome after all services are initialized
func (*Plugin) RequireAdmin ΒΆ added in v0.0.3
func (p *Plugin) RequireAdmin(resourceType string) PermissionMiddlewareFunc
RequireAdmin creates a middleware that requires admin permission on a resource type
func (*Plugin) RequireDelete ΒΆ added in v0.0.3
func (p *Plugin) RequireDelete(resourceType string) PermissionMiddlewareFunc
RequireDelete creates a middleware that requires delete permission
func (*Plugin) RequireOwnership ΒΆ added in v0.0.3
func (p *Plugin) RequireOwnership(resourceType, resourceIDParam string) PermissionMiddlewareFunc
RequireOwnership creates a middleware that requires the user to own the resource This is a common pattern for user-owned resources
func (*Plugin) RequirePermission ΒΆ added in v0.0.3
func (p *Plugin) RequirePermission(resourceType, action string) PermissionMiddlewareFunc
RequirePermission creates a permission-checking middleware for specific resource type and action This is a convenience function for common use cases
func (*Plugin) RequirePermissionWithConfig ΒΆ added in v0.0.3
func (p *Plugin) RequirePermissionWithConfig(config PermissionMiddlewareConfig) PermissionMiddlewareFunc
RequirePermissionWithConfig creates a middleware with full configuration
func (*Plugin) RequirePermissionWithID ΒΆ added in v0.0.3
func (p *Plugin) RequirePermissionWithID(resourceType, action, resourceIDParam string) PermissionMiddlewareFunc
RequirePermissionWithID creates a middleware that checks permission for a specific resource instance
func (*Plugin) RequireRead ΒΆ added in v0.0.3
func (p *Plugin) RequireRead(resourceType string) PermissionMiddlewareFunc
RequireRead creates a middleware that requires read permission
func (*Plugin) RequireWrite ΒΆ added in v0.0.3
func (p *Plugin) RequireWrite(resourceType string) PermissionMiddlewareFunc
RequireWrite creates a middleware that requires write permission
func (*Plugin) ResourceRegistry ΒΆ added in v0.0.3
func (p *Plugin) ResourceRegistry() *providers.ResourceProviderRegistry
ResourceRegistry returns the resource provider registry for registering resource loaders
func (*Plugin) WireFromAuthsome ΒΆ added in v0.0.3
WireFromAuthsome wires all services from the AuthSome instance This is the recommended method to call after plugin initialization
func (*Plugin) WireMigrationService ΒΆ added in v0.0.3
func (p *Plugin) WireMigrationService(rbacAdapter *migration.RBACServiceAdapter) error
WireMigrationService wires the migration service to RBAC repositories This should be called after plugin initialization when RBAC services are available
func (*Plugin) WireUserAttributeProvider ΒΆ added in v0.0.3
func (p *Plugin) WireUserAttributeProvider(cfg providers.AuthsomeUserProviderConfig) error
WireUserAttributeProvider wires the user attribute provider to AuthSome services This should be called after plugin initialization when services are available
type PluginOption ΒΆ added in v0.0.3
type PluginOption func(*Plugin)
PluginOption is a functional option for configuring the permissions plugin
func WithCacheBackend ΒΆ added in v0.0.3
func WithCacheBackend(backend string) PluginOption
WithCacheBackend sets the cache backend
func WithCacheEnabled ΒΆ added in v0.0.3
func WithCacheEnabled(enabled bool) PluginOption
WithCacheEnabled sets whether caching is enabled
func WithDefaultConfig ΒΆ added in v0.0.3
func WithDefaultConfig(cfg *Config) PluginOption
WithDefaultConfig sets the default configuration for the plugin
func WithMaxPoliciesPerOrg ΒΆ added in v0.0.3
func WithMaxPoliciesPerOrg(max int) PluginOption
WithMaxPoliciesPerOrg sets the maximum policies per organization
func WithMetricsEnabled ΒΆ added in v0.0.3
func WithMetricsEnabled(enabled bool) PluginOption
WithMetricsEnabled sets whether metrics are enabled
func WithMode ΒΆ added in v0.0.3
func WithMode(mode string) PluginOption
WithMode sets the evaluation mode
func WithParallelEvaluation ΒΆ added in v0.0.3
func WithParallelEvaluation(enabled bool) PluginOption
WithParallelEvaluation sets whether parallel evaluation is enabled
type Service ΒΆ
type Service struct {
// contains filtered or unexported fields
}
Service is the main permissions service V2 Architecture: App β Environment β Organization
func NewService ΒΆ added in v0.0.3
NewService creates a new permissions service with all dependencies
func (*Service) CreateAction ΒΆ
func (s *Service) CreateAction(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, req *handlers.CreateActionRequest) (*core.ActionDefinition, error)
CreateAction creates a new action definition
func (*Service) CreateDefaultNamespace ΒΆ
func (s *Service) CreateDefaultNamespace(ctx context.Context, appID, envID xid.ID, orgID *xid.ID) error
CreateDefaultNamespace creates a default namespace for a new app/env or organization
func (*Service) CreateNamespace ΒΆ
func (s *Service) CreateNamespace(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, userID xid.ID, req *handlers.CreateNamespaceRequest) (*core.Namespace, error)
CreateNamespace creates a new namespace
func (*Service) CreatePolicy ΒΆ
func (s *Service) CreatePolicy(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, userID xid.ID, req *handlers.CreatePolicyRequest) (*core.Policy, error)
CreatePolicy creates a new permission policy
func (*Service) CreateResource ΒΆ
func (s *Service) CreateResource(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, req *handlers.CreateResourceRequest) (*core.ResourceDefinition, error)
CreateResource creates a new resource definition
func (*Service) DeleteAction ΒΆ
func (s *Service) DeleteAction(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, actionID xid.ID) error
DeleteAction deletes an action definition
func (*Service) DeleteNamespace ΒΆ
func (s *Service) DeleteNamespace(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, namespaceID xid.ID) error
DeleteNamespace deletes a namespace
func (*Service) DeletePolicy ΒΆ
func (s *Service) DeletePolicy(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, policyID xid.ID) error
DeletePolicy deletes a policy
func (*Service) DeleteResource ΒΆ
func (s *Service) DeleteResource(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, resourceID xid.ID) error
DeleteResource deletes a resource definition
func (*Service) Evaluate ΒΆ
func (s *Service) Evaluate(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, userID xid.ID, req *handlers.EvaluateRequest) (*engine.Decision, error)
Evaluate evaluates a permission check - THE CORE FEATURE
func (*Service) EvaluateBatch ΒΆ
func (s *Service) EvaluateBatch(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, userID xid.ID, req *handlers.BatchEvaluateRequest) ([]*handlers.BatchEvaluationResult, error)
EvaluateBatch evaluates multiple permission checks efficiently
func (*Service) GetAnalytics ΒΆ
func (s *Service) GetAnalytics(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, timeRange map[string]interface{}) (*handlers.AnalyticsSummary, error)
GetAnalytics retrieves analytics data
func (*Service) GetMigrationStatus ΒΆ
func (s *Service) GetMigrationStatus(ctx context.Context, appID, envID xid.ID, orgID *xid.ID) (*core.MigrationStatus, error)
GetMigrationStatus retrieves migration status
func (*Service) GetNamespace ΒΆ
func (s *Service) GetNamespace(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, namespaceID xid.ID) (*core.Namespace, error)
GetNamespace retrieves a namespace by ID
func (*Service) GetPolicy ΒΆ
func (s *Service) GetPolicy(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, policyID xid.ID) (*core.Policy, error)
GetPolicy retrieves a policy by ID
func (*Service) GetResource ΒΆ
func (s *Service) GetResource(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, resourceID xid.ID) (*core.ResourceDefinition, error)
GetResource retrieves a resource definition by ID
func (*Service) GetTemplate ΒΆ
GetTemplate retrieves a specific policy template
func (*Service) InstantiateTemplate ΒΆ
func (s *Service) InstantiateTemplate(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, userID xid.ID, templateID string, req *handlers.InstantiateTemplateRequest) (*core.Policy, error)
InstantiateTemplate creates a policy from a template
func (*Service) InvalidateAppCache ΒΆ
InvalidateAppCache invalidates the cache for a specific app
func (*Service) InvalidateEnvironmentCache ΒΆ added in v0.0.3
InvalidateEnvironmentCache invalidates the cache for a specific environment
func (*Service) InvalidateOrganizationCache ΒΆ
func (s *Service) InvalidateOrganizationCache(ctx context.Context, appID, envID, orgID xid.ID) error
InvalidateOrganizationCache invalidates the cache for a specific organization
func (*Service) InvalidateUserCache ΒΆ
InvalidateUserCache invalidates the cache for a specific user
func (*Service) ListActions ΒΆ
func (s *Service) ListActions(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, namespaceID xid.ID) ([]*core.ActionDefinition, error)
ListActions lists action definitions for a namespace
func (*Service) ListAuditEvents ΒΆ
func (s *Service) ListAuditEvents(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, filters map[string]interface{}) ([]*core.AuditEvent, int, error)
ListAuditEvents lists audit log entries
func (*Service) ListNamespaces ΒΆ
func (s *Service) ListNamespaces(ctx context.Context, appID, envID xid.ID, orgID *xid.ID) ([]*core.Namespace, error)
ListNamespaces lists namespaces for an app/env/org
func (*Service) ListPolicies ΒΆ
func (s *Service) ListPolicies(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, filters map[string]interface{}) ([]*core.Policy, int, error)
ListPolicies lists policies for an app/env/org
func (*Service) ListResources ΒΆ
func (s *Service) ListResources(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, namespaceID xid.ID) ([]*core.ResourceDefinition, error)
ListResources lists resource definitions for a namespace
func (*Service) ListTemplates ΒΆ
ListTemplates lists available policy templates
func (*Service) MigrateFromRBAC ΒΆ
func (s *Service) MigrateFromRBAC(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, req *handlers.MigrateRBACRequest) (*core.MigrationStatus, error)
MigrateFromRBAC migrates RBAC policies to permissions
func (*Service) SetMigrationService ΒΆ added in v0.0.3
func (s *Service) SetMigrationService(svc *migration.RBACMigrationService)
SetMigrationService sets the migration service
func (*Service) TestPolicy ΒΆ
func (s *Service) TestPolicy(ctx context.Context, req *handlers.TestPolicyRequest) (*handlers.TestPolicyResponse, error)
TestPolicy tests a policy against test cases
func (*Service) UpdateNamespace ΒΆ
func (s *Service) UpdateNamespace(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, namespaceID xid.ID, req *handlers.UpdateNamespaceRequest) (*core.Namespace, error)
UpdateNamespace updates an existing namespace
func (*Service) UpdatePolicy ΒΆ
func (s *Service) UpdatePolicy(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, userID xid.ID, policyID xid.ID, req *handlers.UpdatePolicyRequest) (*core.Policy, error)
UpdatePolicy updates an existing policy
func (*Service) ValidatePolicy ΒΆ
func (s *Service) ValidatePolicy(ctx context.Context, req *handlers.ValidatePolicyRequest) (*handlers.ValidatePolicyResponse, error)
ValidatePolicy validates a policy expression
type StatusResponse ΒΆ
type StatusResponse = handlers.StatusResponse
Response types - use from handlers package