summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2018-03-05 09:57:15 -0800
committerGitHub <noreply@github.com>2018-03-05 09:57:15 -0800
commitbf3126fe8749b46ca5b92f0c85bf54ea1b6bf9ad (patch)
tree820795d4f3d26615ab6d292ad71bba9ff236c8d0
parenta365dc77b26c7ddde1636617afc6281d0fbbf2b6 (diff)
parent5f8a3f4e5ffb372be05c3a5b218fa9392609439d (diff)
downloadchef-bf3126fe8749b46ca5b92f0c85bf54ea1b6bf9ad.tar.gz
Merge pull request #6947 from chef/registry_key
registry_key: Properly limit allowed values for architecture
-rw-r--r--lib/chef/resource/registry_key.rb28
-rw-r--r--spec/unit/resource/registry_key_spec.rb6
2 files changed, 14 insertions, 20 deletions
diff --git a/lib/chef/resource/registry_key.rb b/lib/chef/resource/registry_key.rb
index 565ff278ea..8ca111bf33 100644
--- a/lib/chef/resource/registry_key.rb
+++ b/lib/chef/resource/registry_key.rb
@@ -15,14 +15,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-require "chef/provider/registry_key"
+
require "chef/resource"
require "chef/digester"
class Chef
class Resource
- # Use the registry_key resource to create and delete registry keys in Microsoft Windows.
class RegistryKey < Chef::Resource
+ resource_name :registry_key
+ provides :registry_key
+
+ description "Use the registry_key resource to create and delete registry keys in Microsoft Windows."
+ introduced "11.0"
+
identity_attr :key
state_attrs :values
@@ -62,8 +67,6 @@ class Chef
def initialize(name, run_context = nil)
super
- @architecture = :machine
- @recursive = false
@key = name
@values, @unscrubbed_values = [], []
end
@@ -102,21 +105,8 @@ class Chef
end
end
- def recursive(arg = nil)
- set_or_return(
- :recursive,
- arg,
- :kind_of => [TrueClass, FalseClass]
- )
- end
-
- def architecture(arg = nil)
- set_or_return(
- :architecture,
- arg,
- :kind_of => Symbol
- )
- end
+ property :recursive, [TrueClass, FalseClass], default: false
+ property :architecture, Symbol, default: :machine, equal_to: [:machine, :x86_64, :i386]
private
diff --git a/spec/unit/resource/registry_key_spec.rb b/spec/unit/resource/registry_key_spec.rb
index 07ad4f820b..d8eea74ed4 100644
--- a/spec/unit/resource/registry_key_spec.rb
+++ b/spec/unit/resource/registry_key_spec.rb
@@ -25,7 +25,7 @@ describe Chef::Resource::RegistryKey, "initialize" do
expect(resource.resource_name).to eql(:registry_key)
end
- it "sets the key equal to the argument to initialize" do
+ it "sets the key property to the resource name" do
expect(resource.key).to eql('HKCU\Software\Raxicoricofallapatorius')
end
@@ -159,6 +159,10 @@ describe Chef::Resource::RegistryKey, "architecture" do
end
end
+ it "does not allow other symbols" do
+ expect { resource.architecture(:nope) }.to raise_error(ArgumentError)
+ end
+
it "does not allow a hash" do
expect { resource.architecture({ :sonic => :screwdriver }) }.to raise_error(ArgumentError)
end