Documentation
¶
Overview ¶
Package environment defines the environment domain entity and its store interface. Environments partition an App into isolated contexts (development, staging, production). Each App has one or more environments; all user-facing entities (users, sessions, organizations, etc.) are scoped to an environment.
Index ¶
- Variables
- type CloneRequest
- type CloneResult
- type CloneSource
- type CloneTarget
- type Cloner
- type Environment
- type List
- type Metadata
- type OAuthProviderOverride
- type PermissionForClone
- type Query
- type RoleForClone
- type Settings
- func (s *Settings) AllowTestCredentialsEnabled() bool
- func (s *Settings) ApplySessionOverrides(cfg *account.SessionConfig)
- func (s *Settings) IsBreachCheckEnabled() bool
- func (s *Settings) IsLockoutEnabled() bool
- func (s *Settings) IsRateLimitEnabled() bool
- func (s *Settings) SkipEmailVerificationEnabled() bool
- type Store
- type Type
- type WebhookForClone
Constants ¶
This section is empty.
Variables ¶
var ValidTypes = []Type{TypeDevelopment, TypeStaging, TypeProduction}
ValidTypes is the set of allowed environment types.
Functions ¶
This section is empty.
Types ¶
type CloneRequest ¶
type CloneRequest struct {
// SourceEnvID is the environment to clone from.
SourceEnvID id.EnvironmentID
// Name for the new environment (required).
Name string
// Slug for the new environment (required).
Slug string
// Type for the new environment (required).
Type Type
// Description for the new environment (optional).
Description string
// SettingsOverride merges on top of the source environment's settings (optional).
SettingsOverride *Settings
// WebhookURLOverride replaces webhook URLs in cloned webhooks (optional).
WebhookURLOverride string
}
CloneRequest configures an environment clone operation.
type CloneResult ¶
type CloneResult struct {
// Environment is the newly created environment.
Environment *Environment
// RoleIDMap maps old role IDs to new role IDs.
RoleIDMap map[string]string
// PermissionIDMap maps old permission IDs to new permission IDs.
PermissionIDMap map[string]string
// WebhookIDMap maps old webhook IDs to new webhook IDs.
WebhookIDMap map[string]string
// RolesCloned is the number of roles cloned.
RolesCloned int
// PermissionsCloned is the number of permissions cloned.
PermissionsCloned int
// WebhooksCloned is the number of webhooks cloned.
WebhooksCloned int
}
CloneResult holds the output of a clone operation.
type CloneSource ¶
type CloneSource interface {
// ListRolesForClone returns all roles in the source environment.
ListRolesForClone(ctx context.Context, appID id.AppID, envID id.EnvironmentID) ([]*RoleForClone, error)
// ListPermissionsForClone returns all permissions for one of the app's roles.
ListPermissionsForClone(ctx context.Context, appID, roleID string) ([]*PermissionForClone, error)
// ListWebhooksForClone returns all webhooks in the source environment.
ListWebhooksForClone(ctx context.Context, appID id.AppID, envID id.EnvironmentID) ([]*WebhookForClone, error)
}
CloneSource provides read access to the entities being cloned. This interface is implemented by the store or service layer.
type CloneTarget ¶
type CloneTarget interface {
// CreateClonedRole creates a role in the target environment.
CreateClonedRole(ctx context.Context, r *RoleForClone) error
// CreateClonedPermission creates a permission in the target environment.
CreateClonedPermission(ctx context.Context, p *PermissionForClone) error
// CreateClonedWebhook creates a webhook in the target environment.
CreateClonedWebhook(ctx context.Context, w *WebhookForClone) error
}
CloneTarget provides write access for creating cloned entities.
type Cloner ¶
type Cloner struct {
// contains filtered or unexported fields
}
Cloner executes environment clone operations.
func NewCloner ¶
func NewCloner(envStore Store, source CloneSource, target CloneTarget) *Cloner
NewCloner creates a new Cloner.
func (*Cloner) Clone ¶
func (c *Cloner) Clone(ctx context.Context, req CloneRequest) (*CloneResult, error)
Clone creates a new environment by cloning config and structure from a source. It clones: roles (with hierarchy), permissions, and webhooks. It does NOT clone: users, sessions, organizations, API keys, or user data.
type Environment ¶
type Environment struct {
ID id.EnvironmentID `json:"id"`
AppID id.AppID `json:"app_id"`
Name string `json:"name"`
Slug string `json:"slug"`
Type Type `json:"type"`
IsDefault bool `json:"is_default"`
Color string `json:"color,omitempty"`
Description string `json:"description,omitempty"`
Settings *Settings `json:"settings,omitempty"`
ClonedFrom id.EnvironmentID `json:"cloned_from,omitempty"`
Metadata Metadata `json:"metadata,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Environment represents an isolated context within an App. Each App has one or more environments. All user-facing entities (users, sessions, organizations, etc.) are scoped to an environment.
type List ¶
type List struct {
Environments []*Environment `json:"environments"`
Total int `json:"total"`
}
List is a list of environments for an app.
type OAuthProviderOverride ¶
type OAuthProviderOverride struct {
ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret,omitempty"`
RedirectURL string `json:"redirect_url,omitempty"`
}
OAuthProviderOverride allows per-environment OAuth credentials.
type PermissionForClone ¶
type PermissionForClone struct {
ID string
AppID string
RoleID string
Action string
Resource string
}
PermissionForClone is a minimal permission representation used during cloning.
type RoleForClone ¶
type RoleForClone struct {
ID string
AppID string
EnvID string
ParentID string
Name string
Slug string
Description string
}
RoleForClone is a minimal role representation used during cloning. This avoids coupling the environment package to rbac or warden types.
type Settings ¶
type Settings struct {
// Auth behavior overrides.
SkipEmailVerification *bool `json:"skip_email_verification,omitempty"`
AllowTestCredentials *bool `json:"allow_test_credentials,omitempty"`
// Session overrides.
TokenTTLSeconds *int `json:"token_ttl_seconds,omitempty"`
RefreshTokenTTLSeconds *int `json:"refresh_token_ttl_seconds,omitempty"`
// TokenExchangeTTLSeconds caps RFC 8693 token exchange for this env.
TokenExchangeTTLSeconds *int `json:"token_exchange_ttl_seconds,omitempty"`
// Password policy overrides.
PasswordMinLength *int `json:"password_min_length,omitempty"`
CheckBreached *bool `json:"check_breached,omitempty"`
// Rate limit overrides.
RateLimitEnabled *bool `json:"rate_limit_enabled,omitempty"`
SignInRateLimit *int `json:"signin_rate_limit,omitempty"`
SignUpRateLimit *int `json:"signup_rate_limit,omitempty"`
RateLimitWindowSecs *int `json:"rate_limit_window_seconds,omitempty"`
// Lockout overrides.
LockoutEnabled *bool `json:"lockout_enabled,omitempty"`
LockoutMaxAttempts *int `json:"lockout_max_attempts,omitempty"`
// Webhook URL override (for dev/staging webhook receivers).
WebhookURLOverride string `json:"webhook_url_override,omitempty"`
// Social/OAuth provider overrides (different client IDs per environment).
OAuthOverrides map[string]OAuthProviderOverride `json:"oauth_overrides,omitempty"`
}
Settings holds per-environment configuration overrides. All fields are pointers so nil means "inherit from the App-level config". Stored as JSONB for schema flexibility.
func DefaultSettingsForType ¶
DefaultSettingsForType returns the default Settings for a given environment type.
func MergeSettings ¶
MergeSettings merges override settings on top of base settings. Non-nil fields in override take precedence. Returns a new Settings.
func (*Settings) AllowTestCredentialsEnabled ¶
AllowTestCredentialsEnabled returns whether test credentials are allowed.
func (*Settings) ApplySessionOverrides ¶
func (s *Settings) ApplySessionOverrides(cfg *account.SessionConfig)
ApplySessionOverrides applies session-related overrides from environment settings onto the given session config. Only non-nil fields are applied.
func (*Settings) IsBreachCheckEnabled ¶
IsBreachCheckEnabled returns whether password breach checking is enabled.
func (*Settings) IsLockoutEnabled ¶
IsLockoutEnabled returns whether account lockout is enabled.
func (*Settings) IsRateLimitEnabled ¶
IsRateLimitEnabled returns whether rate limiting is enabled.
func (*Settings) SkipEmailVerificationEnabled ¶
SkipEmailVerificationEnabled returns whether email verification should be skipped.
type Store ¶
type Store interface {
// CreateEnvironment persists a new environment.
CreateEnvironment(ctx context.Context, e *Environment) error
// GetEnvironment retrieves an environment by ID.
GetEnvironment(ctx context.Context, envID id.EnvironmentID) (*Environment, error)
// GetEnvironmentBySlug retrieves an environment by app ID and slug.
GetEnvironmentBySlug(ctx context.Context, appID id.AppID, slug string) (*Environment, error)
// GetDefaultEnvironment retrieves the default environment for an app.
GetDefaultEnvironment(ctx context.Context, appID id.AppID) (*Environment, error)
// UpdateEnvironment updates an existing environment.
UpdateEnvironment(ctx context.Context, e *Environment) error
// DeleteEnvironment removes an environment by ID.
// Returns an error if the environment is the default for its app.
DeleteEnvironment(ctx context.Context, envID id.EnvironmentID) error
// ListEnvironments returns all environments for an app.
ListEnvironments(ctx context.Context, appID id.AppID) ([]*Environment, error)
// SetDefaultEnvironment sets the given environment as the default for its app,
// clearing the default flag on any previously default environment.
SetDefaultEnvironment(ctx context.Context, appID id.AppID, envID id.EnvironmentID) error
}
Store defines the persistence interface for environment operations.
type Type ¶
type Type string
Type identifies the kind of environment.
func (Type) DefaultColor ¶
DefaultColor returns the default UI badge color for the environment type.
func (Type) DefaultName ¶
DefaultName returns the default display name for the environment type.