Skip to content

Commit c149873

Browse files
committed
Updated to check generic-service exists in default before accessing values
1 parent c17ee33 commit c149873

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

includes/helm.py

+26-25
Original file line numberDiff line numberDiff line change
@@ -122,23 +122,35 @@ def get_info_from_helm(component, repo, services):
122122
log.debug(
123123
f'Container image found in image->repository for {component_name}: {container_image}'
124124
)
125-
if (
126-
container_image := helm_default_values.get('generic-service')
127-
.get('image')
128-
.get('repository')
129-
):
130-
data['container_image'] = container_image
131-
log.debug(
132-
f'Container image found in generic-service->image->repository for {component_name}: {container_image}'
133-
)
125+
if 'generic-service' in helm_default_values:
126+
if 'generic-service' in helm_default_values and (
127+
container_image := helm_default_values.get('generic-service')
128+
.get('image')
129+
.get('repository')
130+
):
131+
data['container_image'] = container_image
132+
log.debug(
133+
f'Container image found in generic-service->image->repository for {component_name}: {container_image}'
134+
)
135+
# Try to get the productID
136+
if helm_product_id := helm_default_values.get('generic-service', {}).get(
137+
'productId', {}
138+
):
139+
data['product'] = sc.get_id('products', 'p_id', helm_product_id)
140+
# Get modsecurity data defaults, if enabled.
141+
for mod_security_type in [
142+
'modsecurity_enabled',
143+
'modsecurity_audit_enabled',
144+
'modsecurity_snippet',
145+
]:
146+
mod_security_defaults[mod_security_type] = (
147+
helm_default_values.get('generic-service', {})
148+
.get('ingress', {})
149+
.get(mod_security_type, None)
150+
)
134151
if not data.get('container_image'):
135152
log.info(f'No container image found for {component_name}')
136153

137-
# Try to get the productID
138-
if helm_product_id := helm_default_values.get('generic-service', {}).get(
139-
'productId', {}
140-
):
141-
data['product'] = sc.get_id('products', 'p_id', helm_product_id)
142154
# If the service catalogue product ID already exists (there is no reason why it shouldn't), use that instead
143155
# TODO: use the product_id from the repository variables?
144156
if (
@@ -149,17 +161,6 @@ def get_info_from_helm(component, repo, services):
149161
):
150162
data['product'] = sc_product_id
151163

152-
# Get modsecurity data defaults, if enabled.
153-
for mod_security_type in [
154-
'modsecurity_enabled',
155-
'modsecurity_audit_enabled',
156-
'modsecurity_snippet',
157-
]:
158-
mod_security_defaults[mod_security_type] = (
159-
helm_default_values.get('generic-service', {})
160-
.get('ingress', {})
161-
.get(mod_security_type, None)
162-
)
163164
alert_severity_label_default = helm_default_values.get(
164165
'generic-prometheus-alerts', {}
165166
).get('alertSeverity', None)

0 commit comments

Comments
 (0)