summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVivek Singh <vivek.singh@msystechnologies.com>2020-09-02 21:48:39 +0530
committerVivek Singh <vivek.singh@msystechnologies.com>2020-09-02 21:48:39 +0530
commit402af5b5ebb72b2cc0c1b8deffeafa02f90eed1e (patch)
tree48171d6f912447e8664a09f9448ded9a1928f2b1
parentc0468588af33fa5ac6e07e7fc8e51fb6f44a8ce1 (diff)
downloadchef-VSingh/bootstrap-context-transport-connection.tar.gz
Introduce bootstrap_context train transport_connectionVSingh/bootstrap-context-transport-connection
Signed-off-by: Vivek Singh <vivek.singh@msystechnologies.com>
-rw-r--r--chef-config/lib/chef-config/config.rb4
-rw-r--r--chef-utils/lib/chef-utils/dsl/train_helpers.rb8
-rw-r--r--chef-utils/lib/chef-utils/internal.rb2
-rw-r--r--lib/chef/chef_class.rb16
-rw-r--r--lib/chef/knife/bootstrap.rb7
-rw-r--r--lib/chef/knife/core/bootstrap_context.rb14
6 files changed, 42 insertions, 9 deletions
diff --git a/chef-config/lib/chef-config/config.rb b/chef-config/lib/chef-config/config.rb
index a767d072ef..2a1a8aa3d6 100644
--- a/chef-config/lib/chef-config/config.rb
+++ b/chef-config/lib/chef-config/config.rb
@@ -379,7 +379,7 @@ module ChefConfig
#
# @param path [String]
def self.path_accessible?(path)
- File.exist?(path) && File.readable?(path) && File.writable?(path)
+ ChefUtils.file_exist?(path) && File.readable?(path) && File.writable?(path)
end
# Where cookbook files are stored on the server (by content checksum)
@@ -920,7 +920,7 @@ module ChefConfig
end
# returns a platform specific path to the user home dir if set, otherwise default to current directory.
- default( :user_home ) { PathHelper.home || Dir.pwd }
+ default( :user_home ) { ChefUtils.home || PathHelper.home || Dir.pwd }
# Enable file permission fixup for selinux. Fixup will be done
# only if selinux is enabled in the system.
diff --git a/chef-utils/lib/chef-utils/dsl/train_helpers.rb b/chef-utils/lib/chef-utils/dsl/train_helpers.rb
index a821383eac..83c967817c 100644
--- a/chef-utils/lib/chef-utils/dsl/train_helpers.rb
+++ b/chef-utils/lib/chef-utils/dsl/train_helpers.rb
@@ -57,6 +57,14 @@ module ChefUtils
end
end
+ def home
+ if __transport_connection
+ __transport_connection.run_command("echo $HOME").stdout&.strip
+ else
+ ENV["$HOME"]
+ end
+ end
+
extend self
end
end
diff --git a/chef-utils/lib/chef-utils/internal.rb b/chef-utils/lib/chef-utils/internal.rb
index aa52005912..483231df9c 100644
--- a/chef-utils/lib/chef-utils/internal.rb
+++ b/chef-utils/lib/chef-utils/internal.rb
@@ -85,6 +85,8 @@ module ChefUtils
# Software consumers MUST override this method with their own implementation. The default behavior here is subject to change.
return Chef.run_context.transport_connection if defined?(Chef) && Chef.respond_to?(:run_context) && Chef&.run_context&.transport_connection
+ return Chef.bootstrap_context.transport_connection if defined?(Chef) && Chef.respond_to?(:bootstrap_context) && Chef&.bootstrap_context&.transport_connection
+
nil
end
diff --git a/lib/chef/chef_class.rb b/lib/chef/chef_class.rb
index bcb5eec4e4..2cb1e157c6 100644
--- a/lib/chef/chef_class.rb
+++ b/lib/chef/chef_class.rb
@@ -54,6 +54,10 @@ class Chef
#
attr_reader :run_context
+
+
+ attr_reader :bootstrap_context
+
# Register an event handler with user specified block
#
# @return[Chef::EventDispatch::Base] handler object
@@ -162,6 +166,17 @@ class Chef
@run_context = run_context
end
+
+ #
+ # Sets the bootstrap_context object
+ #
+ # @param bootstrap_context [Chef::BootstrapContext]
+ #
+ # @api private
+ def set_bootstrap_context(bootstrap_context)
+ @bootstrap_context = bootstrap_context
+ end
+
#
# Resets the internal state
#
@@ -173,6 +188,7 @@ class Chef
@resource_priority_map = nil
@provider_handler_map = nil
@resource_handler_map = nil
+ @bootstrap_context = nil
end
# @api private
diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb
index a3f7d3a23c..71ae2f1d0d 100644
--- a/lib/chef/knife/bootstrap.rb
+++ b/lib/chef/knife/bootstrap.rb
@@ -522,7 +522,7 @@ class Chef
Knife::Core::WindowsBootstrapContext.new(config, config[:run_list], Chef::Config, secret)
else
require_relative "core/bootstrap_context"
- Knife::Core::BootstrapContext.new(config, config[:run_list], Chef::Config, secret)
+ Knife::Core::BootstrapContext.new(config, config[:run_list], Chef::Config, secret, connection.connection)
end
end
@@ -554,6 +554,7 @@ class Chef
plugin_create_instance!
$stdout.sync = true
connect!
+ set_bootstrap_context
register_client
content = render_template
@@ -564,6 +565,10 @@ class Chef
connection.del_file!(bootstrap_path) if connection && bootstrap_path
end
+ def set_bootstrap_context
+ Chef.set_bootstrap_context(bootstrap_context)
+ end
+
def register_client
# chef-vault integration must use the new client-side hawtness, otherwise to use the
# new client-side hawtness, just delete your validation key.
diff --git a/lib/chef/knife/core/bootstrap_context.rb b/lib/chef/knife/core/bootstrap_context.rb
index a70e463089..22e8aaa7da 100644
--- a/lib/chef/knife/core/bootstrap_context.rb
+++ b/lib/chef/knife/core/bootstrap_context.rb
@@ -35,12 +35,14 @@ class Chef
attr_accessor :client_pem
attr_accessor :config
attr_accessor :chef_config
-
- def initialize(config, run_list, chef_config, secret = nil)
- @config = config
- @run_list = run_list
- @chef_config = chef_config
- @secret = secret
+ attr_accessor :transport_connection
+
+ def initialize(config, run_list, chef_config, secret = nil, transport_connection = nil)
+ @config = config
+ @run_list = run_list
+ @chef_config = chef_config
+ @secret = secret
+ @transport_connection = transport_connection
end
def bootstrap_environment