Help us shape the future of Go! Take the 2026 Go Developer Survey

userconfig

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Overview

Package userconfig stores non-secret, per-profile state between runs: which instance a profile signs in to, which OAuth application it uses, who signed in, where the token went and which scopes GitLab granted.

It lives under a base directory — os.UserConfigDir()/gitlab-mcp unless GITLAB_MCP_CONFIG_DIR names another inside the home directory — and a non-default profile lives under profiles/<name>/ below it. The token is internal/credentials' business, not this package's.

Index

Constants

View Source
const AppDir = "gitlab-mcp"

AppDir is the directory name under the user's config directory.

View Source
const DefaultProfile = "default"

DefaultProfile is the profile used when none is named.

Variables

View Source
var ErrInvalidProfile = errors.New("userconfig: invalid profile name")

ErrInvalidProfile means a profile name does not match ProfilePattern.

View Source
var ErrNotFound = errors.New("userconfig: no config file for this profile; run `gitlab-mcp login`")

ErrNotFound means the profile has no config file yet.

View Source
var ErrOutsideHome = errors.New("userconfig: the config directory must be inside your home directory")

ErrOutsideHome means the config directory override resolves outside the home directory.

View Source
var ProfilePattern = regexp.MustCompile(`^[a-z0-9][a-z0-9_-]{0,63}$`)

ProfilePattern is what a profile name may be. The name becomes a directory and a keyring account, so it is kept to characters that are safe as both on every platform.

Functions

func BaseDir

func BaseDir(override string, allowOutsideHome bool) (string, error)

BaseDir resolves the application directory. An empty override means the platform default.

An override is refused outside the home directory, compared by real path, unless allowOutsideHome is set. This package creates the directory 0700 and writes 0600 files into it, so a mistyped value such as /etc or the SSH directory would re-permission something that is not ours.

func ValidProfile

func ValidProfile(name string) error

ValidProfile refuses a name that does not match ProfilePattern.

Types

type Config

type Config struct {
	// Instance is the normalized base URL the profile signed in to:
	// gitlab.com, or the test instance. The token is sent nowhere else.
	Instance string `json:"instance"`
	// ClientID is the OAuth application id. Not a secret: the
	// application is public and has none.
	ClientID string `json:"client_id"`
	// Username is who signed in, read from /user after login.
	Username string `json:"username,omitempty"`
	// TokenStore is where login put the token: keyring or file.
	TokenStore string `json:"token_store,omitempty"`
	// Scopes is what GitLab granted at the last login, not what was
	// requested. A scope requested and refused is the failure worth
	// seeing, and storing the request would hide it.
	Scopes    []string  `json:"scopes,omitempty"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

Config is the stored, non-secret profile state.

type Dir

type Dir string

Dir is one resolved base directory. Every path this package hands out is under it.

func (Dir) ConfigPath

func (d Dir) ConfigPath(profile string) string

ConfigPath is the profile's config file.

func (Dir) Load

func (d Dir) Load(profile string) (Config, error)

Load reads the profile's config. ErrNotFound if absent.

func (Dir) LockPath

func (d Dir) LockPath(profile string) string

LockPath is the file the token refresh locks, one per profile, so two processes sharing a profile never spend one refresh token twice.

func (Dir) Profile

func (d Dir) Profile(profile string) string

Profile returns the directory holding one profile's files.

func (Dir) Profiles

func (d Dir) Profiles() ([]string, error)

Profiles lists every configured profile, sorted, the default included.

func (Dir) Remove

func (d Dir) Remove(profile string) error

Remove deletes the profile's config file. A missing file is fine.

func (Dir) Resolve

func (d Dir) Resolve(named string) (string, error)

Resolve picks the profile to use: the one named, else DefaultProfile.

func (Dir) Save

func (d Dir) Save(profile string, c Config) error

Save writes the profile's config, keeping CreatedAt from the first save and stamping UpdatedAt.

func (Dir) SharingClient

func (d Dir) SharingClient(profile string) ([]string, error)

SharingClient returns the other profiles that use this profile's OAuth application on the same instance. logout names them, because the usual next step after logging out — deleting or renewing the application in GitLab — signs every one of them out too.

func (Dir) TokenFilePath

func (d Dir) TokenFilePath(profile string) string

TokenFilePath is the plaintext fallback for the token.

Jump to

Keyboard shortcuts

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