dmctl

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: MIT Imports: 41 Imported by: 0

Documentation

Overview

Package dmctl implements command dispatch, configuration and output for the administrative CLI.

Design

server/cmd/dmctl delegates to Run so behavior is testable without a subprocess. Configuration stores credential references by default; explicit inline storage requires an option and warning. JSON output preserves server bytes, while human and NDJSON modes provide table and streaming output. HTTP handling and offline schema explanation live in subpackages. Exit codes distinguish usage, authorization, request failure and partial success.

References

Index

Constants

View Source
const (
	ExitOK      = 0
	ExitFailed  = 1 // the request failed: network, 5xx, malformed response
	ExitUsage   = 2 // unknown verb, bad flag, missing argument
	ExitPartial = 3 // the request succeeded but some targets did not
	ExitAuth    = 4 // 401 or 403

)

Exit codes. They are documented and distinct so a script can tell a usage mistake from a refusal from a partial success. Both reference CLIs exit 1 from arbitrary depth, which tells a caller nothing.

View Source
const (
	EnvServer  = "DMCTL_SERVER"
	EnvToken   = "DMCTL_TOKEN" // #nosec G101 -- the variable name, not a credential
	EnvContext = "DMCTL_CONTEXT"
	EnvConfig  = "DMCTL_CONFIG"
	EnvOutput  = "DMCTL_OUTPUT"
)

Environment variables read for the global flags. The flag help quotes these constants rather than repeating the names, so a rename cannot leave the help describing a variable the tool no longer reads.

View Source
const DefaultServer = "http://127.0.0.1:8080"

DefaultServer is used when neither -server, DMCTL_SERVER, nor the selected config context names one.

Variables

View Source
var (
	// ErrUsage is a command-line mistake rather than a server refusal.
	ErrUsage = errors.New("usage")
	// ErrPartial is a request that succeeded with some targets refused.
	ErrPartial = errors.New("partial success")
)

Errors that select an exit code.

View Source
var ErrConfigPermissions = errors.New("dmctl: config file is readable by other users")

ErrConfigPermissions is a config file other users can read.

View Source
var ErrEmptyCredential = errors.New("dmctl: credential environment variable is empty")

ErrEmptyCredential identifies an empty environment-backed credential.

Functions

func DefaultConfigPath

func DefaultConfigPath(getenv func(string) string) string

DefaultConfigPath is where the config lives when none is given.

func ExitCode

func ExitCode(err error) int

ExitCode maps an error to a process exit status.

func Run

func Run(
	ctx context.Context,
	args []string,
	getenv func(string) string,
	stdin io.Reader,
	stdout, stderr io.Writer,
) error

Run parses argv and dispatches. It returns an error; the caller maps it to an exit code with ExitCode.

func Verbs

func Verbs() []string

Verbs lists every registered verb, sorted. It exists so a test can assert the help and the dispatch table agree without repeating the list, which is what let new verbs ship undiscoverable.

Types

type Config

type Config struct {
	Current  string             `json:"current"`
	Contexts map[string]Context `json:"contexts"`
}

Config is the on-disk configuration.

A context holds a reference to a credential, never the credential. micromdm's mdmctl writes the live API token into ~/.micromdm/<name>.json under a directory it creates 0777, and its `config print` echoes the token to stdout; nanohubctl writes the key and prints it too. The file is the thing that leaks, and naming an environment variable or a file path costs the operator nothing.

type Context

type Context struct {
	Server string `json:"server"`
	// TokenEnv names an environment variable holding the credential.
	//nolint:tagliatelle // established on-disk configuration key
	TokenEnv string `json:"token_env,omitempty"`
	// TokenFile names a file holding the credential.
	//nolint:tagliatelle // established on-disk configuration key
	TokenFile string `json:"token_file,omitempty"`
	// Token stores an inline credential. Writing it requires explicit opt-in and
	// emits a warning; token_env and token_file are the default alternatives.
	Token string `json:"token,omitempty"`
}

Context is one server the CLI talks to.

Directories

Path Synopsis
Package adminclient implements dmctl's internal HTTP access to the reference server admin API.
Package adminclient implements dmctl's internal HTTP access to the reference server admin API.
Package explain resolves compiled schema identifiers and renders their support metadata.
Package explain resolves compiled schema identifiers and renders their support metadata.

Jump to

Keyboard shortcuts

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