service

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package service 实现 FlowLink 控制面的用例编排、权限检查和领域规则。

service 依赖 repository、auth、core 和 engine 抽象,但不直接依赖 Gin。

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrWorkspaceAlreadyJoined 表示申请人已经是工作空间成员。
	ErrWorkspaceAlreadyJoined = errors.New("user is already a workspace member")
	// ErrWorkspaceJoinPending 表示申请人已经有一张待处理的加入申请。
	ErrWorkspaceJoinPending = errors.New("workspace join request is already pending")
)
View Source
var (
	// ErrWorkflowRepositoryRequired 表示 workflow 管理服务缺少仓储。
	ErrWorkflowRepositoryRequired = errors.New("workflow repository is required")
	// ErrWorkflowValidatorRequired 表示 workflow 管理服务缺少校验器。
	ErrWorkflowValidatorRequired = errors.New("workflow validator is required")
	// ErrWorkflowProgressRepositoryRequired 表示启用环境流水线时缺少推进状态仓储。
	ErrWorkflowProgressRepositoryRequired = errors.New("workflow progress repository is required")
)
View Source
var ErrAdminRepositoryRequired = errors.New("admin repository is required")

ErrAdminRepositoryRequired 表示平台管理服务缺少仓储。

View Source
var ErrApprovalAlreadyFinished = errors.New("approval request is already finished")

ErrApprovalAlreadyFinished 表示审批单已经结束,不能重复处理。

View Source
var ErrApprovalForbidden = errors.New("current user is not allowed to judge this approval")

ErrApprovalForbidden 表示当前用户不能处理该审批单。

View Source
var ErrApprovalRepositoryRequired = errors.New("approval repository is required")

ErrApprovalRepositoryRequired 表示审批服务缺少仓储。

View Source
var ErrEnvironmentReferenceRepositoryRequired = errors.New("environment reference repository is required")

ErrEnvironmentReferenceRepositoryRequired 表示环境删除缺少引用查询能力。

View Source
var ErrInvalidCredentials = errors.New("invalid username or password")

ErrInvalidCredentials 表示用户名或密码不匹配。

View Source
var ErrPasswordMismatch = errors.New("old password does not match")

ErrPasswordMismatch 表示修改密码时旧密码不匹配。

View Source
var ErrSystemRoleImmutable = errors.New("system role cannot be modified")

ErrSystemRoleImmutable 表示系统角色不允许修改。

View Source
var ErrTraceIDRequired = errors.New("trace id is required")

ErrTraceIDRequired 表示事件查询缺少 trace ID。

View Source
var ErrTraceRepositoryRequired = errors.New("trace repository is required")

ErrTraceRepositoryRequired 表示 trace 服务缺少仓储。

View Source
var ErrUserDisabled = errors.New("user is disabled")

ErrUserDisabled 表示用户账号已被禁用。

View Source
var ErrUsernameAlreadyExists = errors.New("username already exists")

ErrUsernameAlreadyExists 表示注册用户名已存在。

View Source
var ErrWorkerWorkflowRepositoryRequired = errors.New("worker workflow repository is required")

ErrWorkerWorkflowRepositoryRequired 表示 worker 拉取服务缺少 workflow 仓储。

View Source
var ErrWorkflowRunnerRequired = errors.New("workflow runner is required")

ErrWorkflowRunnerRequired 表示 workflow 执行服务缺少 runner。

View Source
var ErrWorkflowSecretResolution = errors.New("workflow secret reference cannot be resolved")

Functions

func SeedDefaultPermissions

func SeedDefaultPermissions(ctx context.Context, permissions repository.PermissionRepository, roles repository.RoleRepository, workspace string) error

SeedDefaultPermissions 初始化工作空间默认权限并刷新 super_admin 角色。

Types

type ApplyWorkspaceJoinRequest

type ApplyWorkspaceJoinRequest struct {
	Workspace string `json:"workspace"`
	Reason    string `json:"reason"`
}

ApplyWorkspaceJoinRequest 是用户申请加入工作空间的请求。

