Skip to content

Commit

Permalink
Merge 3f1e2a6 into 5196c49
Browse files Browse the repository at this point in the history
  • Loading branch information
jmthomas authored Jul 5, 2022
2 parents 5196c49 + 3f1e2a6 commit ab8c6f5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
14 changes: 9 additions & 5 deletions cosmos/bin/cosmos
Original file line number Diff line number Diff line change
Expand Up @@ -294,18 +294,22 @@ def validate_plugin(plugin_file_path, scope:, variables_file: nil)
variables = nil
variables = JSON.parse(File.read(variables_file)) if variables_file
puts "Installing #{File.basename(plugin_file_path)}"
plugin_hash = Cosmos::PluginModel.install_phase1(plugin_file_path, variables, scope: scope, validate_only: true)
Cosmos::PluginModel.install_phase2(plugin_hash['name'], plugin_hash['variables'], scope: scope, validate_only: true,
plugin_hash = Cosmos::PluginModel.install_phase1(plugin_file_path, existing_variables: variables, scope: scope, validate_only: true)
Cosmos::PluginModel.install_phase2(plugin_hash, scope: scope, validate_only: true,
gem_file_path: plugin_file_path)
puts "Successfully validated #{File.basename(plugin_file_path)}"
result = 0 # bash and Windows consider 0 success
rescue => e
puts "Error: #{e.message}"
result = ERROR_CODE
ensure
name = Psych.safe_load(`gem spec #{plugin_file_path} name`).to_s
version = Psych.safe_load(`gem spec #{plugin_file_path} version`, permitted_classes: [Gem::Version]).to_s
Gem::Uninstaller.new(name, {:version => version, :force => true}).uninstall
begin
name = Psych.safe_load(`gem spec #{plugin_file_path} name`).to_s
version = Psych.safe_load(`gem spec #{plugin_file_path} version`, permitted_classes: [Gem::Version]).to_s
Gem::Uninstaller.new(name, {:version => version, :force => true}).uninstall
rescue => e
puts "Could not uninstall #{plugin_file_path} due to #{e.message}"
end
exit(result)
end

Expand Down
13 changes: 7 additions & 6 deletions cosmos/lib/cosmos/models/plugin_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,10 @@ def self.install_phase1(gem_file_path, existing_variables: nil, existing_plugin_
# Called by the PluginsController to create the plugin
# Because this uses ERB it must be run in a seperate process from the API to
# prevent corruption and single require problems in the current proces
def self.install_phase2(plugin_hash, scope:, validate_only: false)
rubys3_client = Aws::S3::Client.new

def self.install_phase2(plugin_hash, scope:, gem_file_path: nil, validate_only: false)
# Ensure config bucket exists
unless validate_only
rubys3_client = Aws::S3::Client.new
begin
rubys3_client.head_bucket(bucket: 'config')
rescue Aws::S3::Errors::NotFound
Expand All @@ -153,9 +152,11 @@ def self.install_phase2(plugin_hash, scope:, validate_only: false)
begin
tf = nil

# Get the gem from local gem server
gem_name = plugin_hash['name'].split("__")[0]
gem_file_path = Cosmos::GemModel.get(temp_dir, gem_name)
# Get the gem from local gem server if it hasn't been passed
unless gem_file_path
gem_name = plugin_hash['name'].split("__")[0]
gem_file_path = Cosmos::GemModel.get(temp_dir, gem_name)
end

# Actually install the gem now (slow)
Cosmos::GemModel.install(gem_file_path, scope: scope)
Expand Down

0 comments on commit ab8c6f5

Please sign in to comment.