-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
98 lines (89 loc) · 2.21 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
88
89
90
91
92
93
94
95
96
97
98
package config
import (
"fmt"
"github.com/BurntSushi/toml"
log "github.com/sirupsen/logrus"
)
type configWebServer struct {
ListenIP string
ListenPort int
}
type configLDAPClient struct {
BaseDN string
BindUser string
BindPassword string
BindHost string
BindPort int
}
type configLDAPServer struct {
BaseDN string
ListenIP string
ListenPort int
}
type configUser struct {
Name string
wfhchair string
wfhtable string
OtherGroups []int
PassSHA256 string
PrimaryGroup int
SSHKeys []string
UnixID int
Description string
Gecos string //https://en.wikipedia.org/wiki/Gecos_field
}
type configwfhtable struct {
Name string
Description string
Stock int
}
type configwfhchair struct {
Name string
Description string
Stock int
}
type configGroup struct {
Name string
UnixID int
}
type Config struct {
Debug bool
Groups []configGroup
Users []configUser
wfhchair []configwfhchair
wfhtable []configwfhtable
LDAPClient configLDAPClient
LDAPServer configLDAPServer
WebServer configWebServer
}
func NewConfigGroup() configGroup {
cfgGroup := configGroup{}
return cfgGroup
}
func NewConfigUser() configUser {
cfgUser := configUser{}
return cfgUser
}
func NewConfig(configFile string) (cfg Config, err error) {
err = cfg.parseFile(configFile)
if err != nil {
return cfg, err
}
return cfg, nil
}
func (cfg *Config) parseFile(configFile string) error {
if _, err := toml.DecodeFile(configFile, &cfg); err != nil {
return err
}
return nil
}
func (cfg Config) Dump() {
var configLogger = log.WithFields(log.Fields{"Owner": "Config"})
log.SetLevel(log.DebugLevel)
configLogger.Debug("Dumping configuration information")
configLogger.Debug(fmt.Sprintf("Web server listening on: %s:%d", cfg.WebServer.ListenIP, cfg.WebServer.ListenPort))
configLogger.Debug(fmt.Sprintf("Connecting to LDAP server on: %s:%d", cfg.LDAPClient.BindHost, cfg.LDAPClient.BindPort))
configLogger.Debug(fmt.Sprintf("BaseDN: %s", cfg.LDAPClient.BaseDN))
configLogger.Debug(fmt.Sprintf("Using credentials: %s / %s", cfg.LDAPClient.BindUser, cfg.LDAPClient.BindPassword))
configLogger.Debug(fmt.Sprintf("Debug mode: %t", cfg.Debug))
}