context

package
v1.1.2 Latest Latest
Warning

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

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

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// KeyringServiceName is the service name akt registers with the OS
	// keyring backend (Keychain on macOS, libsecret on Linux). The service
	// name is the lookup key, which is why akt cannot see entries written
	// by the legacy CLI and vice versa (SPEC §1.12).
	KeyringServiceName = "akt"

	// LegacyKeyringServiceName is the service name used by the legacy
	// akash / provider-services CLIs. It exists so the first-run wizard can
	// explain the mismatch; akt never opens a keyring under this name.
	LegacyKeyringServiceName = "akash"
)
View Source
const (
	EnvConsoleOrganization = "AKT_CONSOLE_ORGANIZATION"
	EnvConsoleProject      = "AKT_CONSOLE_PROJECT"
)

Environment variables that select the Console organization and project for one invocation, overriding the context's stored selection (SPEC §7.1.1).

View Source
const (
	AuthMethodKeyring    = "keyring"
	AuthMethodConsoleAPI = "console-api"
)

Authentication methods a context can use (SPEC §1.4, §7).

View Source
const (
	ProviderAuthJWT  = "jwt"
	ProviderAuthMTLS = "mtls"
)
View Source
const ConfigVersion = 1

ConfigVersion is the current schema version.

View Source
const DefaultConsoleAPIURL = "https://console-api.akash.network"

DefaultConsoleAPIURL is the default Console API base URL (SPEC §7.2).

View Source
const EnvConsoleAPIKey = "AKT_CONSOLE_API_KEY"

EnvConsoleAPIKey is the environment variable holding the Console API key. It overrides the per-context stored credential (SPEC §7.1).

Variables

View Source
var DefaultHome = filepath.Join(os.Getenv("HOME"), ".config", "akt")

DefaultHome is the fallback home directory used when no override or env var is set. It matches the last-resort path in ConfigHome.

Functions

func ActionLogPath

func ActionLogPath(root, name string) string

ActionLogPath returns the action log file path for a named context.

func ConfigHome

func ConfigHome(override string) (string, error)

ConfigHome resolves the akt home directory.

Resolution order:

  1. override parameter (from --home flag)
  2. AKT_HOME env var
  3. $XDG_CONFIG_HOME/akt
  4. ~/.config/akt

func ConfigPath

func ConfigPath(root string) string

ConfigPath returns the path to config.yaml within the given config root.

func ConsoleAPIKeyPath

func ConsoleAPIKeyPath(root, ctxName string) string

ConsoleAPIKeyPath returns the path of a context's stored Console API key. The credential lives inside the context's data directory so renames move it and deletes remove it (SPEC §7.1).

func ContextDir

func ContextDir(root, name string) string

ContextDir returns the data directory for a named context.

func ContextWorkflowsDir

func ContextWorkflowsDir(root, name string) string

ContextWorkflowsDir returns the per-context workflows directory.

func EnsureContextDirs

func EnsureContextDirs(root, name string) error

EnsureContextDirs creates the store and action log directories for a context. The context directory is 0700: it holds per-context secrets (the Console API credential) alongside the store and action log.

func KeyringDir

func KeyringDir(root string, kr Keyring) string

KeyringDir returns the directory for a named keyring.

func NetworkTemplates

func NetworkTemplates() map[string]Network

NetworkTemplates returns pre-configured network definitions for known Akash networks. Returns a fresh map on each call to prevent mutation of shared state.

func NewViper

func NewViper(root string) (*viper.Viper, error)

NewViper creates a Viper instance configured for the given root directory. It reads config.yaml, binds environment variables with the AKT_ prefix, and sets defaults from DefaultConfig.

func ResolveConsoleAPIKey

func ResolveConsoleAPIKey(root, ctxName string) string

ResolveConsoleAPIKey resolves the effective Console API key for a context per SPEC §7.1: environment variable first, then the stored per-context credential. The --console-api-key flag override is applied by the CLI layer on top of this.

func ResolveProviderAuthType added in v0.0.3

func ResolveProviderAuthType(value string) (string, error)

ResolveProviderAuthType applies the context default and validates the provider gateway authentication enum at the configuration boundary.

func SaveConfig

func SaveConfig(root string, cfg *Config) error

SaveConfig writes the config to config.yaml in the given root. It creates the root directory and parent directories as needed. Uses YAML encoder with 2-space indentation.

func SetConsoleAPIKey

func SetConsoleAPIKey(root, ctxName, key string) error

SetConsoleAPIKey stores (or, with an empty key, removes) a context's Console API key. The file is written with 0600 permissions and is never part of config.yaml.

