lib/kitchen/configurable.rb in test-kitchen-1.4.2 vs lib/kitchen/configurable.rb in test-kitchen-1.5.0.rc.1

- old
+ new

@@ -293,24 +293,56 @@ # of shell. # # @param code [String] the shell code to be wrapped # @return [String] wrapped shell code # @api private + # rubocop:disable Metrics/AbcSize, Metrics/MethodLength + # rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity def wrap_shell_code(code) env = [] if config[:http_proxy] env << shell_env_var("http_proxy", config[:http_proxy]) env << shell_env_var("HTTP_PROXY", config[:http_proxy]) + else + export_proxy(env, "http") end if config[:https_proxy] env << shell_env_var("https_proxy", config[:https_proxy]) env << shell_env_var("HTTPS_PROXY", config[:https_proxy]) + else + export_proxy(env, "https") end + if config[:ftp_proxy] + env << shell_env_var("ftp_proxy", config[:ftp_proxy]) + env << shell_env_var("FTP_PROXY", config[:ftp_proxy]) + else + export_proxy(env, "ftp") + end + # if http_proxy was set from environment variable or https_proxy was set + # from environment variable, or ftp_proxy was set from environment + # variable, include no_proxy environment variable, if set. + if (!config[:http_proxy] && (ENV["http_proxy"] || ENV["HTTP_PROXY"])) || + (!config[:https_proxy] && (ENV["https_proxy"] || ENV["HTTPS_PROXY"])) || + (!config[:ftp_proxy] && (ENV["ftp_proxy"] || ENV["FTP_PROXY"])) + env << shell_env_var("no_proxy", ENV["no_proxy"]) if ENV["no_proxy"] + env << shell_env_var("NO_PROXY", ENV["NO_PROXY"]) if ENV["NO_PROXY"] + end if powershell_shell? env.join("\n").concat("\n").concat(code) else Util.wrap_command(env.join("\n").concat("\n").concat(code)) end + end + + # Helper method to export + # + # @param env [Array] the environment to modify + # @param code [String] the type of proxy to export, one of 'http', 'https' or 'ftp' + # @api private + def export_proxy(env, type) + env << shell_env_var("#{type}_proxy", ENV["#{type}_proxy"]) if ENV["#{type}_proxy"] + env << shell_env_var("#{type.upcase}_PROXY", ENV["#{type.upcase}_PROXY"]) if + ENV["#{type.upcase}_PROXY"] end # Class methods which will be mixed in on inclusion of Configurable module. module ClassMethods