Documentation
¶
Overview ¶
Package internal provides shared utilities for CLI commands.
Index ¶
- Constants
- Variables
- func AWSParamStrategyFactory(ctx context.Context) (staging.FullStrategy, error)
- func AWSSecretStrategyFactory(ctx context.Context) (staging.FullStrategy, error)
- func AzureAppConfigNamespace(ctx context.Context) string
- func AzureAppConfigParamStrategyFactory(ctx context.Context) (staging.FullStrategy, error)
- func AzureAppConfigStagingScopeResolver(ctx context.Context) (staging.ResolvedScope, error)
- func AzureAppConfigStore(ctx context.Context) (provider.Store, error)
- func AzureKeyVaultSecretStrategyFactory(ctx context.Context) (staging.FullStrategy, error)
- func AzureKeyVaultStagingScopeResolver(ctx context.Context) (staging.ResolvedScope, error)
- func AzureKeyVaultStore(ctx context.Context) (provider.Store, error)
- func CommandNotFound(_ context.Context, cmd *cli.Command, command string)
- func GoogleCloudSecretStore(ctx context.Context) (provider.Store, error)
- func GoogleCloudSecretStrategyFactory(ctx context.Context) (staging.FullStrategy, error)
- func GoogleCloudStagingScopeResolver(ctx context.Context) (staging.ResolvedScope, error)
- func ParamStore(ctx context.Context) (provider.Store, error)
- func ResolveValue(ctx context.Context, src ValueSource) (value string, proceed bool, err error)
- func SecretStore(ctx context.Context) (provider.Store, error)
- func Stdin(cmd *cli.Command) io.Reader
- func ValueStdinFlag() cli.Flag
- func WithAzureAppConfigNamespace(ctx context.Context, namespace string) context.Context
- func WithAzureStoreName(ctx context.Context, storeName string) context.Context
- func WithAzureVaultName(ctx context.Context, vaultName string) context.Context
- func WithGoogleCloudProject(ctx context.Context, project string) context.Context
- func WithPager(cmd *cli.Command, noPager bool, fn func(stdout, stderr io.Writer) error) error
- type ValueSource
Constants ¶
const CommandNotFoundExitCode = 1
CommandNotFoundExitCode is the process exit code produced for an unknown command. urfave/cli's CommandNotFound hook is a void func, so Command.Run returns nil after it runs and the process would otherwise exit 0 — making scripts/CI treat typos as success. The handlers exit non-zero explicitly.
const FlagValueStdin = "value-stdin"
FlagValueStdin is the name of the flag that reads a create/update value from stdin instead of a positional argument, keeping the secret out of argv (and therefore out of ps/proc/cmdline and shell history).
Variables ¶
var ErrValueRequired = errors.New( "value is required: pass it as an argument, pipe it in with --" + FlagValueStdin + ", or run interactively to edit it in $EDITOR", )
ErrValueRequired is returned when no value was provided and the editor fallback is unavailable because the session is non-interactive (a pipe, CI, or any non-TTY stdin). It never hangs waiting on an editor.
var ErrValueStdinNeedsYes = errors.New( "--" + FlagValueStdin + " consumes stdin, so the confirmation prompt cannot be read; " + "re-run with --yes to acknowledge the update", )
ErrValueStdinNeedsYes is returned when the value was read from stdin via --value-stdin but a confirmation prompt would still run afterwards. The prompt reads from the same stdin, which has already been consumed, so it would immediately hit EOF. Rather than fail cryptically, we detect this up front and tell the user to re-run with --yes. We intentionally neither imply --yes nor read the confirmation from /dev/tty, so the acknowledgement stays explicit.
Functions ¶
func AWSParamStrategyFactory ¶ added in v1.8.2
func AWSParamStrategyFactory(ctx context.Context) (staging.FullStrategy, error)
AWSParamStrategyFactory builds a staging FullStrategy for the parameter service, wrapping a provider.Store resolved through the registry. It satisfies staging.StrategyFactory.
func AWSSecretStrategyFactory ¶ added in v1.8.2
func AWSSecretStrategyFactory(ctx context.Context) (staging.FullStrategy, error)
AWSSecretStrategyFactory builds a staging FullStrategy for the secret service, wrapping a provider.Store resolved through the registry. It satisfies staging.StrategyFactory.
func AzureAppConfigNamespace ¶ added in v1.4.5
AzureAppConfigNamespace returns the Azure App Configuration namespace resolved into ctx by WithAzureAppConfigNamespace (empty = the null/default namespace).
func AzureAppConfigParamStrategyFactory ¶ added in v0.8.1
func AzureAppConfigParamStrategyFactory(ctx context.Context) (staging.FullStrategy, error)
AzureAppConfigParamStrategyFactory builds a staging FullStrategy for Azure App Configuration, wrapping a provider.Store resolved for the context's store. It satisfies staging.StrategyFactory.
func AzureAppConfigStagingScopeResolver ¶ added in v0.8.1
func AzureAppConfigStagingScopeResolver(ctx context.Context) (staging.ResolvedScope, error)
AzureAppConfigStagingScopeResolver resolves the Azure App Configuration staging scope from the store name stashed in the context (see WithAzureStoreName). It performs no network calls.
func AzureAppConfigStore ¶ added in v0.8.0
AzureAppConfigStore resolves a provider.Store for the Azure App Configuration (param) service. The store name is read from the context (see WithAzureStoreName); it returns a clear error when no store name was resolved.
func AzureKeyVaultSecretStrategyFactory ¶ added in v0.8.1
func AzureKeyVaultSecretStrategyFactory(ctx context.Context) (staging.FullStrategy, error)
AzureKeyVaultSecretStrategyFactory builds a staging FullStrategy for Azure Key Vault secrets, wrapping a provider.Store resolved for the context's vault. It satisfies staging.StrategyFactory.
func AzureKeyVaultStagingScopeResolver ¶ added in v0.8.1
func AzureKeyVaultStagingScopeResolver(ctx context.Context) (staging.ResolvedScope, error)
AzureKeyVaultStagingScopeResolver resolves the Azure Key Vault staging scope from the vault name stashed in the context (see WithAzureVaultName). It performs no network calls.
func AzureKeyVaultStore ¶ added in v0.8.0
AzureKeyVaultStore resolves a provider.Store for the Azure Key Vault (secret) service. The vault name is read from the context (see WithAzureVaultName); it returns a clear error when no vault name was resolved.
func CommandNotFound ¶
CommandNotFound is a shared handler for unknown subcommands. It displays the command help and an error message, then exits non-zero.
func GoogleCloudSecretStore ¶ added in v0.8.1
GoogleCloudSecretStore resolves a provider.Store for the Google Cloud Secret Manager service. The project id is read from the context (see WithGoogleCloudProject); it returns a clear error when no project could be resolved.
func GoogleCloudSecretStrategyFactory ¶ added in v0.8.1
func GoogleCloudSecretStrategyFactory(ctx context.Context) (staging.FullStrategy, error)
GoogleCloudSecretStrategyFactory builds a staging FullStrategy for Google Cloud Secret Manager, wrapping a provider.Store resolved for the context's project. It satisfies staging.StrategyFactory.
func GoogleCloudStagingScopeResolver ¶ added in v0.8.1
func GoogleCloudStagingScopeResolver(ctx context.Context) (staging.ResolvedScope, error)
GoogleCloudStagingScopeResolver resolves the Google Cloud staging scope from the project stashed in the context (see WithGoogleCloudProject). It performs no network calls. It satisfies staging.ScopeResolver.
func ParamStore ¶ added in v0.8.0
ParamStore resolves a provider.Store for the parameter service via the registry (AWS by default).
func ResolveValue ¶ added in v1.8.0
ResolveValue determines the value for a create/update command. Precedence:
- --value-stdin: read the whole of stdin (one trailing newline trimmed).
- the positional value argument, when supplied.
- $EDITOR fallback: open an empty buffer and use whatever is saved.
proceed reports whether the command should continue. It is false only when the editor fallback returns an empty value, which is treated as a cancellation (matching the staging add/edit UX). --value-stdin and the positional argument always proceed, even with an empty value, because those are explicit.
When ConfirmRequired is set alongside --value-stdin, ResolveValue returns ErrValueStdinNeedsYes instead of reading stdin, because the later confirmation prompt would find stdin already consumed.
func SecretStore ¶ added in v0.8.0
SecretStore resolves a provider.Store for the secret service via the registry (AWS by default).
func Stdin ¶ added in v1.8.0
Stdin returns the command's configured reader, falling back to os.Stdin when none is set. The production app leaves Reader unset, so this preserves the real stdin there while letting tests inject a reader through cmd.Root().Reader.
func ValueStdinFlag ¶ added in v1.8.0
ValueStdinFlag returns the shared --value-stdin flag used by the direct create/update commands across every provider.
func WithAzureAppConfigNamespace ¶ added in v1.4.5
WithAzureAppConfigNamespace returns a context carrying the resolved Azure App Configuration namespace (the axis Azure calls a "label"), merged onto any base scope already present. The azure param subgroup's Before hook sets it (from --namespace/--ns or the AZURE_APPCONFIG_NAMESPACE env). Empty is the null (default) namespace and also overrides an env default back to null.
func WithAzureStoreName ¶ added in v0.8.0
WithAzureStoreName returns a context carrying the resolved Azure App Configuration store name, merged onto any base scope already present. The azure param subgroup's Before hook sets it (from --store-name or its env fallback).
func WithAzureVaultName ¶ added in v0.8.0
WithAzureVaultName returns a context carrying the resolved Azure Key Vault name, merged onto any base scope already present. The azure secret subgroup's Before hook sets it (from --vault-name or its env fallback).
func WithGoogleCloudProject ¶ added in v0.8.1
WithGoogleCloudProject returns a context carrying the resolved Google Cloud project id. The gcloud command group sets it once (from --project or the GOOGLE_CLOUD_PROJECT env) so every gcloud subcommand can resolve a store without threading the flag through the generic command Config.
Types ¶
type ValueSource ¶ added in v1.8.0
type ValueSource struct {
// FromStdin is true when --value-stdin was given.
FromStdin bool
// HasArg is true when a positional value argument was supplied.
HasArg bool
// Arg is the positional value argument (only meaningful when HasArg).
Arg string
// Stdin is the reader used when FromStdin is true (nil -> os.Stdin).
Stdin io.Reader
// OpenEditor is the editor seam used for the fallback path (nil -> editor.Open).
OpenEditor editor.OpenFunc
// ConfirmRequired is true when the command would prompt for confirmation on
// the same stdin after resolving the value (i.e. an update without --yes).
// Combined with FromStdin this is the double-consume case, so ResolveValue
// fails with ErrValueStdinNeedsYes instead of letting the later prompt hit
// EOF.
ConfirmRequired bool
}
ValueSource describes where a create/update value may come from. Exactly one of the non-editor sources is selected by ResolveValue's precedence rules.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package apptest provides helpers for constructing the CLI app with a deterministic provider-detection result, so command tests do not depend on the ambient environment (which decides the top-level param/secret aliases).
|
Package apptest provides helpers for constructing the CLI app with a deterministic provider-detection result, so command tests do not depend on the ambient environment (which decides the top-level param/secret aliases). |