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

fix: Add update support for SSH Keys #24

Merged
merged 2 commits into from
Mar 12, 2024
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [v0.3.4] - 2024-03-12
### Added
- Add ability to update SSH Keys.

## [v0.3.3] - 2024-03-12
### Added
- Add ability to create, get and delete SSH Keys.
Expand Down
8 changes: 8 additions & 0 deletions pkg/api/ssh/key/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,12 @@ type (
DeleteRequest struct {
ID string `json:"key_id"`
}

// UpdateRequest represents a request to update a specific SSH Key.
UpdateRequest struct {
ID string `json:"key_id"`
Label string `json:"label"`
Content string `json:"content"`
CustomImageAccess string `json:"custom_image_access"`
}
)
5 changes: 5 additions & 0 deletions pkg/api/ssh/key/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ type (
DeleteResponse struct {
models.APIResponse
}

// UpdateResponse represents a result of the update an SSH Key call.
UpdateResponse struct {
models.APIResponse
}
)
37 changes: 37 additions & 0 deletions pkg/api/ssh/key/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package key

import (
"context"
"net/url"

"github.com/sitehostnz/gosh/pkg/utils"
)

// Update an SSH Key.
func (s *Client) Update(ctx context.Context, opts UpdateRequest) (response UpdateResponse, err error) {
u := "ssh/key/update.json"

keys := []string{
"key_id",
"params[label]",
"params[content]",
"params[custom_image_access]",
}

values := url.Values{}
values.Add("key_id", opts.ID)
values.Add("params[label]", opts.Label)
values.Add("params[content]", opts.Content)
values.Add("params[custom_image_access]", opts.CustomImageAccess)

req, err := s.client.NewRequest("POST", u, utils.Encode(values, keys))
if err != nil {
return response, err
}

if err := s.client.Do(ctx, req, &response); err != nil {
return response, err
}

return response, nil
}
Loading