forked from test-kitchen/test-kitchen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from ashiqueps/CHEF-12878-provisioner-updates
Chef-infra provisioner to use the new omnitruck apis
- Loading branch information
Showing
11 changed files
with
186 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require_relative "../command" | ||
require "kitchen/licensing/base" | ||
|
||
module Kitchen | ||
module Command | ||
# Command to manage the licenses | ||
class License < Kitchen::Command::Base | ||
def call | ||
case args[0] | ||
when "list" | ||
ChefLicensing.list_license_keys_info | ||
when "add" | ||
ChefLicensing.add_license | ||
else | ||
ChefLicensing.fetch_and_persist.each do |key| | ||
puts "License_key: #{key}" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright:: Chef Software Inc. | ||
# License:: Apache License, Version 2.0 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
require_relative "config" | ||
require "chef-licensing" | ||
require "faraday_middleware" | ||
|
||
module Kitchen | ||
module Licensing | ||
class Base | ||
|
||
OMNITRUCK_URLS = { | ||
"free" => "https://chefdownload-trial.chef.io", | ||
"trial" => "https://chefdownload-trial.chef.io", | ||
"commercial" => "https://chefdownload-commerical.chef.io", | ||
}.freeze | ||
|
||
class << self | ||
def get_license_keys | ||
keys = ChefLicensing.license_keys | ||
raise ChefLicensing::InvalidLicense, "A valid license is required to perform this action." if keys.blank? | ||
|
||
client = get_license_client(keys) | ||
|
||
[keys.last, client.license_type, install_sh_url(client.license_type, keys)] | ||
end | ||
|
||
def get_license_client(keys) | ||
ChefLicensing::Api::Client.info(license_keys: keys) | ||
end | ||
|
||
def install_sh_url(type, keys, ext = "sh") | ||
OMNITRUCK_URLS[type] + "/install.#{ext}?license_id=#{keys.join(",")}" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright:: Chef Software Inc. | ||
# License:: Apache License, Version 2.0 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
require "chef-licensing" | ||
|
||
ChefLicensing.configure do |config| | ||
config.chef_product_name = "Test Kitchen" | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
# | ||
# Author:: Fletcher Nichol (<[email protected]>) | ||
# | ||
|
@@ -16,13 +17,15 @@ | |
# limitations under the License. | ||
|
||
require_relative "chef_base" | ||
require "kitchen/licensing/base" | ||
|
||
module Kitchen | ||
module Provisioner | ||
# Chef Zero provisioner. | ||
# | ||
# @author Fletcher Nichol <[email protected]> | ||
class ChefInfra < ChefBase | ||
|
||
kitchen_provisioner_api_version 2 | ||
|
||
plugin_version Kitchen::VERSION | ||
|
@@ -32,6 +35,8 @@ class ChefInfra < ChefBase | |
default_config :json_attributes, true | ||
default_config :chef_zero_host, nil | ||
default_config :chef_zero_port, 8889 | ||
default_config :chef_license_key, nil | ||
default_config :chef_license_server, [] | ||
|
||
default_config :chef_client_path do |provisioner| | ||
provisioner | ||
|
@@ -51,12 +56,47 @@ 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}" | ||
|
||
sudo("echo '#{file_content}' > #{file_location}") | ||
end | ||
|
||
def run_command | ||
cmd = "#{sudo(config[:chef_client_path])} --local-mode".tap { |str| str.insert(0, "& ") if powershell_shell? } | ||
cmd = "#{context_env_command} #{sudo(config[:chef_client_path])} --local-mode --chef-license-key=#{config[:chef_license_key]} " | ||
|
||
chef_cmd(cmd) | ||
end | ||
|
||
def check_license | ||
super | ||
|
||
info("Fetching the Chef license key") | ||
unless config[:chef_license_server].nil? || config[:chef_license_server].empty? | ||
ENV["CHEF_LICENSE_SERVER"] = config[:chef_license_server].join(",") | ||
end | ||
|
||
key, type, install_sh_url = if config[:chef_license_key].nil? | ||
Licensing::Base.get_license_keys | ||
else | ||
key = config[:chef_license_key] | ||
client = Licensing::Base.get_license_client([key]) | ||
|
||
[key, client.license_type, Licensing::Base.install_sh_url(client.license_type, [key])] | ||
end | ||
|
||
config[:chef_license_key] = key | ||
config[:install_sh_url] = install_sh_url | ||
config[:chef_license_type] = type | ||
end | ||
|
||
private | ||
|
||
# Adds optional flags to a chef-client command, depending on | ||
|
@@ -162,6 +202,18 @@ def shim_command | |
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}'; &" | ||
else | ||
"export TEST_KITCHEN_CONTEXT=#{context_key};" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters