Sha256: 6f591c65f39099c6c32c86fb0d64c9bbe2d09ec0b6222525a3cc6d1ad43d990d

Contents?: true

Size: 1.75 KB

Versions: 225

Compression:

Stored size: 1.75 KB

Contents

class Specinfra::Command::Windows::Base::RegistryKey < Specinfra::Command::Windows::Base
  class << self
    REGISTRY_KEY_TYPES = {
      :type_string       => 'String',
      :type_binary       => 'Binary',
      :type_dword        => 'DWord',
      :type_qword        => 'QWord',
      :type_multistring  => 'MultiString',
      :type_expandstring => 'ExpandString'
    }

    def check_exists(key_name)
      cmd = "(Get-Item 'Registry::#{key_name}') -ne $null"
      create_command cmd
    end

    def check_has_property(key_name, key_property)
      cmd = "(Get-Item 'Registry::#{key_name}').GetValueKind('#{key_property[:name]}') -eq '#{get_key_type(key_property[:type])}'"
      create_command cmd
    end

    def check_has_value(key_name, key_property)
      value = convert_key_property_value key_property
      cmd = "(Compare-Object (Get-Item 'Registry::#{key_name}').GetValue('#{key_property[:name]}') #{value}) -eq $null"
      create_command cmd
    end

    private
    def do_not_convert?(key_type)
      key_type.to_s =~ /_converted/i
    end

    def get_key_type(key_type)
       REGISTRY_KEY_TYPES[key_type.to_s.gsub("_converted",'').to_sym]
    end

    def convert_key_property_value property
      return property[:value] if do_not_convert? property[:type]
      case property[:type]
      when :type_binary
        byte_array = [property[:value]].pack('H*').bytes.to_a
        "([byte[]] #{byte_array.join(',')})"
      when :type_dword
        [property[:value].rjust(8, '0').scan(/[0-9a-f]{2}/i).reverse.join].pack("H*").unpack("l").first
      when :type_qword
        property[:value].hex
      else
        string_array = property[:value].split("\n").map {|s| "'#{s}'"}.reduce {|acc, s| "#{acc},#{s}"}
        "@(#{string_array})"
      end
    end
  end
end

Version data entries

225 entries across 225 versions & 3 rubygems

Version Path
specinfra-2.71.0 lib/specinfra/command/windows/base/registry_key.rb
specinfra-2.70.2 lib/specinfra/command/windows/base/registry_key.rb
specinfra-2.70.1 lib/specinfra/command/windows/base/registry_key.rb
specinfra-2.70.0 lib/specinfra/command/windows/base/registry_key.rb
specinfra-2.69.0 lib/specinfra/command/windows/base/registry_key.rb
specinfra-2.68.2 lib/specinfra/command/windows/base/registry_key.rb
specinfra-2.68.1 lib/specinfra/command/windows/base/registry_key.rb
specinfra-2.68.0 lib/specinfra/command/windows/base/registry_key.rb
specinfra-2.67.10 lib/specinfra/command/windows/base/registry_key.rb
specinfra-2.67.9 lib/specinfra/command/windows/base/registry_key.rb
specinfra-2.67.8 lib/specinfra/command/windows/base/registry_key.rb
specinfra-2.67.7 lib/specinfra/command/windows/base/registry_key.rb
specinfra-2.67.6 lib/specinfra/command/windows/base/registry_key.rb
specinfra-2.67.5 lib/specinfra/command/windows/base/registry_key.rb
specinfra-2.67.3 lib/specinfra/command/windows/base/registry_key.rb
specinfra-2.67.2 lib/specinfra/command/windows/base/registry_key.rb
specinfra-2.67.1 lib/specinfra/command/windows/base/registry_key.rb
specinfra-2.67.0 lib/specinfra/command/windows/base/registry_key.rb
specinfra-2.66.9 lib/specinfra/command/windows/base/registry_key.rb
specinfra-2.66.8 lib/specinfra/command/windows/base/registry_key.rb