saltstack-formulas / postgres-formula

http://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html
Other
77 stars 283 forks source link

fix(macros): fix `format_kwargs` macro #296

Closed sticky-note closed 4 years ago

sticky-note commented 4 years ago

PR progress checklist (to be filled in by reviewers)


What type of PR is this?

Primary type

Secondary type

Does this PR introduce a BREAKING CHANGE?

No.

Related issues and/or pull requests

Quote kwargs values on format_kwargs macro to resolve sls rendering failure on special characters :

    Data failed to compile:
----------
    Rendering SLS 'base:postgres.manage' failed: found character '%' that cannot start any token; line 17
---
[...]
  postgres_user.present:
    - createdb: False
    - createroles: False
    - inherit: True
    - name: username
    - password: %0q`]O/)/d|v(Sj3-JR$HK8;    <======================
    - replication: False
    - user: postgres
    - onchanges:
      - test: postgres-reload-modules

[...]
---
ERROR: Minions returned with non-zero exit code

Describe the changes you're proposing

Pillar / config required to test the proposed changes

Debug log showing how the proposed changes work

Documentation checklist

Testing checklist

Additional context

myii commented 4 years ago

@sticky-note Thanks for the PR. Just tracking back through the use of format_kwargs:

https://github.com/saltstack-formulas/postgres-formula/blob/3df38b1be2aa6181d1ed6158c93cb8a006454209/postgres/upstream.sls#L22-L23

https://github.com/saltstack-formulas/postgres-formula/blob/fbd8f65561a9078b39e74e0ba40c82e93a6ee871/postgres/macros.jinja#L13-L32

https://github.com/saltstack-formulas/postgres-formula/blob/cd6eb0be1669f6a370d1314238fbe7f6bfa3e2d4/postgres/manage.sls#L26-L30

https://github.com/saltstack-formulas/postgres-formula/blob/35850da22cb4f61144a61098b9869603b6e0a682/pillar.example#L135-L150


@vutny Can I get your opinion about this?

sticky-note commented 4 years ago

@Myii hmmmm, you're right. Non-empty strings are evaluated as true. Is there a way to test the type of a value ?

sticky-note commented 4 years ago

Tested a salt-call state.show_sls postgres on this pillar:

postgres:
  users:
    test_dba:
      ensure: present
      password: '%=Hec$K8;'
      createdb: false
      createroles: false
      inherit: true
      replication: false

It seems that boolean strings are correctly computed in Booleans :

(...)
    postgres_user-test_dba:
        ----------
        __env__:
            base
        __sls__:
            postgres.manage
        postgres_user:
            |_
              ----------
              createdb:
                  False
            |_
              ----------
              createroles:
                  False
            |_
              ----------
              inherit:
                  True
            |_
              ----------
              name:
                  test_dba
            |_
              ----------
              password:
                  %=Hec$K8;
            |_
              ----------
              replication:
                  False
            |_
              ----------
              user:
                  postgres
            |_
              ----------
              onchanges:
                  |_
                    ----------
                    test:
                        postgres-reload-modules
            - present
            |_
              ----------
              order:
                  10011
(...)

I think it's because format_kwargs is never called directly but not sure at all

pull-assistant[bot] commented 4 years ago
Score: 1.00

Best reviewed: commit by commit


Optimal code review plan

     fix(macros): fix `format_kwargs` macro

Powered by Pull Assistant. Last update 5e6511b ... 5e6511b. Read the comment docs.

sticky-note commented 4 years ago

@myii @vutny Is that better like that ?

sticky-note commented 4 years ago

What about this PR @vutny @myii ? :)

myii commented 4 years ago

@sticky-note Did you test this out first?

sticky-note commented 4 years ago

@myii | quote doesn't work with : in strings for example. | yaml_dquote has better escaping power and encapsulate into " like I wanted

myii commented 4 years ago

Merged, thanks @sticky-note -- apologies for the delay.

sticky-note commented 4 years ago

@myii No problem, I didn't have so much time too ;)

saltstack-formulas-travis commented 4 years ago

:tada: This PR is included in version 0.41.2 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: