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
- func DefaultConfigPath() string
- func NewConfigTokenSource(ctx context.Context, oauth2Cfg *oauth2.Config, ...) (oauth2.TokenSource, error)
- type Config
- func (c *Config) Auth(name string) *v1beta1.Auth
- func (c *Config) Auths() []*v1beta1.Auth
- func (c *Config) Context(name string) *v1beta1.Context
- func (c *Config) Contexts() []*v1beta1.Context
- func (c *Config) CurrentContext() *v1beta1.Context
- func (c *Config) Extensions() map[string]*structpb.Struct
- func (c *Config) Instance(name string) *v1beta1.Instance
- func (c *Config) Instances() []*v1beta1.Instance
- func (c *Config) Load() error
- func (c *Config) NewClient(options ...gitlab.ClientOptionFunc) (*gitlab.Client, error)
- func (c *Config) NewClientForContext(name string, options ...gitlab.ClientOptionFunc) (*gitlab.Client, error)
- func (c *Config) Save() error
- type ConfigOption
- type ConfigValidator
- type Extension
- type OAuth2Settings
Constants ¶
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.
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) CurrentContext ¶
CurrentContext returns the currently active context.
func (*Config) Extensions ¶
Extensions returns the custom configuration data.
func (*Config) Load ¶
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 ¶
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.
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 ¶
ConfigValidator is a function that validates a Config structure.
type Extension ¶
type Extension[T any] struct { // contains filtered or unexported fields }
func NewExtensionForContext ¶
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.