mdmctl

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package mdmctl implements the admin CLI. cmd/mdmctl is a main that parses argv and calls Run; everything else lives here.

Why

The split is forced by arithmetic rather than taste. scripts/coverage-gate.sh computes the repository figure from every package in the merged profile, including exempt ones, and make test runs with -coverpkg=./..., so an uncovered command package still drags the total down. The cmd/ exemption suppresses the per-package line and nothing more. Keeping the logic here means it is gated at 95% like everything else; micromdm's cmd/mdmctl is 3185 lines with three trivial tests, and nanohubctl has none.

Two behaviours are worth knowing about. Credentials are referenced, never stored: the config file holds the name of an environment variable or a file path, and there is no subcommand whose job is printing a secret. And the output modes are separate on purpose, with -output json emitting the server's bytes unchanged so canonical JSON survives to jq.

References

  • Decision record: docs/research/decisions/0035-mdmctl-structure-and-credentials.md
  • Decision record: docs/research/decisions/0036-mdmctl-explain-over-schema-support.md
  • Decision record: docs/research/decisions/0034-admin-api-and-authorization.md
  • Plan of record: docs/research/implementation_plan.md (phase 8)
  • E2E scenarios: docs/testing/e2e-scenarios.md (E2E-024)

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 DefaultServer = "http://127.0.0.1:8080"

DefaultServer is used when neither -server, MDMCTL_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("mdmctl: config file is readable by other users")

ErrConfigPermissions is a config file other users can read.

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.
	TokenEnv string `json:"token_env,omitempty"`
	// TokenFile names a file holding the credential.
	TokenFile string `json:"token_file,omitempty"`
	// Token is an inlined credential. Writing one requires an explicit flag
	// and prints a warning; it exists because some environments have nowhere
	// better, not because it is a good idea.
	Token string `json:"token,omitempty"`
}

Context is one server the CLI talks to.

Directories

Path Synopsis
Package adminclient is the typed HTTP client mdmctl uses against the reference server's admin API.
Package adminclient is the typed HTTP client mdmctl uses against the reference server's admin API.
Package explain answers what a command, declaration, profile payload, or status item is, and where Apple says it applies.
Package explain answers what a command, declaration, profile payload, or status item is, and where Apple says it applies.

Jump to

Keyboard shortcuts

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