Sha256: 7b1d8645dc46956121a02cc4ecd118357edbcde3fe9b38dc07c2d503b4afe7c6

Contents?: true

Size: 1.84 KB

Versions: 78

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.head(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

78 entries across 78 versions & 3 rubygems

Version Path
puppet-parse-0.1.4 lib/vendor/puppet/face/file/download.rb
puppet-parse-0.1.3 lib/vendor/puppet/face/file/download.rb
puppet-parse-0.1.2 lib/vendor/puppet/face/file/download.rb
puppet-parse-0.1.1 lib/vendor/puppet/face/file/download.rb
puppet-2.7.26 lib/puppet/face/file/download.rb
puppet-3.6.2 lib/puppet/face/file/download.rb
puppet-3.6.2-x86-mingw32 lib/puppet/face/file/download.rb
puppet-3.6.1 lib/puppet/face/file/download.rb
puppet-3.6.1-x86-mingw32 lib/puppet/face/file/download.rb
puppet-3.6.0 lib/puppet/face/file/download.rb
puppet-3.6.0-x86-mingw32 lib/puppet/face/file/download.rb
puppet-3.6.0.rc1 lib/puppet/face/file/download.rb
puppet-3.6.0.rc1-x86-mingw32 lib/puppet/face/file/download.rb
puppet-3.5.1 lib/puppet/face/file/download.rb
puppet-3.5.1-x86-mingw32 lib/puppet/face/file/download.rb
puppet-3.5.1.rc1 lib/puppet/face/file/download.rb
puppet-3.5.1.rc1-x86-mingw32 lib/puppet/face/file/download.rb
puppet-3.5.0.rc3 lib/puppet/face/file/download.rb
puppet-3.5.0.rc3-x86-mingw32 lib/puppet/face/file/download.rb
puppet-3.5.0.rc2 lib/puppet/face/file/download.rb