Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 13 additions & 21 deletions lib/puppet/type/file/content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,19 @@
if value == :absent
value
elsif value.is_a?(String) && checksum?(value)
# XXX This is potentially dangerous because it means users can't write a file whose
# entire contents are a plain checksum unless it is a Binary content.
Puppet.puppet_deprecation_warning([
# TRANSLATORS "content" is an attribute and should not be translated
_('Using a checksum in a file\'s "content" property is deprecated.'),
# TRANSLATORS "filebucket" is a resource type and should not be translated. The quoted occurrence of "content" is an attribute and should not be translated.
_('The ability to use a checksum to retrieve content from the filebucket using the "content" property will be removed in a future release.'),
# TRANSLATORS "content" is an attribute and should not be translated.
_('The literal value of the "content" property will be written to the file.'),
# TRANSLATORS "static catalogs" should not be translated.
_('The checksum retrieval functionality is being replaced by the use of static catalogs.'),
_('See https://puppet.com/docs/puppet/latest/static_catalogs.html for more information.')
].join(" "),
:file => @resource.file,
:line => @resource.line) if !@actual_content && !resource.parameter(:source)
value
# Our argument looks like a checksum. Is it the value of the content
# attribute in Puppet code, that happens to look like a checksum, or is
# it an actual checksum computed on the actual content?
if @actual_content || resource.parameter(:source)
# Actual content is already set, value contains it's checksum
value
else
# The content only happens to look like a checksum by chance.
@actual_content = value.is_a?(Puppet::Pops::Types::PBinaryType::Binary) ? value.binary_buffer : value
resource.parameter(:checksum).sum(@actual_content)
end
else
# Our argument is definitely not a checksum: set actual_value and return calculated checksum.
@actual_content = value.is_a?(Puppet::Pops::Types::PBinaryType::Binary) ? value.binary_buffer : value
resource.parameter(:checksum).sum(@actual_content)
end
Expand Down Expand Up @@ -155,17 +151,13 @@
def each_chunk_from
if actual_content.is_a?(String)
yield actual_content
elsif content_is_really_a_checksum? && actual_content.nil?
elsif actual_content.nil?
yield read_file_from_filebucket
elsif actual_content.nil?

Check failure on line 156 in lib/puppet/type/file/content.rb

View workflow job for this annotation

GitHub Actions / AIO Package Rake Checks

Lint/DuplicateElsifCondition: Duplicate `elsif` condition detected.

Check failure on line 156 in lib/puppet/type/file/content.rb

View workflow job for this annotation

GitHub Actions / rubocop

Lint/DuplicateElsifCondition: Duplicate `elsif` condition detected.
yield ''
end
end

def content_is_really_a_checksum?
checksum?(should)
end

def read_file_from_filebucket
dipper = resource.bucket
raise "Could not get filebucket from file" unless dipper
Expand Down
14 changes: 0 additions & 14 deletions spec/integration/type/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -640,20 +640,6 @@ def get_aces_for_path_by_sid(path, sid)
it_should_behave_like "files are backed up", {} do
let(:filebucket_digest) { method(:digest) }
end

it "should give a checksum deprecation warning" do
expect(Puppet).to receive(:puppet_deprecation_warning).with('Using a checksum in a file\'s "content" property is deprecated. The ability to use a checksum to retrieve content from the filebucket using the "content" property will be removed in a future release. The literal value of the "content" property will be written to the file. The checksum retrieval functionality is being replaced by the use of static catalogs. See https://puppet.com/docs/puppet/latest/static_catalogs.html for more information.', {:file => 'my/file.pp', :line => 5})
d = digest("this is some content")
catalog.add_resource described_class.new(:path => path, :content => "{#{digest_algorithm}}#{d}")
catalog.apply
end

it "should not give a checksum deprecation warning when no content is specified while checksum and checksum value are used" do
expect(Puppet).not_to receive(:puppet_deprecation_warning)
d = digest("this is some content")
catalog.add_resource described_class.new(:path => path, :checksum => digest_algorithm, :checksum_value => d)
catalog.apply
end
end

CHECKSUM_TYPES_TO_TRY.each do |checksum_type, checksum|
Expand Down
Loading