Skip to content

Commit

Permalink
VPC key changed to SSH key
Browse files Browse the repository at this point in the history
  • Loading branch information
rcmadhankumar committed Mar 6, 2023
1 parent 8576719 commit f454c77
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions cmd/capibmadm/cmd/vpc/key/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,22 @@ func CreateCommand() *cobra.Command {
# Create key in VPC
export IBMCLOUD_API_KEY=<api-key>
capibmadm vpc key create --name <key-name> --region <region> --public-key "<public-key-string>"
Using file-path to VPC key : capibmadm vpc key create --name <key-name> --region <region> --key-path <path/to/vpc/key>
Using file-path to SSH key : capibmadm vpc key create --name <key-name> --region <region> --key-path <path/to/ssh/key>
`,
}

options.AddCommonFlags(cmd)
var keyCreateOption keyCreateOptions
var filePath string
cmd.Flags().StringVar(&keyCreateOption.name, "name", keyCreateOption.name, "Key Name")
cmd.Flags().StringVar(&filePath, "key-path", "", "The absolute path to the VPC key file.")
cmd.Flags().StringVar(&filePath, "key-path", "", "The absolute path to the SSH key file.")
cmd.Flags().StringVar(&keyCreateOption.publicKey, "public-key", keyCreateOption.publicKey, "Public Key")
_ = cmd.MarkFlagRequired("name")
// TODO: Flag validation is handled in PreRunE until the support for MarkFlagsMutuallyExclusiveAndRequired is available.
// Related issue: https://github.com/spf13/cobra/issues/1216
cmd.PreRunE = func(cmd *cobra.Command, args []string) error {
if (keyCreateOption.publicKey == "") == (filePath == "") {
return fmt.Errorf("the required flags either key-path of vpc key or the public-key within double quotation marks is not found")
return fmt.Errorf("the required flags either key-path of SSH key or the public-key within double quotation marks is not found")
}
return nil
}
Expand All @@ -78,7 +78,7 @@ Using file-path to VPC key : capibmadm vpc key create --name <key-name> --region
}

if _, _, _, _, err := ssh.ParseAuthorizedKey([]byte(keyCreateOption.publicKey)); err != nil {
return fmt.Errorf("the provided VPC key is invalid. %w ", err)
return fmt.Errorf("the provided SSH key is invalid. %w ", err)
}
return createKey(cmd.Context(), keyCreateOption)
}
Expand Down Expand Up @@ -117,6 +117,6 @@ func createKey(ctx context.Context, keyCreateOption keyCreateOptions) error {
if err != nil {
return err
}
log.Info("VPC Key created successfully,", "key-name", *key.Name)
log.Info("SSH Key created successfully,", "key-name", *key.Name)
return nil
}
2 changes: 1 addition & 1 deletion cmd/capibmadm/cmd/vpc/key/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@ func deleteKey(keyDeleteOption keyDeleteOptions) error {
if _, err := vpcClient.DeleteKey(options); err != nil {
return err
}
log.Info("VPC Key deleted succssfully,", "key-name", keyDeleteOption.name)
log.Info("SSH Key deleted successfully,", "key-name", keyDeleteOption.name)
return nil
}
4 changes: 2 additions & 2 deletions docs/book/src/topics/capibmadm/vpc/key.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ capibmadm vpc key list --region <region> --resource-group-name <resource-group>

--public-key: Public key string within a double quotation marks. For example, "ssh-rsa AAA... ".

--key-path: The absolute path to the VPC key file.
--key-path: The absolute path to the SSH key file.


#### Example:
Expand All @@ -48,7 +48,7 @@ capibmadm vpc key list --region <region> --resource-group-name <resource-group>

capibmadm vpc key create --name <key-name> --region <region> --public-key "<public-key-string>"

capibmadm vpc key create --name <key-name> --region <region> --key-path <path/to/vpc/key>
capibmadm vpc key create --name <key-name> --region <region> --key-path <path/to/ssh/key>
```

### 3. capibmadm vpc key delete
Expand Down

0 comments on commit f454c77

Please sign in to comment.