Skip to content
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

Fix race condition by memoizing Tempfile objects #461

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
35 changes: 21 additions & 14 deletions lib/puppet/provider/java_ks/keytool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,17 @@ def certificate
# When no certificate file is specified, we infer the usage of
# certificate content and create a tempfile containing this value.
# we leave it to to the tempfile to clean it up after the pupet run exists.
file = Tempfile.new('certificate')
# Check if the specified value is a Sensitive data type. If so, unwrap it and use
# the value.
content = @resource[:certificate_content].respond_to?(:unwrap) ? @resource[:certificate_content].unwrap : @resource[:certificate_content]
file.write(content)
file.close
file.path
@temp_certificate_file ||= begin
file = Tempfile.new('certificate')
# Check if the specified value is a Sensitive data type. If so, unwrap it and use
# the value.
content = @resource[:certificate_content].respond_to?(:unwrap) ? @resource[:certificate_content].unwrap : @resource[:certificate_content]
file.write(content)
file.close
file
end

@temp_certificate_file.path
end

def private_key
Expand All @@ -300,13 +304,16 @@ def private_key
# When no private key file is specified, we infer the usage of
# private key content and create a tempfile containing this value.
# we leave it to to the tempfile to clean it up after the pupet run exists.
file = Tempfile.new('private_key')
# Check if the specified value is a Sensitive data type. If so, unwrap it and use
# the value.
content = @resource[:private_key_content].respond_to?(:unwrap) ? @resource[:private_key_content].unwrap : @resource[:private_key_content]
file.write(content)
file.close
file.path
@temp_private_key_file ||= begin
file = Tempfile.new('private_key')
# Check if the specified value is a Sensitive data type. If so, unwrap it and use
# the value.
content = @resource[:private_key_content].respond_to?(:unwrap) ? @resource[:private_key_content].unwrap : @resource[:private_key_content]
file.write(content)
file.close
file
end
@temp_private_key_file.path
end

def private_key_type
Expand Down
Loading