mirror of https://github.com/mitchell/selfpass.git
Refactors to spc timeouts and password error handling
This commit is contained in:
parent
f90c19d0f4
commit
e51ee55f07
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/mitchellh/go-homedir"
|
"github.com/mitchellh/go-homedir"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
@ -69,7 +70,7 @@ func (mgr *ConfigManager) OpenConfig() (output string, v *viper.Viper, err error
|
||||||
return output, nil, err
|
return output, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = mgr.v.ReadConfig(bytes.NewBuffer(contents)); err != nil && err.Error() == "While parsing config: (1, 1): unexpected token" {
|
if err = mgr.v.ReadConfig(bytes.NewBuffer(contents)); err != nil && strings.HasPrefix(err.Error(), "While parsing config") {
|
||||||
return output, nil, fmt.Errorf("incorrect master password")
|
return output, nil, fmt.Errorf("incorrect master password")
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return output, nil, err
|
return output, nil, err
|
||||||
|
|
|
@ -130,7 +130,7 @@ password.`,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*25)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
c, err := initClient(ctx).Create(ctx, ci)
|
c, err := initClient(ctx).Create(ctx, ci)
|
||||||
|
|
|
@ -21,7 +21,7 @@ func MakeDelete(initConfig CredentialClientInit) *cobra.Command {
|
||||||
check(survey.AskOne(prompt, &confirmed, nil))
|
check(survey.AskOne(prompt, &confirmed, nil))
|
||||||
|
|
||||||
if confirmed {
|
if confirmed {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*25)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
check(initConfig(ctx).Delete(ctx, args[0]))
|
check(initConfig(ctx).Delete(ctx, args[0]))
|
||||||
|
|
|
@ -26,13 +26,16 @@ func MakeGet(repo clitypes.ConfigRepo, initClient CredentialClientInit) *cobra.C
|
||||||
decrypting password.`,
|
decrypting password.`,
|
||||||
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
client := initClient(ctx)
|
client := initClient(ctx)
|
||||||
masterpass, cfg, err := repo.OpenConfig()
|
masterpass, cfg, err := repo.OpenConfig()
|
||||||
check(err)
|
check(err)
|
||||||
|
|
||||||
|
ctx, cancel = context.WithTimeout(context.Background(), time.Second*5)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
mdch, errch := client.GetAllMetadata(ctx, "")
|
mdch, errch := client.GetAllMetadata(ctx, "")
|
||||||
mds := map[string][]types.Metadata{}
|
mds := map[string][]types.Metadata{}
|
||||||
|
|
||||||
|
@ -42,7 +45,7 @@ decrypting password.`,
|
||||||
for count := 0; ; count++ {
|
for count := 0; ; count++ {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
check(fmt.Errorf("context timeout"))
|
check(ctx.Err())
|
||||||
|
|
||||||
case err := <-errch:
|
case err := <-errch:
|
||||||
check(err)
|
check(err)
|
||||||
|
|
|
@ -22,7 +22,7 @@ func MakeList(initClient CredentialClientInit) *cobra.Command {
|
||||||
includes almost all the information but the most sensitive.`,
|
includes almost all the information but the most sensitive.`,
|
||||||
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*20)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
mdch, errch := initClient(ctx).GetAllMetadata(ctx, sourceHost)
|
mdch, errch := initClient(ctx).GetAllMetadata(ctx, sourceHost)
|
||||||
|
@ -34,7 +34,7 @@ includes almost all the information but the most sensitive.`,
|
||||||
for count := 0; ; count++ {
|
for count := 0; ; count++ {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
check(fmt.Errorf("context timeout"))
|
check(ctx.Err())
|
||||||
|
|
||||||
case err := <-errch:
|
case err := <-errch:
|
||||||
check(err)
|
check(err)
|
||||||
|
|
Loading…
Reference in New Issue