From eea6d8b2f711225ec266206cbedeff4c147aedb0 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Tue, 21 Jul 2020 19:52:04 -0700 Subject: clean up the chefutils wiring with a common helper class also fixes a FIXME in the YARD Signed-off-by: Lamont Granquist --- chef-utils/lib/chef-utils/internal.rb | 4 ++-- lib/chef/dsl/platform_introspection.rb | 9 ++------ lib/chef/mixin/chef_utils_wiring.rb | 40 ++++++++++++++++++++++++++++++++++ lib/chef/mixin/shell_out.rb | 17 ++------------- lib/chef/mixin/which.rb | 7 ++---- lib/chef/platform/service_helpers.rb | 16 ++------------ 6 files changed, 50 insertions(+), 43 deletions(-) create mode 100644 lib/chef/mixin/chef_utils_wiring.rb diff --git a/chef-utils/lib/chef-utils/internal.rb b/chef-utils/lib/chef-utils/internal.rb index 6986b5250a..aa52005912 100644 --- a/chef-utils/lib/chef-utils/internal.rb +++ b/chef-utils/lib/chef-utils/internal.rb @@ -75,9 +75,9 @@ module ChefUtils end end - # This should be set to a Train::FIXME instance. You should wire this up to nil for not using a train transport connection. + # This should be set to a Train::Plugins::Transport instance. You should wire this up to nil for not using a train transport connection. # - # @return [Train::FIXME] + # @return [Train::Plugins::Transport] # # @api private # diff --git a/lib/chef/dsl/platform_introspection.rb b/lib/chef/dsl/platform_introspection.rb index 4cf381c037..8755644689 100644 --- a/lib/chef/dsl/platform_introspection.rb +++ b/lib/chef/dsl/platform_introspection.rb @@ -17,6 +17,7 @@ # require "chef-utils" unless defined?(ChefUtils::CANARY) +require "chef/mixin/chef_utils_wiring" unless defined?(Chef::Mixin::ChefUtilsWiring) class Chef module DSL @@ -25,6 +26,7 @@ class Chef # #value_for_platform. module PlatformIntrospection include ChefUtils + include Chef::Mixin::ChefUtilsWiring # Implementation class for determining platform dependent values class PlatformDependentValue @@ -258,13 +260,6 @@ class Chef # ^^^^^^ NOTE: PLEASE DO NOT CONTINUE TO ADD THESE KINDS OF PLATFORM_VERSION APIS WITHOUT ^^^^^^^ # ^^^^^^ GOING THROUGH THE DESIGN REVIEW PROCESS AND ADDRESS THE EXISTING CHEF-SUGAR ONES ^^^^^^^ # ^^^^^^ DO "THE HARD RIGHT THING" AND ADDRESS THE BROADER PROBLEM AND FIX IT ALL. ^^^^^^^ - - private - - # dependency injection, see: ChefUtils::Internal - def __transport_connection - Chef.run_context.transport_connection - end end end end diff --git a/lib/chef/mixin/chef_utils_wiring.rb b/lib/chef/mixin/chef_utils_wiring.rb new file mode 100644 index 0000000000..938520059c --- /dev/null +++ b/lib/chef/mixin/chef_utils_wiring.rb @@ -0,0 +1,40 @@ +#-- +# Copyright:: Copyright (c) Chef Software Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require_relative "../log" +require_relative "../config" +require_relative "../chef_class" + +class Chef + module Mixin + # Common Dependency Injection wiring for ChefUtils-related modules + module ChefUtilsWiring + private + + def __config + Chef::Config + end + + def __log + Chef::Log + end + + def __transport_connection + Chef.run_context&.transport_connection + end + end + end +end diff --git a/lib/chef/mixin/shell_out.rb b/lib/chef/mixin/shell_out.rb index e136fe09ba..c3eacc57f0 100644 --- a/lib/chef/mixin/shell_out.rb +++ b/lib/chef/mixin/shell_out.rb @@ -16,26 +16,13 @@ # limitations under the License. require "mixlib/shellout/helper" unless defined?(Mixlib::ShellOut::Helper) -require_relative "../log" -require_relative "../config" -require_relative "../chef_class" +require "chef/mixin/chef_utils_wiring" unless defined?(Chef::Mixin::ChefUtilsWiring) class Chef module Mixin module ShellOut include Mixlib::ShellOut::Helper - - def __config - Chef::Config - end - - def __log - Chef::Log - end - - def __transport_connection - Chef.run_context&.transport_connection - end + include Chef::Mixin::ChefUtilsWiring end end end diff --git a/lib/chef/mixin/which.rb b/lib/chef/mixin/which.rb index 2e6fd13b68..01357d76a5 100644 --- a/lib/chef/mixin/which.rb +++ b/lib/chef/mixin/which.rb @@ -17,12 +17,14 @@ require "chef-utils/dsl/which" unless defined?(ChefUtils::DSL::Which) require "chef-utils/dsl/path_sanity" unless defined?(ChefUtils::DSL::PathSanity) +require "chef/mixin/chef_utils_wiring" unless defined?(Chef::Mixin::ChefUtilsWiring) class Chef module Mixin module Which include ChefUtils::DSL::Which include ChefUtils::DSL::PathSanity + include ChefUtilsWiring private @@ -32,11 +34,6 @@ class Chef def __extra_path __sane_paths end - - # dependency injection, see: ChefUtils::Internal - def __transport_connection - Chef.run_context&.transport_connection - end end end end diff --git a/lib/chef/platform/service_helpers.rb b/lib/chef/platform/service_helpers.rb index 456e679e03..627fd8d694 100644 --- a/lib/chef/platform/service_helpers.rb +++ b/lib/chef/platform/service_helpers.rb @@ -18,11 +18,13 @@ require_relative "../chef_class" require "chef-utils" unless defined?(ChefUtils::CANARY) +require "chef/mixin/chef_utils_wiring" unless defined?(Chef::Mixin::ChefUtilsWiring) class Chef class Platform module ServiceHelpers include ChefUtils::DSL::Service + include Chef::Mixin::ChefUtilsWiring def service_resource_providers providers = [] @@ -49,20 +51,6 @@ class Chef configs end - private - - def __config - Chef::Config - end - - def __log - Chef::Log - end - - def __transport_connection - Chef.run_context&.transport_connection - end - extend self end end -- cgit v1.2.1