Skip to content
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

perf(map.jinja): remove inactive formulas & files from dicts before merging #69

Merged
merged 4 commits into from
Oct 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion ssf/map.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,31 @@
{#- Start imports as #}
{%- import_yaml tplroot ~ "/defaults.yaml" as defaults %}
{%- import_yaml tplroot ~ "/formulas.yaml" as formulas %}
{%- set config = salt['config.get'](tplroot, default={}, merge=None) or {} %}

{#- Reduce dict sizes before merging, by removing formulas that aren't active #}
{%- for k, v in defaults[tplroot].semrel_formulas.items() %}
{%- if k not in config.active.semrel_formulas %}
{%- do defaults[tplroot].semrel_formulas.pop(k, None) %}
{%- endif %}
{%- endfor %}
{%- for k, v in formulas[tplroot].semrel_formulas.items() %}
{%- if k not in config.active.semrel_formulas %}
{%- do formulas[tplroot].semrel_formulas.pop(k, None) %}
{%- else %}
{#- Reduce dict sizes further, by removing files that aren't active #}
{%- for f_k, f_v in v.semrel_files.items() %}
{%- if f_k not in config.active.semrel_files %}
{%- do formulas[tplroot].semrel_formulas[k].semrel_files.pop(f_k, None) %}
{%- endif %}
{%- endfor %}
{%- endif %}
{%- endfor %}

{#- Merge the formulas #}
{%- do salt['defaults.merge'](defaults, formulas) %}

{#- Merge the ssf config (e.g. from pillar) #}
{%- set config = salt['config.get'](tplroot, default={}, merge='recurse') or {} %}
{%- do salt['defaults.merge'](defaults[tplroot], config) %}

{#- Prepare the export #}
Expand Down