app/controllers/kpm/plugins_controller.rb in killbill-kpm-ui-1.0.2 vs app/controllers/kpm/plugins_controller.rb in killbill-kpm-ui-2.0.0

- old
+ new

@@ -1,27 +1,28 @@ +# frozen_string_literal: true + require 'kpm/client' module KPM class PluginsController < EngineController - def index nodes_by_kb_version, @kb_version = killbill_version @warning_message = '' - plugins = [] - if nodes_by_kb_version.size > 1 + @plugins = {} + if !nodes_by_kb_version.nil? && nodes_by_kb_version.size > 1 @warning_message = different_versions_warning_message(nodes_by_kb_version) else + full_kb_version = nodes_by_kb_version.nil? ? 'LATEST' : nodes_by_kb_version.keys.first begin - plugins = ::Killbill::KPM::KPMClient.get_available_plugins(true, options_for_klient) - rescue => e - # No connectivity, GitHub down, ... - Rails.logger.warn("Unable to get latest plugins, trying built-in directory: #{e.inspect}") - plugins = ::Killbill::KPM::KPMClient.get_available_plugins(false, options_for_klient) + plugins_metadata = ::Killbill::KPM::KPMClient.get_available_plugins(full_kb_version, true, options_for_klient) + rescue StandardError => e + # No connectivity or version not in Nexus + Rails.logger.warn("Unable to get latest plugins for version #{full_kb_version}: #{e.inspect}") + plugins_metadata = ::Killbill::KPM::KPMClient.get_available_plugins('LATEST', false, options_for_klient) end - plugins.select! { |plugin_key, info| info['versions'].keys.include?(@kb_version) } + @plugins = Hash[plugins_metadata['plugins'].sort] end - @plugins = Hash[plugins.sort] end private def different_versions_warning_message(nodes_by_kb_version) @@ -41,8 +42,7 @@ nodes_info.each do |node| nodes_by_kb_version[node.kb_version] = "#{(nodes_by_kb_version[node.kb_version] || '')} #{node.node_name}" end [nodes_by_kb_version, first_node_version.scan(/(\d+\.\d+)(\.\d)?/).flatten[0]] end - end end