-
Notifications
You must be signed in to change notification settings - Fork 45
Allow file content that looks like a checksum. #170
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
base: main
Are you sure you want to change the base?
Changes from all commits
5b353b3
742edb3
4d671f4
a9ca544
de06ed3
e28dbd3
bd8d56e
cdca923
d983288
012415d
6a12f6b
968efc8
8639e0f
92621e6
a0c14e8
551a4b5
379b5fd
2654372
2665666
8a2d027
b3d1b7f
03e85d5
c6c40d1
a73dfdc
399816a
16bbe9a
09ede3c
cb04bf3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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 | ||
|
Comment on lines
+154
to
155
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be removed.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be related to above discussion (or I could very well be mistaken about all this :-) ). |
||
| elsif actual_content.nil? | ||
|
Check failure on line 156 in lib/puppet/type/file/content.rb
|
||
| 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 | ||
|
|
||
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 this can be removed.
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 tried without it but got obscure errors. I think the problem was that the checksum mechanism is not only used for the functionality we're trying to remove, but also for other purposes in the file handling code. Probably has to do with filebuckets.
It seems like "value" can legitimately contain a checksum if this attribute ("content") was already set. I'm not sure about this, but as I understand it, since we are in a "munge" block, we're transforming the value of the attribute prior to storing it. In the standard case, when user sets the "content" attribute to something in Puppet code, we store the actual content in
@actual_contentand attribute value holds the checksum.As I recall, when I first removed theses lines, I had loads of errors in filebucket-related code elsewhere because, presumably, other code assumes that file content attribute value is in fact a checksum...
If you think I'm mistaken, I'll try to delete those lines again and see what CI says this time.