-
Notifications
You must be signed in to change notification settings - Fork 14
/
common_config.go
62 lines (58 loc) · 1.64 KB
/
common_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
package common
import (
"fmt"
"github.com/cyberark/conjur-authn-k8s-client/pkg/log"
"strconv"
"time"
)
// Config defines the configuration parameters common for both authentications
type Config struct {
Account string
ClientCertPath string
ClientCertRetryCountLimit int
ContainerMode string
SSLCertificate []byte
TokenFilePath string
TokenRefreshTimeout time.Duration
URL string
Username *Username
}
// LoadConfig is a constructor for common Config object
func (config *Config) LoadConfig(settings map[string]string) {
for key, value := range settings {
switch key {
case "CONJUR_ACCOUNT":
config.Account = value
case "CONJUR_AUTHN_LOGIN":
if len(value) == 0 {
config.Username = nil
} else {
username, _ := NewUsername(value)
config.Username = username
}
case "CONJUR_AUTHN_URL":
config.URL = value
case "CONJUR_SSL_CERTIFICATE":
config.SSLCertificate = []byte(value)
case "CONTAINER_MODE":
config.ContainerMode = value
case "CONJUR_AUTHN_TOKEN_FILE":
config.TokenFilePath = value
case "CONJUR_CLIENT_CERT_PATH":
config.ClientCertPath = value
case "CONJUR_CLIENT_CERT_RETRY_COUNT_LIMIT":
limit, _ := strconv.Atoi(value)
config.ClientCertRetryCountLimit = limit
case "CONJUR_TOKEN_TIMEOUT":
timeout, _ := durationFromString(key, value)
config.TokenRefreshTimeout = timeout
}
}
}
func durationFromString(key, value string) (time.Duration, error) {
duration, err := time.ParseDuration(value)
if err != nil {
return 0, fmt.Errorf(log.CAKC060, key, value)
}
return duration, nil
}