Skip to content

Commit

Permalink
feat: add get-by-ids endpoint (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
tangowithfoxtrot authored Aug 20, 2024
1 parent 37c61a2 commit 4abbe86
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ bin/
dist/
hack/cert-manager.yaml
hack/rootCA.pem

# Bitwarden state file
.bitwarden-state
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,46 @@ Response:
}
```

### GetSecretsByIds

`/rest/api/1/secrets-by-ids`

Method `GET`.

```json
{
"ids": [
"f5847eef-2f89-43bc-885a-b18a01178e3e", "0cab75c4-ba26-4996-a8bf-517095857ce3"
]
}
```

Response:
```json
{
"data": [
{
"creationDate": "2024-04-04",
"id": "f5847eef-2f89-43bc-885a-b18a01178e3e",
"key": "test",
"note": "note",
"organizationId": "f5847eef-2f89-43bc-885a-b18a01178e3e",
"revisionDate": "2024-04-04",
"value": "value"
},
{
"creationDate": "2024-04-05",
"id": "0cab75c4-ba26-4996-a8bf-517095857ce3",
"key": "test2",
"note": "note2",
"organizationId": "f5847eef-2f89-43bc-885a-b18a01178e3e",
"revisionDate": "2024-04-05",
"value": "value2"
}
]
}
```

### ListSecrets

`/rest/api/1/secrets`
Expand Down
21 changes: 21 additions & 0 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (s *Server) Run(_ context.Context) error {
// The header will always contain the right credentials.
warden.Get("/secret", s.getSecretHandler)
warden.Get("/secrets", s.listSecretsHandler)
warden.Get("/secrets-by-ids", s.getByIdsSecretHandler)
warden.Delete("/secret", s.deleteSecretHandler)
warden.Post("/secret", s.createSecretHandler)
warden.Put("/secret", s.updateSecretHandler)
Expand Down Expand Up @@ -111,6 +112,26 @@ func (s *Server) getSecretHandler(w http.ResponseWriter, r *http.Request) {
s.handleResponse(secretResponse, w)
}

func (s *Server) getByIdsSecretHandler(w http.ResponseWriter, r *http.Request) {
request := &sdk.SecretsGetRequest{}
c, err := s.getClient(r, &request)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)

return
}
defer c.Close()

secretResponse, err := c.Secrets().GetByIDS(request.IDS)
if err != nil {
http.Error(w, "failed to get secrets: "+err.Error(), http.StatusBadRequest)

return
}

s.handleResponse(secretResponse, w)
}

func (s *Server) listSecretsHandler(w http.ResponseWriter, r *http.Request) {
request := &sdk.SecretIdentifiersRequest{}
c, err := s.getClient(r, &request)
Expand Down

0 comments on commit 4abbe86

Please sign in to comment.