-
Notifications
You must be signed in to change notification settings - Fork 501
/
Copy pathGlobalConfig.go
98 lines (86 loc) · 3.75 KB
/
GlobalConfig.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
/*
* Copyright (c) 2024. Devtron Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package util
import (
"github.com/caarlos0/env"
)
type EnvironmentVariables struct {
GlobalEnvVariables *GlobalEnvVariables
DevtronSecretConfig *DevtronSecretConfig
DeploymentServiceTypeConfig *DeploymentServiceTypeConfig
TerminalEnvVariables *TerminalEnvVariables
GlobalClusterConfig *GlobalClusterConfig
InternalEnvVariables *InternalEnvVariables
}
type DeploymentServiceTypeConfig struct {
ExternallyManagedDeploymentType bool `env:"IS_INTERNAL_USE" envDefault:"false"`
HelmInstallASyncMode bool `env:"RUN_HELM_INSTALL_IN_ASYNC_MODE_HELM_APPS" envDefault:"false"`
UseDeploymentConfigData bool `env:"USE_DEPLOYMENT_CONFIG_DATA" envDefault:"false"`
ShouldCheckNamespaceOnClone bool `env:"SHOULD_CHECK_NAMESPACE_ON_CLONE" envDefault:"false" description:"should we check if namespace exists or not while cloning app" deprecated:"false"`
}
type GlobalEnvVariables struct {
GitOpsRepoPrefix string `env:"GITOPS_REPO_PREFIX" envDefault:""`
EnableAsyncHelmInstallDevtronChart bool `env:"ENABLE_ASYNC_INSTALL_DEVTRON_CHART" envDefault:"false"`
EnableAsyncArgoCdInstallDevtronChart bool `env:"ENABLE_ASYNC_ARGO_CD_INSTALL_DEVTRON_CHART" envDefault:"false"`
ArgoGitCommitRetryCountOnConflict int `env:"ARGO_GIT_COMMIT_RETRY_COUNT_ON_CONFLICT" envDefault:"3"`
ArgoGitCommitRetryDelayOnConflict int `env:"ARGO_GIT_COMMIT_RETRY_DELAY_ON_CONFLICT" envDefault:"1"`
ExposeCiMetrics bool `env:"EXPOSE_CI_METRICS" envDefault:"false"`
ExecuteWireNilChecker bool `env:"EXECUTE_WIRE_NIL_CHECKER" envDefault:"false"`
}
type GlobalClusterConfig struct {
ClusterStatusCronTime int `env:"CLUSTER_STATUS_CRON_TIME" envDefault:"15"`
}
type DevtronSecretConfig struct {
DevtronSecretName string `env:"DEVTRON_SECRET_NAME" envDefault:"devtron-secret"`
DevtronDexSecretNamespace string `env:"DEVTRON_DEX_SECRET_NAMESPACE" envDefault:"devtroncd"`
}
type TerminalEnvVariables struct {
RestrictTerminalAccessForNonSuperUser bool `env:"RESTRICT_TERMINAL_ACCESS_FOR_NON_SUPER_USER" envDefault:"false"`
}
type InternalEnvVariables struct {
// GoRuntimeEnv specifies the runtime environment of the application,
// - enum:
// "development"
// "production"
// - default: "production"
// - use cases: test cases to set the runtime environment
GoRuntimeEnv string `env:"GO_RUNTIME_ENV" envDefault:"production"`
}
func (i *InternalEnvVariables) IsDevelopmentEnv() bool {
if i == nil {
return false
}
return i.GoRuntimeEnv == "development"
}
func (i *InternalEnvVariables) SetDevelopmentEnv() *InternalEnvVariables {
i.GoRuntimeEnv = "development"
return i
}
func GetEnvironmentVariables() (*EnvironmentVariables, error) {
cfg := &EnvironmentVariables{
GlobalEnvVariables: &GlobalEnvVariables{},
DevtronSecretConfig: &DevtronSecretConfig{},
DeploymentServiceTypeConfig: &DeploymentServiceTypeConfig{},
TerminalEnvVariables: &TerminalEnvVariables{},
GlobalClusterConfig: &GlobalClusterConfig{},
InternalEnvVariables: &InternalEnvVariables{},
}
err := env.Parse(cfg)
if err != nil {
return nil, err
}
return cfg, err
}