aboutsummaryrefslogtreecommitdiff
path: root/internal/router/router.go
diff options
context:
space:
mode:
authorRaúl Benencia <raul@thousandeyes.com>2018-04-13 16:30:31 -0700
committerRaúl Benencia <raul@thousandeyes.com>2018-05-11 15:02:34 -0700
commit77c172b823b64ebface655681ab0749b9d2f7081 (patch)
tree09c13e626eb95ae1d33e76ed683172eab1ab6c96 /internal/router/router.go
First public commit
Diffstat (limited to 'internal/router/router.go')
-rw-r--r--internal/router/router.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/internal/router/router.go b/internal/router/router.go
new file mode 100644
index 0000000..abe4f8b
--- /dev/null
+++ b/internal/router/router.go
@@ -0,0 +1,63 @@
+// Copyright 2018 ThousandEyes Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+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.HandleFunc("/configs/{key}", handlers.TemplateHandler).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
+}
nihil fit ex nihilo