Sha256: 2509019f4dd64e141fc2c9454eb23045ba5654e083f840ec04d8759de6669296

Contents?: true

Size: 1.36 KB

Versions: 24

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

require_relative '../../../puppet/util/checksums'

# Specify which checksum algorithm to use when checksumming
# files.
Puppet::Type.type(:file).newparam(:checksum) do
  include Puppet::Util::Checksums

  desc "The checksum type to use when determining whether to replace a file's contents.

    The default checksum type is #{Puppet.default_digest_algorithm}."

  newvalues(*Puppet::Util::Checksums.known_checksum_types)

  defaultto do
    Puppet[:digest_algorithm].to_sym
  end

  validate do |value|
    if Puppet::Util::Platform.fips_enabled? && (value == :md5 || value == :md5lite)
      raise ArgumentError, _("MD5 is not supported in FIPS mode")
    end
  end

  def sum(content)
    content = content.is_a?(Puppet::Pops::Types::PBinaryType::Binary) ? content.binary_buffer : content
    type = digest_algorithm
    "{#{type}}" + send(type, content)
  end

  def sum_file(path)
    type = digest_algorithm
    method = type.to_s + "_file"
    "{#{type}}" + send(method, path).to_s
  end

  def sum_stream(&block)
    type = digest_algorithm
    method = type.to_s + "_stream"
    checksum = send(method, &block)
    "{#{type}}#{checksum}"
  end

  private

  # Return the appropriate digest algorithm with fallbacks in case puppet defaults have not
  # been initialized.
  def digest_algorithm
    value || Puppet[:digest_algorithm].to_sym
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
puppet-8.8.1 lib/puppet/type/file/checksum.rb
puppet-8.8.1-x86-mingw32 lib/puppet/type/file/checksum.rb
puppet-8.8.1-x64-mingw32 lib/puppet/type/file/checksum.rb
puppet-8.8.1-universal-darwin lib/puppet/type/file/checksum.rb
puppet-8.7.0 lib/puppet/type/file/checksum.rb
puppet-8.7.0-x86-mingw32 lib/puppet/type/file/checksum.rb
puppet-8.7.0-x64-mingw32 lib/puppet/type/file/checksum.rb
puppet-8.7.0-universal-darwin lib/puppet/type/file/checksum.rb
puppet-8.6.0 lib/puppet/type/file/checksum.rb
puppet-8.6.0-x86-mingw32 lib/puppet/type/file/checksum.rb
puppet-8.6.0-x64-mingw32 lib/puppet/type/file/checksum.rb
puppet-8.6.0-universal-darwin lib/puppet/type/file/checksum.rb
puppet-8.5.1 lib/puppet/type/file/checksum.rb
puppet-8.5.1-x86-mingw32 lib/puppet/type/file/checksum.rb
puppet-8.5.1-x64-mingw32 lib/puppet/type/file/checksum.rb
puppet-8.5.1-universal-darwin lib/puppet/type/file/checksum.rb
puppet-8.5.0 lib/puppet/type/file/checksum.rb
puppet-8.5.0-x86-mingw32 lib/puppet/type/file/checksum.rb
puppet-8.5.0-x64-mingw32 lib/puppet/type/file/checksum.rb
puppet-8.5.0-universal-darwin lib/puppet/type/file/checksum.rb