-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
54 lines (47 loc) · 1.37 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
package main
import (
"log"
"github.com/spf13/viper"
)
// LDAPServer contains LDAPAddress
type LDAPServer struct {
URL string `json:"URL"`
}
// Config contains the LdapServer
type Config struct {
LdapServer LDAPServer `json:"LdapServer"`
BaseDN string `json:"BaseDN"`
PublicKeyAttribute string `json:"PublicKeyAttribute"`
IgnoreInsecureCertificates bool `json:"IgnoreInsecureCertificates"`
}
func readConfig(config *Config) {
viper.SetConfigName("ldapPubKeyReader")
viper.SetConfigType("json")
viper.AddConfigPath("/etc/ssh")
viper.AddConfigPath("/etc")
viper.AddConfigPath(".")
err := viper.ReadInConfig()
if err != nil {
panic(err)
}
LDAPSERVER := viper.GetString("LdapServer.URL")
if LDAPSERVER == "" {
log.Fatal("LdapServer.URL variable is not defined in config file")
} else {
config.LdapServer.URL = LDAPSERVER
}
BASEDN := viper.GetString("BaseDN")
if BASEDN == "" {
log.Fatal("BaseDN variable is not defined in config file")
} else {
config.BaseDN = BASEDN
}
PUBLICKEYATTRIBUTE := viper.GetString("PublicKeyAttribute")
if PUBLICKEYATTRIBUTE == "" {
config.PublicKeyAttribute = "sshPublicKey"
} else {
config.PublicKeyAttribute = PUBLICKEYATTRIBUTE
}
IGNOREINSECURECERTIFICATES := viper.GetBool("IgnoreInsecureCertificates")
config.IgnoreInsecureCertificates = IGNOREINSECURECERTIFICATES
}