type ApprovalHandler

type ApprovalHandler interface {
	ExecuteApproved(ctx context.Context, request *admin.ApprovalRequest) error
}

ApprovalHandler 是审批通过后执行具体领域动作的扩展点。

type ApprovalJudgedHandler

type ApprovalJudgedHandler interface {
	ExecuteJudged(ctx context.Context, request *admin.ApprovalRequest, status admin.ApprovalStatus) error
}

ApprovalJudgedHandler 是审批单状态落定后的可选扩展点。

type ApprovalListRequest

type ApprovalListRequest struct {
	Workspace  string                   `json:"workspace"`
	ObjectType admin.ApprovalObjectType `json:"objectType"`
	Status     admin.ApprovalStatus     `json:"status"`
	Keyword    string                   `json:"keyword"`
	Offset     int                      `json:"offset"`
	Limit      int                      `json:"limit"`
}

ApprovalListRequest 是查询审批单列表的 service 请求。

type ApprovalService

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

ApprovalService 实现审批提交、查询、处理和通过后回调。

func NewApprovalService

func NewApprovalService(approvals repository.ApprovalRepository, checker auth.PermissionChecker) *ApprovalService

NewApprovalService 创建审批服务。

func (*ApprovalService) AllRequests

func (*ApprovalService) ApplyWorkspaceJoin

ApplyWorkspaceJoin 校验成员关系和重复申请后创建加入工作空间审批。

func (*ApprovalService) Detail

func (s *ApprovalService) Detail(ctx context.Context, workspace string, requestID string) (*admin.ApprovalRequest, error)

func (*ApprovalService) Judge

func (*ApprovalService) MyRequests

func (*ApprovalService) PendingForMe

func (*ApprovalService) RegisterNode

func (s *ApprovalService) RegisterNode(objectType admin.ApprovalObjectType, node ApprovalHandler)

func (*ApprovalService) Submit

func (*ApprovalService) UseWorkspaceJoinRepositories

func (s *ApprovalService) UseWorkspaceJoinRepositories(
	workspaces repository.WorkspaceRepository,
	members repository.WorkspaceMemberRepository,
) *ApprovalService

UseWorkspaceJoinRepositories 安装加入工作空间所需的查询仓储。

type ApprovalSubmittedHandler

type ApprovalSubmittedHandler interface {
	ExecuteSubmitted(ctx context.Context, request *admin.ApprovalRequest) error
}

ApprovalSubmittedHandler 是审批单创建后的可选扩展点。

type AuthService

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

AuthService 实现登录、注册、令牌解析和当前用户信息查询。

func NewAuthService

NewAuthService 创建认证服务。

func (*AuthService) CurrentUserPayload

func (s *AuthService) CurrentUserPayload(ctx context.Context, principal *auth.Principal) (map[string]interface{}, error)

func (*AuthService) Login

func (s *AuthService) Login(ctx context.Context, req *LoginRequest) (map[string]interface{}, error)

func (*AuthService) Parse

func (s *AuthService) Parse(ctx context.Context, tokenString string) (*auth.Principal, error)

func (*AuthService) RefreshToken

func (s *AuthService) RefreshToken(ctx context.Context, principal *auth.Principal, req *RefreshTokenRequest) (map[string]interface{}, error)

func (*AuthService) Register

func (s *AuthService) Register(ctx context.Context, req *LoginRequest) (map[string]interface{}, error)

type CloneWorkflowRequest

type CloneWorkflowRequest struct {
	Env              string `json:"env"`
	Workspace        string `json:"workspace"`
	SourceWorkflowID string `json:"sourceWorkflowId"`
	SourceVersion    string `json:"sourceVersion"`
	TargetWorkflowID string `json:"targetWorkflowId"`
	TargetName       string `json:"targetName"`
	TargetVersion    string `json:"targetVersion"`
	Description      string `json:"description"`
}

CloneWorkflowRequest 用于从任意版本复制出一个新的可编辑版本。

type CompareWorkflowVersionRequest

