-
Notifications
You must be signed in to change notification settings - Fork 51
/
parameters.go
51 lines (43 loc) · 1.63 KB
/
parameters.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
package env
import (
"os"
"strconv"
"go.aporeto.io/trireme-lib/controller/constants"
"go.aporeto.io/trireme-lib/controller/pkg/claimsheader"
)
// RemoteParameters holds all configuration objects that must be passed
// during the initialization of the monitor.
type RemoteParameters struct {
LogToConsole bool
LogWithID bool
LogLevel string
LogFormat string
CompressedTags claimsheader.CompressionType
DisableLogWrite bool
}
// GetParameters retrieves log parameters for Remote Enforcer.
func GetParameters() (logToConsole bool, logID string, logLevel string, logFormat string, compressedTagsVersion claimsheader.CompressionType, DisableLogWrite bool) {
logLevel = os.Getenv(constants.EnvLogLevel)
if logLevel == "" {
logLevel = "info"
}
logFormat = os.Getenv(constants.EnvLogFormat)
if logLevel == "" {
logFormat = "json"
}
if console := os.Getenv(constants.EnvLogToConsole); console == constants.EnvLogToConsoleEnable {
logToConsole = true
}
logID = os.Getenv(constants.EnvLogID)
compressedTagsVersion = claimsheader.CompressionTypeNone
if console := os.Getenv(constants.EnvCompressedTags); console != string(claimsheader.CompressionTypeNone) {
if console == string(claimsheader.CompressionTypeV1) {
compressedTagsVersion = claimsheader.CompressionTypeV1
} else if console == string(claimsheader.CompressionTypeV2) {
compressedTagsVersion = claimsheader.CompressionTypeV2
}
}
// here we skip the error handling because the env is passed from the main enforcerd, so it has to be either true or false.
DisableLogWrite, _ = strconv.ParseBool(os.Getenv(constants.EnvDisableLogWrite))
return
}