diff --git a/sp/commands/commands.go b/sp/commands/commands.go index 88a0edd..c311405 100644 --- a/sp/commands/commands.go +++ b/sp/commands/commands.go @@ -13,7 +13,7 @@ import ( "github.com/mitchell/selfpass/services/credentials/types" ) -type CredentialsClientInit func(ctx context.Context) (c types.CredentialsClient) +type credentialsClientInit func(ctx context.Context) (c types.CredentialsClient) var errSourceNotFound = errors.New("source host not found") diff --git a/sp/commands/create.go b/sp/commands/create.go index 1ecb82c..f904665 100644 --- a/sp/commands/create.go +++ b/sp/commands/create.go @@ -17,7 +17,7 @@ import ( clitypes "github.com/mitchell/selfpass/sp/types" ) -func makeCreate(repo clitypes.ConfigRepo, initClient CredentialsClientInit) *cobra.Command { +func makeCreate(repo clitypes.ConfigRepo, initClient credentialsClientInit) *cobra.Command { flags := credentialFlagSet{}.withPasswordFlags() createCmd := &cobra.Command{ @@ -32,6 +32,7 @@ password.`, cleancb bool newpass bool ci types.CredentialInput + prompt survey.Prompt ) masterpass, cfg, err := repo.OpenConfig() @@ -71,7 +72,7 @@ password.`, key := cfg.GetString(clitypes.KeyPrivateKey) keypass := crypto.GeneratePBKDF2Key([]byte(masterpass), []byte(key)) - prompt := &survey.Confirm{Message: "Do you want a random password?", Default: true} + prompt = &survey.Confirm{Message: "Do you want a random password?", Default: true} check(survey.AskOne(prompt, &newpass, nil)) if newpass { @@ -108,7 +109,7 @@ password.`, if otp { var secret string - prompt := &survey.Password{Message: "OTP secret:"} + prompt = &survey.Password{Message: "OTP secret:"} check(survey.AskOne(prompt, &secret, nil)) ciphersecret, err := crypto.CBCEncrypt(keypass, []byte(secret)) @@ -117,14 +118,24 @@ password.`, ci.OTPSecret = base64.StdEncoding.EncodeToString(ciphersecret) var copyotp bool - prompt2 := &survey.Confirm{Message: "Copy new OTP to clipboard?", Default: true} - check(survey.AskOne(prompt2, ©otp, nil)) + prompt = &survey.Confirm{Message: "Copy new OTP to clipboard?", Default: true} + check(survey.AskOne(prompt, ©otp, nil)) if copyotp { otp, err := totp.GenerateCode(secret, time.Now()) check(err) check(clipboard.WriteAll(otp)) + + prompt = &survey.Confirm{Message: "Anotha one?", Default: true} + check(survey.AskOne(prompt, ©otp, nil)) + + if copyotp { + otp, err := totp.GenerateCode(secret, time.Now().Add(time.Second*30)) + check(err) + + check(clipboard.WriteAll(otp)) + } } } diff --git a/sp/commands/delete.go b/sp/commands/delete.go index d7adc71..b8c34b9 100644 --- a/sp/commands/delete.go +++ b/sp/commands/delete.go @@ -9,7 +9,7 @@ import ( "gopkg.in/AlecAivazis/survey.v1" ) -func makeDelete(initClient CredentialsClientInit) *cobra.Command { +func makeDelete(initClient credentialsClientInit) *cobra.Command { flags := credentialFlagSet{}.withHostFlag() deleteCmd := &cobra.Command{ diff --git a/sp/commands/gcm-to-cbc.go b/sp/commands/gcm-to-cbc.go index 22b3441..24a75e8 100644 --- a/sp/commands/gcm-to-cbc.go +++ b/sp/commands/gcm-to-cbc.go @@ -14,7 +14,7 @@ import ( clitypes "github.com/mitchell/selfpass/sp/types" ) -func makeGCMToCBC(repo clitypes.ConfigRepo, initClient CredentialsClientInit) *cobra.Command { +func makeGCMToCBC(repo clitypes.ConfigRepo, initClient credentialsClientInit) *cobra.Command { gcmToCBC := &cobra.Command{ Use: "gcm-to-cbc", Hidden: true, diff --git a/sp/commands/get.go b/sp/commands/get.go index 26db92a..c8fb5e4 100644 --- a/sp/commands/get.go +++ b/sp/commands/get.go @@ -15,7 +15,7 @@ import ( clitypes "github.com/mitchell/selfpass/sp/types" ) -func makeGet(repo clitypes.ConfigRepo, initClient CredentialsClientInit) *cobra.Command { +func makeGet(repo clitypes.ConfigRepo, initClient credentialsClientInit) *cobra.Command { flags := credentialFlagSet{}.withHostFlag() getCmd := &cobra.Command{ diff --git a/sp/commands/list.go b/sp/commands/list.go index 744f0f9..b4fe308 100644 --- a/sp/commands/list.go +++ b/sp/commands/list.go @@ -11,7 +11,7 @@ import ( "github.com/mitchell/selfpass/services/credentials/types" ) -func makeList(initClient CredentialsClientInit) *cobra.Command { +func makeList(initClient credentialsClientInit) *cobra.Command { flags := credentialFlagSet{}.withHostFlag() listCmd := &cobra.Command{ diff --git a/sp/commands/root.go b/sp/commands/root.go index fd09231..7f31fb5 100644 --- a/sp/commands/root.go +++ b/sp/commands/root.go @@ -11,6 +11,7 @@ import ( "github.com/mitchell/selfpass/sp/types" ) +// Execute is the main entrypoint for the `sp` CLI tool. func Execute() { rootCmd := &cobra.Command{ Use: "sp", @@ -41,7 +42,7 @@ can interact with the entire Selfpass API.`, check(rootCmd.Execute()) } -func makeInitClient(repo types.ConfigRepo, initClient credtypes.CredentialsClientInit) CredentialsClientInit { +func makeInitClient(repo types.ConfigRepo, initClient credtypes.CredentialsClientInit) credentialsClientInit { return func(ctx context.Context) credtypes.CredentialsClient { _, cfg, err := repo.OpenConfig() check(err) diff --git a/sp/commands/update.go b/sp/commands/update.go index dc69cc7..a212d06 100644 --- a/sp/commands/update.go +++ b/sp/commands/update.go @@ -17,7 +17,7 @@ import ( clitypes "github.com/mitchell/selfpass/sp/types" ) -func makeUpdate(repo clitypes.ConfigRepo, initClient CredentialsClientInit) *cobra.Command { +func makeUpdate(repo clitypes.ConfigRepo, initClient credentialsClientInit) *cobra.Command { flags := credentialFlagSet{}.withHostFlag().withPasswordFlags() updateCmd := &cobra.Command{ @@ -143,7 +143,7 @@ password.`, if otp { var secret string - prompt := &survey.Password{Message: "OTP secret:"} + prompt = &survey.Password{Message: "OTP secret:"} check(survey.AskOne(prompt, &secret, nil)) ciphersecret, err := crypto.CBCEncrypt(keypass, []byte(secret)) @@ -152,14 +152,24 @@ password.`, ci.OTPSecret = base64.StdEncoding.EncodeToString(ciphersecret) var copyotp bool - prompt2 := &survey.Confirm{Message: "Copy new OTP to clipboard?", Default: true} - check(survey.AskOne(prompt2, ©otp, nil)) + prompt = &survey.Confirm{Message: "Copy new OTP to clipboard?", Default: true} + check(survey.AskOne(prompt, ©otp, nil)) if copyotp { otp, err := totp.GenerateCode(secret, time.Now()) check(err) check(clipboard.WriteAll(otp)) + + prompt = &survey.Confirm{Message: "Anotha one?", Default: true} + check(survey.AskOne(prompt, ©otp, nil)) + + if copyotp { + otp, err := totp.GenerateCode(secret, time.Now().Add(time.Second*30)) + check(err) + + check(clipboard.WriteAll(otp)) + } } } diff --git a/sp/go.mod b/sp/go.mod index c9720ff..20be702 100644 --- a/sp/go.mod +++ b/sp/go.mod @@ -4,7 +4,6 @@ go 1.12 require ( github.com/atotto/clipboard v0.1.2 - github.com/davecgh/go-spew v1.1.1 github.com/google/uuid v1.1.1 github.com/mitchell/selfpass/services v0.0.0-00010101000000-000000000000 github.com/mitchellh/go-homedir v1.1.0 diff --git a/sp/go.sum b/sp/go.sum index 2146303..7c37d01 100644 --- a/sp/go.sum +++ b/sp/go.sum @@ -48,7 +48,6 @@ github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5m github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g= -github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=