Compare commits
No commits in common. "2a1e0337fd46913d547072b6e518e73fdf0289b6" and "dd2e95f8af45fa93a3d3b0ace80175735a7e4623" have entirely different histories.
2a1e0337fd
...
dd2e95f8af
@ -22,7 +22,3 @@ Read the rules in AGENTS.md and follow them.
|
|||||||
* The test suite is fast and local. When running tests, don't run
|
* The test suite is fast and local. When running tests, don't run
|
||||||
individual parts of the test suite, always run the whole thing by running
|
individual parts of the test suite, always run the whole thing by running
|
||||||
"make test".
|
"make test".
|
||||||
|
|
||||||
* Do not stop working on a task until you have reached the definition of
|
|
||||||
done provided to you in the initial instruction. Don't do part or most of
|
|
||||||
the work, do all of the work until the criteria for done are met.
|
|
||||||
|
@ -27,7 +27,6 @@ type Instance struct {
|
|||||||
func NewCLIInstance() *Instance {
|
func NewCLIInstance() *Instance {
|
||||||
fs := afero.NewOsFs()
|
fs := afero.NewOsFs()
|
||||||
stateDir := secret.DetermineStateDir("")
|
stateDir := secret.DetermineStateDir("")
|
||||||
|
|
||||||
return &Instance{
|
return &Instance{
|
||||||
fs: fs,
|
fs: fs,
|
||||||
stateDir: stateDir,
|
stateDir: stateDir,
|
||||||
@ -71,7 +70,6 @@ func getStdinScanner() *bufio.Scanner {
|
|||||||
if stdinScanner == nil {
|
if stdinScanner == nil {
|
||||||
stdinScanner = bufio.NewScanner(os.Stdin)
|
stdinScanner = bufio.NewScanner(os.Stdin)
|
||||||
}
|
}
|
||||||
|
|
||||||
return stdinScanner
|
return stdinScanner
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,9 +87,7 @@ func readLineFromStdin(prompt string) (string, error) {
|
|||||||
if err := scanner.Err(); err != nil {
|
if err := scanner.Err(); err != nil {
|
||||||
return "", fmt.Errorf("failed to read from stdin: %w", err)
|
return "", fmt.Errorf("failed to read from stdin: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return "", fmt.Errorf("failed to read from stdin: EOF")
|
return "", fmt.Errorf("failed to read from stdin: EOF")
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings.TrimSpace(scanner.Text()), nil
|
return strings.TrimSpace(scanner.Text()), nil
|
||||||
}
|
}
|
||||||
|
@ -23,14 +23,12 @@ func newEncryptCmd() *cobra.Command {
|
|||||||
|
|
||||||
cli := NewCLIInstance()
|
cli := NewCLIInstance()
|
||||||
cli.cmd = cmd
|
cli.cmd = cmd
|
||||||
|
|
||||||
return cli.Encrypt(args[0], inputFile, outputFile)
|
return cli.Encrypt(args[0], inputFile, outputFile)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Flags().StringP("input", "i", "", "Input file (default: stdin)")
|
cmd.Flags().StringP("input", "i", "", "Input file (default: stdin)")
|
||||||
cmd.Flags().StringP("output", "o", "", "Output file (default: stdout)")
|
cmd.Flags().StringP("output", "o", "", "Output file (default: stdout)")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,14 +44,12 @@ func newDecryptCmd() *cobra.Command {
|
|||||||
|
|
||||||
cli := NewCLIInstance()
|
cli := NewCLIInstance()
|
||||||
cli.cmd = cmd
|
cli.cmd = cmd
|
||||||
|
|
||||||
return cli.Decrypt(args[0], inputFile, outputFile)
|
return cli.Decrypt(args[0], inputFile, outputFile)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Flags().StringP("input", "i", "", "Input file (default: stdin)")
|
cmd.Flags().StringP("input", "i", "", "Input file (default: stdin)")
|
||||||
cmd.Flags().StringP("output", "o", "", "Output file (default: stdout)")
|
cmd.Flags().StringP("output", "o", "", "Output file (default: stdout)")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,6 @@ func newGenerateSecretCmd() *cobra.Command {
|
|||||||
force, _ := cmd.Flags().GetBool("force")
|
force, _ := cmd.Flags().GetBool("force")
|
||||||
|
|
||||||
cli := NewCLIInstance()
|
cli := NewCLIInstance()
|
||||||
|
|
||||||
return cli.GenerateSecret(cmd, args[0], length, secretType, force)
|
return cli.GenerateSecret(cmd, args[0], length, secretType, force)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -135,7 +134,6 @@ func (cli *Instance) GenerateSecret(
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmd.Printf("Generated and stored %d-character %s secret: %s\n", length, secretType, secretName)
|
cmd.Printf("Generated and stored %d-character %s secret: %s\n", length, secretType, secretName)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +42,5 @@ func newRootCmd() *cobra.Command {
|
|||||||
cmd.AddCommand(newVersionCmd())
|
cmd.AddCommand(newVersionCmd())
|
||||||
|
|
||||||
secret.Debug("newRootCmd completed")
|
secret.Debug("newRootCmd completed")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
@ -26,13 +26,11 @@ func newAddCmd() *cobra.Command {
|
|||||||
cli := NewCLIInstance()
|
cli := NewCLIInstance()
|
||||||
cli.cmd = cmd // Set the command for stdin access
|
cli.cmd = cmd // Set the command for stdin access
|
||||||
secret.Debug("Created CLI instance, calling AddSecret")
|
secret.Debug("Created CLI instance, calling AddSecret")
|
||||||
|
|
||||||
return cli.AddSecret(args[0], force)
|
return cli.AddSecret(args[0], force)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Flags().BoolP("force", "f", false, "Overwrite existing secret")
|
cmd.Flags().BoolP("force", "f", false, "Overwrite existing secret")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,13 +42,11 @@ func newGetCmd() *cobra.Command {
|
|||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
version, _ := cmd.Flags().GetString("version")
|
version, _ := cmd.Flags().GetString("version")
|
||||||
cli := NewCLIInstance()
|
cli := NewCLIInstance()
|
||||||
|
|
||||||
return cli.GetSecretWithVersion(cmd, args[0], version)
|
return cli.GetSecretWithVersion(cmd, args[0], version)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Flags().StringP("version", "v", "", "Get a specific version (default: current)")
|
cmd.Flags().StringP("version", "v", "", "Get a specific version (default: current)")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,13 +66,11 @@ func newListCmd() *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cli := NewCLIInstance()
|
cli := NewCLIInstance()
|
||||||
|
|
||||||
return cli.ListSecrets(cmd, jsonOutput, filter)
|
return cli.ListSecrets(cmd, jsonOutput, filter)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Flags().Bool("json", false, "Output in JSON format")
|
cmd.Flags().Bool("json", false, "Output in JSON format")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +85,6 @@ func newImportCmd() *cobra.Command {
|
|||||||
force, _ := cmd.Flags().GetBool("force")
|
force, _ := cmd.Flags().GetBool("force")
|
||||||
|
|
||||||
cli := NewCLIInstance()
|
cli := NewCLIInstance()
|
||||||
|
|
||||||
return cli.ImportSecret(cmd, args[0], sourceFile, force)
|
return cli.ImportSecret(cmd, args[0], sourceFile, force)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -99,7 +92,6 @@ func newImportCmd() *cobra.Command {
|
|||||||
cmd.Flags().StringP("source", "s", "", "Source file to import from (required)")
|
cmd.Flags().StringP("source", "s", "", "Source file to import from (required)")
|
||||||
cmd.Flags().BoolP("force", "f", false, "Overwrite existing secret")
|
cmd.Flags().BoolP("force", "f", false, "Overwrite existing secret")
|
||||||
_ = cmd.MarkFlagRequired("source")
|
_ = cmd.MarkFlagRequired("source")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +131,6 @@ func (cli *Instance) AddSecret(secretName string, force bool) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
secret.Debug("vault.AddSecret completed successfully")
|
secret.Debug("vault.AddSecret completed successfully")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,7 +246,6 @@ func (cli *Instance) ListSecrets(cmd *cobra.Command, jsonOutput bool, filter str
|
|||||||
cmd.Println("No secrets found in current vault.")
|
cmd.Println("No secrets found in current vault.")
|
||||||
cmd.Println("Run 'secret add <name>' to create one.")
|
cmd.Println("Run 'secret add <name>' to create one.")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,6 +297,5 @@ func (cli *Instance) ImportSecret(cmd *cobra.Command, secretName, sourceFile str
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmd.Printf("Successfully imported secret '%s' from file '%s'\n", secretName, sourceFile)
|
cmd.Printf("Successfully imported secret '%s' from file '%s'\n", secretName, sourceFile)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -41,13 +41,11 @@ func newUnlockersListCmd() *cobra.Command {
|
|||||||
|
|
||||||
cli := NewCLIInstance()
|
cli := NewCLIInstance()
|
||||||
cli.cmd = cmd
|
cli.cmd = cmd
|
||||||
|
|
||||||
return cli.UnlockersList(jsonOutput)
|
return cli.UnlockersList(jsonOutput)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Flags().Bool("json", false, "Output in JSON format")
|
cmd.Flags().Bool("json", false, "Output in JSON format")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +62,6 @@ func newUnlockersAddCmd() *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmd.Flags().String("keyid", "", "GPG key ID for PGP unlockers")
|
cmd.Flags().String("keyid", "", "GPG key ID for PGP unlockers")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,7 +169,6 @@ func (cli *Instance) UnlockersList(jsonOutput bool) error {
|
|||||||
case "pgp":
|
case "pgp":
|
||||||
unlocker = secret.NewPGPUnlocker(cli.fs, unlockerDir, diskMetadata)
|
unlocker = secret.NewPGPUnlocker(cli.fs, unlockerDir, diskMetadata)
|
||||||
}
|
}
|
||||||
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -212,7 +208,6 @@ func (cli *Instance) UnlockersList(jsonOutput bool) error {
|
|||||||
if len(unlockers) == 0 {
|
if len(unlockers) == 0 {
|
||||||
cli.cmd.Println("No unlockers found in current vault.")
|
cli.cmd.Println("No unlockers found in current vault.")
|
||||||
cli.cmd.Println("Run 'secret unlockers add passphrase' to create one.")
|
cli.cmd.Println("Run 'secret unlockers add passphrase' to create one.")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,7 +263,6 @@ func (cli *Instance) UnlockersAdd(unlockerType string, cmd *cobra.Command) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmd.Printf("Created passphrase unlocker: %s\n", passphraseUnlocker.GetID())
|
cmd.Printf("Created passphrase unlocker: %s\n", passphraseUnlocker.GetID())
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
case "keychain":
|
case "keychain":
|
||||||
@ -281,7 +275,6 @@ func (cli *Instance) UnlockersAdd(unlockerType string, cmd *cobra.Command) error
|
|||||||
if keyName, err := keychainUnlocker.GetKeychainItemName(); err == nil {
|
if keyName, err := keychainUnlocker.GetKeychainItemName(); err == nil {
|
||||||
cmd.Printf("Keychain Item Name: %s\n", keyName)
|
cmd.Printf("Keychain Item Name: %s\n", keyName)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
case "pgp":
|
case "pgp":
|
||||||
@ -302,7 +295,6 @@ func (cli *Instance) UnlockersAdd(unlockerType string, cmd *cobra.Command) error
|
|||||||
|
|
||||||
cmd.Printf("Created PGP unlocker: %s\n", pgpUnlocker.GetID())
|
cmd.Printf("Created PGP unlocker: %s\n", pgpUnlocker.GetID())
|
||||||
cmd.Printf("GPG Key ID: %s\n", gpgKeyID)
|
cmd.Printf("GPG Key ID: %s\n", gpgKeyID)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -38,13 +38,11 @@ func newVaultListCmd() *cobra.Command {
|
|||||||
jsonOutput, _ := cmd.Flags().GetBool("json")
|
jsonOutput, _ := cmd.Flags().GetBool("json")
|
||||||
|
|
||||||
cli := NewCLIInstance()
|
cli := NewCLIInstance()
|
||||||
|
|
||||||
return cli.ListVaults(cmd, jsonOutput)
|
return cli.ListVaults(cmd, jsonOutput)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Flags().Bool("json", false, "Output in JSON format")
|
cmd.Flags().Bool("json", false, "Output in JSON format")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +83,6 @@ func newVaultImportCmd() *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cli := NewCLIInstance()
|
cli := NewCLIInstance()
|
||||||
|
|
||||||
return cli.VaultImport(cmd, vaultName)
|
return cli.VaultImport(cmd, vaultName)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -150,7 +147,6 @@ func (cli *Instance) CreateVault(cmd *cobra.Command, name string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmd.Printf("Created vault '%s'\n", vlt.GetName())
|
cmd.Printf("Created vault '%s'\n", vlt.GetName())
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,7 +157,6 @@ func (cli *Instance) SelectVault(cmd *cobra.Command, name string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmd.Printf("Selected vault '%s' as current\n", name)
|
cmd.Printf("Selected vault '%s' as current\n", name)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,6 @@ func VersionCommands(cli *Instance) *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
versionCmd.AddCommand(listCmd, promoteCmd)
|
versionCmd.AddCommand(listCmd, promoteCmd)
|
||||||
|
|
||||||
return versionCmd
|
return versionCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,7 +154,6 @@ func (cli *Instance) ListVersions(cmd *cobra.Command, secretName string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
w.Flush()
|
w.Flush()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,6 @@ func EncryptToRecipient(data []byte, recipient age.Recipient) ([]byte, error) {
|
|||||||
|
|
||||||
result := buf.Bytes()
|
result := buf.Bytes()
|
||||||
Debug("EncryptToRecipient completed successfully", "result_length", len(result))
|
Debug("EncryptToRecipient completed successfully", "result_length", len(result))
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +113,6 @@ func (h *colorizedHandler) Handle(_ context.Context, record slog.Record) error {
|
|||||||
}
|
}
|
||||||
first = false
|
first = false
|
||||||
output += fmt.Sprintf("%s=%#v", attr.Key, attr.Value.Any())
|
output += fmt.Sprintf("%s=%#v", attr.Key, attr.Value.Any())
|
||||||
|
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
output += "}\033[0m"
|
output += "}\033[0m"
|
||||||
@ -121,7 +120,6 @@ func (h *colorizedHandler) Handle(_ context.Context, record slog.Record) error {
|
|||||||
|
|
||||||
output += "\n"
|
output += "\n"
|
||||||
_, err := h.output.Write([]byte(output))
|
_, err := h.output.Write([]byte(output))
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user