Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/ovhcloud_cloud_ssh-key.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Manage SSH keys in the given cloud project

* [ovhcloud cloud](ovhcloud_cloud.md) - Manage your projects and services in the Public Cloud universe (MKS, MPR, MRS, Object Storage...)
* [ovhcloud cloud ssh-key create](ovhcloud_cloud_ssh-key_create.md) - Create a new SSH key
* [ovhcloud cloud ssh-key delete](ovhcloud_cloud_ssh-key_delete.md) - Delete a SSH key
* [ovhcloud cloud ssh-key get](ovhcloud_cloud_ssh-key_get.md) - Get information about a SSH key
* [ovhcloud cloud ssh-key list](ovhcloud_cloud_ssh-key_list.md) - List SSH keys

37 changes: 37 additions & 0 deletions doc/ovhcloud_cloud_ssh-key_delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
## ovhcloud cloud ssh-key delete

Delete a SSH key

```
ovhcloud cloud ssh-key delete <ssh_key_id> [flags]
```

### Options

```
-h, --help help for delete
```

### Options inherited from parent commands

```
--cloud-project string Cloud project ID
-d, --debug Activate debug mode (will log all HTTP requests details)
-e, --ignore-errors Ignore errors in API calls when it is not fatal to the execution
-o, --output string Output format: json, yaml, interactive, or a custom format expression (using https://github.com/PaesslerAG/gval syntax)
Examples:
--output json
--output yaml
--output interactive
--output 'id' (to extract a single field)
--output 'nested.field.subfield' (to extract a nested field)
--output '[id, "name"]' (to extract multiple fields as an array)
--output '{"newKey": oldKey, "otherKey": nested.field}' (to extract and rename fields in an object)
--output 'name+","+type' (to extract and concatenate fields in a string)
--output '(nbFieldA + nbFieldB) * 10' (to compute values from numeric fields)
```

### SEE ALSO

* [ovhcloud cloud ssh-key](ovhcloud_cloud_ssh-key.md) - Manage SSH keys in the given cloud project

7 changes: 7 additions & 0 deletions internal/cmd/cloud_ssh_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,12 @@ func initCloudSSHKeyCommand(cloudCmd *cobra.Command) {
sshKeyCreateCmd.MarkFlagsMutuallyExclusive("from-file", "editor")
sshKeyCmd.AddCommand(sshKeyCreateCmd)

sshKeyCmd.AddCommand(&cobra.Command{
Use: "delete <ssh_key_id>",
Short: "Delete a SSH key",
Run: cloud.DeleteCloudSSHKey,
Args: cobra.ExactArgs(1),
})

cloudCmd.AddCommand(sshKeyCmd)
}
18 changes: 18 additions & 0 deletions internal/services/cloud/cloud_ssh_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package cloud
import (
_ "embed"
"fmt"
"net/url"

"github.com/ovh/ovhcloud-cli/internal/assets"
"github.com/ovh/ovhcloud-cli/internal/display"
Expand Down Expand Up @@ -91,3 +92,20 @@ func CreateCloudSSHKey(cmd *cobra.Command, _ []string) {

display.OutputInfo(&flags.OutputFormatConfig, nil, "✅ SSH key successfully created")
}

func DeleteCloudSSHKey(_ *cobra.Command, args []string) {
projectID, err := getConfiguredCloudProject()
if err != nil {
display.OutputError(&flags.OutputFormatConfig, "%s", err)
return
}

endpoint := fmt.Sprintf("/v1/cloud/project/%s/sshkey/%s", projectID, url.PathEscape(args[0]))

if err := httpLib.Client.Delete(endpoint, nil); err != nil {
display.OutputError(&flags.OutputFormatConfig, "error deleting SSH key %q: %s", args[0], err)
return
}

display.OutputInfo(&flags.OutputFormatConfig, nil, "✅ SSH key successfully deleted")
}