From: Luke Kanies <[email protected]> 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 <[email protected]> --- lib/puppet/face/file/download.rb | 36 ++++++++++++++++++++++++++ lib/puppet/face/file/store.rb | 12 ++++++++ spec/shared_behaviours/an_indirector_face.rb | 6 ++++ spec/unit/face/file_spec.rb | 7 ++++- 4 files changed, 60 insertions(+), 1 deletions(-) create mode 100644 lib/puppet/face/file/download.rb create mode 100644 lib/puppet/face/file/store.rb create mode 100644 spec/shared_behaviours/an_indirector_face.rb diff --git a/lib/puppet/face/file/download.rb b/lib/puppet/face/file/download.rb new file mode 100644 index 0000000..f5413d4 --- /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 0000000..4c9523b --- /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 diff --git a/spec/shared_behaviours/an_indirector_face.rb b/spec/shared_behaviours/an_indirector_face.rb new file mode 100644 index 0000000..cba74b6 --- /dev/null +++ b/spec/shared_behaviours/an_indirector_face.rb @@ -0,0 +1,6 @@ +shared_examples_for "an indirector face" do + [:find, :search, :save, :destroy, :info].each do |action| + it { should be_action action } + it { should respond_to action } + end +end diff --git a/spec/unit/face/file_spec.rb b/spec/unit/face/file_spec.rb index a362923..c3f0572 100755 --- a/spec/unit/face/file_spec.rb +++ b/spec/unit/face/file_spec.rb @@ -3,5 +3,10 @@ require 'spec_helper' require 'puppet/face' describe Puppet::Face[:file, '0.0.1'] do - it "should actually have some tests..." + it_should_behave_like "an indirector face" + + [:download, :store].each do |action| + it { should be_action action } + it { should respond_to action } + end end -- 1.7.5 -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
