From d3d1292ba26cb775ed4e5d41f5cbdccef2d1d80e Mon Sep 17 00:00:00 2001 From: Sathish Date: Tue, 30 Jul 2024 20:34:32 +0530 Subject: [PATCH] use bundler to call `install_from_remote_gems` method Signed-off-by: Sathish --- lib/inspec/plugin/v2/installer.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/inspec/plugin/v2/installer.rb b/lib/inspec/plugin/v2/installer.rb index 0697e762c..844654a97 100644 --- a/lib/inspec/plugin/v2/installer.rb +++ b/lib/inspec/plugin/v2/installer.rb @@ -316,6 +316,35 @@ module Inspec::Plugin::V2 end end + + def install_from_remote_gems(plugin_name, opts) + require 'bundler' + gemfile_path = ::Bundler.default_gemfile + + File.open(gemfile_path, 'a') do |file| + file.puts <<-GEM + source 'http://4d7c88175115126e2264b3cc6b709a9a@localhost:9292/private' do + gem '#{plugin_name}' + end + GEM + end + + # Bundler.with_unbundled_env do + # require 'bundler/rubygems_gem_installer' + # installer = Bundler::RubyGemsGemInstaller.at(gemfile_path) + # installer.install(plugin_name) + # end + + ::Bundler.with_unbundled_env do + ::Bundler::CLI.start(['install']) + end + + plugin_spec = ::Bundler.load.specs.find { |spec| spec.name == plugin_name } + require 'byebug'; byebug + raise "Plugin #{plugin_name} installation failed!" unless plugin_spec + plugin_spec.version + end + def install_gem_to_plugins_dir(new_plugin_dependency, # rubocop: disable Metrics/AbcSize extra_request_sets = [], update_mode = false)