Documentation
¶
Index ¶
- Constants
- Variables
- func ComputeHash(data []byte, algorithmBits int) string
- func ComputeIdentityHash(identity *vault.Identity) string
- func ExitWithError(err error)
- func PrintHelp(w io.Writer)
- func PrintSuccess(w io.Writer, message string)
- func PrintVersion(w io.Writer, version, commit, date string)
- func PrintWarning(w io.Writer, message string)
- func ResolveConfigPath(configPath string, silent bool, stderr io.Writer) string
- type CLI
- func (c *CLI) Close() error
- func (c *CLI) IdentityAdd(fingerprint string, all bool) *Error
- func (c *CLI) IdentityList(jsonOutput bool) *Error
- func (c *CLI) Login(fingerprint string) *Error
- func (c *CLI) Output() *output.Handler
- func (c *CLI) SecretGet(secretKey string, all bool, last bool, jsonOutput bool, vaultPath string, ...) *Error
- func (c *CLI) SecretPut(secretKeyArg, vaultPath string, fromIndex int) *Error
- func (c *CLI) SecretRevoke(secretKey, targetFingerprint string, vaultIndex int) *Error
- func (c *CLI) SecretRevokeAll(secretKey, targetFingerprint string) *Error
- func (c *CLI) SecretShare(secretKey, targetFingerprint string, vaultIndex int) *Error
- func (c *CLI) SecretShareAll(secretKey, targetFingerprint string) *Error
- func (c *CLI) SetJSONMode(enabled bool)
- func (c *CLI) Validate(fix bool) *Error
- func (c *CLI) VaultDefrag(dryRun bool, jsonOutput bool, skipConfirm bool, vaultPath string, ...) *Error
- func (c *CLI) VaultList(jsonOutput bool) *Error
- func (c *CLI) Warnf(format string, args ...interface{})
- type DefragStatsJSON
- type Error
- func HandleInteractiveSelection(options []string, prompt string, stderr io.Writer) (int, *Error)
- func InitConfig(configPath string, initialVaults []string, gpgProgram string, ...) *Error
- func InitVaultFile(vaultPath string, stdout, stderr io.Writer) *Error
- func InitVaultInteractiveStandalone(configPath string, stdout, stderr io.Writer) *Error
- func NewError(message string, code ExitCode) *Error
- func PromptConfirm(prompt string, stderr io.Writer) (bool, *Error)
- type ExitCode
- type IdentityInfoJSON
- type IdentityListJSON
- type SecretValueJSON
- type ValidationError
- type VaultListJSON
- type VaultResolver
Constants ¶
const ( ExitSuccess = output.ExitSuccess ExitGeneralError = output.ExitGeneralError ExitConfigError = output.ExitConfigError ExitVaultError = output.ExitVaultError ExitGPGError = output.ExitGPGError ExitAuthError = output.ExitAuthError ExitValidationError = output.ExitValidationError ExitFingerprintRequired = output.ExitFingerprintRequired ExitAccessDenied = output.ExitAccessDenied ExitAlgorithmNotAllowed = output.ExitAlgorithmNotAllowed )
Exit code constants - aliases to output package.
Variables ¶
var ErrUserCancelled = errors.New("cancelled by user")
ErrUserCancelled is returned when the user cancels an interactive prompt (Ctrl-C or Escape)
Functions ¶
func ComputeHash ¶
ComputeHash computes a cryptographic hash of the data based on the algorithm bits Uses SHA-512 for keys >= 256 bits (RSA 4096, ECC P-521), SHA-256 for smaller keys
func ComputeIdentityHash ¶
ComputeIdentityHash computes the canonical hash for an identity
func ExitWithError ¶
func ExitWithError(err error)
ExitWithError exits the program with the given error.
func PrintSuccess ¶
PrintSuccess prints a success message to stdout.
func PrintVersion ¶
PrintVersion prints the version information
func PrintWarning ¶
PrintWarning prints a warning to stderr.
func ResolveConfigPath ¶
ResolveConfigPath returns the effective config path considering: 1. Explicit configPath argument (highest priority, e.g. -c flag) 2. /etc/dotsecenv/config (if SUID mode) 3. DOTSECENV_CONFIG env var (if not SUID mode) 4. XDG default path If configPath is specified and DOTSECENV_CONFIG is set, prints a warning to stderr (unless silent).
Types ¶
type CLI ¶
type CLI struct {
Silent bool
Strict bool // Strict mode: certain warnings become errors
// contains filtered or unexported fields
}
CLI represents the command-line interface
func (*CLI) IdentityAdd ¶
IdentityAdd adds an identity to the vault
func (*CLI) IdentityList ¶
IdentityList lists all identities in all vaults
func (*CLI) SecretGet ¶
func (c *CLI) SecretGet(secretKey string, all bool, last bool, jsonOutput bool, vaultPath string, fromIndex int) *Error
SecretGet retrieves a secret from the vault. If c.Strict is true (from config), only returns a value if the user has access to the LATEST value of the secret.
func (*CLI) SecretRevoke ¶
SecretRevoke re-encrypts a secret without the specified fingerprint, effectively revoking their access. If the secret is shared with the fingerprint, it re-encrypts with every other public key except the one corresponding to the fingerprint, updates available_to, regenerates the hash, and signs it.
func (*CLI) SecretRevokeAll ¶
SecretRevokeAll revokes access to a secret from a fingerprint across all vaults.
func (*CLI) SecretShare ¶
SecretShare shares a secret with another identity
func (*CLI) SecretShareAll ¶
SecretShareAll shares a secret with a fingerprint across all vaults where the secret exists.
func (*CLI) SetJSONMode ¶
SetJSONMode enables or disables JSON output mode for the current command. This creates a new handler with fresh warning collection.
func (*CLI) VaultDefrag ¶
func (c *CLI) VaultDefrag(dryRun bool, jsonOutput bool, skipConfirm bool, vaultPath string, fromIndex int) *Error
VaultDefrag shows fragmentation stats or performs defragmentation on a single vault
type DefragStatsJSON ¶
type DefragStatsJSON struct {
Vault string `json:"vault"`
TotalEntries int `json:"total_entries"`
TotalLines int `json:"total_lines"`
FragmentationRatio float64 `json:"fragmentation_ratio"`
RecommendDefrag bool `json:"recommend_defrag"`
Reason string `json:"reason"`
Defragmented bool `json:"defragmented,omitempty"`
}
DefragStatsJSON is the JSON output structure for defrag stats
type Error ¶
Error represents a CLI error with an exit code. Kept for backward compatibility; new code should use output.Error.
func HandleInteractiveSelection ¶
HandleInteractiveSelection prompts the user to select from options and handles cancellation uniformly. It opens /dev/tty directly for input, allowing interactive selection even when stdin is piped. Returns the selected index and nil on success, or writes "Cancelled." to stderr and returns an error on cancellation.
func InitConfig ¶
func InitConfig(configPath string, initialVaults []string, gpgProgram string, noGPGProgram bool, stdout, stderr io.Writer) *Error
InitConfig initializes a configuration file with FIPS-compliant defaults. gpgProgram: if non-empty, use this value for gpg.program (without validation) noGPGProgram: if true, skip GPG detection entirely and leave gpg.program empty
func InitVaultFile ¶
InitVaultFile initializes a specific vault file
func InitVaultInteractiveStandalone ¶
InitVaultInteractiveStandalone allows user to select a vault from config to initialize This runs without requiring the vaults to be openable (since they might not exist yet)
func NewError ¶
NewError creates a new CLI error. For new code, prefer output.NewError with a structured code.
func PromptConfirm ¶
PromptConfirm asks the user for a y/n confirmation. Returns true if confirmed, false if declined, or an error on cancellation. Opens /dev/tty directly to work even when stdin is piped.
type ExitCode ¶
ExitCode represents the exit code for an error. This is an alias to the output package for backward compatibility.
type IdentityInfoJSON ¶
type IdentityInfoJSON struct {
Algorithm string `json:"algorithm"`
AlgorithmBits int `json:"algorithm_bits"`
Curve string `json:"curve,omitempty"`
CreatedAt time.Time `json:"created_at"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
Fingerprint string `json:"fingerprint"`
UID string `json:"uid"`
}
IdentityInfoJSON is the JSON output structure for identity info
type IdentityListJSON ¶
type IdentityListJSON struct {
Vault string `json:"vault"`
Identities []IdentityInfoJSON `json:"identities"`
}
IdentityListJSON is the JSON output structure for identity list
type SecretValueJSON ¶
type SecretValueJSON struct {
AddedAt time.Time `json:"added_at"`
Value string `json:"value"`
Vault string `json:"vault,omitempty"`
}
SecretValueJSON is the JSON output structure for secret values
type ValidationError ¶
type ValidationError struct {
Level string // "GLOBAL", "IDENTITY", "SECRET", "STRUCTURE"
Message string
Path string // For errors in specific items
}
ValidationError represents a validation error with context
type VaultListJSON ¶
type VaultListJSON struct {
Position int `json:"position"`
Vault string `json:"vault"`
Secrets []string `json:"secrets"`
}
VaultListJSON is the JSON output structure for vault list
type VaultResolver ¶
type VaultResolver interface {
GetIdentityByFingerprint(fingerprint string) *vault.Identity
AddSecret(secret vault.Secret, index int) error
SaveAll() error
GetSecretFromAnyVault(key string, stderr io.Writer) (*vault.SecretValue, error)
GetAccessibleSecretFromAnyVault(key, fingerprint string, strict bool) (*vault.SecretValue, error)
GetSecretByKeyFromVault(index int, key string) *vault.Secret
FindSecretVaultIndex(key string) int
GetVaultManager(index int) *vault.Manager
AddIdentity(identity vault.Identity, index int) error
GetConfig() vault.VaultConfig
GetVaultPaths() []string
IsPathInConfig(path string) bool
IdentityExistsInVault(fingerprint string, index int) bool
SaveVault(index int) error
CloseAll() error
GetLoadError(index int) error
GetSecret(index int, key string) (*vault.SecretValue, error)
OpenVaultsFromPaths(paths []string, stderr io.Writer) error
OpenVaults(stderr io.Writer) error
VaultCount() int
}
VaultResolver defines the interface for vault operations required by the CLI