-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
42 lines (34 loc) · 843 Bytes
/
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
package main
import (
"fmt"
"io/ioutil"
"gopkg.in/yaml.v3"
"k8s.io/klog/v2"
)
type requesAuthz struct {
Method string `json:"method"`
PathRegEx []string `json:"pathregex"`
}
type headerRules map[string][]requesAuthz
//ConfigFile is the structure used to map the config file.
type ConfigFile struct {
Listen string `yaml:"listen"`
ServerAPIURL string `yaml:"serverAPIURL"`
ServerAPIToken string `yaml:"serverAPIToken"`
HeaderToken string `yaml:"headerToken"`
Rules headerRules `yaml:"rules"`
}
var (
config ConfigFile
)
func (cfg *ConfigFile) loadConfig(path string) error {
file, err := ioutil.ReadFile(path)
if err != nil {
klog.Warning(fmt.Sprintf("Config file not found on %v.", path))
}
err = yaml.Unmarshal(file, cfg)
if err != nil {
return err
}
return nil
}