Refactors to spc timeouts and password error handling

This commit is contained in:
Mitchell 2019-06-12 16:51:29 -07:00
parent f90c19d0f4
commit e51ee55f07
5 changed files with 11 additions and 7 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt"
"io/ioutil"
"os"
"strings"
"github.com/mitchellh/go-homedir"
"github.com/spf13/viper"
@ -69,7 +70,7 @@ func (mgr *ConfigManager) OpenConfig() (output string, v *viper.Viper, err error
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")
} else if err != nil {
return output, nil, err

View File

@ -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()
c, err := initClient(ctx).Create(ctx, ci)

View File

@ -21,7 +21,7 @@ func MakeDelete(initConfig CredentialClientInit) *cobra.Command {
check(survey.AskOne(prompt, &confirmed, nil))
if confirmed {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*25)
defer cancel()
check(initConfig(ctx).Delete(ctx, args[0]))

View File

@ -26,13 +26,16 @@ func MakeGet(repo clitypes.ConfigRepo, initClient CredentialClientInit) *cobra.C
decrypting password.`,
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()
client := initClient(ctx)
masterpass, cfg, err := repo.OpenConfig()
check(err)
ctx, cancel = context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
mdch, errch := client.GetAllMetadata(ctx, "")
mds := map[string][]types.Metadata{}
@ -42,7 +45,7 @@ decrypting password.`,
for count := 0; ; count++ {
select {
case <-ctx.Done():
check(fmt.Errorf("context timeout"))
check(ctx.Err())
case err := <-errch:
check(err)

View File

@ -22,7 +22,7 @@ func MakeList(initClient CredentialClientInit) *cobra.Command {
includes almost all the information but the most sensitive.`,
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()
mdch, errch := initClient(ctx).GetAllMetadata(ctx, sourceHost)
@ -34,7 +34,7 @@ includes almost all the information but the most sensitive.`,
for count := 0; ; count++ {
select {
case <-ctx.Done():
check(fmt.Errorf("context timeout"))
check(ctx.Err())
case err := <-errch:
check(err)