Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-goodisman committed Apr 4, 2024
1 parent 889f52d commit 169fb5e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/alicebob/miniredis v2.5.0+incompatible
github.com/deckarep/golang-set v1.7.1
github.com/go-redis/redis/v7 v7.4.1
github.com/go-redis/redis/v8 v8.11.5
github.com/gorilla/websocket v1.4.2
github.com/juju/mgo/v2 v2.0.0-20210302023703-70d5d206e208
github.com/juju/replicaset v0.0.0-20210302050932-0303c8575745
Expand All @@ -29,7 +30,6 @@ require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/golang/protobuf v1.4.3 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/gomodule/redigo v1.8.5 // indirect
Expand Down
26 changes: 26 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,8 +44,32 @@ 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/...
func deleteDenylistEntry(response http.ResponseWriter, request *http.Request, denylist *Denylist) {
id := request.URL.Path
deleted := denylist.DeleteEntry(id)

if !deleted {
http.Error(response, "denylist entry not found with that id", http.StatusNotFound)
return
}

response.WriteHeader(http.StatusNoContent)
}

0 comments on commit 169fb5e

Please sign in to comment.