Skip to content
This repository has been archived by the owner on Apr 2, 2020. It is now read-only.

Commit

Permalink
Update reserve endpoint to accept a list of hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
dmorn committed Feb 7, 2019
1 parent 75a0bdf commit 84a5b78
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions remote/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,15 @@ func makePoliciesStickyHandler(s *store.SourceStore) http.HandlerFunc {
}
}

type ReservedPolicyInput struct {
PoliciesInput
Hosts []string `json:"hosts"`
}

func makePoliciesReserveHandler(s *store.SourceStore) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
var payload PoliciesInput
var payload ReservedPolicyInput
if err := json.NewDecoder(r.Body).Decode(&payload); err != nil {
writeError(w, err, http.StatusBadRequest)
return
Expand All @@ -133,12 +138,12 @@ func makePoliciesReserveHandler(s *store.SourceStore) http.HandlerFunc {
writeError(w, fmt.Errorf("validation error: source_id cannot be empty"), http.StatusBadRequest)
return
}
if payload.Target == "" {
writeError(w, fmt.Errorf("validation error: target cannot be empty"), http.StatusBadRequest)
if len(payload.Hosts) == 0 {
writeError(w, fmt.Errorf("validation error: hosts cannot be empty list"), http.StatusBadRequest)
return
}

p := store.NewReservedPolicy(payload.Issuer, payload.SourceID, payload.Target)
p := store.NewReservedPolicy(payload.Issuer, payload.SourceID, payload.Hosts...)
p.Reason = payload.Reason
handlePolicy(s, p, w, r)
}
Expand Down

0 comments on commit 84a5b78

Please sign in to comment.