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