From 1efea66f6c11142c8b8451eb7ce1f816ea6fce4e Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Fri, 5 Apr 2019 12:45:31 +0200 Subject: [PATCH] F #3167: Set enterprise repo as a constant --- src/sunstone/routes/support.rb | 44 ++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/sunstone/routes/support.rb b/src/sunstone/routes/support.rb index 0ea8a91a2d4..454c1e9081e 100644 --- a/src/sunstone/routes/support.rb +++ b/src/sunstone/routes/support.rb @@ -20,7 +20,8 @@ # rubocop:disable Style/GlobalVars UNSUPPORTED_RUBY = !(RUBY_VERSION =~ /^1.8/).nil? -GITHUB_TAGS_URL='https://api.github.com/repos/opennebula/one/tags' +GITHUB_TAGS_URL = 'https://api.github.com/repos/opennebula/one/tags' +ENTREPRISE_REPO_URL = 'https://downloads.opennebula.systems/repo//' begin require 'zendesk_api' @@ -35,7 +36,7 @@ require 'scrub_rb' end -def valid_user_with_id(client) +def invalid_user_with_id(client) client.current_user.nil? || client.current_user.id.nil? end @@ -74,7 +75,9 @@ def zendesk_client # use the API at https://yoursubdomain.zendesk.com/api/v2 end - error 401, 'Incorrect Zendesk account credentials' if valid_user_with_id + if invalid_user_with_id(client) + error 401, 'Incorrect Zendesk account credentials' + end client end @@ -175,20 +178,20 @@ def check_zendesk_api_gem body_hash = JSON.parse(@request_body) - zen_api = ZendesAPI::Request + zen_api = ZendeskAPI::Request zrequest = zen_api.new( - zendesk_client, - :subject => body_hash['subject'], - :comment => { :value => body_hash['description'] }, - :custom_fields => [ - { :id => SUPPORT[:custom_field_severity], - :value => body_hash['severity'] }, - { :id => SUPPORT[:custom_field_version], - :value => body_hash['opennebula_version'] } - ], - :tags => [body_hash['severity']] - ) + zendesk_client, + :subject => body_hash['subject'], + :comment => { :value => body_hash['description'] }, + :custom_fields => [ + { :id => SUPPORT[:custom_field_severity], + :value => body_hash['severity'] }, + { :id => SUPPORT[:custom_field_version], + :value => body_hash['opennebula_version'] } + ], + :tags => [body_hash['severity']] + ) if zrequest.save [201, JSON.pretty_generate(zrequest_to_one(zrequest))] @@ -201,8 +204,6 @@ def check_zendesk_api_gem get '/support/check' do one_version = OpenNebula::VERSION if !one_version.empty? && - !$conf[:check_remote_support].nil? && - !$conf[:check_remote_support].empty? && !$conf[:token_remote_support].nil? && !$conf[:token_remote_support].empty? @@ -219,7 +220,7 @@ def check_zendesk_api_gem major_version = version.slice(0..version.rindex('.') - 1) full_version = "#{major_version}.#{minor_version}" - url = $conf[:check_remote_support].sub('', full_version) + url = ENTREPRISE_REPO_URL.sub('', full_version) begin http = Curl.get(url) do |http_options| token_enc = Base64.strict_encode64($conf[:token_remote_support]) @@ -243,7 +244,7 @@ def check_zendesk_api_gem # Returns latest available version get '/support/check/version' do $conf[:one_version_time] = 0 if $conf[:one_version_time].nil? - $conf[:one_last_version] = 0 if $conf[:one_last_version].nil? + $conf[:one_last_version] = '0' if $conf[:one_last_version].nil? find = 'release-' validate_time = Time.now.to_i - $conf[:one_version_time] @@ -273,9 +274,10 @@ def check_zendesk_api_gem $conf[:one_last_version] = version end - minor_version = version.slice(version.rindex('.') + 1..-1).to_i + minor_version = version.slice(version.rindex('.').to_i + 1..-1).to_i + memory_version_index = memory_version.rindex('.').to_i minor_memory_version = - memory_version.slice(memory_version.rindex('.') + 1..-1).to_i + memory_version.slice(memory_version_index.to_i + 1..-1).to_i if version.to_f == memory_version.to_f && minor_version >= minor_memory_version