Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relocate License Logic on Windows systems into Ruby #212

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 5 additions & 22 deletions providers/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.major < '15'
new_resource.exec_command
else
''
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
post_action = if (new_resource.post_install_action == 'exec') && (desired_version.major >= 15)
"#{new_resource.exec_command} --chef-license #{license_provided}"
elsif desired_version.major < '15'
new_resource.exec_command
else
''
end
post_action = if new_resource.post_install_action != 'exec'
''
elsif desired_version.major >= 15
"#{new_resource.exec_command} --chef-license #{license_provided}"
else
new_resource.exec_command
end

I think this conditional needs to change to maintain the old behavior.

The whitespace is probably all wrong because I'm trying to do this in github's comment box.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. Thank you.


license_provided = node['chef_client']['chef_license'] || ''

powershell_script 'Chef Infra Client Upgrade Script' do
code <<-EOH
$command = {
Expand Down Expand Up @@ -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
Expand Down