mirror of
https://github.com/arcanericky/totp.git
synced 2026-05-16 23:45:44 +03:00
release fixes
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
@@ -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.")
|
||||
|
||||
@@ -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.")
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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)
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user