aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorraul-te <46945030+raul-te@users.noreply.github.com>2020-04-01 10:41:17 -0700
committerGitHub <noreply@github.com>2020-04-01 10:41:17 -0700
commitb709a777f56511e233cd4652e73ec46c7641652b (patch)
tree0acfa9bef4458aee5d04dd87535b4473c096eac4
parenta21d894fb128e49d6ef912bbed51bfb0754223fa (diff)
parent5f2ba83e131c5a67f979abb909fecb59651c44ac (diff)
Merge pull request #6 from rul/support-config-subdirectories
Support config subdirectories
-rw-r--r--configs/data-dir/ipxe/debian.ipxe.slc2
-rw-r--r--configs/data-dir/ipxe/storage.ipxe.slc2
-rw-r--r--configs/data-dir/ipxe/ubuntu-minimal.ipxe.slc2
-rw-r--r--configs/data-dir/preseed/common.preseed.slc2
-rw-r--r--configs/data-dir/preseed/debian.preseed.slc6
-rw-r--r--configs/data-dir/preseed/storage.preseed.slc4
-rw-r--r--configs/data-dir/preseed/ubuntu-minimal.preseed.slc4
-rw-r--r--internal/handlers/templates.go14
-rw-r--r--internal/router/router.go4
9 files changed, 25 insertions, 15 deletions
diff --git a/configs/data-dir/ipxe/debian.ipxe.slc b/configs/data-dir/ipxe/debian.ipxe.slc
index 8717d5e..6a29bbd 100644
--- a/configs/data-dir/ipxe/debian.ipxe.slc
+++ b/configs/data-dir/ipxe/debian.ipxe.slc
@@ -10,7 +10,7 @@ chain http://{{.baseURL}}/configs/linux.cfg?hostname={{.hostname}}
imgfree
-kernel ${mirror}/linux auto=true priority=critical initrd=initrd.gz keyboard-configuration/xkb-keymap=us preseed/url=http://{{.baseURL}}/configs/debian.preseed ${linuxargs}
+kernel ${mirror}/linux auto=true priority=critical initrd=initrd.gz keyboard-configuration/xkb-keymap=us preseed/url=http://{{.baseURL}}/configs/preseeds/debian?encrypt_home={{.encrypt_home}} ${linuxargs}
initrd ${mirror}/initrd.gz
boot
{{end}}
diff --git a/configs/data-dir/ipxe/storage.ipxe.slc b/configs/data-dir/ipxe/storage.ipxe.slc
index 457dad7..174949d 100644
--- a/configs/data-dir/ipxe/storage.ipxe.slc
+++ b/configs/data-dir/ipxe/storage.ipxe.slc
@@ -10,7 +10,7 @@ chain --autofree http://{{.baseURL}}/configs/linux.cfg?hostname={{.hostname}}
imgfree
-kernel ${mirror}/linux auto=true priority=critical initrd=initrd.gz preseed/url=http://{{.baseURL}}/configs/storage.preseed ${linuxargs}
+kernel ${mirror}/linux auto=true priority=critical initrd=initrd.gz preseed/url=http://{{.baseURL}}/configs/preseeds/storage ${linuxargs}
initrd ${mirror}/initrd.gz
boot
{{end}} \ No newline at end of file
diff --git a/configs/data-dir/ipxe/ubuntu-minimal.ipxe.slc b/configs/data-dir/ipxe/ubuntu-minimal.ipxe.slc
index e52f63c..ef4e61e 100644
--- a/configs/data-dir/ipxe/ubuntu-minimal.ipxe.slc
+++ b/configs/data-dir/ipxe/ubuntu-minimal.ipxe.slc
@@ -10,7 +10,7 @@ chain http://{{.baseURL}}/configs/linux.cfg?hostname={{.hostname}}
imgfree
-kernel ${mirror}/linux auto=true priority=critical initrd=initrd.gz preseed/url=http://{{.baseURL}}/configs/ubuntu-minimal.preseed ${linuxargs}
+kernel ${mirror}/linux auto=true priority=critical initrd=initrd.gz preseed/url=http://{{.baseURL}}/configs/preseeds/ubuntu-minimal ${linuxargs}
initrd ${mirror}/initrd.gz
boot
{{end}}
diff --git a/configs/data-dir/preseed/common.preseed.slc b/configs/data-dir/preseed/common.preseed.slc
index bcbf98b..8abd284 100644
--- a/configs/data-dir/preseed/common.preseed.slc
+++ b/configs/data-dir/preseed/common.preseed.slc
@@ -1,4 +1,4 @@
-{{define "common.preseed"}}
+{{define "preseeds/common"}}
d-i auto-install/enable boolean true
d-i debian-installer/locale string en_US
d-i console-setup/ask_detect boolean false
diff --git a/configs/data-dir/preseed/debian.preseed.slc b/configs/data-dir/preseed/debian.preseed.slc
index 0915fe3..ab37afc 100644
--- a/configs/data-dir/preseed/debian.preseed.slc
+++ b/configs/data-dir/preseed/debian.preseed.slc
@@ -1,5 +1,5 @@
-{{define "debian.preseed" -}}
-{{template "common.preseed"}}
+{{define "preseeds/debian" -}}
+{{template "preseeds/common"}}
d-i partman-auto/method string regular
d-i partman-lvm/device_remove_lvm boolean true
@@ -15,7 +15,7 @@ d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
-d-i user-setup/encrypt-home boolean false
+d-i user-setup/encrypt-home boolean {{.encrypt_home}}
d-i base-installer/install-recommends boolean true
diff --git a/configs/data-dir/preseed/storage.preseed.slc b/configs/data-dir/preseed/storage.preseed.slc
index 982b41b..ca2aadc 100644
--- a/configs/data-dir/preseed/storage.preseed.slc
+++ b/configs/data-dir/preseed/storage.preseed.slc
@@ -1,5 +1,5 @@
-{{define "storage.preseed" -}}
-{{template "common.preseed"}}
+{{define "preseeds/storage" -}}
+{{template "preseeds/common"}}
# The method should be set to "raid".
d-i partman-auto/method string raid
diff --git a/configs/data-dir/preseed/ubuntu-minimal.preseed.slc b/configs/data-dir/preseed/ubuntu-minimal.preseed.slc
index 2138764..08013ff 100644
--- a/configs/data-dir/preseed/ubuntu-minimal.preseed.slc
+++ b/configs/data-dir/preseed/ubuntu-minimal.preseed.slc
@@ -1,5 +1,5 @@
-{{define "ubuntu-minimal.preseed" -}}
-{{template "common.preseed"}}
+{{define "preseeds/ubuntu-minimal" -}}
+{{template "preseeds/common"}}
d-i partman-auto/method string regular
d-i partman-lvm/device_remove_lvm boolean true
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