-
Notifications
You must be signed in to change notification settings - Fork 11
/
gen.go
123 lines (109 loc) · 2.58 KB
/
gen.go
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//go:build ignore
package main
import (
_ "embed"
"fmt"
"io"
"log"
"net/http"
"os"
"regexp"
"sort"
"strings"
"text/template"
"gopkg.in/yaml.v3"
"k8s.io/utils/strings/slices"
)
//go:embed JITSI_VERSION
var VERSION string
var SERVICES = []string{"web", "prosody", "jicofo", "jvb", "jibri"}
var COMPOSES = []string{"docker-compose.yml", "jibri.yml"}
var EXCLUDE_PATTERNS = []string{"_SECRET", "_PASSWORD"}
var EXCLUDES = []string{
"JVB_OCTO_BIND_ADDRESS",
"JVB_OCTO_RELAY_ID",
"JVB_WS_SERVER_ID",
"TURN_CREDENTIALS",
"TURN_HOST",
"TURN_PORT",
"TURNS_HOST",
"TURNS_PORT",
"LOCAL_ADDRESS",
"COLIBRI_WEBSOCKET_REGEX",
}
var ADDITIONALS = map[string][]string{
"prosody": {"JWT_APP_SECRET"}, // TODO in a secret
}
type Compose struct {
Services map[string]ComposeService
}
type ComposeService struct {
Environment []string
}
type Environment struct {
Name string
Variables []string
}
var Template = template.Must(template.New("").Parse(`// Code generated by go generate; DO NOT EDIT.
package controllers
{{ range . }}
var {{ .Name }}Variables = []string{
{{- range .Variables }}
"{{ . }}",
{{- end }}
}
{{ end -}}
`))
func main() {
environments := []Environment{}
re := regexp.MustCompile(`^\w*`)
for _, file := range COMPOSES {
url := fmt.Sprintf("https://raw.githubusercontent.com/jitsi/docker-jitsi-meet/%s/%s", VERSION, file)
resp, err := http.Get(url)
handleErr(err)
body, err := io.ReadAll(resp.Body)
handleErr(err)
var compose Compose
err = yaml.Unmarshal(body, &compose)
handleErr(err)
for serviceName, service := range compose.Services {
environment := Environment{
Name: strings.Title(serviceName),
Variables: []string{},
}
for _, v := range service.Environment {
variable := re.FindString(v)
if shouldSkip(variable) {
continue
}
environment.Variables = append(environment.Variables, variable)
}
additional, ok := ADDITIONALS[serviceName]
if ok {
environment.Variables = append(environment.Variables, additional...)
}
environments = append(environments, environment)
}
}
sort.SliceStable(environments, func(i, j int) bool {
return environments[i].Name < environments[j].Name
})
f, err := os.Create("controllers/environments.go")
handleErr(err)
defer f.Close()
Template.Execute(f, environments)
fmt.Println("environments.go generated")
}
func handleErr(err error) {
if err != nil {
log.Fatal(err)
}
}
func shouldSkip(variable string) bool {
for _, pattern := range EXCLUDE_PATTERNS {
if strings.Contains(variable, pattern) {
return true
}
}
return slices.Contains(EXCLUDES, variable)
}