Check for unique HTTP route & method (#102) (#111)

Check for uniqueness in HTTP routes, returning error 409 when a route + method combination is duplicated.
This commit is contained in:
Kaustubh Phatak
2017-02-13 15:58:19 -08:00
committed by Soam Vasani
parent 6be861afc8
commit 9e5db82cc9
2 changed files with 18 additions and 0 deletions
+14
View File
@@ -56,6 +56,20 @@ func (api *API) HTTPTriggerApiCreate(w http.ResponseWriter, r *http.Request) {
return
}
triggers, err := api.HTTPTriggerStore.List()
if err != nil {
api.respondWithError(w, err)
return
}
for _, url := range triggers {
if url.UrlPattern == t.UrlPattern && url.Method == t.Method {
err = fission.MakeError(fission.ErrorNameExists,
"HTTPTrigger with same URL & method already exists")
api.respondWithError(w, err)
return
}
}
uid, err := api.HTTPTriggerStore.Create(&t)
if err != nil {
api.respondWithError(w, err)