...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package config
17
18 import (
19 "time"
20
21 "github.com/kelseyhightower/envconfig"
22 "github.com/pkg/errors"
23 )
24
25
26 type ChaosDashboardConfig struct {
27 ListenHost string `envconfig:"LISTEN_HOST" default:"0.0.0.0" json:"listen_host"`
28 ListenPort int `envconfig:"LISTEN_PORT" default:"2333" json:"listen_port"`
29 MetricHost string `envconfig:"METRIC_HOST" default:"0.0.0.0" json:"-"`
30 MetricPort int `envconfig:"METRIC_PORT" default:"2334" json:"-"`
31 EnableLeaderElection bool `envconfig:"ENABLE_LEADER_ELECTION" json:"-"`
32 Database *DatabaseConfig `json:"-"`
33 PersistTTL *TTLConfigWithStringTime `json:"-"`
34
35 ClusterScoped bool `envconfig:"CLUSTER_SCOPED" default:"true" json:"cluster_mode"`
36
37
38 TargetNamespace string `envconfig:"TARGET_NAMESPACE" default:"" json:"target_namespace"`
39
40
41 EnableFilterNamespace bool `envconfig:"ENABLE_FILTER_NAMESPACE" default:"false"`
42
43 SecurityMode bool `envconfig:"SECURITY_MODE" default:"true" json:"security_mode"`
44
45 GcpSecurityMode bool `envconfig:"GCP_SECURITY_MODE" default:"false" json:"gcp_security_mode"`
46 GcpClientId string `envconfig:"GCP_CLIENT_ID" default:"" json:"-"`
47 GcpClientSecret string `envconfig:"GCP_CLIENT_SECRET" default:"" json:"-"`
48
49 RootUrl string `envconfig:"ROOT_URL" default:"http://localhost:2333" json:"root_path"`
50
51
52 EnableProfiling bool `envconfig:"ENABLE_PROFILING" default:"true" json:"-"`
53
54
55 DNSServerCreate bool `envconfig:"DNS_SERVER_CREATE" default:"true" json:"dns_server_create"`
56 Version string `json:"version"`
57
58
59 QPS float32 `envconfig:"QPS" default:"200" json:"-"`
60
61 Burst int `envconfig:"BURST" default:"300" json:"-"`
62 }
63
64
65 type DatabaseConfig struct {
66 Driver string `envconfig:"DATABASE_DRIVER" default:"sqlite3"`
67
68
69
70 Datasource string `envconfig:"DATABASE_DATASOURCE" default:"core.sqlite"`
71 }
72
73
74 type TTLConfig struct {
75
76 ResyncPeriod time.Duration
77
78
79 EventTTL time.Duration
80
81 ExperimentTTL time.Duration
82
83 ScheduleTTL time.Duration
84
85 WorkflowTTL time.Duration
86 }
87
88
89 type TTLConfigWithStringTime struct {
90 ResyncPeriod string `envconfig:"CLEAN_SYNC_PERIOD" default:"12h"`
91
92 EventTTL string `envconfig:"TTL_EVENT" default:"168h"`
93 ExperimentTTL string `envconfig:"TTL_EXPERIMENT" default:"336h"`
94 ScheduleTTL string `envconfig:"TTL_SCHEDULE" default:"336h"`
95 WorkflowTTL string `envconfig:"TTL_WORKFLOW" default:"336h"`
96 }
97
98 func (config *TTLConfigWithStringTime) Parse() (*TTLConfig, error) {
99 syncPeriod, err := time.ParseDuration(config.ResyncPeriod)
100 if err != nil {
101 return nil, errors.Wrap(err, "parse configuration sync period")
102 }
103
104 eventTTL, err := time.ParseDuration(config.EventTTL)
105 if err != nil {
106 return nil, errors.Wrap(err, "parse configuration TTL for event")
107 }
108
109 experimentTTL, err := time.ParseDuration(config.ExperimentTTL)
110 if err != nil {
111 return nil, errors.Wrap(err, "parse configuration TTL for experiment")
112 }
113
114 scheduleTTL, err := time.ParseDuration(config.ScheduleTTL)
115 if err != nil {
116 return nil, errors.Wrap(err, "parse configuration TTL for schedule")
117 }
118
119 workflowTTL, err := time.ParseDuration(config.WorkflowTTL)
120 if err != nil {
121 return nil, errors.Wrap(err, "parse configuration TTL for workflow")
122 }
123
124 return &TTLConfig{
125 ResyncPeriod: syncPeriod,
126 EventTTL: eventTTL,
127 ExperimentTTL: experimentTTL,
128 ScheduleTTL: scheduleTTL,
129 WorkflowTTL: workflowTTL,
130 }, nil
131 }
132
133
134 func GetChaosDashboardEnv() (*ChaosDashboardConfig, error) {
135 cfg := ChaosDashboardConfig{}
136 err := envconfig.Process("", &cfg)
137 return &cfg, err
138 }
139