This repository has been archived by the owner on Apr 5, 2024. It is now read-only.
/
config.go
94 lines (72 loc) · 3.06 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
/* Copyright (c) Edgeless Systems GmbH
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
package core
import (
"os"
)
// Config is an EDB config.
type Config struct {
DataPath string `json:",omitempty"`
DatabaseAddress string `json:",omitempty"`
APIAddress string `json:",omitempty"`
CertificateDNSName string `json:",omitempty"`
Debug bool `json:",omitempty"`
LogDir string `json:",omitempty"`
ManifestFilePath string `json:",omitempty"`
}
// EnvDataPath is the name of the optional environment variable holding the data path for edb
const EnvDataPath = "EDG_EDB_DATA_PATH"
// EnvDatabaseAddress is the name of the optional environment variable holding the database address
const EnvDatabaseAddress = "EDG_EDB_DATABASE_ADDR"
// EnvAPIAddress is the name of the optional environment variable holding the API address
const EnvAPIAddress = "EDG_EDB_API_ADDR"
// EnvCertificateDNSName is the name of the optional environment variable holding the DNS Name used for the certificate generated by edb
const EnvCertificateDNSName = "EDG_EDB_CERT_DNS"
// EnvDebug is a flag to enable debug logging for edb
const EnvDebug = "EDG_EDB_DEBUG"
// EnvLogDir is the name of the optional environment variable holding the path for storing the log files
const EnvLogDir = "EDG_EDB_LOG_DIR"
// EnvManifestFile holds the path to the manifest file in case we want edb to automatically deploy one
const EnvManifestFile = "EDG_EDB_MANIFEST_FILE"
// FillConfigFromEnvironment takes an existing config filled with defaults and replaces single values based on environment variables.
func FillConfigFromEnvironment(config Config) Config {
envDataPath := os.Getenv(EnvDataPath)
envDatabaseAddress := os.Getenv(EnvDatabaseAddress)
envAPIAddress := os.Getenv(EnvAPIAddress)
envCertificateDNSName := os.Getenv(EnvCertificateDNSName)
envDebug := os.Getenv(EnvDebug)
envLogDir := os.Getenv(EnvLogDir)
envManifestFilePath := os.Getenv(EnvManifestFile)
if envDataPath != "" {
config.DataPath = envDataPath
}
if envDatabaseAddress != "" {
config.DatabaseAddress = envDatabaseAddress
}
if envAPIAddress != "" {
config.APIAddress = envAPIAddress
}
if envCertificateDNSName != "" {
config.CertificateDNSName = envCertificateDNSName
}
if envDebug != "" {
config.Debug = true
}
if envLogDir != "" {
config.LogDir = envLogDir
config.Debug = true
}
if envManifestFilePath != "" {
config.ManifestFilePath = envManifestFilePath
}
return config
}