Sha256: ec074c5e6ff405ad1b29922f075efe9d534d2f0c0eaa6bbaf6e3eb950c96a80a

Contents?: true

Size: 1.64 KB

Versions: 164

Compression:

Stored size: 1.64 KB

Contents

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

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

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

    files = []
    begin
      catalog.apply do |trans|
        trans.changed?.each do |resource|
          yield resource if block_given?
          files << resource[:path]
        end
      end
    rescue Puppet::Error => detail
      Puppet.log_exception(detail, "Could not retrieve #{name}: #{detail}")
    end
    files
  end

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

  def catalog
    catalog = Puppet::Resource::Catalog.new("PluginSync", @environment)
    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
    defargs = {
      :path => path,
      :recurse => true,
      :links => :follow,
      :source => source,
      :source_permissions => @source_permissions,
      :tag => name,
      :purge => true,
      :force => true,
      :backup => false,
      :noop => false
    }
    if !Puppet.features.microsoft_windows?
      defargs.merge!(
        {
          :owner => Process.uid,
          :group => Process.gid
        }
      )
    end
    return defargs
  end
end

Version data entries

164 entries across 164 versions & 2 rubygems

Version Path
puppet-retrospec-1.8.0 vendor/pup410/lib/puppet/configurer/downloader.rb
puppet-retrospec-1.7.0 vendor/pup410/lib/puppet/configurer/downloader.rb
puppet-4.10.12 lib/puppet/configurer/downloader.rb
puppet-4.10.12-x86-mingw32 lib/puppet/configurer/downloader.rb
puppet-4.10.12-x64-mingw32 lib/puppet/configurer/downloader.rb
puppet-4.10.12-universal-darwin lib/puppet/configurer/downloader.rb
puppet-4.10.11 lib/puppet/configurer/downloader.rb
puppet-4.10.11-x86-mingw32 lib/puppet/configurer/downloader.rb
puppet-4.10.11-x64-mingw32 lib/puppet/configurer/downloader.rb
puppet-4.10.11-universal-darwin lib/puppet/configurer/downloader.rb
puppet-4.10.10 lib/puppet/configurer/downloader.rb
puppet-4.10.10-x86-mingw32 lib/puppet/configurer/downloader.rb
puppet-4.10.10-x64-mingw32 lib/puppet/configurer/downloader.rb
puppet-4.10.10-universal-darwin lib/puppet/configurer/downloader.rb
puppet-retrospec-1.6.1 vendor/pup410/lib/puppet/configurer/downloader.rb
puppet-retrospec-1.6.0 vendor/pup410/lib/puppet/configurer/downloader.rb
puppet-4.10.9 lib/puppet/configurer/downloader.rb
puppet-4.10.9-x86-mingw32 lib/puppet/configurer/downloader.rb
puppet-4.10.9-x64-mingw32 lib/puppet/configurer/downloader.rb
puppet-4.10.9-universal-darwin lib/puppet/configurer/downloader.rb