-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconfigs.go
More file actions
93 lines (86 loc) · 2.16 KB
/
Copy pathconfigs.go
File metadata and controls
93 lines (86 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"encoding/json"
"log"
"os"
)
func LoadDeployments(path string) {
data, err := os.ReadFile(path)
if err != nil {
log.Println("Could not find config file:", path)
os.Exit(1)
}
err = json.Unmarshal(data, Deployment)
if err != nil {
log.Println("Could not read/parse the config file ...", err, path)
os.Exit(1)
}
}
func LoadServers(path string) {
data, err := os.ReadFile(path)
if err != nil {
log.Println("Could not find server config file:", path)
os.Exit(1)
}
S := new(Server)
err = json.Unmarshal(data, S)
if err != nil {
log.Println("Could not read/parse the config file ...", err, path)
os.Exit(1)
}
Servers = append(Servers, S)
return
}
func LoadScript(path string) {
var Services []Script
data, err := os.ReadFile(path)
if err != nil {
log.Println("Could not find service config file:", path)
os.Exit(1)
}
S := new(Script)
err = json.Unmarshal(data, S)
if err != nil {
log.Println("Could not read/parse the config file ...", err, path)
os.Exit(1)
}
Services = append(Services, *S)
for i := range Servers {
newScripts := make([]Script, len(Services))
copy(newScripts, Services)
Servers[i].Scripts = newScripts
// fmt.Println("Loaded", len(Servers[i].Scripts), "scripts for server", Servers[i].Hostname)
}
}
func LoadVariables(path string) {
if path == "" {
return
}
data, err := os.ReadFile(path)
if err != nil {
log.Println("Could not find variables config file:", path)
os.Exit(1)
}
err = json.Unmarshal(data, &Variables)
if err != nil {
log.Println("Could not read/parse the config file ...", err, path)
os.Exit(1)
}
}
func LoadTemplates(path string) {
for i, v := range Servers {
for ii, iv := range v.Scripts {
for iii, iiv := range iv.CMD {
if iiv.Template != nil {
data, err := os.ReadFile(iiv.Template.Local)
if err != nil {
log.Println("Could not find config template file:", iiv.Template.Local)
os.Exit(1)
}
Servers[i].Scripts[ii].CMD[iii].Template.Data = make([]byte, len(data))
Servers[i].Scripts[ii].CMD[iii].Template.Data = data
}
}
}
}
}