contexts

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package contexts reads and writes the CLI config file with the named connections ("contexts"). The file never holds a password.

Index

Constants

View Source
const (
	EnvConfigDir = "OPENARCH_CONFIG_DIR"
	EnvContext   = "OPENARCH_CONTEXT"
)

EnvConfigDir overrides the config folder. EnvContext selects a context.

View Source
const SystemOpenArch = "openarch"

SystemOpenArch is the endpoint system of an OpenArch server.

Variables

View Source
var Systems = []string{SystemOpenArch}

Systems lists the valid endpoint systems.

Functions

func Dir

func Dir(getenv func(string) string) (string, error)

Dir returns the config folder: OPENARCH_CONFIG_DIR, then XDG_CONFIG_HOME/openarch, then %AppData%\openarch on Windows and ~/.config/openarch elsewhere.

func File

func File(dir string) string

File is the config file in a config folder.

func Save

func Save(dir string, c Config) error

Save writes the config file.

func ValidSystem

func ValidSystem(s string) error

ValidSystem checks an endpoint system name.

func ValidateName

func ValidateName(name string) error

ValidateName checks a context name.

Types

type Config

type Config struct {
	CurrentContext string             `yaml:"current-context,omitempty"`
	Contexts       map[string]Context `yaml:"contexts,omitempty"`
}

Config is the content of config.yaml.

func Load

func Load(dir string) (Config, error)

Load reads the config file. A missing file is an empty config.

func (Config) Get

func (c Config) Get(name string) (Context, error)

Get returns a context, or a usage error that lists the valid names.

func (Config) NameForWorkspace

func (c Config) NameForWorkspace(dir string) string

NameForWorkspace returns the name of the context that points to dir, or "".

func (Config) Names

func (c Config) Names() []string

Names returns the context names, sorted.

type Context

type Context struct {
	Workspace string              `yaml:"workspace,omitempty" json:"workspace,omitempty"`
	Endpoints map[string]Endpoint `yaml:"endpoints,omitempty" json:"endpoints,omitempty"`
}

Context is a named connection: a local workspace, or remote endpoints.

func (Context) Kind

func (c Context) Kind() string

Kind is "workspace" or "remote".

type Endpoint

type Endpoint struct {
	URL      string `yaml:"url" json:"url"`
	Username string `yaml:"username" json:"username"`
	Insecure bool   `yaml:"insecure,omitempty" json:"insecure,omitempty"`
}

Endpoint is the connection to one system. The password is in the credential store.

Jump to

Keyboard shortcuts

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