-
Notifications
You must be signed in to change notification settings - Fork 5
/
config.go
104 lines (97 loc) · 2.04 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
99
100
101
102
103
104
package main
// config module
//
// Copyright (c) 2020 - Valentin Kuznetsov <[email protected]>
//
import (
"encoding/json"
"log"
"os"
"path/filepath"
)
// Config variable represents configuration object
var Config Configuration
// helper function to parse server configuration file
func parseConfig(configFile string) error {
data, err := os.ReadFile(filepath.Clean(configFile))
if err != nil {
log.Println("Unable to read", err)
return err
}
err = json.Unmarshal(data, &Config)
if err != nil {
log.Println("Unable to parse", err)
return err
}
if Config.ClientID == "" {
v := os.Getenv("APS_CLIENT_ID")
if v != "" {
Config.ClientID = v
} else {
log.Fatal("No ClientID found in configuration file")
}
}
if Config.ClientSecret == "" {
v := os.Getenv("APS_CLIENT_SECRET")
if v != "" {
Config.ClientSecret = v
} else {
log.Fatal("No ClientSecret found in configuration file")
}
}
// IAM settings
if Config.IAMClientID == "" {
v := os.Getenv("IAM_CLIENT_ID")
if v != "" {
Config.IAMClientID = v
}
}
if Config.IAMClientSecret == "" {
v := os.Getenv("IAM_CLIENT_SECRET")
if v != "" {
Config.IAMClientSecret = v
}
}
if Config.IAMURL == "" {
v := os.Getenv("IAM_URL")
if v != "" {
Config.IAMURL = v
} else {
Config.IAMURL = "https://cms-auth.web.cern.ch"
}
}
// default values
if Config.Port == 0 {
Config.Port = 8181
}
if Config.OAuthURL == "" {
Config.OAuthURL = "https://auth.cern.ch/auth/realms/cern"
}
if Config.ReadTimeout == 0 {
Config.ReadTimeout = 300
}
if Config.WriteTimeout == 0 {
Config.WriteTimeout = 300
}
if Config.IAMBatchSize == 0 {
Config.IAMBatchSize = 100
}
if Config.KeepAlive {
if Config.MaxIdleConns == 0 {
Config.MaxIdleConns = 100
}
if Config.MaxIdleConnsPerHost == 0 {
Config.MaxIdleConnsPerHost = 100
}
if Config.IdleConnTimeout == 0 {
Config.IdleConnTimeout = 90
}
if Config.KeepAliveTimeout == 0 {
Config.KeepAliveTimeout = 30
}
if Config.TLSHandshakeTimeout == 0 {
Config.TLSHandshakeTimeout = 10
}
}
return nil
}