Sha256: a7eae4a31a5ae32b3bb10730b0d224155e493632e724749822d114bf17c36256

Contents?: true

Size: 1.29 KB

Versions: 16

Compression:

Stored size: 1.29 KB

Contents

module Puppet::Pops
module Types

# A Puppet Language type that wraps sensitive information. The sensitive type is parameterized by
# the wrapped value type.
#
#
# @api public
class PSensitiveType < Puppet::Pops::Types::PTypeWithContainedType

  class Sensitive
    def initialize(value)
      @value = value
    end

    def unwrap
      @value
    end

    def to_s
      "Sensitive [value redacted]"
    end

    def inspect
      "#<#{to_s}>"
    end
  end

  def initialize(type = nil)
    @type = type.nil? ? PAnyType.new : type.generalize
  end

  def instance?(o, guard = nil)
    o.is_a?(Sensitive) && @type.instance?(o.unwrap, guard)
  end

  def self.new_function(_, loader)
    @new_function ||= Puppet::Functions.create_loaded_function(:new_Sensitive, loader) do

      dispatch :from_sensitive do
        param 'Sensitive', :value
      end

      dispatch :from_any do
        param 'Any', :value
      end

      def from_any(value)
        Sensitive.new(value)
      end

      # Since the Sensitive value is immutable we can reuse the existing instance instead of making a copy.
      def from_sensitive(value)
        value
      end
    end
  end

  private

  def _assignable?(o, guard)
    self.class == o.class && @type.assignable?(o.type, guard)
  end

  DEFAULT = PSensitiveType.new
end

end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
puppet-4.7.1 lib/puppet/pops/types/p_sensitive_type.rb
puppet-4.7.1-x86-mingw32 lib/puppet/pops/types/p_sensitive_type.rb
puppet-4.7.1-x64-mingw32 lib/puppet/pops/types/p_sensitive_type.rb
puppet-4.7.1-universal-darwin lib/puppet/pops/types/p_sensitive_type.rb
puppet-4.7.0 lib/puppet/pops/types/p_sensitive_type.rb
puppet-4.7.0-x86-mingw32 lib/puppet/pops/types/p_sensitive_type.rb
puppet-4.7.0-x64-mingw32 lib/puppet/pops/types/p_sensitive_type.rb
puppet-4.7.0-universal-darwin lib/puppet/pops/types/p_sensitive_type.rb
puppet-4.6.2 lib/puppet/pops/types/p_sensitive_type.rb
puppet-4.6.2-x86-mingw32 lib/puppet/pops/types/p_sensitive_type.rb
puppet-4.6.2-x64-mingw32 lib/puppet/pops/types/p_sensitive_type.rb
puppet-4.6.2-universal-darwin lib/puppet/pops/types/p_sensitive_type.rb
puppet-4.6.1-x86-mingw32 lib/puppet/pops/types/p_sensitive_type.rb
puppet-4.6.1 lib/puppet/pops/types/p_sensitive_type.rb
puppet-4.6.1-x64-mingw32 lib/puppet/pops/types/p_sensitive_type.rb
puppet-4.6.1-universal-darwin lib/puppet/pops/types/p_sensitive_type.rb