Skip to content

Commit 4840571

Browse files
authored
Small refactoring of config validation (#20801)
* Small refactoring of config validation * local var that explains an operation
1 parent 4f70c61 commit 4840571

File tree

1 file changed

+7
-13
lines changed
  • datadog_checks_dev/datadog_checks/dev/tooling/commands/validate

1 file changed

+7
-13
lines changed

datadog_checks_dev/datadog_checks/dev/tooling/commands/validate/config.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,14 @@ def config(ctx, check, sync, verbose):
110110
version = get_version_string(check)
111111

112112
spec_file_content = read_file(spec_file_path)
113-
default_temp = validate_default_template(spec_file_content)
114-
spec = ConfigSpec(spec_file_content, source=source, version=version)
115-
spec.load()
116113

117-
if not default_temp:
114+
if not validate_default_template(spec_file_content):
118115
message = "Missing default template in init_config or instances section"
119116
check_display_queue.append(lambda message=message, **kwargs: echo_failure(message, **kwargs))
120117
annotate_error(spec_file_path, message)
121118

119+
spec = ConfigSpec(spec_file_content, source=source, version=version)
120+
spec.load()
122121
if spec.errors:
123122
files_failed[spec_file_path] = True
124123
for error in spec.errors:
@@ -184,19 +183,14 @@ def config(ctx, check, sync, verbose):
184183

185184

186185
def validate_default_template(spec_file):
187-
init_config_default = False
188-
instances_default = False
189186
if 'template: init_config' not in spec_file or 'template: instances' not in spec_file:
190187
# This config spec does not have init_config or instances
191188
return True
192-
193189
for line in spec_file.split('\n'):
194-
if any("init_config/{}".format(template) in line for template in TEMPLATES):
195-
init_config_default = True
196-
if any("instances/{}".format(template) in line for template in TEMPLATES):
197-
instances_default = True
198-
199-
if instances_default and init_config_default:
190+
has_default_templates = any("init_config/{}".format(template) in line for template in TEMPLATES) and any(
191+
"instances/{}".format(template) in line for template in TEMPLATES
192+
)
193+
if has_default_templates:
200194
return True
201195
return False
202196

0 commit comments

Comments
 (0)