gitlab

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: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalid  = errors.New("GitLab 配置不合法")
	ErrNotFound = errors.New("GitLab 配置不存在")
	ErrConflict = errors.New("GitLab 交付仓库冲突")
	ErrRequest  = errors.New("GitLab 请求失败")
)

Functions

This section is empty.

Types

type GeneratedFile

type GeneratedFile struct {
	Repository string `json:"repository"`
	Path       string `json:"path"`
	Content    string `json:"content"`
}

type Preview

type Preview struct {
	ProjectKey   string           `json:"project_key"`
	Repositories []RepositoryPlan `json:"repositories"`
	Files        []GeneratedFile  `json:"files"`
}

type ProjectDelivery

type ProjectDelivery struct {
	ProjectKey              string        `json:"project_key"`
	ServerKey               string        `json:"server_key"`
	RootGroup               string        `json:"root_group"`
	SourceServerKey         string        `json:"source_server_key,omitempty"`
	SourceRootGroup         string        `json:"source_root_group,omitempty"`
	DefaultBranch           string        `json:"default_branch"`
	JenkinsfilesProjectID   int64         `json:"jenkinsfiles_project_id,omitempty"`
	JenkinsfilesProjectPath string        `json:"jenkinsfiles_project_path"`
	JenkinsfilesCloneURL    string        `json:"jenkinsfiles_clone_url,omitempty"`
	ManifestsProjectID      int64         `json:"manifests_project_id,omitempty"`
	ManifestsProjectPath    string        `json:"manifests_project_path"`
	ManifestsCloneURL       string        `json:"manifests_clone_url,omitempty"`
	Services                []ServiceSpec `json:"services"`
	ProvisionStatus         string        `json:"provision_status,omitempty"`
	ProvisionError          string        `json:"provision_error,omitempty"`
	LastProvisionedAt       time.Time     `json:"last_provisioned_at,omitempty"`
	CreatedAt               time.Time     `json:"created_at"`
	UpdatedAt               time.Time     `json:"updated_at"`
}

type ProvisionResult

type ProvisionResult struct {
	Delivery     ProjectDelivery  `json:"delivery"`
	Repositories []RepositoryPlan `json:"repositories"`
	CreatedFiles int              `json:"created_files"`
	UpdatedFiles int              `json:"updated_files"`
	DeletedFiles int              `json:"deleted_files"`
}

type RepositoryEndpoints

type RepositoryEndpoints struct {
	ProjectID   int64  `json:"project_id"`
	ProjectPath string `json:"project_path"`
	HTTPS       string `json:"https"`
	SSH         string `json:"ssh"`
}

type RepositoryPlan

type RepositoryPlan struct {
	Kind        string `json:"kind"`
	Name        string `json:"name"`
	ProjectPath string `json:"project_path"`
	CloneURL    string `json:"clone_url,omitempty"`
	Exists      bool   `json:"exists"`
	Managed     bool   `json:"managed"`
}

type SecretKeyReference

type SecretKeyReference struct {
	SecretName string `json:"secret_name"`
	SecretKey  string `json:"secret_key"`
}

SecretKeyReference points at an existing Kubernetes Secret. The platform persists only this reference; the secret value never enters MySQL, GitLab, Jenkins parameters, generated files, or build logs.

type Server

type Server struct {
	Key               string    `json:"key"`
	DisplayName       string    `json:"display_name"`
	BaseURL           string    `json:"base_url"`
	RootGroup         string    `json:"root_group"`
	RootGroups        []string  `json:"root_groups"`
	DefaultBranch     string    `json:"default_branch"`
	Visibility        string    `json:"visibility"`
	AllowInsecureHTTP bool      `json:"allow_insecure_http"`
	Configured        bool      `json:"configured"`
	LastCheckStatus   string    `json:"last_check_status,omitempty"`
	LastCheckError    string    `json:"last_check_error,omitempty"`
	LastCheckedAt     time.Time `json:"last_checked_at,omitempty"`
	CreatedAt         time.Time `json:"created_at"`
	UpdatedAt         time.Time `json:"updated_at"`
}

type ServerAliasCheck

type ServerAliasCheck struct {
	BaseURL                string `json:"base_url"`
	Authenticated          bool   `json:"authenticated"`
	JenkinsfilesProjectID  int64  `json:"jenkinsfiles_project_id,omitempty"`
	JenkinsfilesCloneURL   string `json:"jenkinsfiles_clone_url,omitempty"`
	ManifestsProjectID     int64  `json:"manifests_project_id,omitempty"`
	ManifestsCloneURL      string `json:"manifests_clone_url,omitempty"`
	MatchesCurrentProjects bool   `json:"matches_current_projects"`
}

type ServerInput

type ServerInput struct {
	Key               string   `json:"key"`
	DisplayName       string   `json:"display_name"`
	BaseURL           string   `json:"base_url"`
	AccessToken       string   `json:"access_token"`
	RootGroup         string   `json:"root_group"`
	RootGroups        []string `json:"root_groups"`
	DefaultBranch     string   `json:"default_branch"`
	Visibility        string   `json:"visibility"`
	AllowInsecureHTTP bool     `json:"allow_insecure_http"`
}

