Documentation
¶
Overview ¶
Package config resolves the CLI's connection context — the server URL and how to trust it, the API token, and the active workspace — from flags, environment, and ~/.miabi/config.yaml, in that precedence. The token is never logged.
Index ¶
- func Path() string
- func Save(f *File) error
- type AppRef
- type Context
- type Effective
- type File
- func (f *File) ContextNames() []string
- func (f *File) CurrentContext() *Context
- func (f *File) EnsureContext(name string) *Context
- func (f *File) EnsureCurrent() *Context
- func (f *File) EnsureSelected(flag string) *Context
- func (f *File) Selected(flag string) *Context
- func (f *File) SelectedName(flag string) string
- type Flags
- type Identity
- type Server
- type WorkspaceRef
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AppRef ¶ added in v0.10.0
type AppRef struct {
ID uint `yaml:"id" json:"id"`
Name string `yaml:"name" json:"name"`
DisplayName string `yaml:"display_name,omitempty" json:"display_name,omitempty"`
}
AppRef is the current application bound by `miabi use <app>`, so app-scoped commands need no explicit argument. It belongs to the active Workspace and is cleared whenever the workspace changes. Name is the unique handle commands address by; DisplayName is the free-text label, kept for display.
type Context ¶ added in v0.10.0
type Context struct {
Server Server `yaml:"server,omitempty"`
Token string `yaml:"token,omitempty"`
User *Identity `yaml:"user,omitempty"`
Workspace *WorkspaceRef `yaml:"workspace,omitempty"`
App *AppRef `yaml:"app,omitempty"`
}
Context is one named connection profile: how to reach and trust a Miabi server, the token to authenticate with, and the workspace/app bound for that server. Multiple contexts let you switch between Miabi instances (dev / staging / prod) with `miabi context use`.
func (Context) MarshalYAML ¶ added in v0.10.0
type Effective ¶
type Effective struct {
Context string // the context whose settings apply; "" when none does
URL string
Token string
CA string // path to a CA bundle; may be empty (system roots)
InsecureSkip bool // skip TLS verification
Workspace *WorkspaceRef // from the file; may be nil
App *AppRef // current app bound by `miabi use`; may be nil
}
Effective is the resolved context a command runs against.
func Resolve ¶
Resolve resolves the connection context: it picks the active context (--context → MIABI_CONTEXT → the file's `current`) and applies precedence flags → env → that context's values on top. Flags/env alone are enough (no context needed), so env-only CI keeps working. MIABI_SERVER is preferred over the legacy MIABI_URL. A context named with --context or MIABI_CONTEXT must exist. A server override pointing elsewhere drops the context's token, TLS settings, workspace and app, so they never reach another server.
type File ¶
type File struct {
Current string `yaml:"current,omitempty"`
Contexts map[string]*Context `yaml:"contexts,omitempty"`
// --- Legacy single-context fields (pre-multi-context). Read for backward
// compat and migrated into a context on Load, then cleared so Save writes only
// the multi-context form. Pointers/omitempty so they never re-emit. ---
LegacyServer *Server `yaml:"server,omitempty"`
LegacyToken string `yaml:"token,omitempty"`
LegacyUser *Identity `yaml:"user,omitempty"`
LegacyWorkspace *WorkspaceRef `yaml:"workspace,omitempty"`
LegacyApp *AppRef `yaml:"app,omitempty"`
LegacyURL string `yaml:"url,omitempty"` // oldest flat form
}
File mirrors ~/.miabi/config.yaml: a set of named contexts and the active one.
func Load ¶
Load reads the config file. A missing file is not an error (returns an empty File), so CI that uses only env vars never needs one.
func (*File) ContextNames ¶ added in v0.10.0
ContextNames returns the context names sorted, for listing.
func (*File) CurrentContext ¶ added in v0.10.0
CurrentContext returns the active context, or nil when none is set (e.g. a fresh install, or env-only CI use with no config file).
func (*File) EnsureContext ¶ added in v0.10.0
EnsureContext returns the named context, creating it (and the map) if absent, and makes it the current one. Used by login to write a connection profile.
func (*File) EnsureCurrent ¶ added in v0.10.0
EnsureCurrent returns the current context, creating a "default" one when none is set — so binding a workspace/app works even before an explicit login.
func (*File) EnsureSelected ¶ added in v0.21.0
EnsureSelected is EnsureCurrent for the selected context; it never changes `current`.
func (*File) Selected ¶ added in v0.21.0
Selected returns the selected context, or nil when none is set or it is unknown.
func (*File) SelectedName ¶ added in v0.21.0
SelectedName is the context a command runs against: --context, else MIABI_CONTEXT, else the file's current one.
type Flags ¶ added in v0.10.0
type Flags struct {
Context string // --context (select which context to use for this call)
Server string // --server (or the deprecated --url)
Token string // --token
CA string // --certificate-authority
InsecureSkip bool // --insecure-skip-tls-verify
}
Flags carries the connection flags a command parsed, for Resolve to apply at the top of the precedence chain (flags → env → active context).
type Identity ¶ added in v0.10.0
type Identity struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"` // display name
Username string `yaml:"username,omitempty" json:"username,omitempty"`
Email string `yaml:"email,omitempty" json:"email,omitempty"`
}
Identity is the authenticated user, captured at `miabi login` for offline display (`whoami`/`workspace show`). The token remains the source of truth.
type Server ¶ added in v0.10.0
type Server struct {
URL string `yaml:"url,omitempty"`
// CA is a path to a PEM CA bundle to trust in addition to the system roots
// (for a private/self-signed control-plane certificate). Empty uses system roots.
CA string `yaml:"ca,omitempty"`
// InsecureSkip disables TLS verification entirely. A blunt instrument for dev;
// prefer CA. Never use against a public server.
InsecureSkip bool `yaml:"insecure_skip,omitempty"`
}
Server describes how to reach and trust one Miabi control plane: its base URL, an optional custom CA bundle to trust, and an escape hatch to skip TLS verification (self-signed / homelab).
type WorkspaceRef ¶
type WorkspaceRef struct {
ID uint `yaml:"id" json:"id"`
Name string `yaml:"name" json:"name"`
DisplayName string `yaml:"display_name,omitempty" json:"display_name,omitempty"`
}
WorkspaceRef is the active workspace persisted by `miabi workspace switch`. ID is the durable key (paths address by it); Name is the unique handle and DisplayName the free-text label, kept for display.