Documentation
¶
Index ¶
- Constants
- Variables
- func CannotDeleteDefaultEnvironment() *errs.AuthsomeError
- func CannotDeleteProductionEnvironment() *errs.AuthsomeError
- func CannotModifyDefaultEnvironmentType() *errs.AuthsomeError
- func DefaultEnvironmentNotFound(appID string) *errs.AuthsomeError
- func EnvironmentAlreadyExists(name string) *errs.AuthsomeError
- func EnvironmentLimitReached(limit int) *errs.AuthsomeError
- func EnvironmentNotFound(id string) *errs.AuthsomeError
- func EnvironmentSlugAlreadyExists(slug string) *errs.AuthsomeError
- func EnvironmentTypeForbidden(envType string) *errs.AuthsomeError
- func GetEnvironment(ctx context.Context) interface{}
- func GetEnvironmentID(ctx context.Context) (xid.ID, bool)
- func InvalidConfig(reason string) *errs.AuthsomeError
- func InvalidEnvironmentStatus(status string) *errs.AuthsomeError
- func InvalidEnvironmentType(envType string) *errs.AuthsomeError
- func InvalidSlug(slug string) *errs.AuthsomeError
- func PromotionFailed(reason string) *errs.AuthsomeError
- func PromotionInProgress(id string) *errs.AuthsomeError
- func PromotionNotAllowed() *errs.AuthsomeError
- func PromotionNotFound(id string) *errs.AuthsomeError
- func SetEnvironment(ctx context.Context, env interface{}) context.Context
- func SetEnvironmentID(ctx context.Context, envID xid.ID) context.Context
- func SourceEnvironmentNotFound(id string) *errs.AuthsomeError
- func TargetEnvironmentNotFound(id string) *errs.AuthsomeError
- type AppRepository
- type Bootstrap
- type BootstrapConfig
- type Config
- type ContextKey
- type CreateEnvironmentRequest
- type Environment
- type EnvironmentService
- type ListEnvironmentsFilter
- type ListEnvironmentsResponse
- type ListPromotionsFilter
- type ListPromotionsResponse
- type Middleware
- type MiddlewareConfig
- type PromoteEnvironmentRequest
- type Promotion
- type Repository
- type Service
- func (s *Service) CreateDefaultEnvironment(ctx context.Context, appID xid.ID) (*Environment, error)
- func (s *Service) CreateEnvironment(ctx context.Context, req *CreateEnvironmentRequest) (*Environment, error)
- func (s *Service) DeleteEnvironment(ctx context.Context, id xid.ID) error
- func (s *Service) GetDefaultEnvironment(ctx context.Context, appID xid.ID) (*Environment, error)
- func (s *Service) GetEnvironment(ctx context.Context, id xid.ID) (*Environment, error)
- func (s *Service) GetEnvironmentBySlug(ctx context.Context, appID xid.ID, slug string) (*Environment, error)
- func (s *Service) GetPromotion(ctx context.Context, id xid.ID) (*Promotion, error)
- func (s *Service) ListEnvironments(ctx context.Context, filter *ListEnvironmentsFilter) (*ListEnvironmentsResponse, error)
- func (s *Service) ListPromotions(ctx context.Context, filter *ListPromotionsFilter) (*ListPromotionsResponse, error)
- func (s *Service) PromoteEnvironment(ctx context.Context, req *PromoteEnvironmentRequest) (*Promotion, error)
- func (s *Service) UpdateEnvironment(ctx context.Context, id xid.ID, req *UpdateEnvironmentRequest) (*Environment, error)
- type UpdateEnvironmentRequest
Constants ¶
const ( CodeEnvironmentNotFound = "ENVIRONMENT_NOT_FOUND" CodeEnvironmentAlreadyExists = "ENVIRONMENT_ALREADY_EXISTS" CodeEnvironmentSlugAlreadyExists = "ENVIRONMENT_SLUG_ALREADY_EXISTS" CodeDefaultEnvironmentNotFound = "DEFAULT_ENVIRONMENT_NOT_FOUND" CodeCannotDeleteDefaultEnvironment = "CANNOT_DELETE_DEFAULT_ENVIRONMENT" CodeCannotDeleteProductionEnvironment = "CANNOT_DELETE_PRODUCTION_ENVIRONMENT" CodeCannotModifyDefaultEnvironmentType = "CANNOT_MODIFY_DEFAULT_ENVIRONMENT_TYPE" CodeEnvironmentTypeForbidden = "ENVIRONMENT_TYPE_FORBIDDEN" CodeEnvironmentLimitReached = "ENVIRONMENT_LIMIT_REACHED" CodePromotionNotAllowed = "PROMOTION_NOT_ALLOWED" CodePromotionFailed = "PROMOTION_FAILED" CodePromotionNotFound = "PROMOTION_NOT_FOUND" CodePromotionInProgress = "PROMOTION_IN_PROGRESS" CodeInvalidEnvironmentStatus = "INVALID_ENVIRONMENT_STATUS" CodeInvalidEnvironmentType = "INVALID_ENVIRONMENT_TYPE" CodeSourceEnvironmentNotFound = "SOURCE_ENVIRONMENT_NOT_FOUND" CodeTargetEnvironmentNotFound = "TARGET_ENVIRONMENT_NOT_FOUND" CodeInvalidSlug = "INVALID_SLUG" CodeInvalidConfig = "INVALID_CONFIG" )
Variables ¶
var ( ErrEnvironmentNotFound = &errs.AuthsomeError{Code: CodeEnvironmentNotFound} ErrEnvironmentAlreadyExists = &errs.AuthsomeError{Code: CodeEnvironmentAlreadyExists} ErrEnvironmentSlugAlreadyExists = &errs.AuthsomeError{Code: CodeEnvironmentSlugAlreadyExists} ErrDefaultEnvironmentNotFound = &errs.AuthsomeError{Code: CodeDefaultEnvironmentNotFound} ErrCannotDeleteDefaultEnvironment = &errs.AuthsomeError{Code: CodeCannotDeleteDefaultEnvironment} ErrCannotDeleteProductionEnvironment = &errs.AuthsomeError{Code: CodeCannotDeleteProductionEnvironment} ErrCannotModifyDefaultEnvironmentType = &errs.AuthsomeError{Code: CodeCannotModifyDefaultEnvironmentType} ErrEnvironmentTypeForbidden = &errs.AuthsomeError{Code: CodeEnvironmentTypeForbidden} ErrEnvironmentLimitReached = &errs.AuthsomeError{Code: CodeEnvironmentLimitReached} ErrPromotionNotAllowed = &errs.AuthsomeError{Code: CodePromotionNotAllowed} ErrPromotionFailed = &errs.AuthsomeError{Code: CodePromotionFailed} ErrPromotionNotFound = &errs.AuthsomeError{Code: CodePromotionNotFound} ErrPromotionInProgress = &errs.AuthsomeError{Code: CodePromotionInProgress} ErrInvalidEnvironmentStatus = &errs.AuthsomeError{Code: CodeInvalidEnvironmentStatus} ErrInvalidEnvironmentType = &errs.AuthsomeError{Code: CodeInvalidEnvironmentType} ErrSourceEnvironmentNotFound = &errs.AuthsomeError{Code: CodeSourceEnvironmentNotFound} ErrTargetEnvironmentNotFound = &errs.AuthsomeError{Code: CodeTargetEnvironmentNotFound} ErrInvalidSlug = &errs.AuthsomeError{Code: CodeInvalidSlug} ErrInvalidConfig = &errs.AuthsomeError{Code: CodeInvalidConfig} )
Functions ¶
func CannotDeleteDefaultEnvironment ¶
func CannotDeleteDefaultEnvironment() *errs.AuthsomeError
Environment deletion errors
func CannotDeleteProductionEnvironment ¶
func CannotDeleteProductionEnvironment() *errs.AuthsomeError
func CannotModifyDefaultEnvironmentType ¶
func CannotModifyDefaultEnvironmentType() *errs.AuthsomeError
Environment modification errors
func DefaultEnvironmentNotFound ¶
func DefaultEnvironmentNotFound(appID string) *errs.AuthsomeError
func EnvironmentAlreadyExists ¶
func EnvironmentAlreadyExists(name string) *errs.AuthsomeError
func EnvironmentLimitReached ¶
func EnvironmentLimitReached(limit int) *errs.AuthsomeError
func EnvironmentNotFound ¶
func EnvironmentNotFound(id string) *errs.AuthsomeError
Environment CRUD errors
func EnvironmentSlugAlreadyExists ¶
func EnvironmentSlugAlreadyExists(slug string) *errs.AuthsomeError
func EnvironmentTypeForbidden ¶
func EnvironmentTypeForbidden(envType string) *errs.AuthsomeError
func GetEnvironment ¶
GetEnvironment retrieves full environment from context
func GetEnvironmentID ¶
GetEnvironmentID retrieves environment ID from context
func InvalidConfig ¶
func InvalidConfig(reason string) *errs.AuthsomeError
func InvalidEnvironmentStatus ¶
func InvalidEnvironmentStatus(status string) *errs.AuthsomeError
Validation errors
func InvalidEnvironmentType ¶
func InvalidEnvironmentType(envType string) *errs.AuthsomeError
func InvalidSlug ¶
func InvalidSlug(slug string) *errs.AuthsomeError
func PromotionFailed ¶
func PromotionFailed(reason string) *errs.AuthsomeError
func PromotionInProgress ¶
func PromotionInProgress(id string) *errs.AuthsomeError
func PromotionNotFound ¶
func PromotionNotFound(id string) *errs.AuthsomeError
func SetEnvironment ¶
SetEnvironment sets full environment in context
func SetEnvironmentID ¶
SetEnvironmentID sets environment ID in context
func SourceEnvironmentNotFound ¶
func SourceEnvironmentNotFound(id string) *errs.AuthsomeError
func TargetEnvironmentNotFound ¶
func TargetEnvironmentNotFound(id string) *errs.AuthsomeError
Types ¶
type AppRepository ¶
type AppRepository interface {
Count(ctx context.Context) (int, error)
Create(ctx context.Context, app *schema.App) error
FindBySlug(ctx context.Context, slug string) (*schema.App, error)
}
AppRepository defines minimal interface needed for bootstrap
type Bootstrap ¶
type Bootstrap struct {
// contains filtered or unexported fields
}
Bootstrap handles initial app and environment setup
func NewBootstrap ¶
func NewBootstrap(appRepo AppRepository, envRepo Repository, config BootstrapConfig) *Bootstrap
NewBootstrap creates a new bootstrap instance
func (*Bootstrap) EnsureAppEnvironment ¶
func (b *Bootstrap) EnsureAppEnvironment(ctx context.Context, appID xid.ID) (*schema.Environment, error)
EnsureAppEnvironment ensures an app has a default environment
func (*Bootstrap) EnsureDefaultApp ¶
EnsureDefaultApp ensures the default app exists (non-multitenancy mode)
type BootstrapConfig ¶
type BootstrapConfig struct {
DefaultAppName string `json:"defaultAppName"`
DefaultAppSlug string `json:"defaultAppSlug"`
AutoCreateDefaultApp bool `json:"autoCreateDefaultApp"`
MultitenancyEnabled bool `json:"multitenancyEnabled"`
}
BootstrapConfig holds configuration for bootstrap process
type Config ¶
type Config struct {
AutoCreateDev bool `json:"autoCreateDev"`
DefaultDevName string `json:"defaultDevName"`
AllowPromotion bool `json:"allowPromotion"`
RequireConfirmationForDataCopy bool `json:"requireConfirmationForDataCopy"`
MaxEnvironmentsPerApp int `json:"maxEnvironmentsPerApp"`
AllowedTypes []string `json:"allowedTypes"`
}
Config holds the environment service configuration
type ContextKey ¶
type ContextKey string
ContextKey type for environment context keys
const ( // EnvironmentKey is the context key for full environment object EnvironmentKey ContextKey = "environment" )
type CreateEnvironmentRequest ¶
type CreateEnvironmentRequest struct {
AppID xid.ID `json:"appId" validate:"required"`
Name string `json:"name" validate:"required,min=1,max=100"`
Slug string `json:"slug" validate:"required,min=1,max=50,alphanum"`
Type string `json:"type" validate:"required,oneof=development staging production preview test"`
Config map[string]interface{} `json:"config,omitempty"`
}
CreateEnvironmentRequest represents the request to create an environment
type Environment ¶
type Environment struct {
ID xid.ID `json:"id"`
AppID xid.ID `json:"appId"`
Name string `json:"name"`
Slug string `json:"slug"`
Type string `json:"type"`
Status string `json:"status"`
Config map[string]interface{} `json:"config,omitempty"`
IsDefault bool `json:"isDefault"`
// Audit fields
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt *time.Time `json:"deletedAt,omitempty"`
}
Environment represents an environment DTO This is separate from schema.Environment to maintain proper separation of concerns
func FromSchemaEnvironment ¶
func FromSchemaEnvironment(se *schema.Environment) *Environment
FromSchemaEnvironment converts a schema.Environment model to Environment DTO
func FromSchemaEnvironments ¶
func FromSchemaEnvironments(envs []*schema.Environment) []*Environment
FromSchemaEnvironments converts a slice of schema.Environment to Environment DTOs
func (*Environment) IsActive ¶
func (e *Environment) IsActive() bool
IsActive checks if the environment is active
func (*Environment) IsDeleted ¶
func (e *Environment) IsDeleted() bool
IsDeleted checks if the environment is soft-deleted
func (*Environment) IsDevelopment ¶
func (e *Environment) IsDevelopment() bool
IsDevelopment checks if the environment is development
func (*Environment) IsProduction ¶
func (e *Environment) IsProduction() bool
IsProduction checks if the environment is production
func (*Environment) ToSchema ¶
func (e *Environment) ToSchema() *schema.Environment
ToSchema converts the Environment DTO to a schema.Environment model
type EnvironmentService ¶
type EnvironmentService interface {
// Environment operations
CreateEnvironment(ctx context.Context, req *CreateEnvironmentRequest) (*Environment, error)
CreateDefaultEnvironment(ctx context.Context, appID xid.ID) (*Environment, error)
GetEnvironment(ctx context.Context, id xid.ID) (*Environment, error)
GetEnvironmentBySlug(ctx context.Context, appID xid.ID, slug string) (*Environment, error)
GetDefaultEnvironment(ctx context.Context, appID xid.ID) (*Environment, error)
ListEnvironments(ctx context.Context, filter *ListEnvironmentsFilter) (*ListEnvironmentsResponse, error)
UpdateEnvironment(ctx context.Context, id xid.ID, req *UpdateEnvironmentRequest) (*Environment, error)
DeleteEnvironment(ctx context.Context, id xid.ID) error
// Promotion operations
PromoteEnvironment(ctx context.Context, req *PromoteEnvironmentRequest) (*Promotion, error)
GetPromotion(ctx context.Context, id xid.ID) (*Promotion, error)
ListPromotions(ctx context.Context, filter *ListPromotionsFilter) (*ListPromotionsResponse, error)
}
EnvironmentService defines the contract for environment service operations This allows plugins to decorate the service with additional behavior Following the pattern from core/jwt and core/app architecture
type ListEnvironmentsFilter ¶
type ListEnvironmentsFilter struct {
pagination.PaginationParams
AppID xid.ID `json:"appId" query:"app_id"`
Type *string `json:"type,omitempty" query:"type"`
Status *string `json:"status,omitempty" query:"status"`
IsDefault *bool `json:"isDefault,omitempty" query:"is_default"`
}
ListEnvironmentsFilter represents filter parameters for listing environments
type ListEnvironmentsResponse ¶
type ListEnvironmentsResponse = pagination.PageResponse[*Environment]
ListEnvironmentsResponse represents paginated environment response
type ListPromotionsFilter ¶
type ListPromotionsFilter struct {
pagination.PaginationParams
AppID xid.ID `json:"appId" query:"app_id"`
SourceEnvID *xid.ID `json:"sourceEnvId,omitempty" query:"source_env_id"`
TargetEnvID *xid.ID `json:"targetEnvId,omitempty" query:"target_env_id"`
Status *string `json:"status,omitempty" query:"status"`
PromotedBy *xid.ID `json:"promotedBy,omitempty" query:"promoted_by"`
}
ListPromotionsFilter represents filter parameters for listing promotions
type ListPromotionsResponse ¶
type ListPromotionsResponse = pagination.PageResponse[*Promotion]
ListPromotionsResponse represents paginated promotion response
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware extracts environment context from the request
func NewMiddleware ¶
func NewMiddleware(service *Service, config MiddlewareConfig) *Middleware
NewMiddleware creates a new environment middleware
type MiddlewareConfig ¶
type MiddlewareConfig struct {
HeaderName string `json:"headerName"`
QueryParamName string `json:"queryParamName"`
SubdomainEnabled bool `json:"subdomainEnabled"`
DefaultToDevEnv bool `json:"defaultToDevEnv"`
AllowedSubdomains []string `json:"allowedSubdomains"`
}
MiddlewareConfig holds configuration for environment middleware
type PromoteEnvironmentRequest ¶
type PromoteEnvironmentRequest struct {
SourceEnvID xid.ID `json:"sourceEnvId" validate:"required"`
TargetName string `json:"targetName" validate:"required,min=1,max=100"`
TargetSlug string `json:"targetSlug" validate:"required,min=1,max=50,alphanum"`
TargetType string `json:"targetType" validate:"required,oneof=development staging production preview test"`
IncludeData bool `json:"includeData"`
PromotedBy xid.ID `json:"promotedBy" validate:"required"`
Config map[string]interface{} `json:"config,omitempty"`
}
PromoteEnvironmentRequest represents the request to promote an environment
type Promotion ¶
type Promotion struct {
ID xid.ID `json:"id"`
AppID xid.ID `json:"appId"`
SourceEnvID xid.ID `json:"sourceEnvId"`
TargetEnvID xid.ID `json:"targetEnvId"`
PromotedBy xid.ID `json:"promotedBy"`
Status string `json:"status"`
IncludeData bool `json:"includeData"`
ErrorMessage string `json:"errorMessage,omitempty"`
CompletedAt *time.Time `json:"completedAt,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
Promotion represents an environment promotion DTO
func FromSchemaPromotion ¶
func FromSchemaPromotion(sp *schema.EnvironmentPromotion) *Promotion
FromSchemaPromotion converts a schema.EnvironmentPromotion model to Promotion DTO
func FromSchemaPromotions ¶
func FromSchemaPromotions(promotions []*schema.EnvironmentPromotion) []*Promotion
FromSchemaPromotions converts a slice of schema.EnvironmentPromotion to Promotion DTOs
func (*Promotion) IsCompleted ¶
IsCompleted checks if the promotion is completed
func (*Promotion) IsInProgress ¶
IsInProgress checks if the promotion is in progress
func (*Promotion) ToSchema ¶
func (p *Promotion) ToSchema() *schema.EnvironmentPromotion
ToSchema converts the Promotion DTO to a schema.EnvironmentPromotion model
type Repository ¶
type Repository interface {
// Environment CRUD
Create(ctx context.Context, env *schema.Environment) error
FindByID(ctx context.Context, id xid.ID) (*schema.Environment, error)
FindByAppAndSlug(ctx context.Context, appID xid.ID, slug string) (*schema.Environment, error)
FindDefaultByApp(ctx context.Context, appID xid.ID) (*schema.Environment, error)
// ListEnvironments lists environments with pagination and filtering
ListEnvironments(ctx context.Context, filter *ListEnvironmentsFilter) (*pagination.PageResponse[*schema.Environment], error)
// CountByApp counts environments for an app
CountByApp(ctx context.Context, appID xid.ID) (int, error)
Update(ctx context.Context, env *schema.Environment) error
Delete(ctx context.Context, id xid.ID) error
// Promotion operations
CreatePromotion(ctx context.Context, promotion *schema.EnvironmentPromotion) error
FindPromotionByID(ctx context.Context, id xid.ID) (*schema.EnvironmentPromotion, error)
// ListPromotions lists promotions with pagination and filtering
ListPromotions(ctx context.Context, filter *ListPromotionsFilter) (*pagination.PageResponse[*schema.EnvironmentPromotion], error)
UpdatePromotion(ctx context.Context, promotion *schema.EnvironmentPromotion) error
}
Repository defines the interface for environment data access This follows the Interface Segregation Principle from core/app and core/jwt architecture
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service handles environment-related business logic
func NewService ¶
func NewService(repo Repository, config Config) *Service
NewService creates a new environment service
func (*Service) CreateDefaultEnvironment ¶
CreateDefaultEnvironment creates the default dev environment for an app
func (*Service) CreateEnvironment ¶
func (s *Service) CreateEnvironment(ctx context.Context, req *CreateEnvironmentRequest) (*Environment, error)
CreateEnvironment creates a new environment
func (*Service) DeleteEnvironment ¶
DeleteEnvironment deletes an environment
func (*Service) GetDefaultEnvironment ¶
GetDefaultEnvironment retrieves the default environment for an app
func (*Service) GetEnvironment ¶
GetEnvironment retrieves an environment by ID
func (*Service) GetEnvironmentBySlug ¶
func (s *Service) GetEnvironmentBySlug(ctx context.Context, appID xid.ID, slug string) (*Environment, error)
GetEnvironmentBySlug retrieves an environment by app and slug
func (*Service) GetPromotion ¶
GetPromotion retrieves a promotion by ID
func (*Service) ListEnvironments ¶
func (s *Service) ListEnvironments(ctx context.Context, filter *ListEnvironmentsFilter) (*ListEnvironmentsResponse, error)
ListEnvironments lists environments for an app with pagination
func (*Service) ListPromotions ¶
func (s *Service) ListPromotions(ctx context.Context, filter *ListPromotionsFilter) (*ListPromotionsResponse, error)
ListPromotions lists promotions for an app with pagination
func (*Service) PromoteEnvironment ¶
func (s *Service) PromoteEnvironment(ctx context.Context, req *PromoteEnvironmentRequest) (*Promotion, error)
PromoteEnvironment promotes/clones one environment to another
func (*Service) UpdateEnvironment ¶
func (s *Service) UpdateEnvironment(ctx context.Context, id xid.ID, req *UpdateEnvironmentRequest) (*Environment, error)
UpdateEnvironment updates an environment
type UpdateEnvironmentRequest ¶
type UpdateEnvironmentRequest struct {
Name *string `json:"name,omitempty" validate:"omitempty,min=1,max=100"`
Status *string `json:"status,omitempty" validate:"omitempty,oneof=active inactive maintenance"`
Config map[string]interface{} `json:"config,omitempty"`
Type *string `json:"type,omitempty" validate:"omitempty,oneof=development staging production preview test"`
}
UpdateEnvironmentRequest represents the request to update an environment