-
-
Notifications
You must be signed in to change notification settings - Fork 151
Add function systemd::systemd_escape #243
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
Conversation
fdbba7e
to
f1f0c42
Compare
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.
Can't we just improve the current systemd::escape
function if it's current behavior is wrong?
|
||
def exec_systemd(*args) | ||
exec_args = { failonfail: true, combine: false } | ||
escaped = Puppet::Util::Execution.execute(['systemd-escape', args], **exec_args) |
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.
Relying on an external command should be avoided. Can't we just improve the current systemd::escape
function if it's current behavior is wrong?
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.
See and use #242 to dicuss this. From my point of view its not worth to re-implement the complex logic from systemd-escape
. Can you explain, why external commands should be avoided? Is there a documented guideline?
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.
My personal opinion: Calling out to external tools should always be the last option. But Puppet already does that to systemd. Now it would be nice if there would be a systemd API binding for Ruby, but that doesn't really exist and that would require us to install a gem, which also sucks. We can keep the old function as well, so people can choose between using systemd::systemd_escape
vs systemd::escape
. I think that's fine.
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.
so people can choose between
This was my first intension, too. And thats why I decide to use a different name. In combination with Defferred functions, systemd-escape is executed on the agent, not on the master.
I understand, calling an external tool is slow, but the puppet lange does not provide functions to translate characters to hex which is required to improve the existing function.
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.
The hex translation could be handled by another function/it could be rewritten as a Ruby function, but IMO that only makes it more complicated and there is no guarantee that our reimplementation works like the actual systemd-escape. That's why I think having both implementations is fine.
#242 is here to discuss this. This PR is a proposal for one solution. |
# @param path Use path (-p) ornon-path style escaping. | ||
dispatch :escape do | ||
param 'String', :input | ||
optional_param 'Optional[Boolean]', :path |
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.
I think optional booleans are odd. Can't we simply have a boolean with a default false? Or put in a different way: what's the difference here between nil
/ undef
and false
?
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.
I copy this from here https://github.com/puppetlabs/puppetlabs-stdlib/blob/276e7b7cd97580c9c08b264b3727e5902df1f487/lib/puppet/functions/to_json_pretty.rb#L48 where Optional[Boolean]
is defined, but the default value is false
(like line 14 here).
Whats next here? Planned to merge the PR? Otherwise, I will close the stale PR. |
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.
I feel like we would have the same coverage with less tests: since we mock the execution we just want to test if the parameters passed to #execute
are the expected ones.
Co-authored-by: Ewoud Kohl van Wijngaarden <[email protected]>
Rebased. Test reduced. removed robocup comments. |
@smortex Are you fine with the latest changes? |
This PR is a proposal for #242 and its intended to replace the current function
systemd::escape
.Pull Request (PR) description
This PR add a function
systemd::systemd_escape
based on the system call systemd-escape.See #220 and #95
rubocop:disable Style/OptionalBooleanParameter
is required here, otherwise puppet wont detect the optional parameter.This Pull Request (PR) fixes the following issues
Fixes #242