Refactored config management strategy for spc

This commit is contained in:
mitchell 2019-06-02 01:47:19 -07:00
parent 3d3206ddfe
commit 30e514cb88
10 changed files with 225 additions and 123 deletions

View file

@ -11,14 +11,14 @@ import (
"github.com/atotto/clipboard"
"github.com/pquerna/otp/totp"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"gopkg.in/AlecAivazis/survey.v1"
clitypes "github.com/mitchell/selfpass/cli/types"
"github.com/mitchell/selfpass/credentials/types"
"github.com/mitchell/selfpass/crypto"
)
func MakeCreate(masterpass string, cfg *viper.Viper, initClient CredentialClientInit) *cobra.Command {
func MakeCreate(repo clitypes.ConfigRepo, initClient CredentialClientInit) *cobra.Command {
var length uint
var numbers bool
var specials bool
@ -30,6 +30,9 @@ func MakeCreate(masterpass string, cfg *viper.Viper, initClient CredentialClient
password.`,
Run: func(_ *cobra.Command, args []string) {
masterpass, cfg, err := repo.OpenConfig()
check(err)
mdqs := []*survey.Question{
{
Name: "primary",

View file

@ -10,14 +10,14 @@ import (
"github.com/atotto/clipboard"
"github.com/pquerna/otp/totp"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"gopkg.in/AlecAivazis/survey.v1"
clitypes "github.com/mitchell/selfpass/cli/types"
"github.com/mitchell/selfpass/credentials/types"
"github.com/mitchell/selfpass/crypto"
)
func MakeGet(masterpass string, cfg *viper.Viper, initClient CredentialClientInit) *cobra.Command {
func MakeGet(repo clitypes.ConfigRepo, initClient CredentialClientInit) *cobra.Command {
getCmd := &cobra.Command{
Use: "get",
Short: "Get a credential info and copy password to clipboard",
@ -29,6 +29,9 @@ decrypting password.`,
defer cancel()
client := initClient(ctx)
masterpass, cfg, err := repo.OpenConfig()
check(err)
mdch, errch := client.GetAllMetadata(ctx, "")
mds := map[string][]types.Metadata{}