Skip to content

Commit

Permalink
Merge pull request #15 from chef/ashiqueps/context_updates
Browse files Browse the repository at this point in the history
Updated the kitchen context approach with env variable
  • Loading branch information
ashiqueps authored Nov 14, 2024
2 parents 9a0c360 + 100a520 commit a946210
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
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

0 comments on commit a946210

Please sign in to comment.