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

Updated the kitchen context approach with env variable #15

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions lib/kitchen/licensing/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
require "chef-licensing"

ChefLicensing.configure do |config|
config.chef_product_name = "Test Kitchen"
config.chef_product_name = "Chef Test Kitchen Enterprise"
config.chef_entitlement_id = "x6f3bc76-a94f-4b6c-bc97-4b7ed2b045c0"
config.chef_executable_name = "kitchen"
config.license_server_url = "https://services.chef.io/licensing"
# config.license_server_url = "https://licensing-acceptance.chef.co/License"
end
29 changes: 10 additions & 19 deletions lib/kitchen/provisioner/chef_infra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,6 @@ def create_sandbox
prepare_config_rb
end

def prepare_command
nonce = Base64.encode64(SecureRandom.random_bytes(16)).strip
timestamp = Time.now.utc.to_i.to_s

message = "#{nonce}:#{timestamp}"
signature = OpenSSL::HMAC.hexdigest("SHA256", context_key, message)

file_content = "nonce:#{nonce}\ntimestamp:#{timestamp}\nsignature:#{signature}"
file_location = config[:root_path] + "/#{context_key}"

"echo '#{file_content}' > #{file_location}"
end

def run_command
cmd = "#{context_env_command} #{sudo(config[:chef_client_path])} --local-mode "

Expand Down Expand Up @@ -98,6 +85,14 @@ def check_license
config[:chef_license_type] = type
end

def chef_license_key
config[:chef_license_key]
end

def chef_license_server
config[:chef_license_server]
end

private

# Adds optional flags to a chef-client command, depending on
Expand Down Expand Up @@ -204,15 +199,11 @@ def supports_policyfile?
true
end

def context_key
@context_key ||= SecureRandom.hex(16)
end

def context_env_command
if powershell_shell?
"$env:TEST_KITCHEN_CONTEXT = '#{context_key}'; &"
"$env:IS_KITCHEN = 'true'; &"
else
"export TEST_KITCHEN_CONTEXT=#{context_key};"
"export IS_KITCHEN='true'; "
end
end
end
Expand Down
Loading