From c14e87d8100ea1994363decc795967646674839d Mon Sep 17 00:00:00 2001 From: z00k Date: Wed, 26 Aug 2020 11:34:05 -0500 Subject: [PATCH 1/4] Move license check from PowerShell into Ruby --- providers/default.rb | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/providers/default.rb b/providers/default.rb index 1b8b923..23bd2a0 100644 --- a/providers/default.rb +++ b/providers/default.rb @@ -496,14 +496,16 @@ def execute_install_script(install_script) '' end - post_action = if new_resource.post_install_action == 'exec' + license_provided = node['chef_client']['chef_license'] || '' + + post_action = if (new_resource.post_install_action == 'exec') && (desired_version.major >= 15) + "#{new_resource.exec_command} --chef-license #{license_provided}" + elsif desired_version < '15' new_resource.exec_command else '' end - license_provided = node['chef_client']['chef_license'] || '' - powershell_script 'Chef Infra Client Upgrade Script' do code <<-EOH $command = { @@ -564,25 +566,6 @@ def execute_install_script(install_script) Remove-Item "#{chef_install_dir}/../chef_upgrade.ps1" c:/windows/system32/schtasks.exe /delete /f /tn Chef_upgrade - if ('#{desired_version}' -ge '15') { - - SET CHEF_LICENSE '#{license_provided}' - - #{chef_install_dir}/embedded/bin/ruby.exe -e " - begin - require 'chef/VERSION' - require 'license_acceptance/acceptor' - acceptor = LicenseAcceptance::Acceptor.new(provided: '#{license_provided}') - if acceptor.license_required?('chef', Chef::VERSION) - license_id = acceptor.id_from_mixlib('chef') - acceptor.check_and_persist(license_id, Chef::VERSION) - end - rescue LoadError - puts 'License acceptance might not be needed !' - end - " - } - #{post_action} Get-Service push-jobs-client -ErrorAction SilentlyContinue | start-service From 3db914ce1e5de4d4b5579bd853539e764b22f427 Mon Sep 17 00:00:00 2001 From: z00k Date: Wed, 26 Aug 2020 12:30:02 -0500 Subject: [PATCH 2/4] Missed a property... --- providers/default.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/default.rb b/providers/default.rb index 23bd2a0..e83299e 100644 --- a/providers/default.rb +++ b/providers/default.rb @@ -500,7 +500,7 @@ def execute_install_script(install_script) post_action = if (new_resource.post_install_action == 'exec') && (desired_version.major >= 15) "#{new_resource.exec_command} --chef-license #{license_provided}" - elsif desired_version < '15' + elsif desired_version.major < '15' new_resource.exec_command else '' From e82f150e5367c84096a73d874c751591ee18a881 Mon Sep 17 00:00:00 2001 From: Jeff Dean Date: Fri, 18 Sep 2020 14:15:56 -0500 Subject: [PATCH 3/4] Correct Style issue ---------- Developer's Certificate of Origin 1.1 By making a contribution to this project, I certify that: (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as Indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. Signed-off-by: Jeff Dean --- providers/default.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/default.rb b/providers/default.rb index e83299e..68895a8 100644 --- a/providers/default.rb +++ b/providers/default.rb @@ -496,7 +496,7 @@ def execute_install_script(install_script) '' end - license_provided = node['chef_client']['chef_license'] || '' + license_provided = node['chef_client']['chef_license'] || '' post_action = if (new_resource.post_install_action == 'exec') && (desired_version.major >= 15) "#{new_resource.exec_command} --chef-license #{license_provided}" From d8793d2dce839e169ab726303047045405ddd844 Mon Sep 17 00:00:00 2001 From: Jeff Dean Date: Tue, 22 Sep 2020 08:15:58 -0500 Subject: [PATCH 4/4] Correcting logic to retain prior "!= exec" behavior. ---------- Developer's Certificate of Origin 1.1 By making a contribution to this project, I certify that: (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as Indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. Signed-off-by: Jeff Dean --- providers/default.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/providers/default.rb b/providers/default.rb index 68895a8..dd7b0e8 100644 --- a/providers/default.rb +++ b/providers/default.rb @@ -498,12 +498,12 @@ def execute_install_script(install_script) license_provided = node['chef_client']['chef_license'] || '' - post_action = if (new_resource.post_install_action == 'exec') && (desired_version.major >= 15) + post_action = if new_resource.post_install_action != 'exec' + '' + elsif desired_version.major >= 15 "#{new_resource.exec_command} --chef-license #{license_provided}" - elsif desired_version.major < '15' - new_resource.exec_command else - '' + new_resource.exec_command end powershell_script 'Chef Infra Client Upgrade Script' do