Skip to content

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

Merged
merged 9 commits into from
Mar 25, 2022
Merged

Conversation

jkroepke
Copy link
Contributor

@jkroepke jkroepke commented Jan 23, 2022

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

@jkroepke jkroepke force-pushed the escape branch 7 times, most recently from fdbba7e to f1f0c42 Compare January 23, 2022 17:50
Copy link
Member

@smortex smortex left a 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)
Copy link
Member

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?

Copy link
Contributor Author

@jkroepke jkroepke Jan 23, 2022

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?

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

@jkroepke
Copy link
Contributor Author

Can't we just improve the current systemd::escape function if it's current behavior is wrong?

#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
Copy link
Member

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?

Copy link
Contributor Author

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).

@jkroepke
Copy link
Contributor Author

Whats next here? Planned to merge the PR? Otherwise, I will close the stale PR.

Copy link
Member

@smortex smortex left a 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.

@jkroepke
Copy link
Contributor Author

Rebased. Test reduced. removed robocup comments.

@jkroepke
Copy link
Contributor Author

@smortex Are you fine with the latest changes?

@bastelfreak bastelfreak added the enhancement New feature or request label Mar 25, 2022
@bastelfreak bastelfreak changed the title Proposal: Add function systemd::systemd_escape Add function systemd::systemd_escape Mar 25, 2022
@bastelfreak bastelfreak merged commit 9a845d1 into voxpupuli:master Mar 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

systemd::escape function is does not escape a lot of other characters
4 participants