Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(add): Default public key to <private key>.pub if not given #144

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 8 additions & 9 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -47,21 +43,24 @@ 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")

publicKey, err := readFile(publicKeyFileName)
privateKeyFileName, _ := cmd.Flags().GetString("private-key")
publicKeyFileName, err := cmd.Flags().GetString("public-key")
if err != nil {
return err
publicKeyFileName = privateKeyFileName + ".pub"
}

privateKey, err := readFile(privateKeyFileName)
if err != nil {
return err
}

publicKey, err := readFile(publicKeyFileName)
if err != nil {
publicKey = privateKey + ".pub"
}

item := provider.Item{
Name: name,
Values: []provider.Field{
Expand Down