-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tenant_parser.py: add support for extra-config-paths #104
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
- job: | ||
name: awesome-job | ||
description: | | ||
Job in custom directory, without a playbook or parent. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
|
||
import logging | ||
import os | ||
from collections import defaultdict | ||
|
||
import yaml | ||
|
||
|
@@ -62,7 +63,7 @@ def parse(self): | |
self.tenants.append(tenant_name) | ||
|
||
def _update_repo_map(self, project, connection_name, tenant): | ||
project_name, exclude = self._extract_project(project) | ||
project_name, exclude, extra_config_paths = self._extract_project(project) | ||
|
||
# Map the current tenant to the current repository | ||
repo_tenant_entry = self.repo_map.setdefault( | ||
|
@@ -75,14 +76,27 @@ def _update_repo_map(self, project, connection_name, tenant): | |
repo_tenant_entry["tenants"]["jobs"].append(tenant) | ||
repo_tenant_entry["tenants"]["roles"].append(tenant) | ||
|
||
if extra_config_paths: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand this correctly, this whole block is about creating a default empty list and adding the tenant to it. In that case we could simplify this to: if extra_config_paths:
repo_tenant_extra_config_paths = repo_tenant_entry["tenants"].setdefault("extra_config_paths", defaultdict(lambda: []))
repo_tenant_extra_config_paths[extra_config_path].append(tenant) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. applied There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have tested the behavior using following test:
results are OK (repoMap structure is as we would expect it: no 'extra_config_paths' dict in repos without it defined):
|
||
repo_tenant_extra_config_paths = repo_tenant_entry["tenants"].setdefault( | ||
"extra_config_paths", defaultdict(lambda: []) | ||
) | ||
for extra_config_path in extra_config_paths: | ||
repo_tenant_extra_config_paths[extra_config_path].append(tenant) | ||
|
||
def _extract_project(self, project): | ||
project_name = project | ||
exclude = [] | ||
extra_config_paths = [] | ||
if type(project) is dict: | ||
# Get the first key of the dict containing the project name. | ||
project_name = list(project.keys())[0] | ||
exclude = project.get("exclude", []) | ||
return project_name, exclude | ||
exclude = project[project_name].get("exclude", []) | ||
felixedel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# NOTE (swietlicki): directories in extra-config-path section contain | ||
# trailing slash, while inside the Scraper.iterate_directory() the comparison | ||
# is done against dir names without trailing slash | ||
for item in project[project_name].get("extra-config-paths", []): | ||
extra_config_paths.append(item[:-1] if item.endswith("/") else item) | ||
return project_name, exclude, extra_config_paths | ||
|
||
def _load_tenant_sources_from_file(self, sources_file): | ||
LOGGER.info("Parsing tenant sources file '%s'", sources_file) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing that 😉