summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorLuke Kanies <luke@puppetlabs.com>2011-04-28 00:44:43 +0200
committerDaniel Pittman <daniel@puppetlabs.com>2011-05-03 12:16:50 -0700
commit45adc1a1e482be74d2db9f97e7a4d3be5834ccf2 (patch)
treee99c719a2c1db42c409282a7e21aab04684f7006 /lib/puppet
parentd4df6cc2274e119fb2a67bca0912667b0fef7866 (diff)
downloadpuppet-45adc1a1e482be74d2db9f97e7a4d3be5834ccf2.tar.gz
puppet-45adc1a1e482be74d2db9f97e7a4d3be5834ccf2.tar.xz
puppet-45adc1a1e482be74d2db9f97e7a4d3be5834ccf2.zip
(#7279) Adding some basic file actions
Add the ability to download a file into the local filebucket using a puppet URI or from disk. Also, the ability to store into the filebucket. These provide at least basic UI for moving data around using the filebucket service, and act as an example of how further work can be done. Also, update the code to eliminate a couple of redundant checks on arguments, and add some basic testing around the actions. Mostly only that they exist, at this point. Reviewed-By: Daniel Pittman <daniel@puppetlabs.com>
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/face/file/download.rb36
-rw-r--r--lib/puppet/face/file/store.rb12
2 files changed, 48 insertions, 0 deletions
diff --git a/lib/puppet/face/file/download.rb b/lib/puppet/face/file/download.rb
new file mode 100644
index 000000000..f5413d493
--- /dev/null
+++ b/lib/puppet/face/file/download.rb
@@ -0,0 +1,36 @@
+# Download a specified file into the local filebucket.
+Puppet::Face.define(:file, '0.0.1') do
+ action :download do |*args|
+ when_invoked do |sum, options|
+ if sum =~ /^puppet:\/\// # it's a puppet url
+ require 'puppet/file_serving'
+ require 'puppet/file_serving/content'
+ raise "Could not find metadata for #{sum}" unless content = Puppet::FileServing::Content.indirection.find(sum)
+ file = Puppet::FileBucket::File.new(content.content)
+ else
+ tester = Object.new
+ tester.extend(Puppet::Util::Checksums)
+
+ type = tester.sumtype(sum)
+ sumdata = tester.sumdata(sum)
+
+ key = "#{type}/#{sumdata}"
+
+ Puppet::FileBucket::File.indirection.terminus_class = :file
+ if Puppet::FileBucket::File.indirection.find(key)
+ Puppet.info "Content for '#{sum}' already exists"
+ return
+ end
+
+ Puppet::FileBucket::File.indirection.terminus_class = :rest
+ raise "Could not download content for '#{sum}'" unless file = Puppet::FileBucket::File.indirection.find(key)
+ end
+
+
+ Puppet::FileBucket::File.indirection.terminus_class = :file
+ Puppet.notice "Saved #{sum} to filebucket"
+ Puppet::FileBucket::File.indirection.save file
+ return nil
+ end
+ end
+end
diff --git a/lib/puppet/face/file/store.rb b/lib/puppet/face/file/store.rb
new file mode 100644
index 000000000..4c9523b6c
--- /dev/null
+++ b/lib/puppet/face/file/store.rb
@@ -0,0 +1,12 @@
+# Store a specified file in our filebucket.
+Puppet::Face.define(:file, '0.0.1') do
+ action :store do |*args|
+ when_invoked do |path, options|
+ file = Puppet::FileBucket::File.new(File.read(path))
+
+ Puppet::FileBucket::File.indirection.terminus_class = :file
+ Puppet::FileBucket::File.indirection.save file
+ file.checksum
+ end
+ end
+end