func StoreDBPath added in v0.0.4

func StoreDBPath(root, name string) string

StoreDBPath returns the deployment store database path for a named context. It is the single source of truth for where a context's store lives; every opener must go through it so `akt store status` and a workflow's own persistence (SPEC §6.6) can never disagree about which file they mean.

func StoreDir

func StoreDir(root, name string) string

StoreDir returns the store directory for a named context.

func StoredConsoleAPIKey

func StoredConsoleAPIKey(root, ctxName string) (string, error)

StoredConsoleAPIKey reads a context's stored Console API key. A missing credential file returns an empty key with no error.

func ValidateConsoleOrganization added in v1.1.0

func ValidateConsoleOrganization(value string) error

ValidateConsoleOrganization checks a stored organization selector, which is the organization's id or slug as the Console API accepts them in x-organization-id. Empty clears the selection.

func ValidateConsoleProject added in v1.1.0

func ValidateConsoleProject(value string) error

ValidateConsoleProject checks a stored project selector. A context stores the project's id, which survives renames; names are resolved to ids by `akt console project use`. Empty clears the selection.

func WorkflowsDir

func WorkflowsDir(root string) string

WorkflowsDir returns the global workflows directory within the home.

Types

type Config

type Config struct {
	Version        int            `yaml:"version"                    json:"version"`
	CurrentContext string         `yaml:"current-context"            json:"current_context"`
	Networks       []Network      `yaml:"networks"                   json:"networks"`
	Keyrings       []Keyring      `yaml:"keyrings"                   json:"keyrings"`
	Contexts       []Context      `yaml:"contexts"                   json:"contexts"`
	TUI            TUISettings    `yaml:"tui,omitempty"              json:"tui,omitempty"`
	Plugins        PluginSettings `yaml:"plugins,omitempty"          json:"plugins,omitempty"`
	Defaults       Defaults       `yaml:"defaults,omitempty"         json:"defaults,omitempty"`
}

Config is the top-level configuration structure persisted in config.yaml.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a new empty config with version set.

func LoadConfig

func LoadConfig(root string) (*Config, error)

LoadConfig reads and parses the config.yaml file from the given root using Viper. If the file does not exist, a default config is returned.

type Context

type Context struct {
	Name                string           `yaml:"-"                              json:"name"`
	Network             Network          `yaml:"-"                              json:"network"`
	Keyring             Keyring          `yaml:"-"                              json:"keyring"`
	AuthMethod          string           `yaml:"auth-method,omitempty"          json:"auth_method,omitempty"`
	ConsoleAPIURL       string           `yaml:"console-api-url,omitempty"      json:"console_api_url,omitempty"`
	ConsoleOrganization string           `yaml:"console-organization,omitempty" json:"console_organization,omitempty"`
	ConsoleProject      string           `yaml:"console-project,omitempty"      json:"console_project,omitempty"`
	DefaultAccount      string           `yaml:"default-account,omitempty"      json:"default_account,omitempty"`
	TrackedAccounts     []string         `yaml:"tracked-accounts,omitempty"  json:"tracked_accounts,omitempty"`
	Gas                 string           `yaml:"gas,omitempty"               json:"gas,omitempty"`
	Fees                string           `yaml:"fees,omitempty"              json:"fees,omitempty"`
	ProviderDefaults    ProviderDefaults `yaml:"provider-defaults,omitempty" json:"provider_defaults,omitempty"`

	// Resolved fields -- populated by Manager.Resolve(), not serialized.
	// These are convenience accessors that flatten nested values.
	GasPrices     string `yaml:"-" json:"-"`
	GasAdjustment string `yaml:"-" json:"-"`
	AuthType      string `yaml:"-" json:"-"`
	Root          string `yaml:"-" json:"-"` // config root directory
	// ConsoleAPIKey is the resolved Console API key (env var overrides the
	// per-context credential file, SPEC §7.1). Never serialized.
	ConsoleAPIKey string `yaml:"-" json:"-"`
}

Context defines a named environment that composes a network, keyring, and context-specific settings (store + action log are implicitly per-context).

In config (YAML), Network and Keyring are serialized as name strings that reference top-level network and keyring definitions. After resolution via Manager.Resolve(), the full Network and Keyring objects are populated with all their fields.

TrackedAccounts names the accounts store reconciliation covers (SPEC §6.7): empty means the default account alone, ["*"] every account in the context's keyring.

ConsoleOrganization and ConsoleProject select the Console organization (team) and project that Console calls act in (SPEC §7.1.1). Empty means the API key's own scope, which is how every context behaved before teams. Manager.Resolve applies their environment overrides.

