release fixes

This commit is contained in:
Ricky Pike
2022-07-09 12:58:38 -05:00
parent f825720660
commit 9ad565ea58
6 changed files with 27 additions and 20 deletions

View File

@@ -5,6 +5,7 @@ import (
"errors"
"io"
"os"
"strings"
"time"
"github.com/pquerna/otp/totp"
@@ -92,6 +93,7 @@ func (c *Collection) UpdateSecret(name, value string) (Secret, error) {
return Secret{}, ErrSecretValueEmpty
}
value = strings.ToUpper(value)
_, err := totp.GenerateCode(value, time.Now())
if err != nil {
return Secret{}, err

View File

@@ -505,7 +505,7 @@ func TestCollection_UpdateSecret(t *testing.T) {
},
want: Secret{
Name: "newname",
Value: "seed",
Value: "SEED",
},
wantErr: false,
},
@@ -526,7 +526,7 @@ func TestCollection_UpdateSecret(t *testing.T) {
},
want: Secret{
Name: "testname",
Value: "seed",
Value: "SEED",
},
wantErr: false,
},

View File

@@ -35,10 +35,11 @@ func getConfigDeleteCmd() *cobra.Command {
var (
confirmAll bool
cobraCmd = &cobra.Command{
Use: "delete",
Aliases: []string{"remove", "erase", "rm", "del"},
Short: "Delete a secret",
Long: `Delete a secret`,
Use: "delete",
Aliases: []string{"remove", "erase", "rm", "del"},
Short: "Delete a secret",
Long: `Delete a secret`,
ValidArgsFunction: validArgs,
Run: func(_ *cobra.Command, args []string) {
if len(args) != 1 {
fmt.Fprintln(os.Stderr, "Must provide a secret name to delete.")

View File

@@ -33,10 +33,11 @@ func renameSecret(source, target string) {
func getConfigRenameCmd(rootCmd *cobra.Command) *cobra.Command {
var cobraCmd = &cobra.Command{
Use: "rename",
Aliases: []string{"ren", "mv"},
Short: "Rename a secret",
Long: `Rename a secret`,
Use: "rename",
Aliases: []string{"ren", "mv"},
Short: "Rename a secret",
Long: `Rename a secret`,
ValidArgsFunction: validArgs,
Run: func(_ *cobra.Command, args []string) {
if len(args) != 2 {
fmt.Fprintln(os.Stderr, "Must provide source and target.")

View File

@@ -41,10 +41,11 @@ func updateSecret(name, value string) {
func getConfigUpdateCmd(rootCmd *cobra.Command) *cobra.Command {
var cobraCmd = &cobra.Command{
Use: "update",
Aliases: []string{"add"},
Short: "Add or update a secret",
Long: `Add or update a secret`,
Use: "update",
Aliases: []string{"add"},
Short: "Add or update a secret",
Long: `Add or update a secret`,
ValidArgsFunction: validArgs,
Run: func(_ *cobra.Command, args []string) {
if len(args) != 2 {
fmt.Fprintln(os.Stderr, "Must provide name and secret")

View File

@@ -221,6 +221,13 @@ func run(cmd *cobra.Command, args []string, cfg runVars) {
}
}
func validArgs(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) != 0 {
return nil, cobra.ShellCompDirectiveNoFileComp
}
return getSecretNamesForCompletion(toComplete), cobra.ShellCompDirectiveNoFileComp
}
func getRootCmd() *cobra.Command {
var cfg runVars
@@ -241,12 +248,7 @@ func getRootCmd() *cobra.Command {
}
}
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) != 0 {
return nil, cobra.ShellCompDirectiveNoFileComp
}
return getSecretNamesForCompletion(toComplete), cobra.ShellCompDirectiveNoFileComp
},
ValidArgsFunction: validArgs,
Run: func(cmd *cobra.Command, args []string) {
run(cmd, args, cfg)
},