config

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Path

func Path() string

Path returns the config file location (honoring MIABI_CONFIG, else ~/.miabi/config.yaml).

func Save

func Save(f *File) error

Save writes the config file, creating ~/.miabi with 0700 and the file with 0600 (it holds a token).

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

func (c Context) MarshalYAML() (any, error)

func (*Context) UnmarshalYAML added in v0.10.0

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

type Effective

type Effective struct {
	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

func Resolve(fl Flags) (*Effective, error)

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 missing/unknown context is not an error here — the generic "no server configured" surfaces if nothing else supplies one.

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

func Load() (*File, error)

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

func (f *File) ContextNames() []string

ContextNames returns the context names sorted, for listing.

func (*File) CurrentContext added in v0.10.0

func (f *File) CurrentContext() *Context

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

func (f *File) EnsureContext(name string) *Context

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

func (f *File) EnsureCurrent() *Context

EnsureCurrent returns the current context, creating a "default" one when none is set — so binding a workspace/app works even before an explicit login.

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.

Jump to

Keyboard shortcuts

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