From 5f2ba83e131c5a67f979abb909fecb59651c44ac Mon Sep 17 00:00:00 2001 From: Raul Benencia Date: Wed, 1 Apr 2020 10:09:26 -0700 Subject: Support config subdirectories --- internal/handlers/templates.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'internal/handlers/templates.go') diff --git a/internal/handlers/templates.go b/internal/handlers/templates.go index df1bc58..676812f 100644 --- a/internal/handlers/templates.go +++ b/internal/handlers/templates.go @@ -18,16 +18,19 @@ import ( "encoding/json" "io" "net/http" + "path/filepath" - "github.com/gorilla/mux" "github.com/thousandeyes/shoelaces/internal/utils" ) +// TemplateHandler handles templated config files +type TemplateHandler struct{} + // TemplateHandler is the dynamic configuration provider endpoint. It // receives a key and maybe an environment. -func TemplateHandler(w http.ResponseWriter, r *http.Request) { +func (t *TemplateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { variablesMap := map[string]interface{}{} - configName := mux.Vars(r)["key"] + configName := filepath.Clean(r.URL.Path) if configName == "" { http.Error(w, "No template name provided", http.StatusNotFound) @@ -50,6 +53,11 @@ func TemplateHandler(w http.ResponseWriter, r *http.Request) { } } +// TemplateHandler returns a TemplateHandler instance implementing http.Handler +func TemplateServer() *TemplateHandler { + return &TemplateHandler{} +} + // GetTemplateParams receives a script name and returns the parameters // required for completing that template. func GetTemplateParams(w http.ResponseWriter, r *http.Request) { -- cgit v1.2.3