access

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrForbidden                 = errors.New("project permission denied")
	ErrInvalidProject            = errors.New("invalid project key")
	ErrInvalidProjectDisplayName = errors.New("project display name must contain 1 to 128 characters")
	ErrProjectDescriptionTooLong = errors.New("project description must not exceed 1000 characters")
	ErrInvalidEnvironment        = errors.New("environment must be one of dev, test, uat, or prod")
	ErrInvalidUsername           = errors.New("invalid username")
	ErrInvalidPermission         = errors.New("invalid project permission")
)
View Source
var EnvironmentDefinitions = []EnvironmentDefinition{
	{Key: "dev", DisplayName: "开发环境", Order: 1},
	{Key: "test", DisplayName: "测试环境", Order: 2},
	{Key: "uat", DisplayName: "预发布环境", Order: 3},
	{Key: "prod", DisplayName: "生产环境", Order: 4},
}

Functions

func EnvironmentName

func EnvironmentName(key string) string

func NormalizeProjectKey

func NormalizeProjectKey(value string) string

NormalizeProjectKey converts a user-facing project label into the restricted identifier required by Kubernetes, Terraform and AWS resource names. Chinese and other non-ASCII characters remain available in Project.DisplayName.

func ValidEnvironment

func ValidEnvironment(value string) bool

func ValidProjectKey

func ValidProjectKey(value string) bool

func ValidUsername

func ValidUsername(value string) bool

Types

type BootstrapEnvironment

type BootstrapEnvironment struct {
	ProjectKey  string
	Environment string
	TargetName  string
	Region      string
}

type EnvironmentDefinition

type EnvironmentDefinition struct {
	Key         string `json:"key"`
	DisplayName string `json:"display_name"`
	Order       int    `json:"order"`
}

type Permission

type Permission struct {
	ProjectKey     string `json:"project_key"`
	Username       string `json:"username,omitempty"`
	CanView        bool   `json:"can_view"`
	CanDeploy      bool   `json:"can_deploy"`
	CanConfigure   bool   `json:"can_configure"`
	CanViewSecrets bool   `json:"can_view_secrets"`
}

type PlatformPermission

type PlatformPermission struct {
	CanManageProjects    bool `json:"can_manage_projects"`
	CanManageUsers       bool `json:"can_manage_users"`
	CanManageCredentials bool `json:"can_manage_credentials"`
	CanManageComponents  bool `json:"can_manage_components"`
	CanViewAudit         bool `json:"can_view_audit"`
}

func FullPlatformPermission

func FullPlatformPermission() PlatformPermission

func (PlatformPermission) Any

func (permission PlatformPermission) Any() bool

type Project

type Project struct {
	Key                      string               `json:"key"`
	DisplayName              string               `json:"display_name"`
	Description              string               `json:"description"`
	SelectedAWSCredentialKey string               `json:"selected_aws_credential_key"`
	Environments             []ProjectEnvironment `json:"environments"`
	Permission               Permission           `json:"permission"`
	CreatedAt                time.Time            `json:"created_at"`
	UpdatedAt                time.Time            `json:"updated_at"`
}

type ProjectEnvironment

type ProjectEnvironment struct {
	ProjectKey         string     `json:"project_key"`
	Environment        string     `json:"environment"`
	DisplayName        string     `json:"display_name"`
	TargetName         string     `json:"target_name"`
	Region             string     `json:"region"`
	LifecycleStatus    string     `json:"lifecycle_status,omitempty"`
	LifecycleDetail    string     `json:"lifecycle_detail,omitempty"`
	LifecycleUpdatedAt *time.Time `json:"lifecycle_updated_at,omitempty"`
	LatestJobID        string     `json:"latest_job_id,omitempty"`
	LatestJobAction    string     `json:"latest_job_action,omitempty"`
	LatestJobStatus    string     `json:"latest_job_status,omitempty"`
	LatestJobProgress  int        `json:"latest_job_progress,omitempty"`
	PhaseOneDeployed   bool       `json:"phase_one_deployed"`
	PhaseTwoDeployed   bool       `json:"phase_two_deployed"`
	CreatedAt          time.Time  `json:"created_at"`
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(store Store) *Service

func (*Service) Bootstrap

func (s *Service) Bootstrap(ctx context.Context, adminUsername, adminHash string, environments []BootstrapEnvironment) error

func (*Service) DeleteEnvironment

func (s *Service) DeleteEnvironment(ctx context.Context, project, environment string) error

func (*Service) DeletePermission

func (s *Service) DeletePermission(ctx context.Context, project, username string) error

func (*Service) DeleteProject

func (s *Service) DeleteProject(ctx context.Context, key string) error

func (*Service) DeleteUser

func (s *Service) DeleteUser(ctx context.Context, username string) error

func (*Service) Environment

func (s *Service) Environment(ctx context.Context, project, environment string) (ProjectEnvironment, error)

func (*Service) GetProject

func (s *Service) GetProject(ctx context.Context, key string) (Project, error)

func (*Service) GetUser

func (s *Service) GetUser(ctx context.Context, username string) (User, error)

func (*Service) ListProjects

func (s *Service) ListProjects(ctx context.Context, username string, isAdmin bool) ([]Project, error)

func (*Service) ListUsers

func (s *Service) ListUsers(ctx context.Context) ([]User, error)

func (*Service) Permission

func (s *Service) Permission(ctx context.Context, username string, isAdmin bool, project string) (Permission, error)

func (*Service) RequireConfigure

func (s *Service) RequireConfigure(ctx context.Context, username string, isAdmin bool, project string) error

func (*Service) RequireDeploy

func (s *Service) RequireDeploy(ctx context.Context, username string, isAdmin bool, project string) error

func (*Service) RequireView

func (s *Service) RequireView(ctx context.Context, username string, isAdmin bool, project string) (Permission, error)

func (*Service) RequireViewSecrets

func (s *Service) RequireViewSecrets(ctx context.Context, username string, isAdmin bool, project string) error

func (*Service) SaveEnvironment

func (s *Service) SaveEnvironment(ctx context.Context, item ProjectEnvironment) error

func (*Service) SavePermission

func (s *Service) SavePermission(ctx context.Context, permission Permission) error

func (*Service) SaveProject

func (s *Service) SaveProject(ctx context.Context, project Project) error

func (*Service) SaveUser

func (s *Service) SaveUser(ctx context.Context, user User) error

type Store

type Store interface {
	EnsureAdmin(context.Context, User) error
	GetUser(context.Context, string) (User, error)
	ListUsers(context.Context) ([]User, error)
	SaveUser(context.Context, User) error
	DeleteUser(context.Context, string) error

	EnsureProject(context.Context, Project) error
	ListProjects(context.Context, string, bool) ([]Project, error)
	GetProject(context.Context, string) (Project, error)
	SaveProject(context.Context, Project) error
	DeleteProject(context.Context, string) error

	ListProjectEnvironments(context.Context, string) ([]ProjectEnvironment, error)
	GetProjectEnvironment(context.Context, string, string) (ProjectEnvironment, error)
	SaveProjectEnvironment(context.Context, ProjectEnvironment) error
	DeleteProjectEnvironment(context.Context, string, string) error

	GetPermission(context.Context, string, string) (Permission, error)
	SavePermission(context.Context, Permission) error
	DeletePermission(context.Context, string, string) error
}

type User

type User struct {
	Username            string             `json:"username"`
	DisplayName         string             `json:"display_name"`
	PasswordHash        string             `json:"-"`
	IsAdmin             bool               `json:"is_admin"`
	Active              bool               `json:"active"`
	PlatformPermissions PlatformPermission `json:"platform_permissions"`
	Permissions         []Permission       `json:"permissions"`
	CreatedAt           time.Time          `json:"created_at"`
	UpdatedAt           time.Time          `json:"updated_at"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL