diff options
-rw-r--r-- | lib/chef/mixin/registry_helper.rb | 57 | ||||
-rw-r--r-- | lib/chef/mixins.rb | 1 | ||||
-rw-r--r-- | lib/chef/recipe.rb | 2 | ||||
-rw-r--r-- | lib/chef/resource.rb | 2 |
4 files changed, 62 insertions, 0 deletions
diff --git a/lib/chef/mixin/registry_helper.rb b/lib/chef/mixin/registry_helper.rb new file mode 100644 index 0000000000..f982a69a0a --- /dev/null +++ b/lib/chef/mixin/registry_helper.rb @@ -0,0 +1,57 @@ +# +# Author:: Lamont Granquist (<adam@opscode.com>) +# Copyright:: Copyright (c) 2012 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# +# Helper functions to access the windows registry from within recipes and +# the not_if/only_if blocks in resources. This only exposes the methods +# in the chef/win32/registry class which are reasonably side-effect-free. +# The actual modification of the registry should be done via the registry_key +# resource in a more idempotent way. +# +# +class Chef + module Mixin + module RegistryHelper + def registry_key_exists?(key_path, architecture = :machine) + registry = Chef::Win32::Registry.new(run_context, architecture) + registry.key_exists?(key_path) + end + def registry_get_values(key_path, architecture = :machine) + registry = Chef::Win32::Registry.new(run_context, architecture) + registry.get_values?(key_path) + end + def registry_has_subkeys?(key_path, architecture = :machine) + registry = Chef::Win32::Registry.new(run_context, architecture) + registry.has_subkeys?(key_path) + end + def registry_get_subkeys(key_path, architecture = :machine) + registry = Chef::Win32::Registry.new(run_context, architecture) + registry.get_subkeys?(key_path) + end + def registry_value_exists?(key_path, value, architecture = :machine) + registry = Chef::Win32::Registry.new(run_context, architecture) + registry.value_exists?(key_path, value) + end + def registry_data_exists?(key_path, value, architecture = :machine) + registry = Chef::Win32::Registry.new(run_context, architecture) + registry.data_exists?(key_path, value) + end + end + end +end + diff --git a/lib/chef/mixins.rb b/lib/chef/mixins.rb index 557932c0e6..b0c16c3717 100644 --- a/lib/chef/mixins.rb +++ b/lib/chef/mixins.rb @@ -12,3 +12,4 @@ require 'chef/mixin/path_sanity' require 'chef/mixin/template' require 'chef/mixin/securable' require 'chef/mixin/xml_escape' +require 'chef/mixin/registry_helper' diff --git a/lib/chef/recipe.rb b/lib/chef/recipe.rb index aca35db049..3571d1eb34 100644 --- a/lib/chef/recipe.rb +++ b/lib/chef/recipe.rb @@ -26,6 +26,7 @@ require 'chef/dsl/include_recipe' require 'chef/mixin/from_file' require 'chef/mixin/deprecation' +require 'chef/mixin/registry_helper' class Chef # == Chef::Recipe @@ -39,6 +40,7 @@ class Chef include Chef::Mixin::FromFile include Chef::Mixin::Deprecation + include Chef::Mixin::RegistryHelper attr_accessor :cookbook_name, :recipe_name, :recipe, :params, :run_context diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb index c49bb6684e..c9737cf79a 100644 --- a/lib/chef/resource.rb +++ b/lib/chef/resource.rb @@ -27,6 +27,7 @@ require 'chef/resource_platform_map' require 'chef/node' require 'chef/mixin/deprecation' +require 'chef/mixin/registry_helper' class Chef class Resource @@ -124,6 +125,7 @@ F include Chef::DSL::PlatformIntrospection include Chef::Mixin::ConvertToClassName include Chef::Mixin::Deprecation + include Chef::Mixin::RegistryHelper extend Chef::Mixin::ConvertToClassName |