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 ¶
- Decision record: https://github.com/deploymenttheory/go-apple-dm/blob/main/docs/research/decisions/0035-dmctl-structure-and-credentials.md
- Decision record: https://github.com/deploymenttheory/go-apple-dm/blob/main/docs/research/decisions/0036-dmctl-explain-over-schema-support.md
- Decision record: https://github.com/deploymenttheory/go-apple-dm/blob/main/docs/research/decisions/0034-admin-api-and-authorization.md
- E2E scenarios: https://github.com/deploymenttheory/go-apple-dm/blob/main/docs/testing/e2e-scenarios.md (E2E-024)
Index ¶
Constants ¶
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.
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.
const DefaultServer = "http://127.0.0.1:8080"
DefaultServer is used when neither -server, DMCTL_SERVER, nor the selected config context names one.
Variables ¶
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.
var ErrConfigPermissions = errors.New("dmctl: config file is readable by other users")
ErrConfigPermissions is a config file other users can read.
var ErrEmptyCredential = errors.New("dmctl: credential environment variable is empty")
ErrEmptyCredential identifies an empty environment-backed credential.
Functions ¶
func DefaultConfigPath ¶
DefaultConfigPath is where the config lives when none is given.
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.
Source Files
¶
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. |