Sha256: 81657b58517fa30f56756a92e3dc09b4a92fc1675a99c23898486f77da782881

Contents?: true

Size: 1.84 KB

Versions: 23

Compression:

Stored size: 1.84 KB

Contents

# Download a specified file into the local filebucket.
Puppet::Face.define(:file, '0.0.1') do
  action :download do |*args|
    summary "Download a file into the local filebucket."
    arguments "( {md5}<checksum> | <puppet_url> )"
    returns "Nothing."
    description <<-EOT
      Downloads a file from the puppet master's filebucket and duplicates it in
      the local filebucket. This action's checksum syntax differs from `find`'s,
      and it can accept a <puppet:///> URL.
    EOT
    examples <<-'EOT'
      Download a file by URL:

      $ puppet file download puppet:///modules/editors/vim/.vimrc

      Download a file by MD5 sum:

      $ puppet file download {md5}8f798d4e754db0ac89186bbaeaf0af18
    EOT

    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

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
supply_drop-0.11.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/face/file/download.rb
supply_drop-0.10.2 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/face/file/download.rb
supply_drop-0.10.1 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/face/file/download.rb
supply_drop-0.10.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/face/file/download.rb
puppet-2.7.17 lib/puppet/face/file/download.rb
puppet-2.7.16 lib/puppet/face/file/download.rb
puppet-2.7.14 lib/puppet/face/file/download.rb
puppet-2.7.13 lib/puppet/face/file/download.rb
supply_drop-0.9.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/face/file/download.rb
supply_drop-0.8.1 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/face/file/download.rb
supply_drop-0.8.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/face/file/download.rb
puppet-2.7.12 lib/puppet/face/file/download.rb
puppet-2.7.11 lib/puppet/face/file/download.rb
supply_drop-0.7.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/face/file/download.rb
supply_drop-0.6.1 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/face/file/download.rb
supply_drop-0.6.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/face/file/download.rb
puppet-2.7.9 lib/puppet/face/file/download.rb
puppet-2.7.8 lib/puppet/face/file/download.rb
puppet-2.7.6 lib/puppet/face/file/download.rb
puppet-2.7.5 lib/puppet/face/file/download.rb