Skip to content

Commit f37c17d

Browse files
committed
allow optional parameters in config
1 parent 62d9562 commit f37c17d

2 files changed

Lines changed: 44 additions & 21 deletions

File tree

containers/aggregator-server/main.go

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,50 +34,61 @@ func main() {
3434

3535
// Read Network configuration from environment variables
3636
externalBase := strings.TrimSpace(os.Getenv("AGGREGATOR_EXTERNAL_HOST"))
37+
model.ClientId = strings.TrimSpace(os.Getenv("CLIENT_ID"))
38+
model.ClientSecret = strings.TrimSpace(os.Getenv("CLIENT_SECRET"))
39+
40+
missingRequired := make([]string, 0, 3)
3741
if externalBase == "" {
38-
logrus.Fatal("Environment variables AGGREGATOR_EXTERNAL_HOST must be set")
42+
missingRequired = append(missingRequired, "AGGREGATOR_EXTERNAL_HOST")
43+
}
44+
if model.ClientId == "" {
45+
missingRequired = append(missingRequired, "CLIENT_ID")
3946
}
47+
if model.ClientSecret == "" {
48+
missingRequired = append(missingRequired, "CLIENT_SECRET")
49+
}
50+
if len(missingRequired) > 0 {
51+
logrus.Fatalf("Missing required environment variables: %s", strings.Join(missingRequired, ", "))
52+
}
53+
4054
model.Protocol = "http"
4155
model.ExternalHost = externalBase
4256
if parsed, err := url.Parse(externalBase); err == nil && parsed.Scheme != "" {
4357
model.Protocol = strings.ToLower(parsed.Scheme)
4458
model.ExternalHost = parsed.Host
4559
}
4660

47-
// Read Authorization configuration from environment variables
48-
model.ClientId = os.Getenv("CLIENT_ID")
49-
if model.ClientId == "" {
50-
logrus.Fatal("Environment variable CLIENT_ID must be set")
51-
}
52-
model.ClientSecret = os.Getenv("CLIENT_SECRET")
53-
if model.ClientSecret == "" {
54-
logrus.Fatal("Environment variable CLIENT_SECRET must be set")
55-
}
56-
57-
model.ProvisionClientID = os.Getenv("PROVISION_CLIENT_ID")
58-
model.ProvisionClientSecret = os.Getenv("PROVISION_CLIENT_SECRET")
59-
model.ProvisionWebID = os.Getenv("PROVISION_WEBID")
60-
model.ProvisionIDP = os.Getenv("PROVISION_IDP")
61-
model.ProvisionAuthorizationServer = os.Getenv("PROVISION_AUTHORIZATION_SERVER")
61+
model.ProvisionClientID = strings.TrimSpace(os.Getenv("PROVISION_CLIENT_ID"))
62+
model.ProvisionClientSecret = strings.TrimSpace(os.Getenv("PROVISION_CLIENT_SECRET"))
63+
model.ProvisionWebID = strings.TrimSpace(os.Getenv("PROVISION_WEBID"))
64+
model.ProvisionIDP = strings.TrimSpace(os.Getenv("PROVISION_IDP"))
65+
model.ProvisionAuthorizationServer = strings.TrimSpace(os.Getenv("PROVISION_AUTHORIZATION_SERVER"))
6266
model.IDPServerType = strings.ToLower(strings.TrimSpace(os.Getenv("IDP_SERVER_TYPE")))
6367

6468
allowedTypes := parseAllowedRegistrationTypes(os.Getenv("ALLOWED_REGISTRATION_TYPES"))
6569
model.AllowedRegistrationTypes = allowedTypes
6670
if hasRegistrationType(allowedTypes, "provision") {
71+
missingProvision := make([]string, 0, 5)
6772
if model.ProvisionClientID == "" {
68-
logrus.Fatal("Environment variable PROVISION_CLIENT_ID must be set when provision registration is allowed")
73+
missingProvision = append(missingProvision, "PROVISION_CLIENT_ID")
6974
}
7075
if model.ProvisionClientSecret == "" {
71-
logrus.Fatal("Environment variable PROVISION_CLIENT_SECRET must be set when provision registration is allowed")
76+
missingProvision = append(missingProvision, "PROVISION_CLIENT_SECRET")
7277
}
7378
if model.ProvisionWebID == "" {
74-
logrus.Fatal("Environment variable PROVISION_WEBID must be set when provision registration is allowed")
79+
missingProvision = append(missingProvision, "PROVISION_WEBID")
7580
}
7681
if model.ProvisionIDP == "" {
77-
logrus.Fatal("Environment variable PROVISION_IDP must be set when provision registration is allowed")
82+
missingProvision = append(missingProvision, "PROVISION_IDP")
7883
}
7984
if model.ProvisionAuthorizationServer == "" {
80-
logrus.Fatal("Environment variable PROVISION_AUTHORIZATION_SERVER must be set when provision registration is allowed")
85+
missingProvision = append(missingProvision, "PROVISION_AUTHORIZATION_SERVER")
86+
}
87+
if len(missingProvision) > 0 {
88+
logrus.Fatalf(
89+
"Missing required provisioning environment variables (ALLOWED_REGISTRATION_TYPES includes provision): %s",
90+
strings.Join(missingProvision, ", "),
91+
)
8192
}
8293
}
8394

k8s/app/aggregator.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,61 +91,73 @@ spec:
9191
configMapKeyRef:
9292
name: aggregator-config
9393
key: log_level
94+
optional: true
9495
- name: DISABLE_AUTH
9596
valueFrom:
9697
configMapKeyRef:
9798
name: aggregator-config
9899
key: disable_auth
100+
optional: true
99101
- name: CLIENT_ID
100102
valueFrom:
101103
configMapKeyRef:
102104
name: aggregator-config
103105
key: client_id
106+
optional: true
104107
- name: CLIENT_SECRET
105108
valueFrom:
106109
configMapKeyRef:
107110
name: aggregator-config
108111
key: client_secret
112+
optional: true
109113
- name: AGGREGATOR_EXTERNAL_HOST
110114
valueFrom:
111115
configMapKeyRef:
112116
name: aggregator-config
113117
key: external_host
118+
optional: true
114119
- name: ALLOWED_REGISTRATION_TYPES
115120
valueFrom:
116121
configMapKeyRef:
117122
name: aggregator-config
118123
key: allowed_registration_types
124+
optional: true
119125
- name: PROVISION_CLIENT_ID
120126
valueFrom:
121127
configMapKeyRef:
122128
name: aggregator-config
123129
key: provision_client_id
130+
optional: true
124131
- name: PROVISION_CLIENT_SECRET
125132
valueFrom:
126133
configMapKeyRef:
127134
name: aggregator-config
128135
key: provision_client_secret
136+
optional: true
129137
- name: PROVISION_WEBID
130138
valueFrom:
131139
configMapKeyRef:
132140
name: aggregator-config
133141
key: provision_webid
142+
optional: true
134143
- name: PROVISION_IDP
135144
valueFrom:
136145
configMapKeyRef:
137146
name: aggregator-config
138147
key: provision_idp
148+
optional: true
139149
- name: IDP_SERVER_TYPE
140150
valueFrom:
141151
configMapKeyRef:
142152
name: aggregator-config
143153
key: idp_server_type
154+
optional: true
144155
- name: PROVISION_AUTHORIZATION_SERVER
145156
valueFrom:
146157
configMapKeyRef:
147158
name: aggregator-config
148159
key: provision_authorization_server
160+
optional: true
149161
---
150162
# ========================
151163
# 5 Service: expose aggregator

0 commit comments

Comments
 (0)