summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/indirector/key/file.rb4
-rw-r--r--lib/puppet/indirector/ssl_file.rb8
-rwxr-xr-xspec/unit/indirector/key/file.rb4
-rwxr-xr-xspec/unit/indirector/ssl_file.rb4
4 files changed, 11 insertions, 9 deletions
diff --git a/lib/puppet/indirector/key/file.rb b/lib/puppet/indirector/key/file.rb
index 4536f8aa7..a413ccf63 100644
--- a/lib/puppet/indirector/key/file.rb
+++ b/lib/puppet/indirector/key/file.rb
@@ -34,9 +34,9 @@ class Puppet::SSL::Key::File < Puppet::Indirector::SslFile
super
begin
- File.open(public_key_path(request.key), "w") { |f| f.print request.instance.content.public_key.to_pem }
+ Puppet.settings.writesub(:publickeydir, public_key_path(request.key)) { |f| f.print request.instance.content.public_key.to_pem }
rescue => detail
- raise Puppet::Error, "Could not write %s: %s" % [key, detail]
+ raise Puppet::Error, "Could not write %s: %s" % [request.key, detail]
end
end
end
diff --git a/lib/puppet/indirector/ssl_file.rb b/lib/puppet/indirector/ssl_file.rb
index 4119a656f..de7163700 100644
--- a/lib/puppet/indirector/ssl_file.rb
+++ b/lib/puppet/indirector/ssl_file.rb
@@ -156,12 +156,14 @@ class Puppet::Indirector::SslFile < Puppet::Indirector::Terminus
Puppet.settings.write(self.class.ca_setting) { |f| yield f }
elsif file_location
Puppet.settings.write(self.class.file_setting) { |f| yield f }
- else
+ elsif setting = self.class.directory_setting
begin
- File.open(path, "w") { |f| yield f }
+ Puppet.settings.writesub(setting, path) { |f| yield f }
rescue => detail
- raise Puppet::Error, "Could not write %s: %s" % [path, detail]
+ raise Puppet::Error, "Could not write %s to %s: %s" % [path, setting, detail]
end
+ else
+ raise Puppet::DevError, "You must provide a setting to determine where the files are stored"
end
end
end
diff --git a/spec/unit/indirector/key/file.rb b/spec/unit/indirector/key/file.rb
index 8a1cb04bd..f365bfd60 100755
--- a/spec/unit/indirector/key/file.rb
+++ b/spec/unit/indirector/key/file.rb
@@ -70,11 +70,11 @@ describe Puppet::SSL::Key::File do
end
it "should save the public key when saving the private key" do
- File.stubs(:open).with(@private_key_path, "w")
+ Puppet.settings.stubs(:writesub)
fh = mock 'filehandle'
- File.expects(:open).with(@public_key_path, "w").yields fh
+ Puppet.settings.expects(:writesub).with(:publickeydir, @public_key_path).yields fh
@public_key.expects(:to_pem).returns "my pem"
fh.expects(:print).with "my pem"
diff --git a/spec/unit/indirector/ssl_file.rb b/spec/unit/indirector/ssl_file.rb
index 89f682f38..559e2f98d 100755
--- a/spec/unit/indirector/ssl_file.rb
+++ b/spec/unit/indirector/ssl_file.rb
@@ -173,11 +173,11 @@ describe Puppet::Indirector::SslFile do
end
describe "and a directory setting is set" do
- it "should open the file in write mode" do
+ it "should use the Settings class to write the file" do
@searcher.class.store_in @setting
fh = mock 'filehandle'
fh.stubs :print
- File.expects(:open).with(@certpath, "w").yields(fh)
+ Puppet.settings.expects(:writesub).with(@setting, @certpath).yields fh
@searcher.save(@request)
end