type Service

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

func New

func New(config *appconfig.Config, store Store) (*Service, error)

func (*Service) Activate

func (s *Service) Activate(ctx context.Context, project string, input ProjectDelivery) (ProvisionResult, error)

Activate saves the project bindings and provisions the delivery repository in one API operation. A failed GitLab write intentionally keeps the validated binding and failed status so the same request can be retried without re-entering configuration.

func (*Service) CheckServerAlias

func (s *Service) CheckServerAlias(ctx context.Context, project, rawBaseURL string) (ServerAliasCheck, error)

CheckServerAlias verifies that an alternate public hostname reaches the same GitLab repositories using the already encrypted server token. It does not persist the alias or expose the token.

func (*Service) CheckSourceRepositoryFile

func (s *Service) CheckSourceRepositoryFile(ctx context.Context, project string, projectID int64, branch, path string) (SourceFileCheck, error)

func (*Service) DeleteServer

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

func (*Service) DeliveryRepositoryEndpoints

func (s *Service) DeliveryRepositoryEndpoints(ctx context.Context, project string) ([]RepositoryEndpoints, error)

DeliveryRepositoryEndpoints returns clone endpoints reported by GitLab for the two project-owned delivery repositories. It contains no credentials.

func (*Service) DetachDelivery

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

func (*Service) EnsureSourceRepository

func (s *Service) EnsureSourceRepository(ctx context.Context, project, serviceKey string, files []SourceFile) (SourceRepositoryResult, error)

EnsureSourceRepository creates or updates one platform-owned source repository without ever taking over an unrelated GitLab project. Existing repositories must contain a matching ownership marker before files can be changed.

func (*Service) GetDelivery

func (s *Service) GetDelivery(ctx context.Context, project string) (ProjectDelivery, error)

func (*Service) ListServers

func (s *Service) ListServers(ctx context.Context) ([]Server, error)

func (*Service) ListSourceRepositories

func (s *Service) ListSourceRepositories(ctx context.Context, project, search string) ([]SourceRepositoryOption, error)

func (*Service) ListSourceRepositoryBranches

func (s *Service) ListSourceRepositoryBranches(ctx context.Context, project string, projectID int64) ([]SourceBranchOption, error)

func (*Service) Preview

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

func (*Service) ProjectDeletionBlocker

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

func (*Service) Provision

func (s *Service) Provision(ctx context.Context, project string) (result ProvisionResult, resultErr error)

func (*Service) RelayCloneTarget

func (s *Service) RelayCloneTarget(ctx context.Context, project, kind, serviceKey string) (string, error)

RelayCloneTarget resolves only repositories already owned or registered by the selected project. It never accepts an arbitrary upstream URL.

func (*Service) SaveDelivery

func (s *Service) SaveDelivery(ctx context.Context, project string, input ProjectDelivery) (ProjectDelivery, error)

func (*Service) SaveServer

func (s *Service) SaveServer(ctx context.Context, key string, input ServerInput) (Server, error)

func (*Service) SourceRelayTarget

func (s *Service) SourceRelayTarget(ctx context.Context, project, serviceKey string) (string, string, []byte, error)

SourceRelayTarget returns the project-registered source repository and an in-memory upstream token. Jenkins only sees the project-scoped relay credential; the business GitLab API token is never copied to Jenkins.

func (*Service) SyncDeliveryCredential

func (s *Service) SyncDeliveryCredential(ctx context.Context, project, connectionKey string, cicdService *cicd.Service) (cicd.Credential, error)

SyncDeliveryCredential creates a group-scoped, read_repository-only deploy token and writes it directly into the selected Jenkins credential store. The higher-privilege GitLab API token is never copied to Jenkins.

func (*Service) SyncJobJenkinsfile

func (s *Service) SyncJobJenkinsfile(ctx context.Context, project string, job cicd.Job) (created, updated int, err error)

SyncJobJenkinsfile writes the generated pipeline only for the selected Job. Deployment manifests remain owned by the project service catalog and are synchronized separately, so a Job may safely reference multiple services.

func (*Service) SyncSourceCredential

func (s *Service) SyncSourceCredential(ctx context.Context, project, connectionKey string, serviceKeys []string, cicdService jenkinsCredentialSyncer) (cicd.Credential, error)

SyncSourceCredential issues a project/connection-scoped read_repository deploy token and synchronizes it to the Jenkins used by the Job. When a GitLab gateway blocks deploy-token creation, a previously validated compatibility credential remains usable and is retried for least-privilege rotation on subsequent explicit synchronizations.

func (*Service) TestServer

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

func (*Service) ValidateSourceRepository

func (s *Service) ValidateSourceRepository(ctx context.Context, project, serviceKey string) error

type ServiceSpec

