Sha256: f0004e344d8de37c5c08018f4756c2e2c02e4b91a173b3bde4fbe217921e12a6

Contents?: true

Size: 1.81 KB

Versions: 29

Compression:

Stored size: 1.81 KB

Contents

require 'puppet/configurer'
require 'puppet/resource/catalog'

class Puppet::Configurer::Downloader
  attr_reader :name, :path, :source, :ignore

  # Determine the timeout value to use.
  def self.timeout
    timeout = Puppet[:configtimeout]
    case timeout
    when String
      if timeout =~ /^\d+$/
        timeout = Integer(timeout)
      else
        raise ArgumentError, "Configuration timeout must be an integer"
      end
    when Integer # nothing
    else
      raise ArgumentError, "Configuration timeout must be an integer"
    end

    timeout
  end

  # Evaluate our download, returning the list of changed values.
  def evaluate
    Puppet.info "Retrieving #{name}"

    files = []
    begin
      Timeout.timeout(self.class.timeout) do
        catalog.apply do |trans|
          trans.changed?.find_all do |resource|
            yield resource if block_given?
            files << resource[:path]
          end
        end
      end
    rescue Puppet::Error, Timeout::Error => detail
      puts detail.backtrace if Puppet[:debug]
      Puppet.err "Could not retrieve #{name}: #{detail}"
    end

    files
  end

  def initialize(name, path, source, ignore = nil)
    @name, @path, @source, @ignore = name, path, source, ignore
  end

  def catalog
    catalog = Puppet::Resource::Catalog.new
    catalog.host_config = false
    catalog.add_resource(file)
    catalog
  end

  def file
    args = default_arguments.merge(:path => path, :source => source)
    args[:ignore] = ignore.split if ignore
    Puppet::Type.type(:file).new(args)
  end

  private

  def default_arguments
    {
      :path => path,
      :recurse => true,
      :source => source,
      :tag => name,
      :owner => Process.uid,
      :group => Process.gid,
      :purge => true,
      :force => true,
      :backup => false,
      :noop => false
    }
  end
end

Version data entries

29 entries across 29 versions & 2 rubygems

Version Path
puppet-2.6.18 lib/puppet/configurer/downloader.rb
supply_drop-0.11.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/configurer/downloader.rb
supply_drop-0.10.2 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/configurer/downloader.rb
puppet-2.6.17 lib/puppet/configurer/downloader.rb
supply_drop-0.10.1 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/configurer/downloader.rb
supply_drop-0.10.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/configurer/downloader.rb
puppet-2.6.16 lib/puppet/configurer/downloader.rb
puppet-2.6.15 lib/puppet/configurer/downloader.rb
supply_drop-0.9.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/configurer/downloader.rb
supply_drop-0.8.1 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/configurer/downloader.rb
supply_drop-0.8.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/configurer/downloader.rb
puppet-2.6.14 lib/puppet/configurer/downloader.rb
supply_drop-0.7.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/configurer/downloader.rb
supply_drop-0.6.1 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/configurer/downloader.rb
supply_drop-0.6.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/configurer/downloader.rb
puppet-2.6.13 lib/puppet/configurer/downloader.rb
puppet-2.7.9 lib/puppet/configurer/downloader.rb
puppet-2.7.8 lib/puppet/configurer/downloader.rb
puppet-2.7.6 lib/puppet/configurer/downloader.rb
puppet-2.6.12 lib/puppet/configurer/downloader.rb