From 77c21dc593d32041799214996045b2af67b9e78a Mon Sep 17 00:00:00 2001 From: Gergely Brautigam <182850+Skarlso@users.noreply.github.com> Date: Thu, 20 Jun 2024 08:18:33 +0200 Subject: [PATCH] feat: added update secret endpoint --- docs/release_notes/v0.1.4.md | 3 +++ pkg/server/server.go | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 docs/release_notes/v0.1.4.md diff --git a/docs/release_notes/v0.1.4.md b/docs/release_notes/v0.1.4.md new file mode 100644 index 0000000..a18820b --- /dev/null +++ b/docs/release_notes/v0.1.4.md @@ -0,0 +1,3 @@ +# Release v0.1.4 + +Added update secret endpoint. diff --git a/pkg/server/server.go b/pkg/server/server.go index b01876d..0124e86 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -72,6 +72,7 @@ func (s *Server) Run(_ context.Context) error { warden.Get("/secrets", s.listSecretsHandler) warden.Delete("/secret", s.deleteSecretHandler) warden.Post("/secret", s.createSecretHandler) + warden.Put("/secret", s.updateSecretHandler) r.Mount(api, warden) @@ -170,6 +171,26 @@ func (s *Server) createSecretHandler(w http.ResponseWriter, r *http.Request) { s.handleResponse(response, w) } +func (s *Server) updateSecretHandler(w http.ResponseWriter, r *http.Request) { + request := &sdk.SecretPutRequest{} + c, err := s.getClient(r, &request) + if err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + + return + } + defer c.Close() + + response, err := c.Secrets().Update(request.ID, request.Key, request.Value, request.Note, request.OrganizationID, request.ProjectIDS) + if err != nil { + http.Error(w, "failed to update secret: "+err.Error(), http.StatusBadRequest) + + return + } + + s.handleResponse(response, w) +} + func (s *Server) getClient(r *http.Request, response any) (sdk.BitwardenClientInterface, error) { content, err := io.ReadAll(r.Body) if err != nil {