gitlab

package
v0.5.0 Latest Latest
Warning

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

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

Documentation

Overview

Package gitlab 은 GitLab API v4 를 통해 그룹·프로젝트·파일을 프로비저닝한다.

GitLab 의 Container Registry 와 Package Registry 는 프로젝트 단위로 존재한다. 따라서 공용 베이스 이미지나 npm/maven 패키지를 두려면 그것을 소유할 프로젝트가 반드시 필요하다 — 이 어댑터가 그 프로젝트를 만드는 경로다.

Index

Constants

View Source
const (
	// SecretProvider 는 토큰을 보관할 시크릿 백엔드다.
	SecretProvider = "openbao"

	// AutomationTokenName 은 Nullus 가 발급하는 PAT 의 이름이다.
	// 사람이 만든 토큰과 구분되어야 정리(revoke) 대상을 특정할 수 있다.
	AutomationTokenName = "nullus-automation"
)

Variables

This section is empty.

Functions

func TokenSecretPath

func TokenSecretPath(env, orgID string) string

TokenSecretPath 는 API 토큰의 시크릿 경로다.

스택 모듈의 규약(kv/nullus/{env}/{org}/{module}/{provider}/...)을 따른다.

Types

type Client

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

Client 는 port.SCMProvisioner 의 GitLab 구현체다.

func NewClient

func NewClient(baseURL, token string) *Client

NewClient 는 GitLab API v4 클라이언트를 만든다.

baseURL 은 API 접두사를 뺀 인스턴스 주소다 (예: http://gitlab-webservice-default.ns.svc:8181). token 은 api 스코프를 가진 Personal/Project Access Token 이다.

func (*Client) BaseURL

func (c *Client) BaseURL() string

BaseURL 은 이 클라이언트가 바라보는 인스턴스 주소다.

func (*Client) CommitFiles

func (c *Client) CommitFiles(ctx context.Context, projectID string, spec port.CommitSpec) error

CommitFiles 는 여러 파일을 한 커밋으로 올린다.

GitLab 커밋 API 에는 upsert 액션이 없고, action 은 파일마다 지정한다. 새 프로젝트는 initialize_with_readme 로 README.md 만 있는 상태라 스캐폴딩은 "이미 있는 파일 + 없는 파일" 이 섞인다. 커밋 전체에 하나의 action 을 쓰면 어느 쪽으로 보내도 실패하므로, 트리를 한 번 읽어 파일별로 정한다.

func (*Client) CreateProjectAccessToken

func (c *Client) CreateProjectAccessToken(
	ctx context.Context,
	projectID string,
	spec port.AccessTokenSpec,
) (string, error)

CreateProjectAccessToken 은 프로젝트 범위 토큰을 발급한다.

값은 발급 응답에만 담기므로 호출자가 즉시 보관해야 한다.

func (*Client) DeleteProject

func (c *Client) DeleteProject(ctx context.Context, projectID string) error

get 은 200 이면 true, 404 면 false 를 돌려준다. 그 외는 오류다. DeleteProject 는 프로젝트를 지운다.

이미 없으면 성공으로 본다 — 삭제의 목표는 "없는 상태" 이고, 404 를 오류로 올리면 앞선 시도가 절반쯤 성공한 뒤 재시도할 때 영영 끝나지 않는다.

GitLab 은 기본적으로 지연 삭제(휴지통)로 동작할 수 있다. 그룹 설정에 따라 즉시 지워지지 않고 보존 기간이 지나야 사라지므로, 호출이 성공해도 프로젝트가 잠시 조회될 수 있다.

func (*Client) EnsureGroup

func (c *Client) EnsureGroup(ctx context.Context, spec port.GroupSpec) (*port.SCMGroup, error)

EnsureGroup 은 그룹을 조회하고 없으면 만든다.

func (*Client) EnsureProject

func (c *Client) EnsureProject(ctx context.Context, spec port.ProjectSpec) (*port.SCMProject, error)

EnsureProject 는 프로젝트를 조회하고 없으면 만든다.

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping 은 현재 토큰이 실제로 인증되는지 확인한다.

보관된 토큰은 폐기·만료될 수 있어, 쓰기 전에 한 번 확인하지 않으면 이후 모든 호출이 401 로 죽는다.

func (*Client) SetProjectVariable

func (c *Client) SetProjectVariable(ctx context.Context, projectID string, v port.ProjectVariable) error

SetProjectVariable 은 CI/CD 변수를 등록하거나 이미 있으면 갱신한다.

GitLab 변수 API 에는 upsert 가 없다. POST 로 시도하고 키 충돌이면 PUT 한다 — 재프로비저닝에서 자격증명이 바뀌었는데 예전 값이 남으면 빌드가 계속 실패한다.

func (*Client) WithHTTPClient

func (c *Client) WithHTTPClient(h *http.Client) *Client

WithHTTPClient 는 타임아웃·전송 계층을 교체한다.

func (*Client) WithRegistryHost

func (c *Client) WithRegistryHost(host string) *Client

WithRegistryHost 는 응답에 container_registry_url 이 없을 때 쓸 폴백 호스트를 설정한다.

type KubectlRunner

type KubectlRunner func(ctx context.Context, kubeconfig []byte, args ...string) ([]byte, error)

KubectlRunner 는 kubectl 실행을 추상화한다.

다른 모듈의 동일 타입을 재사용하지 않는다 — 모듈 간 직접 import 를 피하기 위해 CI/CD 컨텍스트가 자기 계약을 소유한다.

type SecretStore

type SecretStore interface {
	GetTokenForStack(ctx context.Context, provider, stackID, path string) (string, error)
	PutTokenForStack(ctx context.Context, provider, stackID, path, value string) error
}

SecretStore 는 토큰 보관에 필요한 최소 동작만 노출한다.

스택 범위 접근을 쓴다 — OpenBao 는 스택마다 배포되므로 전역 주소가 하나일 수 없고, 해당 스택의 저장소에 넣어야 ESO 와 같은 곳을 본다.

type TokenIssuer

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

TokenIssuer 는 GitLab API 토큰을 확보한다.

GitLab 을 외부에 노출하지 않고도 동작해야 하므로 API 가 아니라 toolbox 파드의 gitlab-rails 콘솔로 PAT 를 발급한다. Runner 등록 토큰 발견과 같은 방식이다. PAT 값은 생성 시점에만 읽을 수 있어 발급 즉시 시크릿 저장소에 보관한다.

func NewTokenIssuer

func NewTokenIssuer(kubeconfig port.KubeconfigProvider, runKubectl KubectlRunner, secrets SecretStore) *TokenIssuer

NewTokenIssuer 는 TokenIssuer 를 만든다.

func (*TokenIssuer) EnsureToken

func (t *TokenIssuer) EnsureToken(ctx context.Context, spec port.SCMTokenSpec) (string, error)

EnsureToken 은 보관된 토큰을 돌려주고, 없거나 Force 면 새로 발급한다.

Jump to

Keyboard shortcuts

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