config

package
v0.16.1 Latest Latest
Warning

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

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

Documentation

Overview

Package config manages the Glean CLI's configuration, providing secure storage of credentials using the system keyring with fallback to file-based storage.

Index

Constants

This section is empty.

Variables

View Source
var ConfigPath string

ConfigPath is the path to the fallback config file.

View Source
var ServiceName = "glean-cli"

ServiceName is the service identifier used for keyring operations.

Functions

func ClearConfig

func ClearConfig() error

ClearConfig removes all stored configuration from both keyring and file storage.

func ClearTokenFromStorage added in v0.13.0

func ClearTokenFromStorage() error

ClearTokenFromStorage removes only the API token from keyring and config file, leaving the server URL and other settings intact. This is used during OAuth login to prevent a stale API token from shadowing newly obtained OAuth credentials.

func MaskToken

func MaskToken(token string) string

MaskToken masks a token by showing only the first and last 4 characters and replacing the rest with asterisks.

func NormalizeServerURL added in v0.15.0

func NormalizeServerURL(s string) string

NormalizeServerURL canonicalizes a Glean server URL value. It trims surrounding whitespace, strips trailing slashes, and ensures a scheme is present (defaulting to https). Existing schemes are preserved, so "http://localhost:8080" stays on http.

The function is idempotent — applying it twice yields the same result as applying it once.

Examples:

NormalizeServerURL("acme-be.glean.com")          → "https://acme-be.glean.com"
NormalizeServerURL("https://acme-be.glean.com")  → "https://acme-be.glean.com"
NormalizeServerURL("https://acme-be.glean.com/") → "https://acme-be.glean.com"
NormalizeServerURL("http://localhost:8080")      → "http://localhost:8080"
NormalizeServerURL("")                           → ""

func SaveConfig

func SaveConfig(serverURL, token string) error

SaveConfig stores the server URL and token in both the system keyring and file storage.

func SaveServerURLToFile added in v0.15.0

func SaveServerURLToFile(serverURL string) error

SaveServerURLToFile persists only the server URL in ~/.glean/config.json without touching the system keyring. This is intended for OAuth flows where the URL is not secret and persisting it should not trigger OS keychain prompts.

Types

type Config

type Config struct {
	GleanServerURL    string `json:"server_url"`
	GleanToken        string `json:"token"`
	OAuthClientID     string `json:"oauth_client_id,omitempty"`
	OAuthClientSecret string `json:"oauth_client_secret,omitempty"`
}

Config holds the Glean API credentials and connection settings.

func LoadConfig

func LoadConfig() (*Config, error)

LoadConfig retrieves configuration using the following priority order:

  1. Environment variables (GLEAN_API_TOKEN, GLEAN_SERVER_URL)
  2. System keyring
  3. ~/.glean/config.json

If GLEAN_HOST is set without GLEAN_SERVER_URL, LoadConfig returns an error describing the rename rather than falling through to a "not configured" message from a downstream caller.

type ProjectConfig added in v0.14.0

type ProjectConfig struct {
	DefaultOutput string `json:"default_output,omitempty"`
	DefaultMode   string `json:"default_mode,omitempty"`
	DefaultFields string `json:"default_fields,omitempty"`
}

ProjectConfig holds project-level CLI preferences that can be shared via a .glean/config.json file checked into a repository.

func FindProjectConfig added in v0.14.0

func FindProjectConfig() (*ProjectConfig, error)

FindProjectConfig walks up from the current working directory looking for a .glean/config.json file. Returns nil, nil if no project config is found.

Jump to

Keyboard shortcuts

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