aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/handlers/templates.go14
-rw-r--r--internal/router/router.go4
2 files changed, 14 insertions, 4 deletions
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) {
diff --git a/internal/router/router.go b/internal/router/router.go
index abe4f8b..d729d16 100644
--- a/internal/router/router.go
+++ b/internal/router/router.go
@@ -48,8 +48,10 @@ func ShoelacesRouter(env *environment.Environment) http.Handler {
// Static configuration files endpoint
r.PathPrefix("/configs/static/").Handler(http.StripPrefix("/configs/static/",
handlers.StaticConfigFileServer()))
+
// Dynamic configuration endpoint
- r.HandleFunc("/configs/{key}", handlers.TemplateHandler).Methods("GET")
+ r.PathPrefix("/configs/").Handler(http.StripPrefix("/configs/",
+ handlers.TemplateServer()))
// Called by iPXE boot agents, returns boot script specified on the configuration
// or if the host is unknown makes it retry for a while until the user specifies
nihil fit ex nihilo