diff --git a/README.md b/README.md index efd9a019..10c09cd9 100644 --- a/README.md +++ b/README.md @@ -86,28 +86,30 @@ Injects SSL keys to `ssh-agent` stored in 1Password, Bitwarden and AWS S3. ## How to use it -1. Login to Bitwarden or 1Password with `bw` or `op`. If you are using S3, set your credentials. +1. Login to Bitwarden (and export its session key) or 1Password with `bw` or `op`. If you are using S3, set your credentials. 1. Add your key pairs to your password manager. +> **NOTE:** If not public key is given, the private one, postfixed with `.pub`, will be used. + For 1Password --- ```shell -ssh-manager add --name my-another-server --private-key $PK_PATH --public-key $PUB_KEY_PATH --provider op +ssh-manager add --name my-another-server --private-key $PK_PATH [ --public-key $PUB_KEY_PATH ] --provider op ``` For Bitwarden --- ```shell -ssh-manager add --name my-server --private-key $PK_PATH --public-key $PUB_KEY_PATH --provider bw +ssh-manager add --name my-server --private-key $PK_PATH [ --public-key $PUB_KEY_PATH ] --provider bw ``` For AWS S3 --- ```shell -ssh-manager add --name my-another-server --private-key $PK_PATH --public-key $PUB_KEY_PATH --provider s3 --bucket my-bucket +ssh-manager add --name my-another-server --private-key $PK_PATH [ --public-key $PUB_KEY_PATH ] --provider s3 --bucket my-bucket ``` ## Improvements to be made diff --git a/cmd/add.go b/cmd/add.go index 7b452510..3c0c97d1 100644 --- a/cmd/add.go +++ b/cmd/add.go @@ -21,10 +21,6 @@ func setupAddCommand(cmd *cobra.Command) { cmd.Flags().String("public-key", "", "Public Key file") - if err := cmd.MarkFlagRequired("public-key"); err != nil { - log.Fatalf("Lethal damage: %s\n\n", err) - } - cmd.Flags().String("private-key", "", "Private Key file") if err := cmd.MarkFlagRequired("private-key"); err != nil { @@ -47,10 +43,13 @@ func Add() *cobra.Command { Short: "Add Manager key to given provider.", RunE: func(cmd *cobra.Command, args []string) error { name, _ := cmd.Flags().GetString("name") - publicKeyFileName, _ := cmd.Flags().GetString("public-key") - privateKeyFileName, _ := cmd.Flags().GetString("private-key") providerName, _ := cmd.Flags().GetString("provider") bucket, _ := cmd.Flags().GetString("bucket") + privateKeyFileName, _ := cmd.Flags().GetString("private-key") + publicKeyFileName, err := cmd.Flags().GetString("public-key") + if err != nil { + publicKeyFileName = privateKeyFileName + ".pub" + } publicKey, err := readFile(publicKeyFileName) if err != nil {