voxpupuli / puppet-python

Puppet module for installing and managing Python, pip, virtualenvs and Gunicorn virtual hosts.
https://forge.puppetlabs.com/puppet/python
Apache License 2.0
199 stars 370 forks source link

New function: any_puppet_to_python() #616

Closed smortex closed 2 years ago

smortex commented 2 years ago

Pull Request (PR) description

This function return a String representation of the value passed as parameter.

The idea is to provide a helper function usable in epp templates when the configuration files we are managing are Python scripts, e.g. https://github.com/voxpupuli/puppet-puppetboard, https://github.com/opus-codium/puppet-taiga

This Pull Request (PR) fixes the following issues

n/a

Example usage

EMAIL_USE_TLS = <%= String($taiga::back::email_use_tls, '%T') %>
EMAIL_HOST = <%= if $taiga::back::email_host { String($taiga::back::email_host, '%p') } else { 'None' } %>

becomes:

EMAIL_USE_TLS = <%= any_puppet_to_python($taiga::back::email_use_tls) %>
EMAIL_HOST = <%= any_puppet_to_python($taiga::back::email_host) %>
smortex commented 2 years ago

So… Now I see any2array, any2bool, bool2num, bool2str, dos2unix, num2bool, str2bool, str2saltedpbkdf2, str2saltedpbkdf512, unix2dos in the stdlib and wonder if we should not name this function any2python for consistency, i.e. avoid this.

Since this code has not been released yet, it's a good time to fix it IMHO :wink:

https://www.martinfowler.com/bliki/TwoHardThings.html

bastelfreak commented 2 years ago

maybe we should also submit the function to stdlib?

smortex commented 2 years ago

Let's do that! You know what? The stdlib also has to_json and to_yaml :woozy_face: :exploding_head: :boom: