Skip to content

Commit

Permalink
feat: added update secret endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Skarlso committed Jun 20, 2024
1 parent 659fe4c commit 77c21dc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/release_notes/v0.1.4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Release v0.1.4

Added update secret endpoint.
21 changes: 21 additions & 0 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 77c21dc

Please sign in to comment.