token

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AccessLevelNoPermissions = AccessLevel("no_permissions")
	// AccessLevelMinimalAccessPermissions allows view limited group information without access to projects. For more information, see Users with Minimal Access.
	AccessLevelMinimalAccessPermissions = AccessLevel("minimal_access")
	// AccessLevelGuestPermissions allows view and comment on issues and epics. Cannot push code or access repository. This role applies to private and internal projects only.
	AccessLevelGuestPermissions = AccessLevel("guest")
	// AccessLevelPlannerPermissions allows create and manage issues, epics, milestones, and iterations. Focused on project planning and tracking with the ability to view and collaborate on code changes.
	AccessLevelPlannerPermissions = AccessLevel("planner")
	// AccessLevelReporterPermissions allows view code, create issues, and generate reports. Cannot push code or manage protected branches.
	AccessLevelReporterPermissions = AccessLevel("reporter")
	// AccessLevelSecurityManagerPermissions allows view and manage security vulnerabilities, compliance configurations, and audit events. Focused on security operations without code push access.
	AccessLevelSecurityManagerPermissions = AccessLevel("security_manager")
	// AccessLevelDeveloperPermissions allows push code to non-protected branches, create merge requests, and run CI/CD pipelines. Cannot manage project settings.
	AccessLevelDeveloperPermissions = AccessLevel("developer")
	// AccessLevelMaintainerPermissions allows manage branches, merge requests, CI/CD settings, and project members. Cannot delete the project.
	AccessLevelMaintainerPermissions = AccessLevel("maintainer")
	// AccessLevelOwnerPermissions allows full control over the project or group, including deletion and visibility settings.
	AccessLevelOwnerPermissions = AccessLevel("owner")

	AccessLevelUnknown = AccessLevel("")
)
View Source
const (
	// ScopeApi grants complete read/write access to the API, including all groups and projects, the container registry, the dependency proxy, and the package registry. Also grants complete read/write access to the registry and repository using Git over HTTP
	ScopeApi = Scope("api")
	// ScopeReadApi grants read access to the scoped group and related project API, including the Package Registry
	ScopeReadApi = Scope("read_api")
	// ScopeReadRegistry grants read access (pull) to the Container Registry images if any project within expected group is private and authorization is required.
	ScopeReadRegistry = Scope("read_registry")
	// ScopeWriteRegistry grants write access (push) to the Container Registry.
	ScopeWriteRegistry = Scope("write_registry")
	// ScopeReadRepository grants read access (pull) to the Container Registry images if any project within expected group is private and authorization is required
	ScopeReadRepository = Scope("read_repository")
	// ScopeWriteRepository grants read and write access (pull and push) to all repositories within expected group
	ScopeWriteRepository = Scope("write_repository")

	// ScopeReadPackageRegistry Allows read-only access to the package registry.
	ScopeReadPackageRegistry = Scope("read_package_registry")
	// ScopeWritePackageRegistry Allows read and write access to the package registry.
	ScopeWritePackageRegistry = Scope("write_package_registry")

	// ScopeCreateRunner grants permission to create runners in expected group
	ScopeCreateRunner = Scope("create_runner")
	// ScopeManageRunner grants permission to manage runners in expected group
	ScopeManageRunner = Scope("manage_runner")

	// ScopeReadUser grants read-only access to the authenticated user’s profile through the /user API endpoint, which includes username, public email, and full name. Also grants access to read-only API endpoints under /users.
	ScopeReadUser = Scope("read_user")
	// ScopeSudo grants permission to perform API actions as any user in the system, when authenticated as an administrator.
	ScopeSudo = Scope("sudo")
	// ScopeAdminMode grants permission to perform API actions as an administrator, when Admin Mode is enabled.
	ScopeAdminMode = Scope("admin_mode")

	// ScopeAiFeatures grants permission to perform API actions for GitLab Duo. This scope is designed to work with the GitLab Duo Plugin for JetBrains. For all other extensions, see scope requirements.
	ScopeAiFeatures = Scope("ai_features")
	// ScopeK8SProxy grants permission to perform Kubernetes API calls using the agent for Kubernetes.
	ScopeK8SProxy = Scope("k8s_proxy")
	// ScopeReadServicePing grant access to download Service Ping payload through the API when authenticated as an admin use.
	ScopeReadServicePing = Scope("read_service_ping")

	// ScopeSelfRotate grants permission to rotate this token using the personal access token API. Does not allow rotation of other tokens.
	ScopeSelfRotate = Scope("self_rotate")
	// ScopeReadVirtualRegistry if a project is private and authorization is required, grants read-only (pull) access to container images through the dependency proxy. Available only when the dependency proxy is enabled.
	ScopeReadVirtualRegistry = Scope("read_virtual_registry")
	// ScopeWriteVirtualRegistry if a project is private and authorization is required, grants read (pull), write (push), and delete access to container images through the dependency proxy. Available only when the dependency proxy is enabled.
	ScopeWriteVirtualRegistry = Scope("write_virtual_registry")

	ScopeUnknown = Scope("")
)
View Source
const (
	TypePersonal               = Type("personal")
	TypeProject                = Type("project")
	TypeGroup                  = Type("group")
	TypeUserServiceAccount     = Type("user-service-account")
	TypeGroupServiceAccount    = Type("group-service-account")
	TypePipelineProjectTrigger = Type("pipeline-project-trigger")
	TypeProjectDeploy          = Type("project-deploy")
	TypeGroupDeploy            = Type("group-deploy")

	TypeUnknown = Type("")
)

