-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
82 lines (64 loc) · 1.49 KB
/
config.go
File metadata and controls
82 lines (64 loc) · 1.49 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
package humcommon
import (
"os"
"github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
)
const defaultConfigFilePath = "/etc/https-user-management/config.yaml"
const defaultTokenFilePath = "/etc/https-user-management/user.token"
const defaultUserFilePath = "/etc/https-user-management/user.name"
var AppConfig *Config
var ConfigError bool
type Config struct {
TLS struct {
CA string
Key string
Cert string
}
Debug bool
URL string
TokenFile string
UserFile string
}
func NewConfig(configPath string) (*Config, error) {
// Create config structure
config := &Config{}
// Open config file
file, err := os.Open(configPath)
if err != nil {
return config, err
}
defer file.Close()
// Init new YAML decode
d := yaml.NewDecoder(file)
// Start YAML decoding from file
if err := d.Decode(&config); err != nil {
return config, err
}
return config, nil
}
func init() {
var err error
initLogger()
configFilePath := os.Getenv("HTTPS_USER_MANAGEMENT_CONFIG")
if configFilePath == "" {
configFilePath = defaultConfigFilePath
}
AppConfig, err = NewConfig(configFilePath)
if err != nil {
logger.Debugf("Unable to load config. Error: %v", err)
ConfigError = true
return
}
if AppConfig.TokenFile == "" {
AppConfig.TokenFile = defaultTokenFilePath
}
if AppConfig.UserFile == "" {
AppConfig.UserFile = defaultUserFilePath
}
logger.Debugf("AppConfig: %+v", *AppConfig)
if AppConfig.Debug {
logger.SetLevel(logrus.DebugLevel)
logger.SetReportCaller(true)
}
}