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
- Variables
- func BaseDir(override string, allowOutsideHome bool) (string, error)
- func RealPath(path string) string
- func ValidProfile(name string) error
- func WithinDir(dir, path string) bool
- type Config
- type Dir
- func (d Dir) ConfigPath(profile string) string
- func (d Dir) Load(profile string) (Config, error)
- func (d Dir) LockPath(profile string) string
- func (d Dir) Profile(profile string) string
- func (d Dir) Profiles() ([]string, error)
- func (d Dir) Remove(profile string) error
- func (d Dir) Resolve(named string) (string, error)
- func (d Dir) Save(profile string, c Config) error
- func (d Dir) SharingClient(profile string) ([]string, error)
- func (d Dir) TokenFilePath(profile string) string
Constants ¶
const AppDir = "gitlab-mcp"
AppDir is the directory name under the user's config directory.
const DefaultProfile = "default"
DefaultProfile is the profile used when none is named.
Variables ¶
var ErrInvalidProfile = errors.New("userconfig: invalid profile name")
ErrInvalidProfile means a profile name does not match ProfilePattern.
var ErrNotFound = errors.New("userconfig: no config file for this profile; run `gitlab-mcp login`")
ErrNotFound means the profile has no config file yet.
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.
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 ¶
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 RealPath ¶ added in v2.3.0
RealPath resolves links as far as the file system can, so that two names for one directory compare equal: macOS temporary paths under /var are /private/var, and Windows hands out 8.3 short names. The directory usually does not exist yet, so the deepest existing ancestor is resolved and the rest appended.
func ValidProfile ¶
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 ¶
ConfigPath is the profile's config file.
func (Dir) LockPath ¶
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) Save ¶
Save writes the profile's config, keeping CreatedAt from the first save and stamping UpdatedAt.
func (Dir) SharingClient ¶
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 ¶
TokenFilePath is the plaintext fallback for the token.