From 1c79728984af1b0b065ce5879581f41fa9f03da3 Mon Sep 17 00:00:00 2001 From: Geert Stappers Date: Thu, 5 Jan 2023 00:21:47 +0100 Subject: feat: add human-friendly entry point * Added /start as entry point, for humans and iPXE The '/poll/1/${netX/mac:hexhyp}' is fairly iPXE internal, not something that invites curious people to look better at shoelaces. Neither it is looking nice in DHCP server configuration. This change adds a HTTP handler for '/start'. And '/start' points to '/poll/1/${netX/mac:hexhyp}'. The benefit of it is that human visible documentation can replace the "voodoo" '/poll/1/${netX/mac:hexhyp}' with "friendly" '/start'. Because it is an addition are the existing HTTP handlers not effected, neither the installed deployments effected. Signed-off-by: Geert Stappers --- internal/polling/polling.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'internal/polling/polling.go') diff --git a/internal/polling/polling.go b/internal/polling/polling.go index 853a751..cfd489f 100644 --- a/internal/polling/polling.go +++ b/internal/polling/polling.go @@ -34,6 +34,16 @@ import ( type ManualAction int const ( + startScript = "#!ipxe\n" + + "echo Shoelaces starts polling\n" + + "chain --autofree --replace \\\n" + + " http://{{.baseURL}}/poll/1/${netX/mac:hexhyp}\n" + + "#\n" + + "#\n" + + "# Do\n" + + "# curl http://{{.baseURL}}/poll/1/06-66-de-ad-be-ef\n" + + "# to get an idea about what iPXE will receive.\n" + maxRetry = 10 retryScript = "#!ipxe\n" + @@ -226,6 +236,26 @@ func setHostName(params map[string]interface{}, mac string) { } } +func GenStartScript(logger log.Logger, baseURL string) string { + variablesMap := map[string]interface{}{} + parsedTemplate := &bytes.Buffer{} + + tmpl, err := template.New("retry").Parse(startScript) + if err != nil { + logger.Info("component", "polling", "msg", "Error parsing start template") + panic(err) + } + + variablesMap["baseURL"] = baseURL + err = tmpl.Execute(parsedTemplate, variablesMap) + if err != nil { + logger.Info("component", "polling", "msg", "Error executing start template") + panic(err) + } + + return parsedTemplate.String() +} + func genBootScript(logger log.Logger, templateRenderer *templates.ShoelacesTemplates, baseURL string, script *mappings.Script) string { script.Params["baseURL"] = utils.BaseURLforEnvName(baseURL, script.Environment) text, err := templateRenderer.RenderTemplate(logger, script.Name, script.Params, script.Environment) -- cgit v1.2.3