From 100a520cf8f0f58bf2f9e46fa454e5127811fc49 Mon Sep 17 00:00:00 2001 From: Ashique Saidalavi Date: Thu, 14 Nov 2024 15:09:47 +0530 Subject: [PATCH] Updated the context setting approach Signed-off-by: Ashique Saidalavi --- lib/kitchen/licensing/config.rb | 3 +-- lib/kitchen/provisioner/chef_infra.rb | 29 +++++++++------------------ 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/lib/kitchen/licensing/config.rb b/lib/kitchen/licensing/config.rb index b4cc5d3d1..b730bf632 100644 --- a/lib/kitchen/licensing/config.rb +++ b/lib/kitchen/licensing/config.rb @@ -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 diff --git a/lib/kitchen/provisioner/chef_infra.rb b/lib/kitchen/provisioner/chef_infra.rb index 83bb44338..9cbb522f5 100644 --- a/lib/kitchen/provisioner/chef_infra.rb +++ b/lib/kitchen/provisioner/chef_infra.rb @@ -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 " @@ -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 @@ -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