Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c80f241b41 | ||
|
|
acb4b9cb6a |
No files matched your search
@@ -193,11 +193,11 @@ Moves or renames a secret within the current vault.
|
|||||||
Lists all versions of a secret showing creation time, status, and validity
|
Lists all versions of a secret showing creation time, status, and validity
|
||||||
period.
|
period.
|
||||||
|
|
||||||
STATUS is `current` for the secret's current version, `expired` for another
|
`STATUS` is `current` for the secret's current version, `expired` for another
|
||||||
version whose NOT_AFTER has passed, and `inactive` for any other version. Adding
|
version whose `NOT_AFTER` has passed, and `inactive` for any other version.
|
||||||
a version sets NOT_AFTER on the version that was current;
|
Adding a version sets `NOT_AFTER` on the version that was current;
|
||||||
`secret version promote` sets no times, so after promoting an older version the
|
`secret version promote` sets no times. A version that is not current therefore
|
||||||
newest version shows `inactive`.
|
shows `inactive` when no version was added while it was current.
|
||||||
|
|
||||||
#### `secret version promote <secret-name> <version>`
|
#### `secret version promote <secret-name> <version>`
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ func VersionCommands(cli *Instance) *cobra.Command {
|
|||||||
promoteCmd := &cobra.Command{
|
promoteCmd := &cobra.Command{
|
||||||
Use: "promote <secret-name> <version>",
|
Use: "promote <secret-name> <version>",
|
||||||
Short: "Promote a specific version to current",
|
Short: "Promote a specific version to current",
|
||||||
Long: "Updates the current symlink to point to the specified " +
|
Long: "Rewrites the secret's current file to name the specified " +
|
||||||
"version. The versions' own times are left unchanged; secret " +
|
"version. The versions' own times are left unchanged; secret " +
|
||||||
"list then gives the time of the promote as the secret's last " +
|
"list then gives the time of the promote as the secret's last " +
|
||||||
"update.",
|
"update.",
|
||||||
@@ -297,7 +297,7 @@ func (cli *Instance) PromoteVersion(
|
|||||||
version, vault.ErrVersionNotFound, secretName)
|
version, vault.ErrVersionNotFound, secretName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the current symlink using the proper function
|
// Rewrite the secret's current file to name the version
|
||||||
err = secret.SetCurrentVersion(cli.fs, secretDir, version)
|
err = secret.SetCurrentVersion(cli.fs, secretDir, version)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to update current version: %w", err)
|
return fmt.Errorf("failed to update current version: %w", err)
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
// - TestListVersionsStatusAfterPromote: Tests each version's status after
|
// - TestListVersionsStatusAfterPromote: Tests each version's status after
|
||||||
// promoting an older version
|
// promoting an older version
|
||||||
// - TestPromoteNonExistentVersion: Tests error handling for invalid promotion
|
// - TestPromoteNonExistentVersion: Tests error handling for invalid promotion
|
||||||
|
// - TestPromoteHelpSaysCurrentFileIsRewritten: Tests `secret version promote
|
||||||
|
// --help` text
|
||||||
// - TestGetSecretWithVersion: Tests `secret get --version` flag functionality
|
// - TestGetSecretWithVersion: Tests `secret get --version` flag functionality
|
||||||
// - TestGetSecretWritesBinaryValue: Tests `secret get` output of binary values
|
// - TestGetSecretWritesBinaryValue: Tests `secret get` output of binary values
|
||||||
// - TestGetSecretReturnsWriteError: Tests `secret get` when stdout fails
|
// - TestGetSecretReturnsWriteError: Tests `secret get` when stdout fails
|
||||||
@@ -332,6 +334,23 @@ func TestPromoteNonExistentVersion(t *testing.T) {
|
|||||||
require.ErrorIs(t, err, vault.ErrVersionNotFound)
|
require.ErrorIs(t, err, vault.ErrVersionNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestPromoteHelpSaysCurrentFileIsRewritten is a regression test for
|
||||||
|
// https://git.eeqj.de/sneak/secret/issues/153: `secret version promote
|
||||||
|
// --help` said it updates a symlink, but promote rewrites the secret's
|
||||||
|
// `current` file, which is a plain file.
|
||||||
|
//
|
||||||
|
//nolint:paralleltest // executes the CLI in-process and sets the environment
|
||||||
|
func TestPromoteHelpSaysCurrentFileIsRewritten(t *testing.T) {
|
||||||
|
env := map[string]string{secret.EnvStateDir: t.TempDir()}
|
||||||
|
|
||||||
|
output, err := ExecuteCommandInProcess(
|
||||||
|
[]string{"version", "promote", "--help"}, "", env)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
assert.NotContains(t, output, "symlink")
|
||||||
|
assert.Contains(t, output, "current file")
|
||||||
|
}
|
||||||
|
|
||||||
func TestGetSecretWithVersion(t *testing.T) {
|
func TestGetSecretWithVersion(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,8 @@ type VersionMetadata struct {
|
|||||||
ID string `json:"id"` // ULID
|
ID string `json:"id"` // ULID
|
||||||
CreatedAt *time.Time `json:"createdAt,omitempty"` // When version was created
|
CreatedAt *time.Time `json:"createdAt,omitempty"` // When version was created
|
||||||
NotBefore *time.Time `json:"notBefore,omitempty"` // When this version becomes active
|
NotBefore *time.Time `json:"notBefore,omitempty"` // When this version becomes active
|
||||||
NotAfter *time.Time `json:"notAfter,omitempty"` // Expiry (nil = current)
|
// NotAfter is set when another version is added while this one is current
|
||||||
|
NotAfter *time.Time `json:"notAfter,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Version represents a version of a secret
|
// Version represents a version of a secret
|
||||||
|
|||||||
Reference in new issue
Block a user