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

fix(libmatchers): respect custom delimiter in yaml lookups #267

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
45 changes: 28 additions & 17 deletions TEMPLATE/libmatchers.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -161,28 +161,39 @@
) %}
{%- endif %}

{#- Add `merge:` option to `salt["config.get"]` if configured #}
{%- if cli not in ["ssh", "unknown"] and parsed.query_method == "config.get" and config_get_strategy %}
{%- set query_opts = {
"merge": config_get_strategy,
"delimiter": parsed.query_delimiter,
} %}
{#- Defaults for query #}
{%- set query_opts = {
"delimiter": parsed.query_delimiter,
} %}
{%- set query_opts_msg = (
", delimiter='"
~ parsed.query_delimiter
~ "'"
) %}

{#- Add `merge:` option to `salt["config.get"]` if config_get_strategy is provided #}
{%- if parsed.query_method == "config.get" and config_get_strategy %}
{%- do query_opts.update(
{
"merge": config_get_strategy
}
) %}
{%- set query_opts_msg = (
", delimiter='"
~ parsed.query_delimiter
query_opts_msg
~ "', merge: strategy='"
~ config_get_strategy
~ "'"
) %}
{%- else %}
{%- if cli in ["ssh", "unknown"] %}
{%- do salt["log.warning"](
log_prefix
~ "the 'delimiter' and 'merge' options of 'config.get' are skipped when the salt command type is '"
~ cli
~ "'"
) %}
{%- endif %}
{%- endif %}

{#- Reset 'query_opts' and 'query_opts_msg' if 'cli' is 'ssh' or 'unknown' #}
{%- if cli in ["ssh", "unknown"] %}
{%- do salt["log.warning"](
log_prefix
~ "the 'delimiter' and 'merge' options of 'config.get' are skipped when the salt command type is '"
~ cli
~ "'"
) %}
{%- set query_opts = {} %}
{%- set query_opts_msg = "" %}
{%- endif %}
Expand Down
2 changes: 2 additions & 0 deletions bin/convert-formula.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ convert_formula() {

git mv TEMPLATE "$NEW_NAME"

git mv test/salt/states/TEMPLATE "test/salt/states/$NEW_NAME"

# Replace TEMPLATE within sls and jinja files with py-safe formula name
# due to python limitations on identifier names (no hyphen)
# including when specifying jinja context variables
Expand Down
5 changes: 5 additions & 0 deletions kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ provisioner:
- .git
pillars_from_directories:
- test/salt/pillar
dependencies:
- name: parameters
path: ./test/salt/states
- name: TEMPLATE
path: ./test/salt/states

platforms:
## SALT `tiamat`
Expand Down
3 changes: 3 additions & 0 deletions test/integration/default/files/_mapdata/almalinux-8.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ values:
- C@TEMPLATE:lookup
- C@TEMPLATE
- Y:G@id
- Y:I:!@nested!pillar
master: template-master
nested:
added_in_value: yaml
pkg:
name: bash
rootgroup: root
Expand Down
3 changes: 3 additions & 0 deletions test/integration/default/files/_mapdata/amazonlinux-1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ values:
- C@TEMPLATE:lookup
- C@TEMPLATE
- Y:G@id
- Y:I:!@nested!pillar
master: template-master
nested:
added_in_value: yaml
pkg:
name: cronie
rootgroup: root
Expand Down
3 changes: 3 additions & 0 deletions test/integration/default/files/_mapdata/amazonlinux-2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ values:
- C@TEMPLATE:lookup
- C@TEMPLATE
- Y:G@id
- Y:I:!@nested!pillar
master: template-master
nested:
added_in_value: yaml
pkg:
name: bash
rootgroup: root
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ values:
- C@TEMPLATE:lookup
- C@TEMPLATE
- Y:G@id
- Y:I:!@nested!pillar
master: template-master
nested:
added_in_value: yaml
pkg:
name: bash
rootgroup: root
Expand Down
3 changes: 3 additions & 0 deletions test/integration/default/files/_mapdata/centos-6.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ values:
- C@TEMPLATE:lookup
- C@TEMPLATE
- Y:G@id
- Y:I:!@nested!pillar
master: template-master
nested:
added_in_value: yaml
pkg:
name: cronie
rootgroup: root
Expand Down
3 changes: 3 additions & 0 deletions test/integration/default/files/_mapdata/centos-7.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ values:
- C@TEMPLATE:lookup
- C@TEMPLATE
- Y:G@id
- Y:I:!@nested!pillar
master: template-master
nested:
added_in_value: yaml
pkg:
name: bash
rootgroup: root
Expand Down
3 changes: 3 additions & 0 deletions test/integration/default/files/_mapdata/centos-8.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ values:
- C@TEMPLATE:lookup
- C@TEMPLATE
- Y:G@id
- Y:I:!@nested!pillar
master: template-master
nested:
added_in_value: yaml
pkg:
name: bash
rootgroup: root
Expand Down
3 changes: 3 additions & 0 deletions test/integration/default/files/_mapdata/debian-10.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ values:
- C@TEMPLATE:lookup
- C@TEMPLATE
- Y:G@id
- Y:I:!@nested!pillar
master: template-master
nested:
added_in_value: yaml
pkg:
name: bash
rootgroup: root
Expand Down
3 changes: 3 additions & 0 deletions test/integration/default/files/_mapdata/debian-11.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ values:
- C@TEMPLATE:lookup
- C@TEMPLATE
- Y:G@id
- Y:I:!@nested!pillar
master: template-master
nested:
added_in_value: yaml
pkg:
name: bash
rootgroup: root
Expand Down
3 changes: 3 additions & 0 deletions test/integration/default/files/_mapdata/debian-9.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ values:
- C@TEMPLATE:lookup
- C@TEMPLATE
- Y:G@id
- Y:I:!@nested!pillar
master: template-master
nested:
added_in_value: yaml
pkg:
name: bash
rootgroup: root
Expand Down
3 changes: 3 additions & 0 deletions test/integration/default/files/_mapdata/fedora-31.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ values:
- C@TEMPLATE:lookup
- C@TEMPLATE
- Y:G@id
- Y:I:!@nested!pillar
master: template-master
nested:
added_in_value: yaml
pkg:
name: bash
rootgroup: root
Expand Down
3 changes: 3 additions & 0 deletions test/integration/default/files/_mapdata/fedora-32.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ values:
- C@TEMPLATE:lookup
- C@TEMPLATE
- Y:G@id
- Y:I:!@nested!pillar
master: template-master
nested:
added_in_value: yaml
pkg:
name: bash
rootgroup: root
Expand Down
3 changes: 3 additions & 0 deletions test/integration/default/files/_mapdata/fedora-33.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ values:
- C@TEMPLATE:lookup
- C@TEMPLATE
- Y:G@id
- Y:I:!@nested!pillar
master: template-master
nested:
added_in_value: yaml
pkg:
name: bash
rootgroup: root
Expand Down
3 changes: 3 additions & 0 deletions test/integration/default/files/_mapdata/fedora-34.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ values:
- C@TEMPLATE:lookup
- C@TEMPLATE
- Y:G@id
- Y:I:!@nested!pillar
master: template-master
nested:
added_in_value: yaml
pkg:
name: bash
rootgroup: root
Expand Down
3 changes: 3 additions & 0 deletions test/integration/default/files/_mapdata/fedora-35.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ values:
- C@TEMPLATE:lookup
- C@TEMPLATE
- Y:G@id
- Y:I:!@nested!pillar
master: template-master
nested:
added_in_value: yaml
pkg:
name: bash
rootgroup: root
Expand Down
3 changes: 3 additions & 0 deletions test/integration/default/files/_mapdata/fedora-36.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ values:
- C@TEMPLATE:lookup
- C@TEMPLATE
- Y:G@id
- Y:I:!@nested!pillar
master: template-master
nested:
added_in_value: yaml
pkg:
name: bash
rootgroup: root
Expand Down
3 changes: 3 additions & 0 deletions test/integration/default/files/_mapdata/gentoo-2-sysd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ values:
- C@TEMPLATE:lookup
- C@TEMPLATE
- Y:G@id
- Y:I:!@nested!pillar
master: template-master
nested:
added_in_value: yaml
pkg:
name: app-shells/bash
rootgroup: root
Expand Down
3 changes: 3 additions & 0 deletions test/integration/default/files/_mapdata/gentoo-2-sysv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ values:
- C@TEMPLATE:lookup
- C@TEMPLATE
- Y:G@id
- Y:I:!@nested!pillar
master: template-master
nested:
added_in_value: yaml
pkg:
name: app-shells/bash
rootgroup: root
Expand Down
3 changes: 3 additions & 0 deletions test/integration/default/files/_mapdata/opensuse-15.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ values:
- C@TEMPLATE:lookup
- C@TEMPLATE
- Y:G@id
- Y:I:!@nested!pillar
master: template-master
nested:
added_in_value: yaml
pkg:
name: bash
rootgroup: root
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ values:
- C@TEMPLATE:lookup
- C@TEMPLATE
- Y:G@id
- Y:I:!@nested!pillar
master: template-master
nested:
added_in_value: yaml
pkg:
name: bash
rootgroup: root
Expand Down
3 changes: 3 additions & 0 deletions test/integration/default/files/_mapdata/oraclelinux-7.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ values:
- C@TEMPLATE:lookup
- C@TEMPLATE
- Y:G@id
- Y:I:!@nested!pillar
master: template-master
nested:
added_in_value: yaml
pkg:
name: bash
rootgroup: root
Expand Down
3 changes: 3 additions & 0 deletions test/integration/default/files/_mapdata/oraclelinux-8.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ values:
- C@TEMPLATE:lookup
- C@TEMPLATE
- Y:G@id
- Y:I:!@nested!pillar
master: template-master
nested:
added_in_value: yaml
pkg:
name: bash
rootgroup: root
Expand Down
3 changes: 3 additions & 0 deletions test/integration/default/files/_mapdata/rockylinux-8.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ values:
- C@TEMPLATE:lookup
- C@TEMPLATE
- Y:G@id
- Y:I:!@nested!pillar
master: template-master
nested:
added_in_value: yaml
pkg:
name: bash
rootgroup: root
Expand Down
3 changes: 3 additions & 0 deletions test/integration/default/files/_mapdata/ubuntu-16.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ values:
- C@TEMPLATE:lookup
- C@TEMPLATE
- Y:G@id
- Y:I:!@nested!pillar
master: template-master
nested:
added_in_value: yaml
pkg:
name: bash
rootgroup: root
Expand Down
3 changes: 3 additions & 0 deletions test/integration/default/files/_mapdata/ubuntu-18.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ values:
- C@TEMPLATE:lookup
- C@TEMPLATE
- Y:G@id
- Y:I:!@nested!pillar
master: template-master
nested:
added_in_value: yaml
pkg:
name: bash
rootgroup: root
Expand Down
3 changes: 3 additions & 0 deletions test/integration/default/files/_mapdata/ubuntu-20.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ values:
- C@TEMPLATE:lookup
- C@TEMPLATE
- Y:G@id
- Y:I:!@nested!pillar
master: template-master
nested:
added_in_value: yaml
pkg:
name: bash
rootgroup: root
Expand Down
3 changes: 3 additions & 0 deletions test/integration/default/files/_mapdata/ubuntu-22.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ values:
- C@TEMPLATE:lookup
- C@TEMPLATE
- Y:G@id
- Y:I:!@nested!pillar
master: template-master
nested:
added_in_value: yaml
pkg:
name: bash
rootgroup: root
Expand Down
4 changes: 4 additions & 0 deletions test/salt/pillar/default.sls
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ TEMPLATE:
# Just for testing purposes
winner: pillar
added_in_pillar: pillar_value
nested:
added_in_value: pillar
nested:
pillar: nested_pillar_value
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
#
# Used to test custom delimiters
---
values:
nested:
added_in_value: yaml
...
Loading