-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
87 lines (69 loc) · 1.9 KB
/
config.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
package main
import (
"fmt"
"io/ioutil"
"os"
"gopkg.in/yaml.v2"
)
var config serverConfig
type serverConfig struct {
ServerAddr string `yaml:"server_addr"`
ServerBannedIPs []string `yaml:"server_banned_ips"`
Jwtsecret string `yaml:"jwtsecret"`
ServerUrl string `yaml:"server_url"`
ChallengesDir string `yaml:"challenges_dir"`
SlidesDir string `yaml:"slides_dir"`
FrontendDir string `yaml:"frontend_dir"`
AdminPassword string `yaml:"admin_password"`
UserPassword string `yaml:"user_password"`
GoogleId string `yaml:"googleId"`
GoogleSecret string `yaml:"googleSecret"`
AzureId string `yaml:"azureId"`
AzureSecret string `yaml:"azureSecret"`
ContainerHosts []sContainerHost `yaml:"container_hosts"`
BaseContainers []sBaseContainer `yaml:"base_containers"`
}
type sBaseContainer struct {
Id string
Name string
Bits string
}
type sContainerHost struct {
HostnameAlias string
Hostname string
Aslr bool
Arch string
SshBasePort int
}
func parseConfig() error {
data, err := ioutil.ReadFile("yookiterm-server.yml")
if os.IsNotExist(err) {
return fmt.Errorf("the configuration file (yookiterm-server.yml) doesn't exist")
} else if err != nil {
return fmt.Errorf("unable to read the configuration %s", err)
}
err = yaml.Unmarshal(data, &config)
if err != nil {
return fmt.Errorf("unable to parse the configuration %s", err)
}
if config.ServerAddr == "" {
config.ServerAddr = ":8080"
}
return nil
}
func getBaseContainerByName(containerBaseName string) sBaseContainer {
for _, element := range config.BaseContainers {
if element.Name == containerBaseName {
return element
}
}
return sBaseContainer{}
}
func getContainerHostByAlias(hostnameAlias string) sContainerHost {
for _, element := range config.ContainerHosts {
if element.HostnameAlias == hostnameAlias {
return element
}
}
return sContainerHost{}
}