Variables

ValidAccessLevels is the union of every AccessLevel string the parser accepts. It is the parser whitelist, not a per-token-type validator — per-token-type and per-version gating live in accessLevelMinVersionByTokenType.

View Source
var (
	ValidTokenTypes = []string{
		TypePersonal.String(),
		TypeProject.String(),
		TypeGroup.String(),
		TypeUserServiceAccount.String(),
		TypeGroupServiceAccount.String(),
		TypePipelineProjectTrigger.String(),
		TypeProjectDeploy.String(),
		TypeGroupDeploy.String(),
	}
)

Functions

func AllValidAccessLevels added in v0.12.0

func AllValidAccessLevels() []string

AllValidAccessLevels returns the union of access_levels accepted by any token type at any version — used to populate the OpenAPI schema's AllowedValues at backend startup, before a GitLab version is known.

func AllValidScopes added in v0.12.0

func AllValidScopes() []string

AllValidScopes returns the union of scopes accepted by any token type at any version — used to populate the OpenAPI schema's AllowedValues at backend startup, before a GitLab version is known.

func IsAccessLevelAllowed added in v0.12.0

func IsAccessLevelAllowed(tokenType Type, level AccessLevel, gitlabVersion string) bool

IsAccessLevelAllowed reports whether level is a valid access_level for tokenType on gitlabVersion. Returns false if tokenType does not take an access_level field.

func IsScopeAllowed added in v0.12.0

func IsScopeAllowed(tokenType Type, scope Scope, gitlabVersion string) bool

IsScopeAllowed reports whether scope is a valid scope for tokenType on gitlabVersion. Returns false if tokenType does not take a scopes field.

func IsValidPath added in v0.10.0

func IsValidPath(path string, tokenType Type) (valid bool)

IsValidPath validates a path string for a specified tokenType.

Validation rules:

  • Each segment can contain only ASCII letters, digits, '_', '-', '.'.
  • Path must not start with '-', '_', or '.'.
  • Path must not end with '-', '_', '.', '.git' or '.atom'.
  • Segment count rules per token type: -- TypePersonal, TypeUserServiceAccount: exactly 1 segment. -- TypeGroupServiceAccount: exactly 2 segments. -- TypeProject, TypeGroup, TypeProjectDeploy, TypeGroupDeploy, TypePipelineProjectTrigger: 1 or more segments.

Returns true if valid, else false.

Types

type AccessLevel

type AccessLevel string

func ParseAccessLevel added in v0.11.0

func ParseAccessLevel(value string) (AccessLevel, error)

func ValidAccessLevelsFor added in v0.12.0

func ValidAccessLevelsFor(tokenType Type, gitlabVersion string) (levels []AccessLevel, applicable bool)

ValidAccessLevelsFor returns the access_levels allowed for tokenType on the given GitLab version, sorted by AccessLevel.Value(). applicable is false if tokenType does not take an access_level field at all (e.g. personal, pipeline trigger, deploy tokens). When version is empty the gate is lenient — every level the token type accepts is returned.

func (AccessLevel) String

func (i AccessLevel) String() string

func (AccessLevel) Value

func (i AccessLevel) Value() int

type Scope

type Scope string

func ParseScope

func ParseScope(value string) (Scope, error)

func ValidScopesFor added in v0.12.0

func ValidScopesFor(tokenType Type, gitlabVersion string) (scopes []Scope, applicable bool)

ValidScopesFor returns the scopes allowed for tokenType on the given GitLab version, sorted alphabetically. applicable is false if tokenType does not take a scopes field (pipeline trigger). When version is empty the gate is lenient — every scope the token type accepts is returned.

func (Scope) String

func (i Scope) String() string

type Token

type Token interface {
	Internal() map[string]any
	Data() map[string]any
	Event(map[string]string) map[string]string
	Type() Type
	SetConfigName(string)
	SetRoleName(string)
	SetGitlabRevokesToken(bool)
	SetExpiresAt(*time.Time)
	GetExpiresAt() time.Time
	GetCreatedAt() time.Time
	TTL() time.Duration
}

type Type

type Type string

func ParseType

func ParseType(value string) (Type, error)

func (Type) String

func (i Type) String() string

Jump to

Keyboard shortcuts

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