func (Context) MarshalYAML

func (c Context) MarshalYAML() (interface{}, error)

MarshalYAML serializes a Context to YAML, writing Network and Keyring as name strings.

func (*Context) UnmarshalYAML

func (c *Context) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML deserializes a Context from YAML, reading Network and Keyring as name strings. The full Network and Keyring objects are populated later by Manager.Resolve() or Manager load logic.

type Defaults

type Defaults struct {
	Output        string `yaml:"output,omitempty"         json:"output,omitempty"`
	BroadcastMode string `yaml:"broadcast-mode,omitempty" json:"broadcast_mode,omitempty"`
	// CommandGating selects how commands the context configuration cannot
	// execute are presented: dim (default), hide, or off. Both dim and
	// hide are supported while UX feedback is collected.
	CommandGating string `yaml:"command-gating,omitempty" json:"command_gating,omitempty"`
}

Defaults holds global default values.

type Endpoints

type Endpoints struct {
	RPC  []string `yaml:"rpc"            json:"rpc"`
	API  []string `yaml:"api,omitempty"  json:"api,omitempty"`
	GRPC []string `yaml:"grpc,omitempty" json:"grpc,omitempty"`
}

Endpoints defines the network transport endpoints.

type Keyring

type Keyring struct {
	Name    string `yaml:"name"              json:"name"`
	Backend string `yaml:"backend,omitempty" json:"backend,omitempty"`
	Dir     string `yaml:"dir,omitempty"     json:"dir,omitempty"`
}

Keyring defines wallet storage configuration. Keyrings are shared -- adding a key makes it available to all contexts using the keyring.

func DefaultKeyring

func DefaultKeyring() Keyring

DefaultKeyring returns the default keyring configuration.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager provides CRUD operations for networks, contexts, and keyrings. It holds the config in memory and persists changes to disk. Manager is safe for concurrent use.

func NewManager

func NewManager(root string) (*Manager, error)

NewManager creates a manager by loading (or initialising) config from root.

func (*Manager) ActiveContext

func (m *Manager) ActiveContext(override string) string

ActiveContext resolves which context a run targets: the explicit override (the global --context flag), else current-context, else the sole configured context. Returns "" when no single context can be determined.

func (*Manager) Config

func (m *Manager) Config() Config

Config returns a shallow copy of the current config.

func (*Manager) CreateContext

func (m *Manager) CreateContext(ctx Context) error

CreateContext adds a new context. The referenced network and keyring must exist.

func (*Manager) CreateKeyring

func (m *Manager) CreateKeyring(kr Keyring) error

CreateKeyring adds a new keyring definition.

func (*Manager) CreateNetwork

func (m *Manager) CreateNetwork(net Network) error

CreateNetwork adds a new network definition. If template is non-empty, the network fields are populated from NetworkTemplates.

func (*Manager) CreateNetworkFromTemplate

func (m *Manager) CreateNetworkFromTemplate(name, template string) error

CreateNetworkFromTemplate creates a network from a built-in template. The name parameter overrides the template's default name.

func (*Manager) CurrentContext

func (m *Manager) CurrentContext() string

CurrentContext returns the name of the active context.

func (*Manager) DeleteContext

func (m *Manager) DeleteContext(name string, keepData bool) error

DeleteContext removes a context. Cannot delete the current context. If keepData is false, the context data directory is also removed.

func (*Manager) DeleteNetwork

func (m *Manager) DeleteNetwork(name string) error

DeleteNetwork removes a network. It fails if any context references it.

func (*Manager) ForkNetwork

func (m *Manager) ForkNetwork(srcName, newName string) error

ForkNetwork creates a copy of an existing network with a new name.

func (*Manager) GetContext

func (m *Manager) GetContext(name string) *Context

GetContext returns a context by name, or nil if not found.

func (*Manager) GetKeyring

func (m *Manager) GetKeyring(name string) *Keyring

GetKeyring returns a keyring by name, or nil if not found.

func (*Manager) GetNetwork

func (m *Manager) GetNetwork(name string) *Network

GetNetwork returns a network by name, or nil if not found.

func (*Manager) KeyringUsers added in v0.0.4

func (m *Manager) KeyringUsers(name string) []string

KeyringUsers returns the names of contexts referencing the named keyring.

func (*Manager) ListContexts

func (m *Manager) ListContexts() []Context

ListContexts returns all configured contexts.

func (*Manager) ListKeyrings

func (m *Manager) ListKeyrings() []Keyring

ListKeyrings returns all configured keyrings.

func (*Manager) ListNetworks

