diff options
author | Tim Smith <tsmith@chef.io> | 2021-03-17 19:24:20 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-17 19:24:20 -0700 |
commit | 507cf567cd521cf69fbaed081df2a3f59381e46e (patch) | |
tree | 80f8f745335cd53a802fafbb44c897ce2a267f72 | |
parent | e1d61c3b8fb24d7ae638003d3ff3b367b18151e3 (diff) | |
parent | 1d5cc559fc02122cc6f18cdd832e40680c23295c (diff) | |
download | chef-507cf567cd521cf69fbaed081df2a3f59381e46e.tar.gz |
Merge pull request #11201 from chef/lcg/execute-login-option
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/chef/provider/execute.rb | 3 | ||||
-rw-r--r-- | lib/chef/resource/execute.rb | 7 | ||||
-rw-r--r-- | spec/support/shared/unit/script_resource.rb | 4 | ||||
-rw-r--r-- | spec/unit/resource/powershell_script_spec.rb | 4 |
4 files changed, 12 insertions, 6 deletions
diff --git a/lib/chef/provider/execute.rb b/lib/chef/provider/execute.rb index 20b8a40bf1..b4020b8620 100644 --- a/lib/chef/provider/execute.rb +++ b/lib/chef/provider/execute.rb @@ -27,7 +27,7 @@ class Chef provides :execute, target_mode: true - def_delegators :new_resource, :command, :returns, :environment, :user, :domain, :password, :group, :cwd, :umask, :creates, :elevated, :default_env, :timeout, :input + def_delegators :new_resource, :command, :returns, :environment, :user, :domain, :password, :group, :cwd, :umask, :creates, :elevated, :default_env, :timeout, :input, :login def load_current_resource current_resource = Chef::Resource::Execute.new(new_resource.name) @@ -92,6 +92,7 @@ class Chef opts[:cwd] = cwd if cwd opts[:umask] = umask if umask opts[:input] = input if input + opts[:login] = login if login opts[:default_env] = default_env opts[:log_level] = :info opts[:log_tag] = new_resource.to_s diff --git a/lib/chef/resource/execute.rb b/lib/chef/resource/execute.rb index 5a78160642..88f52bbde1 100644 --- a/lib/chef/resource/execute.rb +++ b/lib/chef/resource/execute.rb @@ -572,6 +572,10 @@ class Chef introduced: "16.2", description: "An optional property to set the input sent to the command as STDIN." + property :login, [ TrueClass, FalseClass ], default: false, + introduced: "17.0", + description: "Use a login shell to run the commands instead of inheriting the existing execution environment." + alias :env :environment def self.set_guard_inherited_attributes(*inherited_attributes) @@ -666,7 +670,8 @@ class Chef :group, :password, :user, - :umask + :umask, + :login ) end diff --git a/spec/support/shared/unit/script_resource.rb b/spec/support/shared/unit/script_resource.rb index 0256112a68..4b51cb7794 100644 --- a/spec/support/shared/unit/script_resource.rb +++ b/spec/support/shared/unit/script_resource.rb @@ -47,9 +47,9 @@ shared_examples_for "a script resource" do end describe "when executing guards" do - it "inherits exactly the :cwd, :domain, :environment, :group, :password, :path, :user, and :umask attributes from a parent resource class" do + it "inherits exactly the :cwd, :domain, :environment, :group, :password, :path, :user, :umask, and :login attributes from a parent resource class" do inherited_difference = Chef::Resource::Script.guard_inherited_attributes - - %i{cwd domain environment group password path user umask} + %i{cwd domain environment group password path user umask login} expect(inherited_difference).to eq([]) end diff --git a/spec/unit/resource/powershell_script_spec.rb b/spec/unit/resource/powershell_script_spec.rb index a913583cfa..0e64a86279 100644 --- a/spec/unit/resource/powershell_script_spec.rb +++ b/spec/unit/resource/powershell_script_spec.rb @@ -47,9 +47,9 @@ describe Chef::Resource::PowershellScript do expect(resource.convert_boolean_return).to eq(false) end - it "inherits exactly the :cwd, :domain, :environment, :group, :password, :path, :user, :umask, :architecture, :elevated, :interpreter properties from a parent resource class" do + it "inherits exactly the :cwd, :domain, :environment, :group, :password, :path, :user, :umask, :architecture, :elevated, :interpreter, :login properties from a parent resource class" do inherited_difference = Chef::Resource::PowershellScript.guard_inherited_attributes - - %i{cwd domain environment group password path user umask architecture elevated interpreter} + %i{cwd domain environment group password path user umask architecture elevated interpreter login} expect(inherited_difference).to eq([]) end |