Tom Hubrecht
ecbad0a638
All checks were successful
Check workflows / check_workflows (push) Successful in 21s
Run pre-commit on all files / check (push) Successful in 24s
Check meta / check_dns (pull_request) Successful in 19s
Check meta / check_meta (pull_request) Successful in 18s
Check workflows / check_workflows (pull_request) Successful in 19s
Build all the nodes / bridge01 (pull_request) Successful in 1m13s
Build all the nodes / geo01 (pull_request) Successful in 1m14s
Build all the nodes / compute01 (pull_request) Successful in 1m44s
Build all the nodes / geo02 (pull_request) Successful in 1m12s
Build all the nodes / rescue01 (pull_request) Successful in 1m30s
Build all the nodes / storage01 (pull_request) Successful in 1m29s
Build all the nodes / vault01 (pull_request) Successful in 1m26s
Build all the nodes / web02 (pull_request) Successful in 1m19s
Run pre-commit on all files / check (pull_request) Successful in 24s
Build all the nodes / web01 (pull_request) Successful in 1m56s
Build all the nodes / web03 (pull_request) Successful in 1m25s
This adds subdirectories for the different types of systems, for the modules and the machines
67 lines
1.5 KiB
Diff
67 lines
1.5 KiB
Diff
diff --git a/internal/hook/hook.go b/internal/hook/hook.go
|
|
index 0510095..0347f26 100644
|
|
--- a/internal/hook/hook.go
|
|
+++ b/internal/hook/hook.go
|
|
@@ -13,12 +13,12 @@ import (
|
|
"errors"
|
|
"fmt"
|
|
"hash"
|
|
- "io/ioutil"
|
|
"log"
|
|
"math"
|
|
"net"
|
|
"net/textproto"
|
|
"os"
|
|
+ "path"
|
|
"reflect"
|
|
"regexp"
|
|
"strconv"
|
|
@@ -750,14 +750,18 @@ func (h *Hooks) LoadFromFile(path string, asTemplate bool) error {
|
|
}
|
|
|
|
// parse hook file for hooks
|
|
- file, e := ioutil.ReadFile(path)
|
|
+ file, e := os.ReadFile(path)
|
|
|
|
if e != nil {
|
|
return e
|
|
}
|
|
|
|
if asTemplate {
|
|
- funcMap := template.FuncMap{"getenv": getenv}
|
|
+ funcMap := template.FuncMap{
|
|
+ "cat": cat,
|
|
+ "credential": credential,
|
|
+ "getenv": getenv,
|
|
+ }
|
|
|
|
tmpl, err := template.New("hooks").Funcs(funcMap).Parse(string(file))
|
|
if err != nil {
|
|
@@ -956,3 +960,27 @@ func compare(a, b string) bool {
|
|
func getenv(s string) string {
|
|
return os.Getenv(s)
|
|
}
|
|
+
|
|
+// cat provides a template function to retrieve content of files
|
|
+// Similarly to getenv, if no file is found, it returns the empty string
|
|
+func cat(s string) string {
|
|
+ data, e := os.ReadFile(s)
|
|
+
|
|
+ if e != nil {
|
|
+ return ""
|
|
+ }
|
|
+
|
|
+ return strings.TrimSuffix(string(data), "\n")
|
|
+}
|
|
+
|
|
+// credential provides a template function to retreive secrets using systemd's LoadCredential mechanism
|
|
+func credential(s string) string {
|
|
+ dir := getenv("CREDENTIALS_DIRECTORY")
|
|
+
|
|
+ // If no credential directory is found, fallback to the env variable
|
|
+ if dir == "" {
|
|
+ return getenv(s)
|
|
+ }
|
|
+
|
|
+ return cat(path.Join(dir, s))
|
|
+}
|