func (m *Manager) ListNetworks() []Network

ListNetworks returns all configured networks.

func (*Manager) NetworkUsers

func (m *Manager) NetworkUsers(name string) []string

NetworkUsers returns the names of contexts referencing a network.

func (*Manager) Reload

func (m *Manager) Reload() error

Reload re-reads the config file from disk, replacing the in-memory state.

func (*Manager) RenameContext

func (m *Manager) RenameContext(oldName, newName string) error

RenameContext renames a context and its data directory.

func (*Manager) Resolve

func (m *Manager) Resolve(name string) (*Context, error)

Resolve resolves the current (or named) context into a fully populated Context. This dereferences the network and keyring names into their full definitions and populates the convenience fields (GasPrices, GasAdjustment, AuthType, Root).

func (*Manager) Root

func (m *Manager) Root() string

Root returns the config root directory.

func (*Manager) UpdateContext

func (m *Manager) UpdateContext(name string, apply func(*Context) error) error

UpdateContext modifies an existing context in-place.

func (*Manager) UpdateContextAndNetwork added in v0.0.3

func (m *Manager) UpdateContextAndNetwork(
	name string,
	forkName string,
	applyContext func(*Context) error,
	applyNetwork func(*Network) error,
) error

UpdateContextAndNetwork applies context and optional network changes in one config write. When forkName is non-empty, the selected network is copied, updated, and assigned only to the named context. A failed validation or save leaves both the in-memory manager and config file at their prior state.

func (*Manager) UpdateKeyring added in v0.0.4

func (m *Manager) UpdateKeyring(name string, apply func(*Keyring) error) error

UpdateKeyring mutates an existing keyring definition in place. Without it the only way to change where a context stores its keys after first run was to hand-edit config.yaml (SPEC §2.2.2).

func (*Manager) UpdateNetwork

func (m *Manager) UpdateNetwork(name string, apply func(*Network) error) error

UpdateNetwork replaces a network definition in-place. All contexts referencing this network see the change.

func (*Manager) UseContext

func (m *Manager) UseContext(name string) error

UseContext switches the active context.

type Network

type Network struct {
	Name          string    `yaml:"name"                      json:"name"`
	ChainID       string    `yaml:"chain-id"                  json:"chain_id"`
	Endpoints     Endpoints `yaml:"endpoints"                 json:"endpoints"`
	GasPrices     string    `yaml:"gas-prices,omitempty"      json:"gas_prices,omitempty"`
	GasAdjustment string    `yaml:"gas-adjustment,omitempty"  json:"gas_adjustment,omitempty"`
	Faucet        string    `yaml:"faucet,omitempty"          json:"faucet,omitempty"`
}

Network defines chain connectivity settings. Networks are shared resources -- multiple contexts can reference the same network.

type PluginSettings

type PluginSettings struct {
	Paths    []string `yaml:"paths,omitempty"    json:"paths,omitempty"`
	Disabled []string `yaml:"disabled,omitempty" json:"disabled,omitempty"`
}

PluginSettings holds plugin-specific configuration.

type ProviderDefaults

type ProviderDefaults struct {
	AuthType string `yaml:"auth-type,omitempty" json:"auth_type,omitempty"`
}

ProviderDefaults holds provider-specific defaults for a context.

type TUISettings

type TUISettings struct {
	Theme             string            `yaml:"theme,omitempty"              json:"theme,omitempty"`
	Keybindings       string            `yaml:"keybindings,omitempty"        json:"keybindings,omitempty"`
	CustomKeybindings map[string]string `yaml:"custom-keybindings,omitempty" json:"custom_keybindings,omitempty"`
	RefreshInterval   string            `yaml:"refresh-interval,omitempty"   json:"refresh_interval,omitempty"`
}

TUISettings holds TUI-specific configuration.

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

Watcher monitors config.yaml for changes and reloads the Manager. Subscribers are notified via callback after each successful reload.

func NewWatcher

func NewWatcher(mgr *Manager) (*Watcher, error)

NewWatcher creates a filesystem watcher on the config file. It does NOT start watching; call Start() to begin.

func (*Watcher) Start

func (w *Watcher) Start() error

Start begins watching the config file for writes. It blocks internally in a goroutine; call Stop() to tear down.

func (*Watcher) Stop

func (w *Watcher) Stop()

Stop terminates the watcher goroutine and releases resources.

func (*Watcher) Subscribe

func (w *Watcher) Subscribe(fn func(*Config))

Subscribe registers a callback that fires after every successful config reload. The callback receives the new Config value. Must be called before Start.

Jump to

Keyboard shortcuts

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