diff options
author | NimishaS <nimisha.sharad@msystechnologies.com> | 2017-07-13 09:21:07 +0000 |
---|---|---|
committer | Bryan McLellan <btm@loftninjas.org> | 2017-07-19 22:16:01 -0400 |
commit | 00761075e711b658bad30dccce27c44e64d121d7 (patch) | |
tree | bbc15555479454f1dfd71565970f7260f24797d2 | |
parent | 319cf1a22bec65fdf0b8abea289fdf14500611ad (diff) | |
download | chef-00761075e711b658bad30dccce27c44e64d121d7.tar.gz |
Added :elevated option for powershell_script resource
Signed-off-by: NimishaS <nimisha.sharad@msystechnologies.com>
-rw-r--r-- | lib/chef/provider/execute.rb | 3 | ||||
-rw-r--r-- | lib/chef/resource/execute.rb | 10 | ||||
-rw-r--r-- | spec/unit/resource/powershell_script_spec.rb | 4 |
3 files changed, 12 insertions, 5 deletions
diff --git a/lib/chef/provider/execute.rb b/lib/chef/provider/execute.rb index d19a95b4ae..d5a0bdfa11 100644 --- a/lib/chef/provider/execute.rb +++ b/lib/chef/provider/execute.rb @@ -27,7 +27,7 @@ class Chef provides :execute - def_delegators :new_resource, :command, :returns, :environment, :user, :domain, :password, :group, :cwd, :umask, :creates + def_delegators :new_resource, :command, :returns, :environment, :user, :domain, :password, :group, :cwd, :umask, :creates, :elevated def load_current_resource current_resource = Chef::Resource::Execute.new(new_resource.name) @@ -102,6 +102,7 @@ class Chef opts[:live_stream] = STDOUT end end + opts[:elevated] = elevated if elevated opts end diff --git a/lib/chef/resource/execute.rb b/lib/chef/resource/execute.rb index dee497e74f..32198e5db0 100644 --- a/lib/chef/resource/execute.rb +++ b/lib/chef/resource/execute.rb @@ -132,6 +132,8 @@ class Chef property :sensitive, [ TrueClass, FalseClass ], default: false, coerce: proc { |x| password ? true : x } + property :elevated, [ TrueClass, FalseClass ], default: false + def self.set_guard_inherited_attributes(*inherited_attributes) @class_inherited_attributes = inherited_attributes end @@ -149,13 +151,13 @@ class Chef end def after_created - validate_identity_platform(user, password, domain) + validate_identity_platform(user, password, domain, elevated) identity = qualify_user(user, password, domain) domain(identity[:domain]) user(identity[:user]) end - def validate_identity_platform(specified_user, password = nil, specified_domain = nil) + def validate_identity_platform(specified_user, password = nil, specified_domain = nil, elevated = false) if node[:platform_family] == "windows" if specified_user && password.nil? raise ArgumentError, "A value for `password` must be specified when a value for `user` is specified on the Windows platform" @@ -164,6 +166,10 @@ class Chef if password || specified_domain raise Exceptions::UnsupportedPlatform, "Values for `domain` and `password` are only supported on the Windows platform" end + + if elevated + raise Exceptions::UnsupportedPlatform, "Value for `elevated` is only supported on the Windows platform" + end end end diff --git a/spec/unit/resource/powershell_script_spec.rb b/spec/unit/resource/powershell_script_spec.rb index 6457090608..9cdb6fdbee 100644 --- a/spec/unit/resource/powershell_script_spec.rb +++ b/spec/unit/resource/powershell_script_spec.rb @@ -59,9 +59,9 @@ describe Chef::Resource::PowershellScript do allow(resource).to receive(:updated).and_return(true) end - it "inherits exactly the :cwd, :environment, :group, :path, :user, :umask, and :architecture attributes from a parent resource class" do + it "inherits exactly the :cwd, :environment, :group, :path, :user, :umask, :architecture, :elevated attributes from a parent resource class" do inherited_difference = Chef::Resource::PowershellScript.guard_inherited_attributes - - [:cwd, :environment, :group, :path, :user, :umask, :architecture ] + [:cwd, :environment, :group, :path, :user, :umask, :architecture, :elevated ] expect(inherited_difference).to eq([]) end |