diff options
author | Josh Cooper <joshcooper@users.noreply.github.com> | 2023-11-22 10:54:32 -0800 |
---|---|---|
committer | Josh Cooper <joshcooper@users.noreply.github.com> | 2023-11-22 15:13:28 -0800 |
commit | be5ae9bc9e198a00f2a790992b663dda374006ba (patch) | |
tree | 60eaae0ad250b7e6efd7329873be74dd77813649 /spec/fixtures/unit/provider/cron/filetype | |
parent | 8990735b40f5aa0e95b444aaff8af08feab35968 (diff) | |
download | puppet-cron_core-be5ae9bc9e198a00f2a790992b663dda374006ba.tar.gz puppet-cron_core-be5ae9bc9e198a00f2a790992b663dda374006ba.tar.bz2 |
Convert ProcessOutput to String explicitly
The `filetype` provider executes `crontab` using Puppet's execution API, which
returns ProcessOutput objects that inherit from String. See puppetlabs/puppet@732d450
The provider later uses String#gsub to strip off the HEADER. In Ruby 2.7, the
gsub method returns a new instance of ProcessOutput:
irb(main):002:0> Puppet::Util::Execution::ProcessOutput.new("# HEADER\n0 4 * * * /etc/init.d/script.sh\n", 0).gsub(/# HEADER/, '').class
=> Puppet::Util::Execution::ProcessOutput
If you later serialize the crontab entries to YAML using `puppet resource`, then
puppet warns about serializing unknown data types:
# puppet resource cron --to_yaml
Warning: Cron[unmanaged:/etc/init.d/script.sh-1]['command'] contains a Puppet::Util::Execution::ProcessOutput value. It will be converted to the String '/etc/init.d/script.sh'
This wasn't an issue with Ruby 3.2, because String#gsub always returns a String:
irb(main):002:0> Puppet::Util::Execution::ProcessOutput.new("# HEADER\n0 4 * * * /etc/init.d/script.sh\n", 0).gsub(/# HEADER/, '').class
=> String
This commit explicitly converts the ProcessOutput to a String so the provider
behaves consistently on all Ruby versions.
Fixes #61
Diffstat (limited to 'spec/fixtures/unit/provider/cron/filetype')
-rw-r--r-- | spec/fixtures/unit/provider/cron/filetype/managed_output | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/spec/fixtures/unit/provider/cron/filetype/managed_output b/spec/fixtures/unit/provider/cron/filetype/managed_output new file mode 100644 index 0000000..684eb5f --- /dev/null +++ b/spec/fixtures/unit/provider/cron/filetype/managed_output @@ -0,0 +1,4 @@ +# HEADER: This file was autogenerated at 2023-11-21 12:32:27 -0700 by puppet. +# HEADER: While it can still be managed manually, it is definitely not recommended. +# HEADER: Note particularly that the comments starting with 'Puppet Name' should +# HEADER: not be deleted, as doing so could cause duplicate cron jobs. |