type CompareWorkflowVersionRequest struct {
	Env          string `json:"env"`
	Workspace    string `json:"workspace"`
	WorkflowID   string `json:"workflowId"`
	LeftVersion  string `json:"leftVersion"`
	RightVersion string `json:"rightVersion"`
}

type DeleteWorkflowRequest

type DeleteWorkflowRequest struct {
	Env        string `json:"env"`
	Workspace  string `json:"workspace"`
	WorkflowID string `json:"workflowId"`
	Version    string `json:"version"`
}

type DisableWorkflowRequest

type DisableWorkflowRequest struct {
	Env        string `json:"env"`
	Workspace  string `json:"workspace"`
	WorkflowID string `json:"workflowId"`
	Version    string `json:"version"`
}

type ExecuteWorkflowRequest

type ExecuteWorkflowRequest struct {
	Env        string         `json:"env"`
	Workspace  string         `json:"workspace"`
	WorkflowID string         `json:"workflowId"`
	Version    string         `json:"version"`
	Envelope   *core.Envelope `json:"envelope"`
}

type GetPublishedWorkflowRequest

type GetPublishedWorkflowRequest struct {
	Env        string `json:"env"`
	Workspace  string `json:"workspace"`
	WorkflowID string `json:"workflowId"`
	Version    string `json:"version"`
}

type GetWorkflowVersionRequest

type GetWorkflowVersionRequest struct {
	Env        string `json:"env"`
	Workspace  string `json:"workspace"`
	WorkflowID string `json:"workflowId"`
	Version    string `json:"version"`
}

type JudgeApprovalRequest

type JudgeApprovalRequest struct {
	Workspace string               `json:"workspace"`
	RequestID string               `json:"requestId"`
	Status    admin.ApprovalStatus `json:"status"`
	Comment   string               `json:"comment"`
}

JudgeApprovalRequest 是审批处理的 service 请求。

type LoginRequest

type LoginRequest struct {
	Username  string `json:"username"`
	Password  string `json:"password"`
	AutoLogin bool   `json:"autoLogin"`
}

LoginRequest 是注册和登录请求。

type PlatformAdminService

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

PlatformAdminService 实现工作空间、用户、角色、权限、成员和审计管理用例。

func NewPlatformAdminService

NewPlatformAdminService 创建平台管理服务。

func (*PlatformAdminService) AddMember

func (s *PlatformAdminService) AddMember(ctx context.Context, member *admin.WorkspaceMember) error

func (*PlatformAdminService) ChangePassword

func (s *PlatformAdminService) ChangePassword(ctx context.Context, oldPassword string, newPassword string) error

func (*PlatformAdminService) CreatePermission

func (s *PlatformAdminService) CreatePermission(ctx context.Context, permission *admin.Permission) error

func (*PlatformAdminService) CreateRole

func (s *PlatformAdminService) CreateRole(ctx context.Context, role *admin.Role) error

func (*PlatformAdminService) CreateUser

func (s *PlatformAdminService) CreateUser(ctx context.Context, user *admin.User) error

func (*PlatformAdminService) CreateWorkspace

func (s *PlatformAdminService) CreateWorkspace(ctx context.Context, workspace *admin.Workspace) error

func (*PlatformAdminService) DeleteRole

func (s *PlatformAdminService) DeleteRole(ctx context.Context, workspace string, roleID string) error

func (*PlatformAdminService) DeleteWorkspaceEnvironment

func (s *PlatformAdminService) DeleteWorkspaceEnvironment(ctx context.Context, workspace string, env string) error

func (*PlatformAdminService) ListAuditLogs

func (s *PlatformAdminService) ListAuditLogs(ctx context.Context, workspace string, resource string, resourceID string, offset int, limit int) ([]*repository.AuditLog, int64, error)

func (*PlatformAdminService) ListMembers

func (s *PlatformAdminService) ListMembers(ctx context.Context, workspace string, offset int, limit int) ([]*admin.WorkspaceMember, int64, error)

func (*PlatformAdminService) ListPermissions

func (s *PlatformAdminService) ListPermissions(ctx context.Context, query *repository.PermissionQuery) ([]*admin.Permission, int64, error)

func (*PlatformAdminService) ListRoles

func (s *PlatformAdminService) ListRoles(ctx context.Context, query *repository.RoleQuery) ([]*admin.Role, int64, error)

func (*PlatformAdminService) ListUsers

func (s *PlatformAdminService) ListUsers(ctx context.Context, query *repository.UserQuery) ([]*admin.User, int64, error)

func (*PlatformAdminService) ListWorkspaceEnvironments

func (*PlatformAdminService) ListWorkspaces

func (s *PlatformAdminService) ListWorkspaces(ctx context.Context, query *repository.WorkspaceQuery) ([]*admin.Workspace, int64, error)

func (*PlatformAdminService) RemoveMember

func (s *PlatformAdminService) RemoveMember(ctx context.Context, workspace string, userID string) error

func (*PlatformAdminService) ResetUserPassword

func (s *PlatformAdminService) ResetUserPassword(ctx context.Context, userID string, password string) error

func (*PlatformAdminService) SaveWorkspaceEnvironment

func (s *PlatformAdminService) SaveWorkspaceEnvironment(ctx context.Context, env *admin.WorkspaceEnvironment) error

func (*PlatformAdminService) SetUserDisabled

func (s *PlatformAdminService) SetUserDisabled(ctx context.Context, userID string, disabled bool) error

func (*PlatformAdminService) UpdateMemberRoles

func (s *PlatformAdminService) UpdateMemberRoles(ctx context.Context, workspace string, userID string, roleIDs []string) error

func (*PlatformAdminService) UpdatePermission

func (s *PlatformAdminService) UpdatePermission(ctx context.Context, permission *admin.Permission) error

func (*PlatformAdminService) UpdateRole

func (s *PlatformAdminService) UpdateRole(ctx context.Context, role *admin.Role) error

func (*PlatformAdminService) UpdateWorkspace

func (s *PlatformAdminService) UpdateWorkspace(ctx context.Context, workspace *admin.Workspace) error

func (*PlatformAdminService) UseEnvironmentReferenceRepository

UseEnvironmentReferenceRepository 启用环境删除前的领域引用校验。

func (*PlatformAdminService) UseEnvironmentRepository

UseEnvironmentRepository 启用工作空间环境管理能力。

type PublishWorkflowRequest

type PublishWorkflowRequest struct {
	Env        string `json:"env"`
	Workspace  string `json:"workspace"`
	WorkflowID string `json:"workflowId"`
	Version    string `json:"version"`
	Remark     string `json:"remark"`
}

PublishWorkflowRequest 中的 Version 是要发布的明确版本号。

type RefreshTokenRequest

type RefreshTokenRequest struct {
	UserID          string `json:"userId"`
	SelectNamespace string `json:"selectNamespace"`
}

RefreshTokenRequest 是刷新令牌或切换命名空间的请求。

type RollbackWorkflowRequest

type RollbackWorkflowRequest struct {
	Env           string `json:"env"`
	Workspace     string `json:"workspace"`
	WorkflowID    string `json:"workflowId"`
	Version       string `json:"version"`
	TargetVersion string `json:"targetVersion"`
}

RollbackWorkflowRequest 从 Version 复制定义并创建可编辑的 TargetVersion,不修改历史版本。

type SaveWorkflowRequest

type SaveWorkflowRequest struct {
	Workflow *core.Workflow `json:"workflow"`
}

type SubmitApprovalRequest

type SubmitApprovalRequest struct {
	Workspace   string                   `json:"workspace"`
	ObjectType  admin.ApprovalObjectType `json:"objectType"`
	ObjectID    string                   `json:"objectId"`
	Title       string                   `json:"title"`
	Reason      string                   `json:"reason"`
	Attrs       map[string]interface{}   `json:"attrs"`
	ApproverIDs []string                 `json:"approverIds"`
}

SubmitApprovalRequest 是提交审批单的 service 请求。

type TraceAdminService

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

