Skip to content

Commit

Permalink
unstub get
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-goodisman committed Apr 4, 2024
1 parent 663a39c commit e1ab2ae
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/denylist/http.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package denylist

import (
"encoding/json"
"net/http"
"strings"
)

// CollectionEndpoint serves the endpoints for the whole Denylist at /denylist
Expand Down Expand Up @@ -42,6 +44,21 @@ func createDenylistEntry(response http.ResponseWriter, request *http.Request, de

// GET /denylist/...
func getDenylistEntry(response http.ResponseWriter, request *http.Request, denylist *Denylist) {
id := request.URL.Path
entry := denylist.GetEntry(id)
if entry == nil {
http.Error(response, "denylist entry not found with that id", http.StatusNotFound)
return
}

payload := map[string]string{
"keys": strings.Join(entry.Keys, KeysSeparator),
"regex": entry.Regex.String(),
}

response.Header().Set("Content-Type", "application/json")
json.NewEncoder(response).Encode(payload)
response.WriteHeader(http.StatusOK)
}

// DELETE /denylist/...
Expand Down

0 comments on commit e1ab2ae

Please sign in to comment.