From 4471dd7252f69c222d81c7b203fc0de4d4ffd8a6 Mon Sep 17 00:00:00 2001 From: "Marc A. Paradise" Date: Tue, 2 Mar 2021 13:19:36 -0500 Subject: Prepare files for knife-gem split Signed-off-by: Marc A. Paradise --- lib/chef/cookbook_site_streaming_uploader.rb | 345 +++++++++++---------- lib/chef/cookbook_uploader.rb | 1 - lib/chef/knife.rb | 26 +- lib/chef/knife/bootstrap.rb | 7 +- lib/chef/knife/bootstrap/client_builder.rb | 8 +- lib/chef/knife/client_bulk_delete.rb | 2 +- lib/chef/knife/client_create.rb | 2 +- lib/chef/knife/client_delete.rb | 2 +- lib/chef/knife/client_edit.rb | 2 +- lib/chef/knife/client_list.rb | 2 +- lib/chef/knife/client_reregister.rb | 2 +- lib/chef/knife/client_show.rb | 2 +- lib/chef/knife/config_list.rb | 2 +- lib/chef/knife/configure.rb | 6 +- lib/chef/knife/cookbook_bulk_delete.rb | 2 +- lib/chef/knife/cookbook_delete.rb | 2 +- lib/chef/knife/cookbook_download.rb | 2 +- lib/chef/knife/cookbook_metadata.rb | 4 +- lib/chef/knife/cookbook_metadata_from_file.rb | 2 +- lib/chef/knife/cookbook_show.rb | 4 +- lib/chef/knife/cookbook_upload.rb | 8 +- lib/chef/knife/core/bootstrap_context.rb | 6 +- lib/chef/knife/core/cookbook_scm_repo.rb | 2 +- lib/chef/knife/core/gem_glob_loader.rb | 33 +- lib/chef/knife/core/hashed_command_loader.rb | 2 +- lib/chef/knife/core/node_editor.rb | 4 +- lib/chef/knife/core/object_loader.rb | 9 +- lib/chef/knife/core/subcommand_loader.rb | 19 +- lib/chef/knife/core/ui.rb | 2 +- lib/chef/knife/core/windows_bootstrap_context.rb | 4 +- lib/chef/knife/data_bag_create.rb | 4 +- lib/chef/knife/data_bag_delete.rb | 2 +- lib/chef/knife/data_bag_edit.rb | 4 +- lib/chef/knife/data_bag_from_file.rb | 12 +- lib/chef/knife/data_bag_list.rb | 2 +- lib/chef/knife/data_bag_secret_options.rb | 6 +- lib/chef/knife/data_bag_show.rb | 4 +- lib/chef/knife/delete.rb | 2 +- lib/chef/knife/deps.rb | 6 +- lib/chef/knife/diff.rb | 2 +- lib/chef/knife/download.rb | 2 +- lib/chef/knife/edit.rb | 4 +- lib/chef/knife/environment_compare.rb | 2 +- lib/chef/knife/environment_create.rb | 2 +- lib/chef/knife/environment_delete.rb | 2 +- lib/chef/knife/environment_edit.rb | 2 +- lib/chef/knife/environment_from_file.rb | 2 +- lib/chef/knife/environment_list.rb | 2 +- lib/chef/knife/environment_show.rb | 2 +- lib/chef/knife/exec.rb | 6 +- lib/chef/knife/key_create.rb | 6 +- lib/chef/knife/key_delete.rb | 2 +- lib/chef/knife/key_edit.rb | 6 +- lib/chef/knife/key_list.rb | 6 +- lib/chef/knife/key_show.rb | 6 +- lib/chef/knife/list.rb | 2 +- lib/chef/knife/node_bulk_delete.rb | 4 +- lib/chef/knife/node_create.rb | 4 +- lib/chef/knife/node_delete.rb | 4 +- lib/chef/knife/node_edit.rb | 4 +- lib/chef/knife/node_environment_set.rb | 2 +- lib/chef/knife/node_from_file.rb | 4 +- lib/chef/knife/node_list.rb | 4 +- lib/chef/knife/node_policy_set.rb | 4 +- lib/chef/knife/node_run_list_add.rb | 4 +- lib/chef/knife/node_run_list_remove.rb | 4 +- lib/chef/knife/node_run_list_set.rb | 4 +- lib/chef/knife/node_show.rb | 4 +- lib/chef/knife/org_create.rb | 2 +- lib/chef/knife/org_user_remove.rb | 4 +- lib/chef/knife/raw.rb | 15 +- lib/chef/knife/role_bulk_delete.rb | 4 +- lib/chef/knife/role_create.rb | 4 +- lib/chef/knife/role_delete.rb | 4 +- lib/chef/knife/role_edit.rb | 4 +- lib/chef/knife/role_env_run_list_add.rb | 4 +- lib/chef/knife/role_env_run_list_clear.rb | 4 +- lib/chef/knife/role_env_run_list_remove.rb | 4 +- lib/chef/knife/role_env_run_list_replace.rb | 4 +- lib/chef/knife/role_env_run_list_set.rb | 4 +- lib/chef/knife/role_from_file.rb | 4 +- lib/chef/knife/role_list.rb | 4 +- lib/chef/knife/role_run_list_add.rb | 4 +- lib/chef/knife/role_run_list_clear.rb | 4 +- lib/chef/knife/role_run_list_remove.rb | 2 +- lib/chef/knife/role_run_list_replace.rb | 4 +- lib/chef/knife/role_run_list_set.rb | 2 +- lib/chef/knife/role_show.rb | 2 +- lib/chef/knife/search.rb | 8 +- lib/chef/knife/serve.rb | 2 +- lib/chef/knife/show.rb | 4 +- lib/chef/knife/ssh.rb | 10 +- lib/chef/knife/ssl_check.rb | 7 +- lib/chef/knife/ssl_fetch.rb | 5 +- lib/chef/knife/status.rb | 2 +- lib/chef/knife/supermarket_install.rb | 4 +- lib/chef/knife/supermarket_share.rb | 12 +- lib/chef/knife/supermarket_unshare.rb | 2 +- lib/chef/knife/tag_create.rb | 2 +- lib/chef/knife/tag_delete.rb | 2 +- lib/chef/knife/tag_list.rb | 2 +- lib/chef/knife/upload.rb | 2 +- lib/chef/knife/user_create.rb | 7 +- lib/chef/knife/user_delete.rb | 3 +- lib/chef/knife/user_list.rb | 1 + lib/chef/knife/user_reregister.rb | 2 +- lib/chef/knife/xargs.rb | 4 +- spec/integration/knife/cookbook_api_ipv6_spec.rb | 2 +- spec/support/shared/integration/knife_support.rb | 1 - spec/unit/application/knife_spec.rb | 1 + spec/unit/cookbook_site_streaming_uploader_spec.rb | 40 +-- spec/unit/knife/core/gem_glob_loader_spec.rb | 7 +- spec/unit/knife/supermarket_install_spec.rb | 3 + spec/unit/knife/supermarket_share_spec.rb | 10 +- 114 files changed, 457 insertions(+), 429 deletions(-) diff --git a/lib/chef/cookbook_site_streaming_uploader.rb b/lib/chef/cookbook_site_streaming_uploader.rb index d7226b79b3..e3a8733993 100644 --- a/lib/chef/cookbook_site_streaming_uploader.rb +++ b/lib/chef/cookbook_site_streaming_uploader.rb @@ -31,214 +31,219 @@ end require "chef-utils/dist" unless defined?(ChefUtils::Dist) class Chef - # == Chef::CookbookSiteStreamingUploader - # A streaming multipart HTTP upload implementation. Used to upload cookbooks - # (in tarball form) to https://supermarket.chef.io - # - # inspired by http://stanislavvitvitskiy.blogspot.com/2008/12/multipart-post-in-ruby.html - class CookbookSiteStreamingUploader - - DefaultHeaders = { "accept" => "application/json", "x-chef-version" => ::Chef::VERSION }.freeze # rubocop:disable Naming/ConstantName - - class << self - - def create_build_dir(cookbook) - tmp_cookbook_path = Tempfile.new("#{ChefUtils::Dist::Infra::SHORT}-#{cookbook.name}-build") - tmp_cookbook_path.close - tmp_cookbook_dir = tmp_cookbook_path.path - File.unlink(tmp_cookbook_dir) - FileUtils.mkdir_p(tmp_cookbook_dir) - Chef::Log.trace("Staging at #{tmp_cookbook_dir}") - checksums_to_on_disk_paths = cookbook.checksums - cookbook.each_file do |manifest_record| - path_in_cookbook = manifest_record[:path] - on_disk_path = checksums_to_on_disk_paths[manifest_record[:checksum]] - dest = File.join(tmp_cookbook_dir, cookbook.name.to_s, path_in_cookbook) - FileUtils.mkdir_p(File.dirname(dest)) - Chef::Log.trace("Staging #{on_disk_path} to #{dest}") - FileUtils.cp(on_disk_path, dest) - end + class Knife + module Core + # == Chef::Knife::Core::CookbookSiteStreamingUploader + # A streaming multipart HTTP upload implementation. Used to upload cookbooks + # (in tarball form) to https://supermarket.chef.io + # + # inspired by http://stanislavvitvitskiy.blogspot.com/2008/12/multipart-post-in-ruby.html + class CookbookSiteStreamingUploader + + DefaultHeaders = { "accept" => "application/json", "x-chef-version" => ::Chef::VERSION }.freeze # rubocop:disable Naming/ConstantName + + class << self + + def create_build_dir(cookbook) + tmp_cookbook_path = Tempfile.new("#{ChefUtils::Dist::Infra::SHORT}-#{cookbook.name}-build") + tmp_cookbook_path.close + tmp_cookbook_dir = tmp_cookbook_path.path + File.unlink(tmp_cookbook_dir) + FileUtils.mkdir_p(tmp_cookbook_dir) + Chef::Log.trace("Staging at #{tmp_cookbook_dir}") + checksums_to_on_disk_paths = cookbook.checksums + cookbook.each_file do |manifest_record| + path_in_cookbook = manifest_record[:path] + on_disk_path = checksums_to_on_disk_paths[manifest_record[:checksum]] + dest = File.join(tmp_cookbook_dir, cookbook.name.to_s, path_in_cookbook) + FileUtils.mkdir_p(File.dirname(dest)) + Chef::Log.trace("Staging #{on_disk_path} to #{dest}") + FileUtils.cp(on_disk_path, dest) + end - # First, generate metadata - Chef::Log.trace("Generating metadata") - kcm = Chef::Knife::CookbookMetadata.new - kcm.config[:cookbook_path] = [ tmp_cookbook_dir ] - kcm.name_args = [ cookbook.name.to_s ] - kcm.run + # First, generate metadata + Chef::Log.trace("Generating metadata") + kcm = Chef::Knife::CookbookMetadata.new + kcm.config[:cookbook_path] = [ tmp_cookbook_dir ] + kcm.name_args = [ cookbook.name.to_s ] + kcm.run - tmp_cookbook_dir - end + tmp_cookbook_dir + end - def post(to_url, user_id, secret_key_filename, params = {}, headers = {}) - make_request(:post, to_url, user_id, secret_key_filename, params, headers) - end + def post(to_url, user_id, secret_key_filename, params = {}, headers = {}) + make_request(:post, to_url, user_id, secret_key_filename, params, headers) + end - def put(to_url, user_id, secret_key_filename, params = {}, headers = {}) - make_request(:put, to_url, user_id, secret_key_filename, params, headers) - end + def put(to_url, user_id, secret_key_filename, params = {}, headers = {}) + make_request(:put, to_url, user_id, secret_key_filename, params, headers) + end - def make_request(http_verb, to_url, user_id, secret_key_filename, params = {}, headers = {}) - boundary = "----RubyMultipartClient" + rand(1000000).to_s + "ZZZZZ" - parts = [] - content_file = nil - - secret_key = OpenSSL::PKey::RSA.new(File.read(secret_key_filename)) - - unless params.nil? || params.empty? - params.each do |key, value| - if value.is_a?(File) - content_file = value - filepath = value.path - filename = File.basename(filepath) - parts << StringPart.new( "--" + boundary + "\r\n" + - "Content-Disposition: form-data; name=\"" + key.to_s + "\"; filename=\"" + filename + "\"\r\n" + - "Content-Type: application/octet-stream\r\n\r\n") - parts << StreamPart.new(value, File.size(filepath)) - parts << StringPart.new("\r\n") - else - parts << StringPart.new( "--" + boundary + "\r\n" + - "Content-Disposition: form-data; name=\"" + key.to_s + "\"\r\n\r\n") - parts << StringPart.new(value.to_s + "\r\n") + def make_request(http_verb, to_url, user_id, secret_key_filename, params = {}, headers = {}) + boundary = "----RubyMultipartClient" + rand(1000000).to_s + "ZZZZZ" + parts = [] + content_file = nil + + secret_key = OpenSSL::PKey::RSA.new(File.read(secret_key_filename)) + + unless params.nil? || params.empty? + params.each do |key, value| + if value.is_a?(File) + content_file = value + filepath = value.path + filename = File.basename(filepath) + parts << StringPart.new( "--" + boundary + "\r\n" + + "Content-Disposition: form-data; name=\"" + key.to_s + "\"; filename=\"" + filename + "\"\r\n" + + "Content-Type: application/octet-stream\r\n\r\n") + parts << StreamPart.new(value, File.size(filepath)) + parts << StringPart.new("\r\n") + else + parts << StringPart.new( "--" + boundary + "\r\n" + + "Content-Disposition: form-data; name=\"" + key.to_s + "\"\r\n\r\n") + parts << StringPart.new(value.to_s + "\r\n") + end + end + parts << StringPart.new("--" + boundary + "--\r\n") end - end - parts << StringPart.new("--" + boundary + "--\r\n") - end - body_stream = MultipartStream.new(parts) + body_stream = MultipartStream.new(parts) - timestamp = Time.now.utc.iso8601 + timestamp = Time.now.utc.iso8601 - url = URI.parse(to_url) + url = URI.parse(to_url) - Chef::Log.logger.debug("Signing: method: #{http_verb}, url: #{url}, file: #{content_file}, User-id: #{user_id}, Timestamp: #{timestamp}") + Chef::Log.logger.debug("Signing: method: #{http_verb}, url: #{url}, file: #{content_file}, User-id: #{user_id}, Timestamp: #{timestamp}") - # We use the body for signing the request if the file parameter - # wasn't a valid file or wasn't included. Extract the body (with - # multi-part delimiters intact) to sign the request. - # TODO: tim: 2009-12-28: It'd be nice to remove this special case, and - # always hash the entire request body. In the file case it would just be - # expanded multipart text - the entire body of the POST. - content_body = parts.inject("") { |result, part| result + part.read(0, part.size) } - content_file.rewind if content_file # we consumed the file for the above operation, so rewind it. + # We use the body for signing the request if the file parameter + # wasn't a valid file or wasn't included. Extract the body (with + # multi-part delimiters intact) to sign the request. + # TODO: tim: 2009-12-28: It'd be nice to remove this special case, and + # always hash the entire request body. In the file case it would just be + # expanded multipart text - the entire body of the POST. + content_body = parts.inject("") { |result, part| result + part.read(0, part.size) } + content_file.rewind if content_file # we consumed the file for the above operation, so rewind it. - signing_options = { - http_method: http_verb, - path: url.path, - user_id: user_id, - timestamp: timestamp } - (content_file && signing_options[:file] = content_file) || (signing_options[:body] = (content_body || "")) + signing_options = { + http_method: http_verb, + path: url.path, + user_id: user_id, + timestamp: timestamp } + (content_file && signing_options[:file] = content_file) || (signing_options[:body] = (content_body || "")) - headers.merge!(Mixlib::Authentication::SignedHeaderAuth.signing_object(signing_options).sign(secret_key)) + headers.merge!(Mixlib::Authentication::SignedHeaderAuth.signing_object(signing_options).sign(secret_key)) - content_file.rewind if content_file + content_file.rewind if content_file - # net/http doesn't like symbols for header keys, so we'll to_s each one just in case - headers = DefaultHeaders.merge(Hash[*headers.map { |k, v| [k.to_s, v] }.flatten]) + # net/http doesn't like symbols for header keys, so we'll to_s each one just in case + headers = DefaultHeaders.merge(Hash[*headers.map { |k, v| [k.to_s, v] }.flatten]) - req = case http_verb - when :put - Net::HTTP::Put.new(url.path, headers) - when :post - Net::HTTP::Post.new(url.path, headers) - end - req.content_length = body_stream.size - req.content_type = "multipart/form-data; boundary=" + boundary unless parts.empty? - req.body_stream = body_stream + req = case http_verb + when :put + Net::HTTP::Put.new(url.path, headers) + when :post + Net::HTTP::Post.new(url.path, headers) + end + req.content_length = body_stream.size + req.content_type = "multipart/form-data; boundary=" + boundary unless parts.empty? + req.body_stream = body_stream - http = Chef::HTTP::BasicClient.new(url).http_client - res = http.request(req) + http = Chef::HTTP::BasicClient.new(url).http_client + res = http.request(req) - # alias status to code and to_s to body for test purposes - # TODO: stop the following madness! - class << res - alias :to_s :body + # alias status to code and to_s to body for test purposes + # TODO: stop the following madness! + class << res + alias :to_s :body - # BUG this makes the response compatible with what response_steps expects to test headers (response.headers[] -> response[]) - def headers # rubocop:disable Lint/NestedMethodDefinition - self - end + # BUG this makes the response compatible with what response_steps expects to test headers (response.headers[] -> response[]) + def headers # rubocop:disable Lint/NestedMethodDefinition + self + end - def status # rubocop:disable Lint/NestedMethodDefinition - code.to_i + def status # rubocop:disable Lint/NestedMethodDefinition + code.to_i + end + end + res end - end - res - end - end + end - class StreamPart - def initialize(stream, size) - @stream, @size = stream, size - end + class StreamPart + def initialize(stream, size) + @stream, @size = stream, size + end - def size - @size - end + def size + @size + end - # read the specified amount from the stream - def read(offset, how_much) - @stream.read(how_much) - end - end + # read the specified amount from the stream + def read(offset, how_much) + @stream.read(how_much) + end + end - class StringPart - def initialize(str) - @str = str - end + class StringPart + def initialize(str) + @str = str + end - def size - @str.length - end + def size + @str.length + end - # read the specified amount from the string starting at the offset - def read(offset, how_much) - @str[offset, how_much] - end - end + # read the specified amount from the string starting at the offset + def read(offset, how_much) + @str[offset, how_much] + end + end - class MultipartStream - def initialize(parts) - @parts = parts - @part_no = 0 - @part_offset = 0 - end + class MultipartStream + def initialize(parts) + @parts = parts + @part_no = 0 + @part_offset = 0 + end - def size - @parts.inject(0) { |size, part| size + part.size } - end + def size + @parts.inject(0) { |size, part| size + part.size } + end - def read(how_much, dst_buf = nil) - if @part_no >= @parts.size - dst_buf.replace("") if dst_buf - return dst_buf - end + def read(how_much, dst_buf = nil) + if @part_no >= @parts.size + dst_buf.replace("") if dst_buf + return dst_buf + end - how_much_current_part = @parts[@part_no].size - @part_offset + how_much_current_part = @parts[@part_no].size - @part_offset - how_much_current_part = if how_much_current_part > how_much - how_much - else - how_much_current_part - end + how_much_current_part = if how_much_current_part > how_much + how_much + else + how_much_current_part + end - how_much_next_part = how_much - how_much_current_part + how_much_next_part = how_much - how_much_current_part - current_part = @parts[@part_no].read(@part_offset, how_much_current_part) + current_part = @parts[@part_no].read(@part_offset, how_much_current_part) - # recurse into the next part if the current one was not large enough - if how_much_next_part > 0 - @part_no += 1 - @part_offset = 0 - next_part = read(how_much_next_part) - result = current_part + (next_part || "") - else - @part_offset += how_much_current_part - result = current_part + # recurse into the next part if the current one was not large enough + if how_much_next_part > 0 + @part_no += 1 + @part_offset = 0 + next_part = read(how_much_next_part) + result = current_part + (next_part || "") + else + @part_offset += how_much_current_part + result = current_part + end + dst_buf ? dst_buf.replace(result || "") : result + end end - dst_buf ? dst_buf.replace(result || "") : result + end end - end end + diff --git a/lib/chef/cookbook_uploader.rb b/lib/chef/cookbook_uploader.rb index 235a539b94..21a15f706c 100644 --- a/lib/chef/cookbook_uploader.rb +++ b/lib/chef/cookbook_uploader.rb @@ -1,7 +1,6 @@ autoload :Set, "set" require_relative "exceptions" -require_relative "knife/cookbook_metadata" require_relative "digester" require_relative "cookbook_manifest" require_relative "cookbook_version" diff --git a/lib/chef/knife.rb b/lib/chef/knife.rb index d277e51105..eafba557b7 100644 --- a/lib/chef/knife.rb +++ b/lib/chef/knife.rb @@ -18,22 +18,26 @@ # require "forwardable" unless defined?(Forwardable) -require_relative "version" +require_relative "knife/version" require "mixlib/cli" unless defined?(Mixlib::CLI) require "chef-utils/dsl/default_paths" unless defined?(ChefUtils::DSL::DefaultPaths) require "chef-utils/dist" unless defined?(ChefUtils::Dist) -require_relative "workstation_config_loader" -require_relative "mixin/convert_to_class_name" -require_relative "mixin/default_paths" +require "chef/workstation_config_loader" unless defined?(Chef::WorkstationConfigLoader) +require "chef/mixin/convert_to_class_name" unless defined?(Chef::ConvertToClassName) +require "chef/mixin/default_paths" unless defined?(Chef::Mixin::DefaultPaths) require_relative "knife/core/subcommand_loader" require_relative "knife/core/ui" -require_relative "local_mode" -require_relative "server_api" -require_relative "http/authenticator" -require_relative "http/http_request" -require_relative "http" +require "chef/local_mode" unless defined?(Chef::LocalMode) +require "chef/server_api" unless defined?(Chef::ServerAPI) +require "http/authenticator" unless defined?(Chef::HTTP::Authenticator) +require "http/http_request" unless defined?(Chef::HTTP::HTTPRequest) +require "http" unless defined?(Chef::HTTP) + +# MPTD: using pp at all? a quick perusal of knife doesn't turn any up, so far. require "pp" unless defined?(PP) +require_relative "application/knife" + class Chef class Knife @@ -639,14 +643,14 @@ class Chef def rest @rest ||= begin - require_relative "server_api" + require "chef/server_api" unless defined?(Chef::ServerAPI) Chef::ServerAPI.new(Chef::Config[:chef_server_url]) end end def noauth_rest @rest ||= begin - require_relative "http/simple_json" + require "chef/http/simple_json" unless defined?(Chef::HTTP::SimpleJSON) Chef::HTTP::SimpleJSON.new(Chef::Config[:chef_server_url]) end end diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb index 340ffaecfd..d57614cb3d 100644 --- a/lib/chef/knife/bootstrap.rb +++ b/lib/chef/knife/bootstrap.rb @@ -416,10 +416,9 @@ class Chef deps do require "erubis" unless defined?(Erubis) - require "net/ssh" unless defined?(Net::SSH) - require_relative "../json_compat" - require_relative "../util/path_helper" + require "chef/json_compat" unless defined?(Chef::JSONCompat) + require "chef-config/path_helper" unless defined?(ChefConfig::PathHelper) require_relative "bootstrap/chef_vault_handler" require_relative "bootstrap/client_builder" require_relative "bootstrap/train_connector" @@ -502,7 +501,7 @@ class Chef bootstrap_files = [] bootstrap_files << File.join(__dir__, "bootstrap/templates", "#{template}.erb") bootstrap_files << File.join(Knife.chef_config_dir, "bootstrap", "#{template}.erb") if Chef::Knife.chef_config_dir - Chef::Util::PathHelper.home(".chef", "bootstrap", "#{template}.erb") { |p| bootstrap_files << p } + ChefConfig::PathHelper.home(".chef", "bootstrap", "#{template}.erb") { |p| bootstrap_files << p } bootstrap_files << Gem.find_files(File.join("chef", "knife", "bootstrap", "#{template}.erb")) bootstrap_files.flatten! diff --git a/lib/chef/knife/bootstrap/client_builder.rb b/lib/chef/knife/bootstrap/client_builder.rb index d9c3d83d06..b1e69d90db 100644 --- a/lib/chef/knife/bootstrap/client_builder.rb +++ b/lib/chef/knife/bootstrap/client_builder.rb @@ -16,10 +16,10 @@ # limitations under the License. # -require_relative "../../node" -require_relative "../../server_api" -require_relative "../../api_client/registration" -require_relative "../../api_client" +require "chef/node" unless defined?(Chef::Node) +require "chef/server_api" unless defined?(Chef::ServerAPI) +require "chef/api_client" unless defined?(Chef::APIClient) +require "chef/api_client/registration" unless defined?(Chef::APIClient::Registration) require "tmpdir" unless defined?(Dir.mktmpdir) class Chef diff --git a/lib/chef/knife/client_bulk_delete.rb b/lib/chef/knife/client_bulk_delete.rb index 38d25583b3..cc200a8bee 100644 --- a/lib/chef/knife/client_bulk_delete.rb +++ b/lib/chef/knife/client_bulk_delete.rb @@ -23,7 +23,7 @@ class Chef class ClientBulkDelete < Knife deps do - require_relative "../api_client_v1" + require "chef/api_client_v1" unless defined?(Chef::ApiClientV1) end option :delete_validators, diff --git a/lib/chef/knife/client_create.rb b/lib/chef/knife/client_create.rb index d6e0eab63b..c79ff25d5e 100644 --- a/lib/chef/knife/client_create.rb +++ b/lib/chef/knife/client_create.rb @@ -24,7 +24,7 @@ class Chef class ClientCreate < Knife deps do - require_relative "../api_client_v1" + require "chef/api_client_v1" unless defined?(Chef::ApiClientV1) end option :file, diff --git a/lib/chef/knife/client_delete.rb b/lib/chef/knife/client_delete.rb index 3ecfa38242..874f2ba642 100644 --- a/lib/chef/knife/client_delete.rb +++ b/lib/chef/knife/client_delete.rb @@ -23,7 +23,7 @@ class Chef class ClientDelete < Knife deps do - require_relative "../api_client_v1" + require "chef/api_client_v1" unless defined?(Chef::ApiClientV1) end option :delete_validators, diff --git a/lib/chef/knife/client_edit.rb b/lib/chef/knife/client_edit.rb index f89f5e38ec..4f58228901 100644 --- a/lib/chef/knife/client_edit.rb +++ b/lib/chef/knife/client_edit.rb @@ -23,7 +23,7 @@ class Chef class ClientEdit < Knife deps do - require_relative "../api_client_v1" + require "chef/api_client_v1" unless defined?(Chef::ApiClientV1) end banner "knife client edit CLIENT (options)" diff --git a/lib/chef/knife/client_list.rb b/lib/chef/knife/client_list.rb index b4fc46767b..f4a4c7e9ad 100644 --- a/lib/chef/knife/client_list.rb +++ b/lib/chef/knife/client_list.rb @@ -23,7 +23,7 @@ class Chef class ClientList < Knife deps do - require_relative "../api_client_v1" + require "chef/api_client_v1" unless defined?(Chef::ApiClientV1) end banner "knife client list (options)" diff --git a/lib/chef/knife/client_reregister.rb b/lib/chef/knife/client_reregister.rb index 6741895b23..3408392d95 100644 --- a/lib/chef/knife/client_reregister.rb +++ b/lib/chef/knife/client_reregister.rb @@ -23,7 +23,7 @@ class Chef class ClientReregister < Knife deps do - require_relative "../api_client_v1" + require "chef/api_client_v1" unless defined?(Chef::ApiClientV1) end banner "knife client reregister CLIENT (options)" diff --git a/lib/chef/knife/client_show.rb b/lib/chef/knife/client_show.rb index 9170c73085..102ff2c4cc 100644 --- a/lib/chef/knife/client_show.rb +++ b/lib/chef/knife/client_show.rb @@ -25,7 +25,7 @@ class Chef include Knife::Core::MultiAttributeReturnOption deps do - require_relative "../api_client_v1" + require "chef/api_client_v1" unless defined?(Chef::ApiClientV1) end banner "knife client show CLIENT (options)" diff --git a/lib/chef/knife/config_list.rb b/lib/chef/knife/config_list.rb index c9f821e2a8..be80ded3b2 100644 --- a/lib/chef/knife/config_list.rb +++ b/lib/chef/knife/config_list.rb @@ -25,7 +25,7 @@ class Chef TABLE_HEADER ||= [" Profile", "Client", "Key", "Server"].freeze deps do - require_relative "../workstation_config_loader" + require "chef/workstation_config_loader" unless defined?(Chef::WorkstationConfigLoader) require "tty-screen" unless defined?(TTY::Screen) require "tty-table" unless defined?(TTY::Table) end diff --git a/lib/chef/knife/configure.rb b/lib/chef/knife/configure.rb index 2a27fd5d88..4a73b6875b 100644 --- a/lib/chef/knife/configure.rb +++ b/lib/chef/knife/configure.rb @@ -26,10 +26,10 @@ class Chef attr_reader :chef_repo, :new_client_key, :validation_client_name, :validation_key deps do - require_relative "../util/path_helper" + require "chef-config/path_helper" unless defined?(ChefConfig::PathHelper) require_relative "client_create" require_relative "user_create" - require "ohai" unless defined?(Ohai::System) + require "ohai" unless defined?(Ohai) Chef::Knife::ClientCreate.load_deps Chef::Knife::UserCreate.load_deps end @@ -138,7 +138,7 @@ class Chef # @return [String] the path to the user's .chef directory def chef_config_path - @chef_config_path ||= Chef::Util::PathHelper.home(".chef") + @chef_config_path ||= ChefConfig::PathHelper.home(".chef") end # @return [String] the full path to the config file (credential file) diff --git a/lib/chef/knife/cookbook_bulk_delete.rb b/lib/chef/knife/cookbook_bulk_delete.rb index d6657ccb4f..d294db842c 100644 --- a/lib/chef/knife/cookbook_bulk_delete.rb +++ b/lib/chef/knife/cookbook_bulk_delete.rb @@ -25,7 +25,7 @@ class Chef deps do require_relative "cookbook_delete" - require_relative "../cookbook_version" + require "chef/cookbook_version" unless defined?(Chef::CookbookVersion) end option :purge, short: "-p", long: "--purge", boolean: true, description: "Permanently remove files from backing data store." diff --git a/lib/chef/knife/cookbook_delete.rb b/lib/chef/knife/cookbook_delete.rb index 04ecb95cf4..fac23ae336 100644 --- a/lib/chef/knife/cookbook_delete.rb +++ b/lib/chef/knife/cookbook_delete.rb @@ -25,7 +25,7 @@ class Chef attr_accessor :cookbook_name, :version deps do - require_relative "../cookbook_version" + require "chef/cookbook_version" unless defined?(Chef::CookbookVersion) end option :all, short: "-a", long: "--all", boolean: true, description: "Delete all versions of the cookbook." diff --git a/lib/chef/knife/cookbook_download.rb b/lib/chef/knife/cookbook_download.rb index a07b519511..dcf7299901 100644 --- a/lib/chef/knife/cookbook_download.rb +++ b/lib/chef/knife/cookbook_download.rb @@ -27,7 +27,7 @@ class Chef attr_accessor :cookbook_name deps do - require_relative "../cookbook_version" + require "chef/cookbook_version" unless defined?(Chef::CookbookVersion) end banner "knife cookbook download COOKBOOK [VERSION] (options)" diff --git a/lib/chef/knife/cookbook_metadata.rb b/lib/chef/knife/cookbook_metadata.rb index 8d8970b1c1..854e7a6609 100644 --- a/lib/chef/knife/cookbook_metadata.rb +++ b/lib/chef/knife/cookbook_metadata.rb @@ -23,8 +23,8 @@ class Chef class CookbookMetadata < Knife deps do - require_relative "../cookbook_loader" - require_relative "../cookbook/metadata" + require "chef/cookbook_loader" unless defined?(Chef::CookbookLoader) + require "chef/cookbook/metadata" unless defined?(Chef::Cookbook::Metadata) end banner "knife cookbook metadata COOKBOOK (options)" diff --git a/lib/chef/knife/cookbook_metadata_from_file.rb b/lib/chef/knife/cookbook_metadata_from_file.rb index d768213384..77a141d426 100644 --- a/lib/chef/knife/cookbook_metadata_from_file.rb +++ b/lib/chef/knife/cookbook_metadata_from_file.rb @@ -25,7 +25,7 @@ class Chef class CookbookMetadataFromFile < Knife deps do - require_relative "../cookbook/metadata" + require "chef/cookbook/metadata" unless defined?(Chef::Cookbook::Metadata) end banner "knife cookbook metadata from file FILE (options)" diff --git a/lib/chef/knife/cookbook_show.rb b/lib/chef/knife/cookbook_show.rb index 0b97fba139..aac26447b9 100644 --- a/lib/chef/knife/cookbook_show.rb +++ b/lib/chef/knife/cookbook_show.rb @@ -23,9 +23,9 @@ class Chef class CookbookShow < Knife deps do - require_relative "../json_compat" + require "chef/json_compat" unless defined?(Chef::JSONCompat) require "uri" unless defined?(URI) - require_relative "../cookbook_version" + require "chef/cookbook_version" unless defined?(Chef::CookbookVersion) end banner "knife cookbook show COOKBOOK [VERSION] [PART] [FILENAME] (options)" diff --git a/lib/chef/knife/cookbook_upload.rb b/lib/chef/knife/cookbook_upload.rb index 9f6f3c4cb2..d9582a3ccc 100644 --- a/lib/chef/knife/cookbook_upload.rb +++ b/lib/chef/knife/cookbook_upload.rb @@ -24,11 +24,11 @@ class Chef class Knife class CookbookUpload < Knife deps do - require_relative "../mixin/file_class" + require "chef/mixin/file_class" unless defined?(Chef::Mixin::FileClass) include Chef::Mixin::FileClass - require_relative "../exceptions" - require_relative "../cookbook_loader" - require_relative "../cookbook_uploader" + require "chef/exceptions" unless defined?(Chef::Exceptions) + require "chef/cookbook_loader" unless defined?(Chef::CookbookLoader) + require "chef/cookbook_uploader" unless defined?(Chef::CookbookUploader) end banner "knife cookbook upload [COOKBOOKS...] (options)" diff --git a/lib/chef/knife/core/bootstrap_context.rb b/lib/chef/knife/core/bootstrap_context.rb index 9aa81da82f..0d71aa8dc3 100644 --- a/lib/chef/knife/core/bootstrap_context.rb +++ b/lib/chef/knife/core/bootstrap_context.rb @@ -16,8 +16,8 @@ # limitations under the License. # -require_relative "../../run_list" -require_relative "../../util/path_helper" +require "run_list" unless defined?(Chef::RunList) +require "chef-config/path_helper" unless defined?(ChefConfig::PathHelper) require "pathname" unless defined?(Pathname) require "chef-utils/dist" unless defined?(ChefUtils::Dist) @@ -230,7 +230,7 @@ class Chef def trusted_certs_content content = "" if chef_config[:trusted_certs_dir] - Dir.glob(File.join(Chef::Util::PathHelper.escape_glob_dir(chef_config[:trusted_certs_dir]), "*.{crt,pem}")).each do |cert| + Dir.glob(File.join(ChefConfig::PathHelper.escape_glob_dir(chef_config[:trusted_certs_dir]), "*.{crt,pem}")).each do |cert| content << "cat > /etc/chef/trusted_certs/#{File.basename(cert)} <<'EOP'\n" + IO.read(File.expand_path(cert)) + "\nEOP\n" end diff --git a/lib/chef/knife/core/cookbook_scm_repo.rb b/lib/chef/knife/core/cookbook_scm_repo.rb index ba194a8a6d..921dadad8b 100644 --- a/lib/chef/knife/core/cookbook_scm_repo.rb +++ b/lib/chef/knife/core/cookbook_scm_repo.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require_relative "../../mixin/shell_out" +require "chef/mixin/shell_out" unless defined?(Chef::Mixin::ShellOut) class Chef class Knife diff --git a/lib/chef/knife/core/gem_glob_loader.rb b/lib/chef/knife/core/gem_glob_loader.rb index d058379e71..921136402f 100644 --- a/lib/chef/knife/core/gem_glob_loader.rb +++ b/lib/chef/knife/core/gem_glob_loader.rb @@ -16,8 +16,8 @@ # limitations under the License. # -require_relative "../../version" -require_relative "../../util/path_helper" +require_relative "../version" +require "chef-config/path_helper" unless defined?(ChefConfig::PathHelper) class Chef class Knife class SubcommandLoader @@ -45,22 +45,24 @@ class Chef find_subcommands_via_dirglob end - def find_subcommands_via_dirglob - # The "require paths" of the core knife subcommands bundled with chef - files = Dir[File.join(Chef::Util::PathHelper.escape_glob_dir(File.expand_path("../../knife", __dir__)), "*.rb")] - subcommand_files = {} - files.each do |knife_file| - rel_path = knife_file[/#{CHEF_ROOT}#{Regexp.escape(File::SEPARATOR)}(.*)\.rb/, 1] - subcommand_files[rel_path] = knife_file - end - subcommand_files - end + # This is already inherited from subcommandloader, and it is identical. + # def find_subcommands_via_dirglob + # # The "require paths" of the core knife subcommands bundled with chef + # files = Dir[File.join(ChefConfig::PathHelper.escape_glob_dir(File.expand_path("../../knife", __dir__)), "*.rb")] + # subcommand_files = {} + # files.each do |knife_file| + # rel_path = knife_file[/#{KNIFE_ROOT}#{Regexp.escape(File::SEPARATOR)}(.*)\.rb/, 1] + # subcommand_files[rel_path] = knife_file + # end + # subcommand_files + # end def find_subcommands_via_rubygems files = find_files_latest_gems "chef/knife/*.rb" subcommand_files = {} files.each do |file| - rel_path = file[/(#{Regexp.escape File.join('chef', 'knife', '')}.*)\.rb/, 1] + + rel_path = file[/(.*)(#{Regexp.escape File.join('chef', 'knife', '')}.*)\.rb/, 2] # When not installed as a gem (ChefDK/appbundler in particular), AND # a different version of Chef is installed via gems, `files` will @@ -82,8 +84,9 @@ class Chef if check_load_path files = $LOAD_PATH.map do |load_path| - Dir["#{File.expand_path glob, Chef::Util::PathHelper.escape_glob_dir(load_path)}#{Gem.suffix_pattern}"] + Dir["#{File.expand_path glob, ChefConfig::PathHelper.escape_glob_dir(load_path)}#{Gem.suffix_pattern}"] end.flatten.select { |file| File.file? file.untaint } + end gem_files = latest_gem_specs.map do |spec| @@ -116,7 +119,7 @@ class Chef spec.require_paths.first end - glob = File.join(Chef::Util::PathHelper.escape_glob_dir(spec.full_gem_path, dirs), glob) + glob = File.join(ChefConfig::PathHelper.escape_glob_dir(spec.full_gem_path, dirs), glob) Dir[glob].map(&:untaint) end diff --git a/lib/chef/knife/core/hashed_command_loader.rb b/lib/chef/knife/core/hashed_command_loader.rb index c1d71f3edf..e419037b67 100644 --- a/lib/chef/knife/core/hashed_command_loader.rb +++ b/lib/chef/knife/core/hashed_command_loader.rb @@ -15,7 +15,7 @@ # limitations under the License. # -require_relative "../../version" +require_relative "../version" class Chef class Knife class SubcommandLoader diff --git a/lib/chef/knife/core/node_editor.rb b/lib/chef/knife/core/node_editor.rb index 2f9b326d16..5980cd888e 100644 --- a/lib/chef/knife/core/node_editor.rb +++ b/lib/chef/knife/core/node_editor.rb @@ -17,8 +17,8 @@ # limitations under the License. # -require_relative "../../json_compat" -require_relative "../../node" +require "chef/json_compat" unless defined?(Chef::JSONCompat) +require "chef/node" unless defined?(Chef::Node) class Chef class Knife diff --git a/lib/chef/knife/core/object_loader.rb b/lib/chef/knife/core/object_loader.rb index 5421fc46ce..edd8921c11 100644 --- a/lib/chef/knife/core/object_loader.rb +++ b/lib/chef/knife/core/object_loader.rb @@ -17,8 +17,8 @@ # autoload :FFI_Yajl, "ffi_yajl" -require_relative "../../util/path_helper" -require_relative "../../data_bag_item" +require "chef-config/path_helper" unless defined?(ChefConfig::PathHelper) +require "chef/data_bag_item" unless defined?(Chef::DataBagItem) class Chef class Knife @@ -40,6 +40,7 @@ class Chef def load_from(repo_location, *components) unless object_file = find_file(repo_location, *components) + puts "ZZZ LOoking for: #{repo_location} #{components}" ui.error "Could not find or open file '#{components.last}' in current directory or in '#{repo_location}/#{components.join("/")}'" exit 1 end @@ -71,14 +72,14 @@ class Chef # # @api public def find_all_objects(path) - path = File.join(Chef::Util::PathHelper.escape_glob_dir(File.expand_path(path)), "*") + path = File.join(ChefConfig::PathHelper.escape_glob_dir(File.expand_path(path)), "*") path << ".{json,rb}" objects = Dir.glob(path) objects.map { |o| File.basename(o) } end def find_all_object_dirs(path) - path = File.join(Chef::Util::PathHelper.escape_glob_dir(File.expand_path(path)), "*") + path = File.join(ChefConfig::PathHelper.escape_glob_dir(File.expand_path(path)), "*") objects = Dir.glob(path) objects.delete_if { |o| !File.directory?(o) } objects.map { |o| File.basename(o) } diff --git a/lib/chef/knife/core/subcommand_loader.rb b/lib/chef/knife/core/subcommand_loader.rb index 26d7e0277c..6f72c61a5e 100644 --- a/lib/chef/knife/core/subcommand_loader.rb +++ b/lib/chef/knife/core/subcommand_loader.rb @@ -16,8 +16,10 @@ # limitations under the License. # -require_relative "../../version" -require_relative "../../util/path_helper" +require_relative "../version" +require "chef-config/path_helper" unless defined?(ChefConfig::PathHelper) +# MPTD - track down why I added this/if it's needed? +require "chef/run_list" unless defined?(Chef::RunList) require_relative "gem_glob_loader" require_relative "hashed_command_loader" @@ -72,7 +74,7 @@ class Chef end def self.plugin_manifest_path - Chef::Util::PathHelper.home(".chef", "plugin_manifest.json") + ChefConfig::PathHelper.home(".chef", "plugin_manifest.json") end def self.generate_hash @@ -141,13 +143,12 @@ class Chef # # This is shared between the custom_manifest_loader and the gem_glob_loader - # def find_subcommands_via_dirglob # The "require paths" of the core knife subcommands bundled with chef - files = Dir[File.join(Chef::Util::PathHelper.escape_glob_dir(File.expand_path("../../knife", __dir__)), "*.rb")] + files = Dir[File.join(ChefConfig::PathHelper.escape_glob_dir(File.expand_path("../../knife", __dir__)), "*.rb")] subcommand_files = {} files.each do |knife_file| - rel_path = knife_file[/#{CHEF_ROOT}#{Regexp.escape(File::SEPARATOR)}(.*)\.rb/, 1] + rel_path = knife_file[/#{KNIFE_ROOT}#{Regexp.escape(File::SEPARATOR)}(.*)\.rb/, 1] subcommand_files[rel_path] = knife_file end subcommand_files @@ -188,12 +189,12 @@ class Chef user_specific_files = [] if chef_config_dir - user_specific_files.concat Dir.glob(File.expand_path("plugins/knife/*.rb", Chef::Util::PathHelper.escape_glob_dir(chef_config_dir))) + user_specific_files.concat Dir.glob(File.expand_path("plugins/knife/*.rb", ChefConfig::PathHelper.escape_glob_dir(chef_config_dir))) end # finally search ~/.chef/plugins/knife/*.rb - Chef::Util::PathHelper.home(".chef", "plugins", "knife") do |p| - user_specific_files.concat Dir.glob(File.join(Chef::Util::PathHelper.escape_glob_dir(p), "*.rb")) + ChefConfig::PathHelper.home(".chef", "plugins", "knife") do |p| + user_specific_files.concat Dir.glob(File.join(ChefConfig::PathHelper.escape_glob_dir(p), "*.rb")) end user_specific_files diff --git a/lib/chef/knife/core/ui.rb b/lib/chef/knife/core/ui.rb index aa84537064..8828df1770 100644 --- a/lib/chef/knife/core/ui.rb +++ b/lib/chef/knife/core/ui.rb @@ -19,7 +19,7 @@ # require "forwardable" unless defined?(Forwardable) -require_relative "../../platform/query_helpers" +require "chef/platform/query_helpers" # MPTD - can't base on defined? because there's no constant added there. require_relative "generic_presenter" require "tempfile" unless defined?(Tempfile) diff --git a/lib/chef/knife/core/windows_bootstrap_context.rb b/lib/chef/knife/core/windows_bootstrap_context.rb index fa8b43f383..0ff209a0b7 100644 --- a/lib/chef/knife/core/windows_bootstrap_context.rb +++ b/lib/chef/knife/core/windows_bootstrap_context.rb @@ -17,7 +17,7 @@ # require_relative "bootstrap_context" -require_relative "../../util/path_helper" +require "chef-config/path_helper" unless defined?(ChefConfig::PathHelper) require "chef-utils/dist" unless defined?(ChefUtils::Dist) class Chef @@ -331,7 +331,7 @@ class Chef def trusted_certs_content content = "" if chef_config[:trusted_certs_dir] - Dir.glob(File.join(Chef::Util::PathHelper.escape_glob_dir(chef_config[:trusted_certs_dir]), "*.{crt,pem}")).each do |cert| + Dir.glob(File.join(ChefConfig::PathHelper.escape_glob_dir(chef_config[:trusted_certs_dir]), "*.{crt,pem}")).each do |cert| content << "> #{bootstrap_directory}/trusted_certs/#{File.basename(cert)} (\n" + escape_and_echo(IO.read(File.expand_path(cert))) + "\n)\n" end diff --git a/lib/chef/knife/data_bag_create.rb b/lib/chef/knife/data_bag_create.rb index 11448c69b7..a8a9caf7e4 100644 --- a/lib/chef/knife/data_bag_create.rb +++ b/lib/chef/knife/data_bag_create.rb @@ -26,8 +26,8 @@ class Chef include DataBagSecretOptions deps do - require_relative "../data_bag" - require_relative "../encrypted_data_bag_item" + require "chef/data_bag" unless defined?(Chef::DataBag) + require "chef/encrypted_data_bag_item" unless defined?(Chef::EncryptedDataBagItem) end banner "knife data bag create BAG [ITEM] (options)" diff --git a/lib/chef/knife/data_bag_delete.rb b/lib/chef/knife/data_bag_delete.rb index ab38244e91..a7b5a4b6fd 100644 --- a/lib/chef/knife/data_bag_delete.rb +++ b/lib/chef/knife/data_bag_delete.rb @@ -23,7 +23,7 @@ class Chef class DataBagDelete < Knife deps do - require_relative "../data_bag" + require "chef/data_bag" unless defined?(Chef::DataBag) end banner "knife data bag delete BAG [ITEM] (options)" diff --git a/lib/chef/knife/data_bag_edit.rb b/lib/chef/knife/data_bag_edit.rb index 1935f2149e..92bff8d7f7 100644 --- a/lib/chef/knife/data_bag_edit.rb +++ b/lib/chef/knife/data_bag_edit.rb @@ -26,8 +26,8 @@ class Chef include DataBagSecretOptions deps do - require_relative "../data_bag_item" - require_relative "../encrypted_data_bag_item" + require "chef/data_bag_item" unless defined?(Chef::DataBagItem) + require "chef/encrypted_data_bag_item" unless defined?(Chef::EncryptedDataBagItem) end banner "knife data bag edit BAG ITEM (options)" diff --git a/lib/chef/knife/data_bag_from_file.rb b/lib/chef/knife/data_bag_from_file.rb index 5f48b0a934..6c889e1927 100644 --- a/lib/chef/knife/data_bag_from_file.rb +++ b/lib/chef/knife/data_bag_from_file.rb @@ -26,11 +26,11 @@ class Chef include DataBagSecretOptions deps do - require_relative "../util/path_helper" - require_relative "../data_bag" - require_relative "../data_bag_item" + require "chef-config/path_helper" unless defined?(ChefConfig::PathHelper) + require "chef/data_bag" unless defined?(Chef::DataBag) + require "chef/data_bag_item" unless defined?(Chef::DataBagItem) + require "chef/encrypted_data_bag_item" unless defined?(Chef::EncryptedDataBagItem) require_relative "core/object_loader" - require_relative "../encrypted_data_bag_item" end banner "knife data bag from file BAG FILE|FOLDER [FILE|FOLDER..] (options)" @@ -42,7 +42,7 @@ class Chef description: "Upload all data bags or all items for specified data bags." def loader - @loader ||= Knife::Core::ObjectLoader.new(DataBagItem, ui) + @loader ||= Knife::Core::ObjectLoader.new(Chef::DataBagItem, ui) end def run @@ -101,7 +101,7 @@ class Chef paths = [] args.each do |path| if File.directory?(path) - paths.concat(Dir.glob(File.join(Chef::Util::PathHelper.escape_glob_dir(path), "*.json"))) + paths.concat(Dir.glob(File.join(ChefConfig::PathHelper.escape_glob_dir(path), "*.json"))) else paths << path end diff --git a/lib/chef/knife/data_bag_list.rb b/lib/chef/knife/data_bag_list.rb index 801bf588b4..8a8e7ba89d 100644 --- a/lib/chef/knife/data_bag_list.rb +++ b/lib/chef/knife/data_bag_list.rb @@ -23,7 +23,7 @@ class Chef class DataBagList < Knife deps do - require_relative "../data_bag" + require "chef/data_bag" unless defined?(Chef::DataBag) end banner "knife data bag list (options)" diff --git a/lib/chef/knife/data_bag_secret_options.rb b/lib/chef/knife/data_bag_secret_options.rb index 8f9f96502f..4d8ba90929 100644 --- a/lib/chef/knife/data_bag_secret_options.rb +++ b/lib/chef/knife/data_bag_secret_options.rb @@ -17,8 +17,8 @@ # require "mixlib/cli" unless defined?(Mixlib::CLI) -require_relative "../config" -require_relative "../encrypted_data_bag_item/check_encrypted" +require "chef/config" unless defined?(Chef::Config) +require "encrypted_data_bag_item/check_encrypted" unless defined?(Chef::EncryptedDataBagItem::CheckEncrypted) class Chef class Knife @@ -60,7 +60,7 @@ class Chef def read_secret # Moving the non 'compile-time' requires into here to speed up knife command loading # IE, if we are not running 'knife data bag *' we don't need to load 'chef/encrypted_data_bag_item' - require_relative "../encrypted_data_bag_item" + require "chef/encrypted_data_bag_item" unless defined?(Chef::EncryptedDataBagItem) if config[:cl_secret] config[:cl_secret] diff --git a/lib/chef/knife/data_bag_show.rb b/lib/chef/knife/data_bag_show.rb index cb7b56c333..3270f45ee2 100644 --- a/lib/chef/knife/data_bag_show.rb +++ b/lib/chef/knife/data_bag_show.rb @@ -26,8 +26,8 @@ class Chef include DataBagSecretOptions deps do - require_relative "../data_bag" - require_relative "../encrypted_data_bag_item" + require "chef/data_bag" unless defined?(Chef::DataBag) + require "chef/encrypted_data_bag_item" unless defined?(Chef::EncryptedDataBagItem) end banner "knife data bag show BAG [ITEM] (options)" diff --git a/lib/chef/knife/delete.rb b/lib/chef/knife/delete.rb index 3e5c545017..2853efc21c 100644 --- a/lib/chef/knife/delete.rb +++ b/lib/chef/knife/delete.rb @@ -24,7 +24,7 @@ class Chef category "path-based" deps do - require_relative "../chef_fs/file_system" + require "chef/chef_fs/file_system" unless defined?(Chef::ChefFS::FileSystem) end option :recurse, diff --git a/lib/chef/knife/deps.rb b/lib/chef/knife/deps.rb index f620b53bfa..fd419f15f9 100644 --- a/lib/chef/knife/deps.rb +++ b/lib/chef/knife/deps.rb @@ -14,7 +14,7 @@ # limitations under the License. # -require_relative "../chef_fs/knife" +require_relative "../chef_fs/knife" unless defined?(Chef::ChefFS::Knife) class Chef class Knife @@ -24,8 +24,8 @@ class Chef category "path-based" deps do - require_relative "../chef_fs/file_system" - require_relative "../run_list" + require "chef/chef_fs/file_system" unless defined?(Chef::ChefFS::FileSystem) + require "chef/run_list" unless defined?(Chef::RunList) end option :recurse, diff --git a/lib/chef/knife/diff.rb b/lib/chef/knife/diff.rb index 3e9336aacc..971f7aa7f4 100644 --- a/lib/chef/knife/diff.rb +++ b/lib/chef/knife/diff.rb @@ -24,7 +24,7 @@ class Chef category "path-based" deps do - require_relative "../chef_fs/command_line" + require "chef/chef_fs/command_line" unless defined?(Chef::ChefFS::CommandLine) end option :recurse, diff --git a/lib/chef/knife/download.rb b/lib/chef/knife/download.rb index ab8c92a1c0..2eda642979 100644 --- a/lib/chef/knife/download.rb +++ b/lib/chef/knife/download.rb @@ -24,7 +24,7 @@ class Chef category "path-based" deps do - require_relative "../chef_fs/command_line" + require "chef/chef_fs/command_line" unless defined?(Chef::ChefFS::CommandLine) end option :recurse, diff --git a/lib/chef/knife/edit.rb b/lib/chef/knife/edit.rb index caca201566..45702d168b 100644 --- a/lib/chef/knife/edit.rb +++ b/lib/chef/knife/edit.rb @@ -24,8 +24,8 @@ class Chef category "path-based" deps do - require_relative "../chef_fs/file_system" - require_relative "../chef_fs/file_system/exceptions" + require "chef/chef_fs/file_system" unless defined?(Chef::ChefFS::FileSystem) + require "chef/chef_fs/file_system/exceptions" unless defined?(Chef::ChefFS::FileSystem::Exceptions) end option :local, diff --git a/lib/chef/knife/environment_compare.rb b/lib/chef/knife/environment_compare.rb index 22abee59c8..532d1fc159 100644 --- a/lib/chef/knife/environment_compare.rb +++ b/lib/chef/knife/environment_compare.rb @@ -23,7 +23,7 @@ class Chef class EnvironmentCompare < Knife deps do - require_relative "../environment" + require "chef/environment" unless defined?(Chef::Environment) end banner "knife environment compare [ENVIRONMENT..] (options)" diff --git a/lib/chef/knife/environment_create.rb b/lib/chef/knife/environment_create.rb index a724f72d4f..cfb36957d4 100644 --- a/lib/chef/knife/environment_create.rb +++ b/lib/chef/knife/environment_create.rb @@ -23,7 +23,7 @@ class Chef class EnvironmentCreate < Knife deps do - require_relative "../environment" + require "chef/environment" unless defined?(Chef::Environment) end banner "knife environment create ENVIRONMENT (options)" diff --git a/lib/chef/knife/environment_delete.rb b/lib/chef/knife/environment_delete.rb index ec1b7cb8d8..65e5a1eb5c 100644 --- a/lib/chef/knife/environment_delete.rb +++ b/lib/chef/knife/environment_delete.rb @@ -23,7 +23,7 @@ class Chef class EnvironmentDelete < Knife deps do - require_relative "../environment" + require "chef/environment" unless defined?(Chef::Environment) end banner "knife environment delete ENVIRONMENT (options)" diff --git a/lib/chef/knife/environment_edit.rb b/lib/chef/knife/environment_edit.rb index 7c6105a6c0..f2ad842069 100644 --- a/lib/chef/knife/environment_edit.rb +++ b/lib/chef/knife/environment_edit.rb @@ -23,7 +23,7 @@ class Chef class EnvironmentEdit < Knife deps do - require_relative "../environment" + require "chef/environment" unless defined?(Chef::Environment) end banner "knife environment edit ENVIRONMENT (options)" diff --git a/lib/chef/knife/environment_from_file.rb b/lib/chef/knife/environment_from_file.rb index a5011a3abf..4b84abd073 100644 --- a/lib/chef/knife/environment_from_file.rb +++ b/lib/chef/knife/environment_from_file.rb @@ -23,7 +23,7 @@ class Chef class EnvironmentFromFile < Knife deps do - require_relative "../environment" + require "chef/environment" unless defined?(Chef::Environment) require_relative "core/object_loader" end diff --git a/lib/chef/knife/environment_list.rb b/lib/chef/knife/environment_list.rb index 7bcdeb6084..7076670fb5 100644 --- a/lib/chef/knife/environment_list.rb +++ b/lib/chef/knife/environment_list.rb @@ -23,7 +23,7 @@ class Chef class EnvironmentList < Knife deps do - require_relative "../environment" + require "chef/environment" unless defined?(Chef::Environment) end banner "knife environment list (options)" diff --git a/lib/chef/knife/environment_show.rb b/lib/chef/knife/environment_show.rb index e336b2d392..0a4000151e 100644 --- a/lib/chef/knife/environment_show.rb +++ b/lib/chef/knife/environment_show.rb @@ -25,7 +25,7 @@ class Chef include Knife::Core::MultiAttributeReturnOption deps do - require_relative "../environment" + require "chef/environment" unless defined?(Chef::Environment) end banner "knife environment show ENVIRONMENT (options)" diff --git a/lib/chef/knife/exec.rb b/lib/chef/knife/exec.rb index d3ce2cee24..3c2f6e5d29 100644 --- a/lib/chef/knife/exec.rb +++ b/lib/chef/knife/exec.rb @@ -24,7 +24,7 @@ class Chef::Knife::Exec < Chef::Knife banner "knife exec [SCRIPT] (options)" deps do - require_relative "../util/path_helper" + require "chef-config/path_helper" unless defined?(ChefConfig::PathHelper) end option :exec, @@ -39,7 +39,7 @@ class Chef::Knife::Exec < Chef::Knife proc: lambda { |o| o.split(":") } deps do - require_relative "../shell/ext" + require "chef/shell/ext" unless defined?(Chef::Shell::Extensions) # MPTD: naming convention mismatch Ext Extensions end def run @@ -47,7 +47,7 @@ class Chef::Knife::Exec < Chef::Knife # Default script paths are chef-repo/.chef/scripts and ~/.chef/scripts config[:script_path] << File.join(Chef::Knife.chef_config_dir, "scripts") if Chef::Knife.chef_config_dir - Chef::Util::PathHelper.home(".chef", "scripts") { |p| config[:script_path] << p } + ChefConfig::PathHelper.home(".chef", "scripts") { |p| config[:script_path] << p } scripts = Array(name_args) context = Object.new diff --git a/lib/chef/knife/key_create.rb b/lib/chef/knife/key_create.rb index 6129cab683..e1baf08bb6 100644 --- a/lib/chef/knife/key_create.rb +++ b/lib/chef/knife/key_create.rb @@ -16,9 +16,9 @@ # limitations under the License. # -require_relative "../key" -require_relative "../json_compat" -require_relative "../exceptions" +require "chef/key" unless defined?(Chef::Key) +require "chef/json_compat" unless defined?(Chef::JSONCompat) +require "chef/exceptions" unless defined?(Chef::Exceptions) class Chef class Knife diff --git a/lib/chef/knife/key_delete.rb b/lib/chef/knife/key_delete.rb index 10f1235924..83b6a8b535 100644 --- a/lib/chef/knife/key_delete.rb +++ b/lib/chef/knife/key_delete.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require_relative "../key" +require "chef/key" unless defined?(Chef::Key) class Chef class Knife diff --git a/lib/chef/knife/key_edit.rb b/lib/chef/knife/key_edit.rb index 3f8918f1a9..25d7b28437 100644 --- a/lib/chef/knife/key_edit.rb +++ b/lib/chef/knife/key_edit.rb @@ -16,9 +16,9 @@ # limitations under the License. # -require_relative "../key" -require_relative "../json_compat" -require_relative "../exceptions" +require "chef/key" unless defined?(Chef::Key) +require "chef/json_compat" unless defined?(Chef::JSONCompat) +require "chef/exceptions" unless defined?(Chef::Exceptions) class Chef class Knife diff --git a/lib/chef/knife/key_list.rb b/lib/chef/knife/key_list.rb index 076b39d251..e01e2807cf 100644 --- a/lib/chef/knife/key_list.rb +++ b/lib/chef/knife/key_list.rb @@ -16,9 +16,9 @@ # limitations under the License. # -require_relative "../key" -require_relative "../json_compat" -require_relative "../exceptions" +require "chef/key" unless defined?(Chef::Key) +require "chef/json_compat" unless defined?(Chef::JSONCompat) +require "chef/exceptions" unless defined?(Chef::Exceptions) class Chef class Knife diff --git a/lib/chef/knife/key_show.rb b/lib/chef/knife/key_show.rb index 8b3d980004..719e79fc17 100644 --- a/lib/chef/knife/key_show.rb +++ b/lib/chef/knife/key_show.rb @@ -16,9 +16,9 @@ # limitations under the License. # -require_relative "../key" -require_relative "../json_compat" -require_relative "../exceptions" +require "chef/key" unless defined?(Chef::Key) +require "chef/json_compat" unless defined?(Chef::JSONCompat) +require "chef/exceptions" unless defined?(Chef::Exceptions) class Chef class Knife diff --git a/lib/chef/knife/list.rb b/lib/chef/knife/list.rb index 1cc398e01a..7fc2231c5f 100644 --- a/lib/chef/knife/list.rb +++ b/lib/chef/knife/list.rb @@ -24,7 +24,7 @@ class Chef category "path-based" deps do - require_relative "../chef_fs/file_system" + require "chef/chef_fs/file_system" unless defined?(Chef::ChefFS::FileSystem) require "tty-screen" end diff --git a/lib/chef/knife/node_bulk_delete.rb b/lib/chef/knife/node_bulk_delete.rb index 874509b730..73975eebc7 100644 --- a/lib/chef/knife/node_bulk_delete.rb +++ b/lib/chef/knife/node_bulk_delete.rb @@ -23,8 +23,8 @@ class Chef class NodeBulkDelete < Knife deps do - require_relative "../node" - require_relative "../json_compat" + require "chef/node" unless defined?(Chef::Node) + require "chef/json_compat" unless defined?(Chef::JSONCompat) end banner "knife node bulk delete REGEX (options)" diff --git a/lib/chef/knife/node_create.rb b/lib/chef/knife/node_create.rb index c0db667b25..ed82cbe7aa 100644 --- a/lib/chef/knife/node_create.rb +++ b/lib/chef/knife/node_create.rb @@ -23,8 +23,8 @@ class Chef class NodeCreate < Knife deps do - require_relative "../node" - require_relative "../json_compat" + require "chef/node" unless defined?(Chef::Node) + require "chef/json_compat" unless defined?(Chef::JSONCompat) end banner "knife node create NODE (options)" diff --git a/lib/chef/knife/node_delete.rb b/lib/chef/knife/node_delete.rb index 7c0c6f0a21..605d99b57f 100644 --- a/lib/chef/knife/node_delete.rb +++ b/lib/chef/knife/node_delete.rb @@ -23,8 +23,8 @@ class Chef class NodeDelete < Knife deps do - require_relative "../node" - require_relative "../json_compat" + require "chef/node" unless defined?(Chef::Node) + require "chef/json_compat" unless defined?(Chef::JSONCompat) end banner "knife node delete [NODE [NODE]] (options)" diff --git a/lib/chef/knife/node_edit.rb b/lib/chef/knife/node_edit.rb index a2585391ea..ebc98f5bff 100644 --- a/lib/chef/knife/node_edit.rb +++ b/lib/chef/knife/node_edit.rb @@ -24,8 +24,8 @@ class Chef class NodeEdit < Knife deps do - require_relative "../node" - require_relative "../json_compat" + require "chef/node" unless defined?(Chef::Node) + require "chef/json_compat" unless defined?(Chef::JSONCompat) require_relative "core/node_editor" end diff --git a/lib/chef/knife/node_environment_set.rb b/lib/chef/knife/node_environment_set.rb index 644b6138b6..84d5b3969b 100644 --- a/lib/chef/knife/node_environment_set.rb +++ b/lib/chef/knife/node_environment_set.rb @@ -23,7 +23,7 @@ class Chef class NodeEnvironmentSet < Knife deps do - require_relative "../node" + require "chef/node" unless defined?(Chef::Node) end banner "knife node environment set NODE ENVIRONMENT" diff --git a/lib/chef/knife/node_from_file.rb b/lib/chef/knife/node_from_file.rb index 86d602ae7c..4f1935641a 100644 --- a/lib/chef/knife/node_from_file.rb +++ b/lib/chef/knife/node_from_file.rb @@ -23,8 +23,8 @@ class Chef class NodeFromFile < Knife deps do - require_relative "../node" - require_relative "../json_compat" + require "chef/node" unless defined?(Chef::Node) + require "chef/json_compat" unless defined?(Chef::JSONCompat) require_relative "core/object_loader" end diff --git a/lib/chef/knife/node_list.rb b/lib/chef/knife/node_list.rb index a8b57aedc5..6aae4a617d 100644 --- a/lib/chef/knife/node_list.rb +++ b/lib/chef/knife/node_list.rb @@ -23,8 +23,8 @@ class Chef class NodeList < Knife deps do - require_relative "../node" - require_relative "../json_compat" + require "chef/node" unless defined?(Chef::Node) + require "chef/json_compat" unless defined?(Chef::JSONCompat) end banner "knife node list (options)" diff --git a/lib/chef/knife/node_policy_set.rb b/lib/chef/knife/node_policy_set.rb index d34ebd9478..3f55529b3d 100644 --- a/lib/chef/knife/node_policy_set.rb +++ b/lib/chef/knife/node_policy_set.rb @@ -23,8 +23,8 @@ class Chef class NodePolicySet < Knife deps do - require_relative "../node" - require_relative "../json_compat" + require "chef/node" unless defined?(Chef::Node) + require "chef/json_compat" unless defined?(Chef::JSONCompat) end banner "knife node policy set NODE POLICY_GROUP POLICY_NAME (options)" diff --git a/lib/chef/knife/node_run_list_add.rb b/lib/chef/knife/node_run_list_add.rb index 40476371eb..695344496a 100644 --- a/lib/chef/knife/node_run_list_add.rb +++ b/lib/chef/knife/node_run_list_add.rb @@ -23,8 +23,8 @@ class Chef class NodeRunListAdd < Knife deps do - require_relative "../node" - require_relative "../json_compat" + require "chef/node" unless defined?(Chef::Node) + require "chef/json_compat" unless defined?(Chef::JSONCompat) end banner "knife node run_list add [NODE] [ENTRY [ENTRY]] (options)" diff --git a/lib/chef/knife/node_run_list_remove.rb b/lib/chef/knife/node_run_list_remove.rb index 484e575475..0c88f8c184 100644 --- a/lib/chef/knife/node_run_list_remove.rb +++ b/lib/chef/knife/node_run_list_remove.rb @@ -23,8 +23,8 @@ class Chef class NodeRunListRemove < Knife deps do - require_relative "../node" - require_relative "../json_compat" + require "chef/node" unless defined?(Chef::Node) + require "chef/json_compat" unless defined?(Chef::JSONCompat) end banner "knife node run_list remove [NODE] [ENTRY [ENTRY]] (options)" diff --git a/lib/chef/knife/node_run_list_set.rb b/lib/chef/knife/node_run_list_set.rb index f356b39d95..37b9aef3d6 100644 --- a/lib/chef/knife/node_run_list_set.rb +++ b/lib/chef/knife/node_run_list_set.rb @@ -23,8 +23,8 @@ class Chef class NodeRunListSet < Knife deps do - require_relative "../node" - require_relative "../json_compat" + require "chef/node" unless defined?(Chef::Node) + require "chef/json_compat" unless defined?(Chef::JSONCompat) end banner "knife node run_list set NODE ENTRIES (options)" diff --git a/lib/chef/knife/node_show.rb b/lib/chef/knife/node_show.rb index 173348dc41..bce2ee3fe9 100644 --- a/lib/chef/knife/node_show.rb +++ b/lib/chef/knife/node_show.rb @@ -29,8 +29,8 @@ class Chef include Knife::Core::MultiAttributeReturnOption deps do - require_relative "../node" - require_relative "../json_compat" + require "chef/node" unless defined?(Chef::Node) + require "chef/json_compat" unless defined?(Chef::JSONCompat) end banner "knife node show NODE (options)" diff --git a/lib/chef/knife/org_create.rb b/lib/chef/knife/org_create.rb index 3c1354ae22..cb5ded26f5 100644 --- a/lib/chef/knife/org_create.rb +++ b/lib/chef/knife/org_create.rb @@ -35,7 +35,7 @@ class Chef attr_accessor :org_name, :org_full_name deps do - require_relative "../org" + require "chef/org" unless defined?(Chef::Org) end def run diff --git a/lib/chef/knife/org_user_remove.rb b/lib/chef/knife/org_user_remove.rb index 50a1471443..fc78f5767c 100644 --- a/lib/chef/knife/org_user_remove.rb +++ b/lib/chef/knife/org_user_remove.rb @@ -29,8 +29,8 @@ class Chef description: "Force removal of user from the organization's admins and billing-admins group." deps do - require_relative "../org" - require "chef/json_compat" + require "chef/org" unless defined?(Chef::Org) + require "chef/json_compat" unless defined?(Chef::JSONCompat) end def run diff --git a/lib/chef/knife/raw.rb b/lib/chef/knife/raw.rb index 5adb36ea70..d288e3f3e4 100644 --- a/lib/chef/knife/raw.rb +++ b/lib/chef/knife/raw.rb @@ -22,13 +22,14 @@ class Chef banner "knife raw REQUEST_PATH (options)" deps do - require_relative "../json_compat" - require_relative "../config" - require_relative "../http" - require_relative "../http/authenticator" - require_relative "../http/cookie_manager" - require_relative "../http/decompressor" - require_relative "../http/json_output" + require "chef/json_compat" unless defined?(Chef::JSONCompat) + require "chef/config" unless defined?(Chef::Config) + # MPTD - most of these are alrady included via ../knife + require "chef/http" unless defined?(Chef::HTTP) + require "chef/http/authenticator" unless defined?(Chef::HTTP::Authenticator) + require "chef/http/cookie_manager" unless defined?(Chef::HTTP::CookieManager) + require "chef/http/decompressor" unless defined?(Chef::HTTP::Decompressor) + require "chef/http/json_output" unless defined?(Chef::HTTP::JSONOutput) end option :method, diff --git a/lib/chef/knife/role_bulk_delete.rb b/lib/chef/knife/role_bulk_delete.rb index f57ac79619..88399bae2c 100644 --- a/lib/chef/knife/role_bulk_delete.rb +++ b/lib/chef/knife/role_bulk_delete.rb @@ -23,8 +23,8 @@ class Chef class RoleBulkDelete < Knife deps do - require_relative "../role" - require_relative "../json_compat" + require "chef/role" unless defined?(Chef::Role) + require "chef/json_compat" unless defined?(Chef::JSONCompat) end banner "knife role bulk delete REGEX (options)" diff --git a/lib/chef/knife/role_create.rb b/lib/chef/knife/role_create.rb index 295445554d..91ff958fe4 100644 --- a/lib/chef/knife/role_create.rb +++ b/lib/chef/knife/role_create.rb @@ -23,8 +23,8 @@ class Chef class RoleCreate < Knife deps do - require_relative "../role" - require_relative "../json_compat" + require "chef/role" unless defined?(Chef::Role) + require "chef/json_compat" unless defined?(Chef::JSONCompat) end banner "knife role create ROLE (options)" diff --git a/lib/chef/knife/role_delete.rb b/lib/chef/knife/role_delete.rb index c46e265c5e..91ac7d3172 100644 --- a/lib/chef/knife/role_delete.rb +++ b/lib/chef/knife/role_delete.rb @@ -23,8 +23,8 @@ class Chef class RoleDelete < Knife deps do - require_relative "../role" - require_relative "../json_compat" + require "chef/role" unless defined?(Chef::Role) + require "chef/json_compat" unless defined?(Chef::JSONCompat) end banner "knife role delete ROLE (options)" diff --git a/lib/chef/knife/role_edit.rb b/lib/chef/knife/role_edit.rb index 1925336646..a1818019cb 100644 --- a/lib/chef/knife/role_edit.rb +++ b/lib/chef/knife/role_edit.rb @@ -23,8 +23,8 @@ class Chef class RoleEdit < Knife deps do - require_relative "../role" - require_relative "../json_compat" + require "chef/role" unless defined?(Chef::Role) + require "chef/json_compat" unless defined?(Chef::JSONCompat) end banner "knife role edit ROLE (options)" diff --git a/lib/chef/knife/role_env_run_list_add.rb b/lib/chef/knife/role_env_run_list_add.rb index b5753b46fc..a39bdcf5cd 100644 --- a/lib/chef/knife/role_env_run_list_add.rb +++ b/lib/chef/knife/role_env_run_list_add.rb @@ -24,8 +24,8 @@ class Chef class RoleEnvRunListAdd < Knife deps do - require_relative "../role" - require_relative "../json_compat" + require "chef/role" unless defined?(Chef::Role) + require "chef/json_compat" unless defined?(Chef::JSONCompat) end banner "knife role env_run_list add [ROLE] [ENVIRONMENT] [ENTRY [ENTRY]] (options)" diff --git a/lib/chef/knife/role_env_run_list_clear.rb b/lib/chef/knife/role_env_run_list_clear.rb index dda523e809..bb0eeabc16 100644 --- a/lib/chef/knife/role_env_run_list_clear.rb +++ b/lib/chef/knife/role_env_run_list_clear.rb @@ -24,8 +24,8 @@ class Chef class RoleEnvRunListClear < Knife deps do - require_relative "../role" - require_relative "../json_compat" + require "chef/role" unless defined?(Chef::Role) + require "chef/json_compat" unless defined?(Chef::JSONCompat) end banner "knife role env_run_list clear [ROLE] [ENVIRONMENT] (options)" diff --git a/lib/chef/knife/role_env_run_list_remove.rb b/lib/chef/knife/role_env_run_list_remove.rb index 57363610ce..c1a028340b 100644 --- a/lib/chef/knife/role_env_run_list_remove.rb +++ b/lib/chef/knife/role_env_run_list_remove.rb @@ -23,8 +23,8 @@ class Chef class RoleEnvRunListRemove < Knife deps do - require_relative "../role" - require_relative "../json_compat" + require "chef/role" unless defined?(Chef::Role) + require "chef/json_compat" unless defined?(Chef::JSONCompat) end banner "knife role env_run_list remove [ROLE] [ENVIRONMENT] [ENTRIES] (options)" diff --git a/lib/chef/knife/role_env_run_list_replace.rb b/lib/chef/knife/role_env_run_list_replace.rb index e76680661e..923a31331f 100644 --- a/lib/chef/knife/role_env_run_list_replace.rb +++ b/lib/chef/knife/role_env_run_list_replace.rb @@ -24,8 +24,8 @@ class Chef class RoleEnvRunListReplace < Knife deps do - require_relative "../role" - require_relative "../json_compat" + require "chef/role" unless defined?(Chef::Role) + require "chef/json_compat" unless defined?(Chef::JSONCompat) end banner "knife role env_run_list replace [ROLE] [ENVIRONMENT] [OLD_ENTRY] [NEW_ENTRY] (options)" diff --git a/lib/chef/knife/role_env_run_list_set.rb b/lib/chef/knife/role_env_run_list_set.rb index 0f1ce62a5d..55a50c6c0d 100644 --- a/lib/chef/knife/role_env_run_list_set.rb +++ b/lib/chef/knife/role_env_run_list_set.rb @@ -24,8 +24,8 @@ class Chef class RoleEnvRunListSet < Knife deps do - require_relative "../role" - require_relative "../json_compat" + require "chef/role" unless defined?(Chef::Role) + require "chef/json_compat" unless defined?(Chef::JSONCompat) end banner "knife role env_run_list set [ROLE] [ENVIRONMENT] [ENTRIES] (options)" diff --git a/lib/chef/knife/role_from_file.rb b/lib/chef/knife/role_from_file.rb index 16e38eeb63..7b51d8706d 100644 --- a/lib/chef/knife/role_from_file.rb +++ b/lib/chef/knife/role_from_file.rb @@ -23,9 +23,9 @@ class Chef class RoleFromFile < Knife deps do - require_relative "../role" + require "chef/role" unless defined?(Chef::Role) require_relative "core/object_loader" - require_relative "../json_compat" + require "chef/json_compat" unless defined?(Chef::JSONCompat) end banner "knife role from file FILE [FILE..] (options)" diff --git a/lib/chef/knife/role_list.rb b/lib/chef/knife/role_list.rb index d6aad053c1..723d956b91 100644 --- a/lib/chef/knife/role_list.rb +++ b/lib/chef/knife/role_list.rb @@ -23,8 +23,8 @@ class Chef class RoleList < Knife deps do - require_relative "../node" - require_relative "../json_compat" + require "chef/node" unless defined?(Chef::Node) + require "chef/json_compat" unless defined?(Chef::JSONCompat) end banner "knife role list (options)" diff --git a/lib/chef/knife/role_run_list_add.rb b/lib/chef/knife/role_run_list_add.rb index 76633ff5f6..4276b9ab2d 100644 --- a/lib/chef/knife/role_run_list_add.rb +++ b/lib/chef/knife/role_run_list_add.rb @@ -24,8 +24,8 @@ class Chef class RoleRunListAdd < Knife deps do - require_relative "../role" - require_relative "../json_compat" + require "chef/role" unless defined?(Chef::Role) + require "chef/json_compat" unless defined?(Chef::JSONCompat) end banner "knife role run_list add [ROLE] [ENTRY [ENTRY]] (options)" diff --git a/lib/chef/knife/role_run_list_clear.rb b/lib/chef/knife/role_run_list_clear.rb index b7106233f0..150dccd7ba 100644 --- a/lib/chef/knife/role_run_list_clear.rb +++ b/lib/chef/knife/role_run_list_clear.rb @@ -24,8 +24,8 @@ class Chef class RoleRunListClear < Knife deps do - require_relative "../role" - require_relative "../json_compat" + require "chef/role" unless defined?(Chef::Role) + require "chef/json_compat" unless defined?(Chef::JSONCompat) end banner "knife role run_list clear [ROLE] (options)" diff --git a/lib/chef/knife/role_run_list_remove.rb b/lib/chef/knife/role_run_list_remove.rb index 884f3bc28d..7a0f82c092 100644 --- a/lib/chef/knife/role_run_list_remove.rb +++ b/lib/chef/knife/role_run_list_remove.rb @@ -23,7 +23,7 @@ class Chef class RoleRunListRemove < Knife deps do - require_relative "../role" + require "chef/role" unless defined?(Chef::Role) end banner "knife role run_list remove [ROLE] [ENTRY] (options)" diff --git a/lib/chef/knife/role_run_list_replace.rb b/lib/chef/knife/role_run_list_replace.rb index 16f789fbef..63c7b87199 100644 --- a/lib/chef/knife/role_run_list_replace.rb +++ b/lib/chef/knife/role_run_list_replace.rb @@ -24,8 +24,8 @@ class Chef class RoleRunListReplace < Knife deps do - require_relative "../role" - require_relative "../json_compat" + require "chef/role" unless defined?(Chef::Role) + require "chef/json_compat" unless defined?(Chef::JSONCompat) end banner "knife role run_list replace [ROLE] [OLD_ENTRY] [NEW_ENTRY] (options)" diff --git a/lib/chef/knife/role_run_list_set.rb b/lib/chef/knife/role_run_list_set.rb index ad1a5e2923..6cddc7376c 100644 --- a/lib/chef/knife/role_run_list_set.rb +++ b/lib/chef/knife/role_run_list_set.rb @@ -24,7 +24,7 @@ class Chef class RoleRunListSet < Knife deps do - require_relative "../role" + require "chef/role" unless defined?(Chef::Role) end banner "knife role run_list set [ROLE] [ENTRIES] (options)" diff --git a/lib/chef/knife/role_show.rb b/lib/chef/knife/role_show.rb index ee90352e50..3a2df8b782 100644 --- a/lib/chef/knife/role_show.rb +++ b/lib/chef/knife/role_show.rb @@ -25,7 +25,7 @@ class Chef include Knife::Core::MultiAttributeReturnOption deps do - require_relative "../role" + require "chef/role" unless defined?(Chef::Role) end banner "knife role show ROLE (options)" diff --git a/lib/chef/knife/search.rb b/lib/chef/knife/search.rb index 620cfb971d..306761f109 100644 --- a/lib/chef/knife/search.rb +++ b/lib/chef/knife/search.rb @@ -27,10 +27,10 @@ class Chef include Knife::Core::MultiAttributeReturnOption deps do - require_relative "../node" - require_relative "../environment" - require_relative "../api_client" - require_relative "../search/query" + require "chef/node" unless defined?(Chef::Node) + require "chef/environment" unless defined?(Chef::Environment) + require "chef/api_client" unless defined?(Chef::APIClient) + require "chef/search/query" unless defined?(Chef::Search::Query) end include Knife::Core::FormattingOptions diff --git a/lib/chef/knife/serve.rb b/lib/chef/knife/serve.rb index d79e05aa85..30e4a28f9a 100644 --- a/lib/chef/knife/serve.rb +++ b/lib/chef/knife/serve.rb @@ -15,7 +15,7 @@ # require_relative "../knife" -require_relative "../local_mode" +require "local_mode" unless defined?(Chef::LocalMode) require "chef-utils/dist" unless defined?(ChefUtils::Dist) class Chef diff --git a/lib/chef/knife/show.rb b/lib/chef/knife/show.rb index 0e5ab9d0fe..cdee271c63 100644 --- a/lib/chef/knife/show.rb +++ b/lib/chef/knife/show.rb @@ -24,8 +24,8 @@ class Chef category "path-based" deps do - require_relative "../chef_fs/file_system" - require_relative "../chef_fs/file_system/exceptions" + require "chef/chef_fs/file_system" unless defined?(Chef::ChefFS::FileSystem) + require "chef/chef_fs/file_system/exceptions" unless defined?(Chef::ChefFS::FileSystem::Exceptions) end option :local, diff --git a/lib/chef/knife/ssh.rb b/lib/chef/knife/ssh.rb index 8681fdfd02..e69de62bc2 100644 --- a/lib/chef/knife/ssh.rb +++ b/lib/chef/knife/ssh.rb @@ -23,13 +23,13 @@ class Chef class Ssh < Knife deps do - require_relative "../mixin/shell_out" + require "chef/mixin/shell_out" unless defined?(Chef::Mixin::ShellOut) require "net/ssh" unless defined?(Net::SSH) require "net/ssh/multi" require "readline" - require_relative "../exceptions" - require_relative "../search/query" - require_relative "../util/path_helper" + require "chef/exceptions" unless defined?(Chef::Exceptions) + require "chef/search/query" unless defined?(Chef::Search::Query) + require "chef-config/path_helper" unless defined?(ChefConfig::PathHelper) include Chef::Mixin::ShellOut end @@ -464,7 +464,7 @@ class Chef def screen tf = Tempfile.new("knife-ssh-screen") - Chef::Util::PathHelper.home(".screenrc") do |screenrc_path| + ChefConfig::PathHelper.home(".screenrc") do |screenrc_path| if File.exist? screenrc_path tf.puts("source #{screenrc_path}") end diff --git a/lib/chef/knife/ssl_check.rb b/lib/chef/knife/ssl_check.rb index 0cc4141d42..c8b24881cc 100644 --- a/lib/chef/knife/ssl_check.rb +++ b/lib/chef/knife/ssl_check.rb @@ -24,13 +24,14 @@ class Chef class SslCheck < Chef::Knife deps do - require_relative "../config" + require "chef/config" unless defined?(Chef::Config) + # MPTD: - we aren't using pp require "pp" unless defined?(PP) require "socket" unless defined?(Socket) require "uri" unless defined?(URI) - require_relative "../http/ssl_policies" + require "chef/http/ssl_policies" unless defined?(Chef::HTTP::DefaultSSLPolicy) require "openssl" unless defined?(OpenSSL) - require_relative "../mixin/proxified_socket" + require "chef/mixin/proxified_socket" unless defined?(Chef::Mixin::ProxifiedSocket) include Chef::Mixin::ProxifiedSocket end diff --git a/lib/chef/knife/ssl_fetch.rb b/lib/chef/knife/ssl_fetch.rb index cfbbc823b2..a005cebe80 100644 --- a/lib/chef/knife/ssl_fetch.rb +++ b/lib/chef/knife/ssl_fetch.rb @@ -23,12 +23,13 @@ class Chef class SslFetch < Chef::Knife deps do - require_relative "../config" + require "chef/config" unless defined?(Chef::Config) require "pp" unless defined?(PP) require "socket" unless defined?(Socket) require "uri" unless defined?(URI) require "openssl" unless defined?(OpenSSL) - require_relative "../mixin/proxified_socket" + require "chef/mixin/mixin/proxified_socket" unless defined?(Chef::Mixin::ProxifiedSocket) + include Chef::Mixin::ProxifiedSocket end diff --git a/lib/chef/knife/status.rb b/lib/chef/knife/status.rb index 34692d6da7..2e72f0a03b 100644 --- a/lib/chef/knife/status.rb +++ b/lib/chef/knife/status.rb @@ -27,7 +27,7 @@ class Chef include Knife::Core::FormattingOptions deps do - require_relative "../search/query" + require "chef/search/query" unless defined?(Chef::Search::Query) end banner "knife status QUERY (options)" diff --git a/lib/chef/knife/supermarket_install.rb b/lib/chef/knife/supermarket_install.rb index a3d3aa7a5d..c979a4d6f4 100644 --- a/lib/chef/knife/supermarket_install.rb +++ b/lib/chef/knife/supermarket_install.rb @@ -23,11 +23,11 @@ class Chef class SupermarketInstall < Knife deps do - require_relative "../exceptions" + require "chef/exceptions" unless defined?(Chef::Exceptions) require "shellwords" unless defined?(Shellwords) require "mixlib/archive" unless defined?(Mixlib::Archive) require_relative "core/cookbook_scm_repo" - require_relative "../cookbook/metadata" + require "chef/cookbook/metadata" unless defined?(Chef::Cookbook::Metadata) end banner "knife supermarket install COOKBOOK [VERSION] (options)" diff --git a/lib/chef/knife/supermarket_share.rb b/lib/chef/knife/supermarket_share.rb index 49b3474566..2c67c86f95 100644 --- a/lib/chef/knife/supermarket_share.rb +++ b/lib/chef/knife/supermarket_share.rb @@ -25,10 +25,10 @@ class Chef include Chef::Mixin::ShellOut deps do - require_relative "../cookbook_loader" - require_relative "../cookbook_uploader" - require_relative "../cookbook_site_streaming_uploader" - require_relative "../mixin/shell_out" + require "chef/cookbook_loader" unless defined?(Chef::CookbookLoader) + require "chef/cookbook_uploader" unless defined?(Chef::CookbookUploader) + require_relative "core/cookbook_site_streaming_uploader" + require "chef/mixin/shell_out" unless defined?(Chef::Mixin::ShellOut) end banner "knife supermarket share COOKBOOK [CATEGORY] (options)" @@ -72,7 +72,7 @@ class Chef if cl.cookbook_exists?(cookbook_name) cookbook = cl[cookbook_name] Chef::CookbookUploader.new(cookbook).validate_cookbooks - tmp_cookbook_dir = Chef::CookbookSiteStreamingUploader.create_build_dir(cookbook) + tmp_cookbook_dir = Chef::Knife::Core::CookbookSiteStreamingUploader.create_build_dir(cookbook) begin Chef::Log.trace("Temp cookbook directory is #{tmp_cookbook_dir.inspect}") ui.info("Making tarball #{cookbook_name}.tgz") @@ -124,7 +124,7 @@ class Chef category_string = Chef::JSONCompat.to_json({ "category" => cookbook_category }) - http_resp = Chef::CookbookSiteStreamingUploader.post(uri, user_id, user_secret_filename, { + http_resp = Chef::Knife::Core::CookbookSiteStreamingUploader.post(uri, user_id, user_secret_filename, { tarball: File.open(cookbook_filename), cookbook: category_string, }) diff --git a/lib/chef/knife/supermarket_unshare.rb b/lib/chef/knife/supermarket_unshare.rb index 686d95f47a..8c86769804 100644 --- a/lib/chef/knife/supermarket_unshare.rb +++ b/lib/chef/knife/supermarket_unshare.rb @@ -23,7 +23,7 @@ class Chef class SupermarketUnshare < Knife deps do - require_relative "../json_compat" + require "chef/json_compat" unless defined?(Chef::JSONCompat) end banner "knife supermarket unshare COOKBOOK" diff --git a/lib/chef/knife/tag_create.rb b/lib/chef/knife/tag_create.rb index 2f0d302e74..ed7d37e7b8 100644 --- a/lib/chef/knife/tag_create.rb +++ b/lib/chef/knife/tag_create.rb @@ -25,7 +25,7 @@ class Chef class TagCreate < Knife deps do - require_relative "../node" + require "chef/node" unless defined?(Chef::Node) end banner "knife tag create NODE TAG ..." diff --git a/lib/chef/knife/tag_delete.rb b/lib/chef/knife/tag_delete.rb index 85fa6a9e27..539ae39273 100644 --- a/lib/chef/knife/tag_delete.rb +++ b/lib/chef/knife/tag_delete.rb @@ -25,7 +25,7 @@ class Chef class TagDelete < Knife deps do - require_relative "../node" + require "chef/node" unless defined?(Chef::Node) end banner "knife tag delete NODE TAG ..." diff --git a/lib/chef/knife/tag_list.rb b/lib/chef/knife/tag_list.rb index 8b91034609..3ab960c361 100644 --- a/lib/chef/knife/tag_list.rb +++ b/lib/chef/knife/tag_list.rb @@ -25,7 +25,7 @@ class Chef class TagList < Knife deps do - require_relative "../node" + require "chef/node" unless defined?(Chef::Node) end banner "knife tag list NODE" diff --git a/lib/chef/knife/upload.rb b/lib/chef/knife/upload.rb index 190549d86a..e8dd052e77 100644 --- a/lib/chef/knife/upload.rb +++ b/lib/chef/knife/upload.rb @@ -24,7 +24,7 @@ class Chef category "path-based" deps do - require_relative "../chef_fs/command_line" + require "chef/chef_fs/command_line" unless defined?(Chef::ChefFS::CommandLine) end option :recurse, diff --git a/lib/chef/knife/user_create.rb b/lib/chef/knife/user_create.rb index aa1d4d54f2..657d112e86 100644 --- a/lib/chef/knife/user_create.rb +++ b/lib/chef/knife/user_create.rb @@ -1,4 +1,5 @@ # +# Author:: Steven Danna () # Author:: Tyler Cloke () # Copyright:: Copyright (c) Chef Software Inc. # License:: Apache License, Version 2.0 @@ -26,7 +27,7 @@ class Chef attr_accessor :user_field deps do - require_relative "../user_v1" + require "chef/user_v1" unless defined?(Chef::UserV1) end option :file, @@ -60,6 +61,10 @@ class Chef @user_field ||= Chef::UserV1.new end + def create_user_from_hash(hash) + Chef::UserV1.from_hash(hash).create + end + def run test_mandatory_field(@name_args[0], "username") user.username @name_args[0] diff --git a/lib/chef/knife/user_delete.rb b/lib/chef/knife/user_delete.rb index 64d729c951..fff109162d 100644 --- a/lib/chef/knife/user_delete.rb +++ b/lib/chef/knife/user_delete.rb @@ -23,7 +23,8 @@ class Chef class UserDelete < Knife deps do - require_relative "../org" + require "chef/user_v1" unless defined?(Chef::UserV1) + require "chef/org" unless defined?(Chef::Org) end banner "knife user delete USER (options)" diff --git a/lib/chef/knife/user_list.rb b/lib/chef/knife/user_list.rb index 3284964a47..ad705922b8 100644 --- a/lib/chef/knife/user_list.rb +++ b/lib/chef/knife/user_list.rb @@ -33,6 +33,7 @@ class Chef results = root_rest.get("users") output(format_list_for_display(results)) end + end end end diff --git a/lib/chef/knife/user_reregister.rb b/lib/chef/knife/user_reregister.rb index ee58c19d9f..cf2adbceb2 100644 --- a/lib/chef/knife/user_reregister.rb +++ b/lib/chef/knife/user_reregister.rb @@ -23,7 +23,7 @@ class Chef class UserReregister < Knife deps do - require_relative "../user_v1" + require "chef/user_v1" unless defined?(Chef::UserV1) end banner "knife user reregister USER (options)" diff --git a/lib/chef/knife/xargs.rb b/lib/chef/knife/xargs.rb index 9dcc724d38..fc82d390cb 100644 --- a/lib/chef/knife/xargs.rb +++ b/lib/chef/knife/xargs.rb @@ -24,8 +24,8 @@ class Chef category "path-based" deps do - require_relative "../chef_fs/file_system" - require_relative "../chef_fs/file_system/exceptions" + require "chef/chef_fs/file_system" unless defined?(Chef::ChefFS::FileSystem) + require "chef/chef_fs/file_system/exceptions" unless defined?(Chef::ChefFS::FileSystem::Exceptions) end # TODO modify to remote-only / local-only pattern (more like delete) diff --git a/spec/integration/knife/cookbook_api_ipv6_spec.rb b/spec/integration/knife/cookbook_api_ipv6_spec.rb index b65cdc697b..f546de4882 100644 --- a/spec/integration/knife/cookbook_api_ipv6_spec.rb +++ b/spec/integration/knife/cookbook_api_ipv6_spec.rb @@ -102,7 +102,7 @@ describe "Knife cookbook API integration with IPv6", :workstation, :not_supporte end it "downloads the cookbook" do - shell_out!("knife cookbook download apache2 #{knife_config_flag} -d #{cache_path}", cwd: chef_dir) + shell_out!("#{knife} cookbook download apache2 #{knife_config_flag} -d #{cache_path}", cwd: chef_dir) expect(Dir["#{cache_path}/*"].map { |entry| File.basename(entry) }).to include("apache2-0.0.1") end end diff --git a/spec/support/shared/integration/knife_support.rb b/spec/support/shared/integration/knife_support.rb index af7b503d16..0f617a41d9 100644 --- a/spec/support/shared/integration/knife_support.rb +++ b/spec/support/shared/integration/knife_support.rb @@ -17,7 +17,6 @@ require "chef/config" require "chef/knife" -require "chef/application/knife" require "logger" require "chef/log" require "chef/chef_fs/file_system_cache" diff --git a/spec/unit/application/knife_spec.rb b/spec/unit/application/knife_spec.rb index bce6b19366..8ac964da8d 100644 --- a/spec/unit/application/knife_spec.rb +++ b/spec/unit/application/knife_spec.rb @@ -79,6 +79,7 @@ describe Chef::Application::Knife do context "validate --format option" do it "should set the default format summary" do + # MPTD - this appears to be genuinely broken, look closer with_argv(*%w{noop knife command}) do expect(@knife).to receive(:exit).with(0) @knife.run diff --git a/spec/unit/cookbook_site_streaming_uploader_spec.rb b/spec/unit/cookbook_site_streaming_uploader_spec.rb index af714094d0..fe030c2d12 100644 --- a/spec/unit/cookbook_site_streaming_uploader_spec.rb +++ b/spec/unit/cookbook_site_streaming_uploader_spec.rb @@ -18,7 +18,7 @@ require "spec_helper" -require "chef/cookbook_site_streaming_uploader" +require "chef/knife/core/cookbook_site_streaming_uploader" class FakeTempfile def initialize(basename) @@ -33,10 +33,10 @@ class FakeTempfile end -describe Chef::CookbookSiteStreamingUploader do +describe Chef::Knife::Core::CookbookSiteStreamingUploader do + let(:subject) { Chef::Knife::Core::CookbookSiteStreamingUploader } describe "create_build_dir" do - before(:each) do @cookbook_repo = File.expand_path(File.join(CHEF_SPEC_DATA, "cookbooks")) @loader = Chef::CookbookLoader.new(@cookbook_repo) @@ -51,7 +51,7 @@ describe Chef::CookbookSiteStreamingUploader do expect(Tempfile).to receive(:new).with("chef-#{cookbook.name}-build").and_return(FakeTempfile.new("chef-#{cookbook.name}-build")) expect(FileUtils).to receive(:mkdir_p).exactly(files_count + 1).times expect(FileUtils).to receive(:cp).exactly(files_count).times - Chef::CookbookSiteStreamingUploader.create_build_dir(cookbook) + subject.create_build_dir(cookbook) end end # create_build_dir @@ -68,17 +68,17 @@ describe Chef::CookbookSiteStreamingUploader do it "should send an http request" do expect_any_instance_of(Net::HTTP).to receive(:request) - Chef::CookbookSiteStreamingUploader.make_request(:post, @uri, "bill", @secret_filename) + subject.make_request(:post, @uri, "bill", @secret_filename) end it "should read the private key file" do expect(File).to receive(:read).with(@secret_filename).and_return(@rsa_key) - Chef::CookbookSiteStreamingUploader.make_request(:post, @uri, "bill", @secret_filename) + subject.make_request(:post, @uri, "bill", @secret_filename) end it "should add the authentication signed header" do expect_any_instance_of(Mixlib::Authentication::SigningObject).to receive(:sign).and_return({}) - Chef::CookbookSiteStreamingUploader.make_request(:post, @uri, "bill", @secret_filename) + subject.make_request(:post, @uri, "bill", @secret_filename) end it "should be able to send post requests" do @@ -87,7 +87,7 @@ describe Chef::CookbookSiteStreamingUploader do expect(Net::HTTP::Post).to receive(:new).once.and_return(post) expect(Net::HTTP::Put).not_to receive(:new) expect(Net::HTTP::Get).not_to receive(:new) - Chef::CookbookSiteStreamingUploader.make_request(:post, @uri, "bill", @secret_filename) + subject.make_request(:post, @uri, "bill", @secret_filename) end it "should be able to send put requests" do @@ -96,23 +96,23 @@ describe Chef::CookbookSiteStreamingUploader do expect(Net::HTTP::Post).not_to receive(:new) expect(Net::HTTP::Put).to receive(:new).once.and_return(put) expect(Net::HTTP::Get).not_to receive(:new) - Chef::CookbookSiteStreamingUploader.make_request(:put, @uri, "bill", @secret_filename) + subject.make_request(:put, @uri, "bill", @secret_filename) end it "should be able to receive files to attach as argument" do - Chef::CookbookSiteStreamingUploader.make_request(:put, @uri, "bill", @secret_filename, { + subject.make_request(:put, @uri, "bill", @secret_filename, { myfile: File.new(File.join(CHEF_SPEC_DATA, "config.rb")), # a dummy file }) end it "should be able to receive strings to attach as argument" do - Chef::CookbookSiteStreamingUploader.make_request(:put, @uri, "bill", @secret_filename, { + subject.make_request(:put, @uri, "bill", @secret_filename, { mystring: "Lorem ipsum", }) end it "should be able to receive strings and files as argument at the same time" do - Chef::CookbookSiteStreamingUploader.make_request(:put, @uri, "bill", @secret_filename, { + subject.make_request(:put, @uri, "bill", @secret_filename, { myfile1: File.new(File.join(CHEF_SPEC_DATA, "config.rb")), mystring1: "Lorem ipsum", myfile2: File.new(File.join(CHEF_SPEC_DATA, "config.rb")), @@ -125,11 +125,11 @@ describe Chef::CookbookSiteStreamingUploader do describe "StreamPart" do before(:each) do @file = File.new(File.join(CHEF_SPEC_DATA, "config.rb")) - @stream_part = Chef::CookbookSiteStreamingUploader::StreamPart.new(@file, File.size(@file)) + @stream_part = Chef::Knife::Core::CookbookSiteStreamingUploader::StreamPart.new(@file, File.size(@file)) end it "should create a StreamPart" do - expect(@stream_part).to be_instance_of(Chef::CookbookSiteStreamingUploader::StreamPart) + expect(@stream_part).to be_instance_of(Chef::Knife::Core::CookbookSiteStreamingUploader::StreamPart) end it "should expose its size" do @@ -147,11 +147,11 @@ describe Chef::CookbookSiteStreamingUploader do describe "StringPart" do before(:each) do @str = "What a boring string" - @string_part = Chef::CookbookSiteStreamingUploader::StringPart.new(@str) + @string_part = Chef::Knife::Core::CookbookSiteStreamingUploader::StringPart.new(@str) end it "should create a StringPart" do - expect(@string_part).to be_instance_of(Chef::CookbookSiteStreamingUploader::StringPart) + expect(@string_part).to be_instance_of(Chef::Knife::Core::CookbookSiteStreamingUploader::StringPart) end it "should expose its size" do @@ -168,15 +168,15 @@ describe Chef::CookbookSiteStreamingUploader do before(:each) do @string1 = "stream1" @string2 = "stream2" - @stream1 = Chef::CookbookSiteStreamingUploader::StringPart.new(@string1) - @stream2 = Chef::CookbookSiteStreamingUploader::StringPart.new(@string2) + @stream1 = Chef::Knife::Core::CookbookSiteStreamingUploader::StringPart.new(@string1) + @stream2 = Chef::Knife::Core::CookbookSiteStreamingUploader::StringPart.new(@string2) @parts = [ @stream1, @stream2 ] - @multipart_stream = Chef::CookbookSiteStreamingUploader::MultipartStream.new(@parts) + @multipart_stream = Chef::Knife::Core::CookbookSiteStreamingUploader::MultipartStream.new(@parts) end it "should create a MultipartStream" do - expect(@multipart_stream).to be_instance_of(Chef::CookbookSiteStreamingUploader::MultipartStream) + expect(@multipart_stream).to be_instance_of(Chef::Knife::Core::CookbookSiteStreamingUploader::MultipartStream) end it "should expose its size" do diff --git a/spec/unit/knife/core/gem_glob_loader_spec.rb b/spec/unit/knife/core/gem_glob_loader_spec.rb index f0c29b86a0..af6d2906bb 100644 --- a/spec/unit/knife/core/gem_glob_loader_spec.rb +++ b/spec/unit/knife/core/gem_glob_loader_spec.rb @@ -24,11 +24,11 @@ describe Chef::Knife::SubcommandLoader::GemGlobLoader do before do allow(ChefUtils).to receive(:windows?) { false } - Chef::Util::PathHelper.class_variable_set(:@@home_dir, home) + ChefConfig::PathHelper.class_variable_set(:@@home_dir, home) end after do - Chef::Util::PathHelper.class_variable_set(:@@home_dir, nil) + ChefConfig::PathHelper.class_variable_set(:@@home_dir, nil) end it "builds a list of the core subcommand file require paths" do @@ -86,6 +86,9 @@ describe Chef::Knife::SubcommandLoader::GemGlobLoader do # source tree of the "primary" chef install, it can be loaded and cause an # error. We also want to ensure that we only load builtin commands from the # "primary" chef install. + # + # MPTD - if it's still a supported scenario, this needs to be redone in + # a knife-gem world. context "when a different version of chef is also installed as a gem" do let(:all_found_commands) do diff --git a/spec/unit/knife/supermarket_install_spec.rb b/spec/unit/knife/supermarket_install_spec.rb index 03cc5d1992..6b1c67e378 100644 --- a/spec/unit/knife/supermarket_install_spec.rb +++ b/spec/unit/knife/supermarket_install_spec.rb @@ -19,6 +19,9 @@ require "spec_helper" require "chef/knife/supermarket_install" +# MPTD - why is this now needed? +require "mixlib/archive" + describe Chef::Knife::SupermarketInstall do let(:knife) { Chef::Knife::SupermarketInstall.new } let(:stdout) { StringIO.new } diff --git a/spec/unit/knife/supermarket_share_spec.rb b/spec/unit/knife/supermarket_share_spec.rb index 088cef9dfd..a3102aff98 100644 --- a/spec/unit/knife/supermarket_share_spec.rb +++ b/spec/unit/knife/supermarket_share_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" require "chef/knife/supermarket_share" require "chef/cookbook_uploader" -require "chef/cookbook_site_streaming_uploader" +require "chef/knife/core/cookbook_site_streaming_uploader" describe Chef::Knife::SupermarketShare do @@ -42,7 +42,7 @@ describe Chef::Knife::SupermarketShare do @cookbook_uploader = Chef::CookbookUploader.new("herpderp", rest: "norest") allow(Chef::CookbookUploader).to receive(:new).and_return(@cookbook_uploader) allow(@cookbook_uploader).to receive(:validate_cookbooks).and_return(true) - allow(Chef::CookbookSiteStreamingUploader).to receive(:create_build_dir).and_return(Dir.mktmpdir) + allow(Chef::Knife::Core::CookbookSiteStreamingUploader).to receive(:create_build_dir).and_return(Dir.mktmpdir) allow(@knife).to receive(:shell_out!).and_return(true) @stdout = StringIO.new @@ -140,7 +140,7 @@ describe Chef::Knife::SupermarketShare do context "when the --dry-run flag is specified" do before do - allow(Chef::CookbookSiteStreamingUploader).to receive(:create_build_dir).and_return("/var/tmp/dummy") + allow(Chef::Knife::Core::CookbookSiteStreamingUploader).to receive(:create_build_dir).and_return("/var/tmp/dummy") @knife.config = { dry_run: true } @so = instance_double("Mixlib::ShellOut") allow(@knife).to receive(:shell_out!).and_return(@so) @@ -165,7 +165,7 @@ describe Chef::Knife::SupermarketShare do before(:each) do @upload_response = double("Net::HTTPResponse") - allow(Chef::CookbookSiteStreamingUploader).to receive(:post).and_return(@upload_response) + allow(Chef::Knife::Core::CookbookSiteStreamingUploader).to receive(:post).and_return(@upload_response) allow(File).to receive(:open).and_return(true) end @@ -174,7 +174,7 @@ describe Chef::Knife::SupermarketShare do response_text = Chef::JSONCompat.to_json({ uri: "https://supermarket.chef.io/cookbooks/cookbook_name" }) allow(@upload_response).to receive(:body).and_return(response_text) allow(@upload_response).to receive(:code).and_return(201) - expect(Chef::CookbookSiteStreamingUploader).to receive(:post).with(/supermarket\.chef\.io/, anything, anything, anything) + expect(Chef::Knife::Core::CookbookSiteStreamingUploader).to receive(:post).with(/supermarket\.chef\.io/, anything, anything, anything) @knife.run end -- cgit v1.2.1