TraceAdminService 实现 trace 查询用例。

func NewTraceAdminService

func NewTraceAdminService(traceRepo repository.TraceRepository, checker auth.PermissionChecker) *TraceAdminService

func (*TraceAdminService) GetEvents

func (*TraceAdminService) Search

type WorkerBootstrapRequest

type WorkerBootstrapRequest = workerpull.WorkerBootstrapRequest

type WorkerPublishedWorkflowRequest

type WorkerPublishedWorkflowRequest = workerpull.WorkerPublishedWorkflowRequest

type WorkerPullService

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

WorkerPullService 实现业务 worker 拉取发布 workflow 的控制面用例。

func NewWorkerPullService

func NewWorkerPullService(workflowRepo repository.WorkflowRepository) *WorkerPullService

func (*WorkerPullService) Bootstrap

func (*WorkerPullService) GetPublished

func (s *WorkerPullService) GetPublished(ctx context.Context, req *WorkerPublishedWorkflowRequest) (*core.Workflow, error)

type WorkflowAdminService

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

WorkflowAdminService 承担控制面的 workflow 生命周期用例。 它只编排权限、校验、仓储和审计,不执行 workflow。

func NewWorkflowAdminService

func NewWorkflowAdminService(
	workflowRepo repository.WorkflowRepository,
	validator WorkflowValidator,
	checker auth.PermissionChecker,
	auditLogs ...repository.AuditLogRepository,
) *WorkflowAdminService

func (*WorkflowAdminService) ClearPublishPending

func (s *WorkflowAdminService) ClearPublishPending(ctx context.Context, req *PublishWorkflowRequest) error

ClearPublishPending 在发布审批被拒绝或取消时释放 pending 环境。

func (*WorkflowAdminService) Clone

func (s *WorkflowAdminService) Clone(ctx context.Context, req *CloneWorkflowRequest) (*core.Workflow, error)

func (*WorkflowAdminService) CompareVersions

func (*WorkflowAdminService) Delete

func (*WorkflowAdminService) Disable

func (*WorkflowAdminService) GetPublished

func (s *WorkflowAdminService) GetPublished(ctx context.Context, req *GetPublishedWorkflowRequest) (*core.Workflow, error)

func (*WorkflowAdminService) GetVersion

func (s *WorkflowAdminService) GetVersion(ctx context.Context, req *GetWorkflowVersionRequest) (*core.WorkflowVersion, error)

func (*WorkflowAdminService) List

func (s *WorkflowAdminService) List(ctx context.Context, query *repository.WorkflowQuery) ([]*core.WorkflowVersion, int64, error)

func (*WorkflowAdminService) ListView

ListView 查询 workflow 列表并附加环境推进视图。

func (*WorkflowAdminService) MarkPublishApproved

func (s *WorkflowAdminService) MarkPublishApproved(ctx context.Context, req *PublishWorkflowRequest) error

MarkPublishApproved 只记录发布授权;真正发布仍需用户再次调用 Publish。

func (*WorkflowAdminService) MarkPublishPending

func (s *WorkflowAdminService) MarkPublishPending(ctx context.Context, req *PublishWorkflowRequest) error

MarkPublishPending 记录 workflow 发布审批正在等待的目标环境。

func (*WorkflowAdminService) Publish

func (s *WorkflowAdminService) Publish(ctx context.Context, req *PublishWorkflowRequest) (*core.WorkflowVersion, error)

Publish 会先读取未发布版本并做协议规范化、校验,然后把规范化定义回写再发布。

func (*WorkflowAdminService) Rollback

func (*WorkflowAdminService) Save

func (*WorkflowAdminService) UseEnvironmentRepository

UseEnvironmentRepository 启用 workspace 环境流水线。 未注入时,workflow 发布保持旧的单环境语义,便于测试和轻量用法继续工作。

func (*WorkflowAdminService) UseProgressRepository

UseProgressRepository 启用 workflow 版本推进状态记录。

func (*WorkflowAdminService) UseSecretCodec

UseSecretCodec enables password-to-secretRef conversion for persisted workflow definitions.

func (*WorkflowAdminService) ValidateWorkflow

func (s *WorkflowAdminService) ValidateWorkflow(ctx context.Context, workflow *core.Workflow) error

type WorkflowApprovalHandler

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

WorkflowApprovalHandler 处理 workflow 发布授权、停用和回滚审批动作。

func NewWorkflowApprovalHandler

func NewWorkflowApprovalHandler(workflow *WorkflowAdminService) *WorkflowApprovalHandler

NewWorkflowApprovalHandler 创建 workflow 审批执行器。

func (*WorkflowApprovalHandler) ExecuteApproved

func (e *WorkflowApprovalHandler) ExecuteApproved(ctx context.Context, request *admin.ApprovalRequest) error

func (*WorkflowApprovalHandler) ExecuteJudged

func (e *WorkflowApprovalHandler) ExecuteJudged(ctx context.Context, request *admin.ApprovalRequest, status admin.ApprovalStatus) error

func (*WorkflowApprovalHandler) ExecuteSubmitted

func (e *WorkflowApprovalHandler) ExecuteSubmitted(ctx context.Context, request *admin.ApprovalRequest) error

type WorkflowCanonicalizer

type WorkflowCanonicalizer interface {
	CanonicalizeWorkflow(workflow *core.Workflow) *core.Workflow
}

WorkflowCanonicalizer 是可选能力;实现方可在保存/发布前规范化 workflow。

type WorkflowExecutionResult

type WorkflowExecutionResult = runtime.ExecutionReport

WorkflowExecutionResult 是 workflow 执行服务返回的执行报告。

type WorkflowExecutionService

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

WorkflowExecutionService 实现 workflow 发布版本执行用例。

func (*WorkflowExecutionService) ExecutePublished

func (*WorkflowExecutionService) UseSecretCodec

UseSecretCodec enables in-process resolution of persisted workflow secretRefs.

type WorkflowValidator

type WorkflowValidator interface {
	Validate(ctx context.Context, workflow *core.Workflow) []*schema.ValidationError
}

WorkflowValidator 是管理服务需要的最小校验接口,避免直接依赖 plan.Assembly。

type WorkflowVersionCompare

type WorkflowVersionCompare struct {
	Left  *core.WorkflowVersion `json:"left"`
	Right *core.WorkflowVersion `json:"right"`
}

type WorkflowVersionView

type WorkflowVersionView struct {
	*core.WorkflowVersion
	Environments            []*admin.WorkspaceEnvironment `json:"environments,omitempty"`
	Progress                *admin.WorkflowProgress       `json:"progress,omitempty"`
	CurrentEnv              string                        `json:"currentEnv,omitempty"`
	PendingEnv              string                        `json:"pendingEnv,omitempty"`
	ApprovalStatus          admin.ApprovalStatus          `json:"approvalStatus,omitempty"`
	NextEnv                 *admin.WorkspaceEnvironment   `json:"nextEnv,omitempty"`
	CanPublish              bool                          `json:"canPublish"`
	PublishRequiresApproval bool                          `json:"publishRequiresApproval"`
	PublishBlockedReason    string                        `json:"publishBlockedReason,omitempty"`
}

WorkflowVersionView 是控制台列表使用的 workflow 版本视图。 它在 core.WorkflowVersion 之外补充环境推进信息,不改变 runtime 协议。

type WorkspaceJoinApprovalHandler

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

WorkspaceJoinApprovalHandler 在审批通过后执行加入工作空间动作。

func NewWorkspaceJoinApprovalHandler

func NewWorkspaceJoinApprovalHandler(platform *PlatformAdminService) *WorkspaceJoinApprovalHandler

NewWorkspaceJoinApprovalHandler 创建工作空间加入审批执行器。

func (*WorkspaceJoinApprovalHandler) ExecuteApproved

func (e *WorkspaceJoinApprovalHandler) ExecuteApproved(ctx context.Context, request *admin.ApprovalRequest) error

Jump to

Keyboard shortcuts

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