From bc7cf2f9035aa1202bf9e61b7537fe4f3dca4834 Mon Sep 17 00:00:00 2001 From: MatthewPierson Date: Tue, 12 Mar 2024 16:28:57 +1300 Subject: [PATCH 1/2] fix: Add update support for SSH Keys --- pkg/api/ssh/key/request.go | 8 ++++++++ pkg/api/ssh/key/response.go | 5 +++++ pkg/api/ssh/key/update.go | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 pkg/api/ssh/key/update.go diff --git a/pkg/api/ssh/key/request.go b/pkg/api/ssh/key/request.go index f7e3be7..588f9ef 100644 --- a/pkg/api/ssh/key/request.go +++ b/pkg/api/ssh/key/request.go @@ -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"` + } ) diff --git a/pkg/api/ssh/key/response.go b/pkg/api/ssh/key/response.go index e43b2e4..274a85d 100644 --- a/pkg/api/ssh/key/response.go +++ b/pkg/api/ssh/key/response.go @@ -37,4 +37,9 @@ type ( DeleteResponse struct { models.APIResponse } + + // UpdateResponse represents a result of the update an SSH Key call. + UpdateResponse struct { + models.APIResponse + } ) diff --git a/pkg/api/ssh/key/update.go b/pkg/api/ssh/key/update.go new file mode 100644 index 0000000..bbc5719 --- /dev/null +++ b/pkg/api/ssh/key/update.go @@ -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 +} From aa2f56c86ccdc6055b60bd4c978f6de6f4dead60 Mon Sep 17 00:00:00 2001 From: MatthewPierson Date: Tue, 12 Mar 2024 17:03:33 +1300 Subject: [PATCH 2/2] chore: Update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ffa3c2..6d78d31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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.