config

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package config resolves the CLI connection context from flags, env and ~/.miabi/config.yaml, in that order.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Path

func Path() string

Path returns MIABI_CONFIG, else ~/.miabi/config.yaml.

func Save

func Save(f *File) error

Save writes the file with mode 0600 because 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 app bound by `miabi use`; it is cleared whenever the workspace changes.

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 (server, token, bound workspace/app).

func (Context) MarshalYAML added in v0.10.0

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

MarshalYAML base64-encodes the token: obfuscation only, not encryption.

func (*Context) UnmarshalYAML added in v0.10.0

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

type Effective

type Effective struct {
	Context      string // "" when no context applies
	URL          string
	Token        string
	CA           string
	InsecureSkip bool
	Workspace    *WorkspaceRef
	App          *AppRef
}

Effective is the resolved context a command runs against.

func Resolve

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

Resolve drops the context's token and settings when a server override points elsewhere, so they never leak.

type File

type File struct {
	Current  string              `yaml:"current,omitempty"`
	Contexts map[string]*Context `yaml:"contexts,omitempty"`

	// Legacy single-context fields, migrated on Load and cleared so Save never re-emits them.
	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"`
}

File mirrors ~/.miabi/config.yaml: a set of named contexts and the active one.

func Load

func Load() (*File, error)

Load treats a missing file as empty, so env-only CI 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.

func (*File) EnsureContext added in v0.10.0

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

EnsureContext returns the named context, creating it if absent, and makes it current.

func (*File) EnsureCurrent added in v0.10.0

func (f *File) EnsureCurrent() *Context

EnsureCurrent creates a "default" context when none is set, so binding works before login.

func (*File) EnsureSelected added in v0.21.0

func (f *File) EnsureSelected(flag string) *Context

EnsureSelected is EnsureCurrent for the selected context; it never changes `current`.

func (*File) Selected added in v0.21.0

func (f *File) Selected(flag string) *Context

Selected returns the selected context, or nil when none is set or it is unknown.

func (*File) SelectedName added in v0.21.0

func (f *File) SelectedName(flag string) string

SelectedName picks --context, else MIABI_CONTEXT, else the file's current context.

type Flags added in v0.10.0

type Flags struct {
	Context      string
	Server       string // --server or the deprecated --url
	Token        string
	CA           string
	InsecureSkip bool
}

Flags carries the parsed connection flags, which take precedence over env and context.

type Identity added in v0.10.0

type Identity struct {
	Name     string `yaml:"name,omitempty" json:"name,omitempty"`
	Username string `yaml:"username,omitempty" json:"username,omitempty"`
	Email    string `yaml:"email,omitempty" json:"email,omitempty"`
}

Identity is captured at login for offline display only; 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 PEM bundle trusted in addition to the system roots.
	CA string `yaml:"ca,omitempty"`
	// InsecureSkip disables TLS verification entirely; never use it against a public server.
	InsecureSkip bool `yaml:"insecure_skip,omitempty"`
}

Server describes how to reach and trust one Miabi control plane.

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.

Jump to

Keyboard shortcuts

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