config

package
v0.144.1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2025 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package config provides functionality around an experimental GitLab config file to handle GitLab instance setups, including where to find them and how to authenticate with them.

Attention: This package is experimental and the Go API and the config file API might change at any time.

Index

Constants

View Source
const (
	// SaaSHostname is the GitLab.com SaaS hostname
	SaaSHostname = "gitlab.com"

	// DefaultConfigFileName is the default name for the config file
	DefaultConfigFileName = "config.yaml"

	// DefaultConfigDirName is the default directory name for GitLab config
	DefaultConfigDirName = "gitlab"

	// ConfigVersion is the current API version for the config schema
	ConfigVersion = "gitlab.com/config/v1beta1"

	// DefaultAPIVersion is the default GitLab Rest API version
	DefaultAPIVersion = "v4"

	// EnvVarGitLabConfigFile is the environment variable name for specifying a custom config file path
	EnvVarGitLabConfigFile = "GITLAB_CONFIG"

	// EnvVarGitLabConfigFile is the environment variable name for specify the current context to use
	EnvVarGitLabContext = "GITLAB_CONTEXT"

	// CredentialSourceNotFoundExitCode is the command exit code used to determine if a credential source wasn't found
	CredentialSourceNotFoundExitCode = 2
)

Variables

This section is empty.

Functions

func DefaultConfigPath

func DefaultConfigPath() string

DefaultConfigPath returns the default configuration file path, checking environment variables and standard locations in order of precedence.

func NewConfigTokenSource

func NewConfigTokenSource(ctx context.Context, oauth2Cfg *oauth2.Config, readToken func() (*oauth2.Token, error), writeToken func(t *oauth2.Token) error) (oauth2.TokenSource, error)

Types

type Config

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

Config represents a GitLab configuration that manages instances, authentication, and contexts for creating GitLab API clients.

func Empty

func Empty(options ...ConfigOption) *Config

Empty creates a new empty Config with no configuration loaded.

func New

func New(options ...ConfigOption) *Config

New creates a new Config with default config path and applies the given options.

func NewFromPath

func NewFromPath(path string, options ...ConfigOption) *Config

NewFromPath creates a new Config from the specified path and applies the given options.

func NewFromString

func NewFromString(s string, options ...ConfigOption) (*Config, error)

NewFromString creates a new Config from a YAML string and applies the given options.

func (*Config) Auth

func (c *Config) Auth(name string) *v1beta1.Auth

Auth returns the authentication configuration for the specified name.

func (*Config) Auths

func (c *Config) Auths() []*v1beta1.Auth

Auths returns all configured authentication methods.

func (*Config) Context

func (c *Config) Context(name string) *v1beta1.Context

func (*Config) Contexts

func (c *Config) Contexts() []*v1beta1.Context

Contexts returns all configured contexts.

func (*Config) CurrentContext

func (c *Config) CurrentContext() *v1beta1.Context

CurrentContext returns the currently active context.

func (*Config) Extensions

func (c *Config) Extensions() map[string]*structpb.Struct

Extensions returns the custom configuration data.

func (*Config) Instance

func (c *Config) Instance(name string) *v1beta1.Instance

Instance returns the instance configuration for the specified name.

func (*Config) Instances

func (c *Config) Instances() []*v1beta1.Instance

Instances returns all configured GitLab instances.

func (*Config) Load

func (c *Config) Load() error

Load reads and parses the configuration file from the configured path. Returns an error if the file cannot be read or parsed.

func (*Config) NewClient

func (c *Config) NewClient(options ...gitlab.ClientOptionFunc) (*gitlab.Client, error)

NewClient creates a new GitLab API client using the current context. Returns an error if the current context cannot be resolved.

func (*Config) NewClientForContext

func (c *Config) NewClientForContext(name string, options ...gitlab.ClientOptionFunc) (*gitlab.Client, error)

NewClientForContext creates a new GitLab API client using the specified context. Returns an error if the context cannot be resolved or the client cannot be created.

func (*Config) Save

func (c *Config) Save() error

Save writes the configuration to the configured file path. Returns an error if the config is invalid or cannot be written.

type ConfigOption

type ConfigOption func(c *Config)

ConfigOption is a function that modifies a Config during initialization.

func WithAdditionalValidator

func WithAdditionalValidator(validator ConfigValidator) ConfigOption

WithAdditionalValidator adds a custom validator to the Config.

func WithAutoCISupport

func WithAutoCISupport() ConfigOption

WithAutoCISupport automatically configures the Config for GitLab CI/CD environments by reading CI environment variables and setting up appropriate authentication.

func WithContext

func WithContext(ctx context.Context) ConfigOption

WithContext sets the context for the Config.

func WithOAuth2Settings

func WithOAuth2Settings(settings OAuth2Settings) ConfigOption

WithOAuth2Settings configures OAuth2 authentication settings for the Config.

func WithPath

func WithPath(path string) ConfigOption

WithPath sets the config file path for the Config.

type ConfigValidator

type ConfigValidator func(c *v1beta1.Config) error

ConfigValidator is a function that validates a Config structure.

type Extension

type Extension[T any] struct {
	// contains filtered or unexported fields
}

func NewExtension

func NewExtension[T any](name string, cfg *Config) *Extension[T]

func NewExtensionForContext

func NewExtensionForContext[T any](name string, cfg *Config, context string) *Extension[T]

func (*Extension[T]) Marshal

func (e *Extension[T]) Marshal() error

func (*Extension[T]) Unmarshal

func (e *Extension[T]) Unmarshal() (*T, error)

type OAuth2Settings

type OAuth2Settings struct {
	AuthorizationFlowEnabled bool
	CallbackServerListenAddr string
	Browser                  gitlaboauth2.BrowserFunc
	ClientID                 string
	ClientSecret             string
	RedirectURL              string
	Scopes                   []string
}

OAuth2Settings configures OAuth2 authentication flow parameters.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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