type ServiceSpec struct {
	Key                        string                        `json:"key"`
	DisplayName                string                        `json:"display_name"`
	WorkloadType               string                        `json:"workload_type"`
	Language                   string                        `json:"language"`
	RuntimeVersion             string                        `json:"runtime_version"`
	SourceRepository           string                        `json:"source_repository"`
	SourceBranch               string                        `json:"source_branch"`
	SourceCredentialID         string                        `json:"source_credential_id,omitempty"`
	ManifestCredentialID       string                        `json:"manifest_credential_id,omitempty"`
	BuildCommand               string                        `json:"build_command,omitempty"`
	BuildContext               string                        `json:"build_context"`
	DockerfileSource           string                        `json:"dockerfile_source,omitempty"`
	Dockerfile                 string                        `json:"dockerfile"`
	DockerfileContent          string                        `json:"dockerfile_content,omitempty"`
	DockerfileContents         map[string]string             `json:"dockerfile_contents,omitempty"`
	ManifestMode               string                        `json:"manifest_mode,omitempty"`
	DockerTarget               string                        `json:"docker_target,omitempty"`
	RunEnvironment             string                        `json:"run_environment,omitempty"`
	ImageRepository            string                        `json:"image_repository"`
	ImagePullSecrets           []string                      `json:"image_pull_secrets,omitempty"`
	ImagePullPolicy            string                        `json:"image_pull_policy"`
	Namespace                  string                        `json:"namespace"`
	WorkloadClass              string                        `json:"workload_class,omitempty"`
	ContainerPort              int                           `json:"container_port"`
	Replicas                   int                           `json:"replicas"`
	RevisionHistoryLimit       int                           `json:"revision_history_limit"`
	Timezone                   string                        `json:"timezone"`
	JavaOptions                []string                      `json:"java_options,omitempty"`
	EnvironmentVariables       map[string]string             `json:"environment_variables,omitempty"`
	SecretEnvironmentVariables map[string]SecretKeyReference `json:"secret_environment_variables,omitempty"`
	CPURequest                 string                        `json:"cpu_request"`
	MemoryRequest              string                        `json:"memory_request"`
	CPULimit                   string                        `json:"cpu_limit"`
	MemoryLimit                string                        `json:"memory_limit"`
	HealthPath                 string                        `json:"health_path,omitempty"`
	EtcdConfigEnabled          bool                          `json:"etcd_config_enabled,omitempty"`
	EtcdHosts                  []string                      `json:"etcd_hosts,omitempty"`
	EtcdConfigKey              string                        `json:"etcd_config_key,omitempty"`
	EtcdUsername               string                        `json:"etcd_username,omitempty"`
	EtcdPasswordCredentialID   string                        `json:"etcd_password_credential_id,omitempty"`
	EtcdConfigFile             string                        `json:"etcd_config_file,omitempty"`
	EtcdMountPath              string                        `json:"etcd_mount_path,omitempty"`
	NginxServerConfig          string                        `json:"nginx_server_config,omitempty"`
}

type SourceBranchOption

type SourceBranchOption struct {
	Name      string `json:"name"`
	Default   bool   `json:"default"`
	Protected bool   `json:"protected"`
}

type SourceFile

type SourceFile struct {
	Path    string `json:"path"`
	Content string `json:"content"`
}

type SourceFileCheck

type SourceFileCheck struct {
	ProjectID int64  `json:"project_id"`
	Branch    string `json:"branch"`
	Path      string `json:"path"`
	Exists    bool   `json:"exists"`
}

type SourceRepositoryOption

type SourceRepositoryOption struct {
	ProjectID       int64  `json:"project_id"`
	Name            string `json:"name"`
	Path            string `json:"path"`
	RootGroup       string `json:"root_group"`
	CloneURL        string `json:"clone_url"`
	DefaultBranch   string `json:"default_branch"`
	SourceServerKey string `json:"source_server_key"`
}

type SourceRepositoryResult

type SourceRepositoryResult struct {
	ProjectID int64  `json:"project_id"`
	FullPath  string `json:"full_path"`
	CloneURL  string `json:"clone_url"`
	Created   bool   `json:"created"`
	Files     int    `json:"files"`
}

type Store

type Store interface {
	ListGitLabServers(context.Context) ([]StoredServer, error)
	GetGitLabServer(context.Context, string) (StoredServer, error)
	SaveGitLabServer(context.Context, StoredServer) error
	DeleteGitLabServer(context.Context, string) error
	GitLabServerBindingCount(context.Context, string) (int, error)
	GitLabServerBindingRootGroups(context.Context, string) ([]string, error)
	GitLabServerSourceRepositories(context.Context, string) ([]string, error)
	GetProjectGitLabDelivery(context.Context, string) (ProjectDelivery, error)
	SaveProjectGitLabDelivery(context.Context, ProjectDelivery) error
	DetachProjectGitLabDelivery(context.Context, string) error
	GetCICDRepository(context.Context, string, string) (cicd.Repository, error)
	SaveCICDRepository(context.Context, cicd.Repository) error
}

type StoredServer

type StoredServer struct {
	Server
	TokenCipher string
}

Jump to

Keyboard shortcuts

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