diff --git a/api/router.go b/api/router.go index 698b66c0..def6fe01 100644 --- a/api/router.go +++ b/api/router.go @@ -100,10 +100,12 @@ func Route() *mux.Router { publicWebHookRouter.Use(StoreMiddleware, JSONMiddleware) publicWebHookRouter.Path("/integrations/{integration_alias}").HandlerFunc(ReceiveIntegration).Methods("POST", "GET", "OPTIONS") - publicWebHookRouter.Path("/terraform/{alias}").HandlerFunc(getTerraformState).Methods("GET") - publicWebHookRouter.Path("/terraform/{alias}").HandlerFunc(addTerraformState).Methods("POST") - publicWebHookRouter.Path("/terraform/{alias}").HandlerFunc(lockTerraformState).Methods("LOCK") - publicWebHookRouter.Path("/terraform/{alias}").HandlerFunc(unlockTerraformState).Methods("UNLOCK") + terraformWebhookRouter := publicWebHookRouter.PathPrefix("/terraform").Subrouter() + terraformWebhookRouter.Use(TerraformInventoryAliasMiddleware) + terraformWebhookRouter.Path("/{alias}").HandlerFunc(getTerraformState).Methods("GET") + terraformWebhookRouter.Path("/{alias}").HandlerFunc(addTerraformState).Methods("POST") + terraformWebhookRouter.Path("/{alias}").HandlerFunc(lockTerraformState).Methods("LOCK") + terraformWebhookRouter.Path("/{alias}").HandlerFunc(unlockTerraformState).Methods("UNLOCK") authenticatedWS := r.PathPrefix(webPath + "api").Subrouter() authenticatedWS.Use(JSONMiddleware, authenticationWithStore) diff --git a/api/terraform.go b/api/terraform.go index 2ab59b49..0bc703c4 100644 --- a/api/terraform.go +++ b/api/terraform.go @@ -4,6 +4,12 @@ package api import "net/http" +func TerraformInventoryAliasMiddleware(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + next.ServeHTTP(w, r) + }) +} + func getTerraformState(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNotFound) }