2019-05-28 01:16:50 +00:00
|
|
|
package commands
|
2019-05-22 15:22:40 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
2019-07-11 02:33:22 +00:00
|
|
|
credrepos "github.com/mitchell/selfpass/services/credentials/repositories"
|
|
|
|
credtypes "github.com/mitchell/selfpass/services/credentials/types"
|
2019-07-11 06:05:59 +00:00
|
|
|
"github.com/mitchell/selfpass/sp/repositories"
|
|
|
|
"github.com/mitchell/selfpass/sp/types"
|
2019-05-22 15:22:40 +00:00
|
|
|
)
|
|
|
|
|
2019-06-02 08:47:19 +00:00
|
|
|
func Execute() {
|
2019-05-22 15:22:40 +00:00
|
|
|
rootCmd := &cobra.Command{
|
2019-07-11 06:05:59 +00:00
|
|
|
Use: "sp",
|
2019-05-22 15:22:40 +00:00
|
|
|
Short: "This is the CLI client for Selfpass.",
|
|
|
|
Long: `This is the CLI client for Selfpass, the self-hosted password manager. With this tool you
|
|
|
|
can interact with the entire Selfpass API.`,
|
2019-05-28 01:16:50 +00:00
|
|
|
Version: "v0.1.0",
|
2019-05-22 15:22:40 +00:00
|
|
|
}
|
|
|
|
|
2019-07-11 06:05:59 +00:00
|
|
|
cfgFile := rootCmd.PersistentFlags().String("config", "", "config file (default is $HOME/.sp.toml)")
|
2019-05-22 15:22:40 +00:00
|
|
|
|
2019-06-02 08:47:19 +00:00
|
|
|
mgr := repositories.NewConfigManager(cfgFile)
|
2019-07-12 01:02:46 +00:00
|
|
|
clientInit := credrepos.NewCredentialsClient
|
2019-05-22 15:22:40 +00:00
|
|
|
|
2019-06-30 04:17:22 +00:00
|
|
|
rootCmd.AddCommand(
|
|
|
|
makeInit(mgr),
|
|
|
|
makeEncrypt(mgr),
|
|
|
|
makeDecrypt(mgr),
|
|
|
|
makeDecryptCfg(mgr),
|
2019-07-11 06:05:59 +00:00
|
|
|
makeList(makeInitClient(mgr, clientInit)),
|
|
|
|
makeCreate(mgr, makeInitClient(mgr, clientInit)),
|
|
|
|
makeUpdate(mgr, makeInitClient(mgr, clientInit)),
|
|
|
|
makeGet(mgr, makeInitClient(mgr, clientInit)),
|
|
|
|
makeDelete(makeInitClient(mgr, clientInit)),
|
|
|
|
makeGCMToCBC(mgr, makeInitClient(mgr, clientInit)),
|
2019-06-30 04:17:22 +00:00
|
|
|
)
|
2019-05-22 15:22:40 +00:00
|
|
|
|
|
|
|
check(rootCmd.Execute())
|
|
|
|
}
|
|
|
|
|
2019-07-12 01:02:46 +00:00
|
|
|
func makeInitClient(repo types.ConfigRepo, initClient credtypes.CredentialsClientInit) CredentialsClientInit {
|
|
|
|
return func(ctx context.Context) credtypes.CredentialsClient {
|
2019-06-02 08:47:19 +00:00
|
|
|
_, cfg, err := repo.OpenConfig()
|
|
|
|
check(err)
|
|
|
|
|
2019-06-05 06:40:06 +00:00
|
|
|
connConfig := cfg.GetStringMapString(types.KeyConnConfig)
|
2019-05-22 15:22:40 +00:00
|
|
|
|
|
|
|
client, err := initClient(
|
|
|
|
ctx,
|
|
|
|
connConfig["target"],
|
|
|
|
connConfig["ca"],
|
|
|
|
connConfig["cert"],
|
|
|
|
connConfig["key"],
|
|
|
|
)
|
|
|
|
check(err)
|
|
|
|
|
2019-06-02 08:47:19 +00:00
|
|
|
return client
|
2019-05-22 15:22:40 +00:00
|
|
|
}
|
|
|
|
}
|