aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--go.mod2
-rw-r--r--internal/handlers/polling.go4
-rw-r--r--internal/router/router.go69
3 files changed, 29 insertions, 46 deletions
diff --git a/go.mod b/go.mod
index aebe3ff..6434f4f 100644
--- a/go.mod
+++ b/go.mod
@@ -1,6 +1,6 @@
module github.com/thousandeyes/shoelaces
-go 1.21
+go 1.22
require (
github.com/gorilla/mux v1.8.0
diff --git a/internal/handlers/polling.go b/internal/handlers/polling.go
index c5aeb50..6a01e99 100644
--- a/internal/handlers/polling.go
+++ b/internal/handlers/polling.go
@@ -21,7 +21,6 @@ import (
"net/http"
"os"
- "github.com/gorilla/mux"
"github.com/thousandeyes/shoelaces/internal/log"
"github.com/thousandeyes/shoelaces/internal/polling"
"github.com/thousandeyes/shoelaces/internal/server"
@@ -49,9 +48,8 @@ func PollHandler(w http.ResponseWriter, r *http.Request) {
return
}
- vars := mux.Vars(r)
// iPXE MAC addresses come with dashes instead of colons
- mac := utils.MacDashToColon(vars["mac"])
+ mac := utils.MacDashToColon(r.PathValue("mac"))
host := r.FormValue("host")
err = validateMACAndIP(env.Logger, mac, ip)
diff --git a/internal/router/router.go b/internal/router/router.go
index 1313705..564de14 100644
--- a/internal/router/router.go
+++ b/internal/router/router.go
@@ -17,52 +17,37 @@ package router
import (
"net/http"
- "github.com/gorilla/mux"
"github.com/thousandeyes/shoelaces/internal/environment"
"github.com/thousandeyes/shoelaces/internal/handlers"
)
// ShoelacesRouter sets up all routes and handlers for shoelaces
func ShoelacesRouter(env *environment.Environment) http.Handler {
- r := mux.NewRouter()
-
- // Main UI page
- r.Handle("/", handlers.RenderDefaultTemplate("index")).Methods("GET")
- // Event Log History page
- r.Handle("/events", handlers.RenderDefaultTemplate("events")).Methods("GET")
- // Currently configured mappings page
- r.Handle("/mappings", handlers.RenderDefaultTemplate("mappings")).Methods("GET")
- // Static files used by the UI
- r.PathPrefix("/static/").Handler(http.StripPrefix("/static/",
- http.FileServer(http.Dir(env.StaticDir))))
- // Manual boot parameters POST endpoint
- r.HandleFunc("/update/target", handlers.UpdateTargetHandler).Methods("POST")
- // Provides a list of the servers that tried to boot but did not match
- // the hostname regex or network mappings
- r.HandleFunc("/ajax/servers", handlers.ServerListHandler).Methods("GET")
- // Event Log History JSON endpoint
- r.HandleFunc("/ajax/events", handlers.ListEvents).Methods("GET")
- // Provides the list of possible parameters for a given template
- r.HandleFunc("/ajax/script/params", handlers.GetTemplateParams)
-
- // Static configuration files endpoint
- r.PathPrefix("/configs/static/").Handler(http.StripPrefix("/configs/static/",
- handlers.StaticConfigFileServer()))
-
- // Dynamic configuration endpoint
- r.PathPrefix("/configs/").Handler(http.StripPrefix("/configs/",
- handlers.TemplateServer()))
-
- // Starting point for iPXE boot agents, usualy defined by DHCP server.
- // Gets the iPXE boot agents into the polling loop.
- r.HandleFunc("/start", handlers.StartPollingHandler).Methods("GET")
- // 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
- // alternative ipxe boot script
- r.HandleFunc("/poll/1/{mac}", handlers.PollHandler).Methods("GET")
- // Serves a generated iPXE boot script providing a selection
- // of all of the boot scripts available on the filesystem for that environment.
- r.HandleFunc("/ipxemenu", handlers.IPXEMenu).Methods("GET")
-
- return r
+ mux := http.NewServeMux()
+ staticFiles := http.StripPrefix("/static/", http.FileServer(http.Dir(env.StaticDir)))
+ staticConfigs := http.StripPrefix("/configs/static/", handlers.StaticConfigFileServer())
+ dynamicConfigs := http.StripPrefix("/configs/", handlers.TemplateServer())
+
+ // UI pages and assets.
+ mux.Handle("GET /{$}", handlers.RenderDefaultTemplate("index"))
+ mux.Handle("GET /events", handlers.RenderDefaultTemplate("events"))
+ mux.Handle("GET /mappings", handlers.RenderDefaultTemplate("mappings"))
+ mux.Handle("GET /static/", staticFiles)
+
+ // UI JSON endpoints and manual boot selection.
+ mux.HandleFunc("POST /update/target", handlers.UpdateTargetHandler)
+ mux.HandleFunc("GET /ajax/servers", handlers.ServerListHandler)
+ mux.HandleFunc("GET /ajax/events", handlers.ListEvents)
+ mux.HandleFunc("GET /ajax/script/params", handlers.GetTemplateParams)
+
+ // Static and templated configuration files served to booting hosts.
+ mux.Handle("GET /configs/static/", staticConfigs)
+ mux.Handle("GET /configs/", dynamicConfigs)
+
+ // iPXE boot endpoints.
+ mux.HandleFunc("GET /start", handlers.StartPollingHandler)
+ mux.HandleFunc("GET /poll/1/{mac}", handlers.PollHandler)
+ mux.HandleFunc("GET /ipxemenu", handlers.IPXEMenu)
+
+ return mux
}
nihil fit ex nihilo