kpm 0.7.2 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +66 -0
  3. data/Gemfile +2 -0
  4. data/README.adoc +111 -109
  5. data/Rakefile +2 -1
  6. data/bin/kpm +4 -2
  7. data/kpm.gemspec +8 -6
  8. data/lib/kpm.rb +3 -0
  9. data/lib/kpm/account.rb +267 -338
  10. data/lib/kpm/base_artifact.rb +33 -39
  11. data/lib/kpm/base_installer.rb +69 -83
  12. data/lib/kpm/blob.rb +29 -0
  13. data/lib/kpm/cli.rb +3 -1
  14. data/lib/kpm/coordinates.rb +6 -9
  15. data/lib/kpm/database.rb +90 -114
  16. data/lib/kpm/diagnostic_file.rb +126 -147
  17. data/lib/kpm/formatter.rb +74 -46
  18. data/lib/kpm/inspector.rb +22 -32
  19. data/lib/kpm/installer.rb +53 -46
  20. data/lib/kpm/kaui_artifact.rb +4 -3
  21. data/lib/kpm/killbill_plugin_artifact.rb +10 -7
  22. data/lib/kpm/killbill_server_artifact.rb +13 -12
  23. data/lib/kpm/migrations.rb +8 -7
  24. data/lib/kpm/nexus_helper/actions.rb +47 -8
  25. data/lib/kpm/nexus_helper/nexus_api_calls_v2.rb +87 -94
  26. data/lib/kpm/nexus_helper/nexus_facade.rb +5 -3
  27. data/lib/kpm/plugins_directory.rb +9 -8
  28. data/lib/kpm/plugins_directory.yml +8 -175
  29. data/lib/kpm/plugins_manager.rb +29 -24
  30. data/lib/kpm/sha1_checker.rb +31 -18
  31. data/lib/kpm/system.rb +105 -136
  32. data/lib/kpm/system_helpers/cpu_information.rb +56 -55
  33. data/lib/kpm/system_helpers/disk_space_information.rb +60 -63
  34. data/lib/kpm/system_helpers/entropy_available.rb +37 -39
  35. data/lib/kpm/system_helpers/memory_information.rb +52 -51
  36. data/lib/kpm/system_helpers/os_information.rb +45 -47
  37. data/lib/kpm/system_helpers/system_proxy.rb +10 -10
  38. data/lib/kpm/tasks.rb +364 -437
  39. data/lib/kpm/tenant_config.rb +68 -83
  40. data/lib/kpm/tomcat_manager.rb +9 -8
  41. data/lib/kpm/trace_logger.rb +18 -16
  42. data/lib/kpm/uninstaller.rb +81 -14
  43. data/lib/kpm/utils.rb +13 -14
  44. data/lib/kpm/version.rb +3 -1
  45. data/packaging/Gemfile +2 -0
  46. data/pom.xml +1 -1
  47. data/spec/kpm/remote/base_artifact_spec.rb +13 -15
  48. data/spec/kpm/remote/base_installer_spec.rb +30 -29
  49. data/spec/kpm/remote/installer_spec.rb +73 -73
  50. data/spec/kpm/remote/kaui_artifact_spec.rb +7 -6
  51. data/spec/kpm/remote/killbill_plugin_artifact_spec.rb +19 -24
  52. data/spec/kpm/remote/killbill_server_artifact_spec.rb +17 -16
  53. data/spec/kpm/remote/migrations_spec.rb +12 -11
  54. data/spec/kpm/remote/nexus_facade_spec.rb +30 -26
  55. data/spec/kpm/remote/tenant_config_spec.rb +27 -26
  56. data/spec/kpm/remote/tomcat_manager_spec.rb +2 -1
  57. data/spec/kpm/unit/actions_spec.rb +52 -0
  58. data/spec/kpm/unit/base_artifact_spec.rb +17 -16
  59. data/spec/kpm/unit/cpu_information_spec.rb +67 -0
  60. data/spec/kpm/unit/disk_space_information_spec.rb +47 -0
  61. data/spec/kpm/unit/entropy_information_spec.rb +36 -0
  62. data/spec/kpm/unit/formatter_spec.rb +163 -0
  63. data/spec/kpm/unit/inspector_spec.rb +34 -42
  64. data/spec/kpm/unit/installer_spec.rb +5 -4
  65. data/spec/kpm/unit/memory_information_spec.rb +102 -0
  66. data/spec/kpm/unit/os_information_spec.rb +38 -0
  67. data/spec/kpm/unit/plugins_directory_spec.rb +34 -18
  68. data/spec/kpm/unit/plugins_manager_spec.rb +61 -65
  69. data/spec/kpm/unit/sha1_checker_spec.rb +107 -60
  70. data/spec/kpm/unit/uninstaller_spec.rb +107 -61
  71. data/spec/kpm/unit_mysql/account_spec.rb +120 -135
  72. data/spec/spec_helper.rb +19 -17
  73. data/tasks/package.rake +18 -18
  74. metadata +17 -8
@@ -1,12 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rexml/document'
2
4
  require 'set'
3
5
 
4
6
  module KPM
5
7
  class KauiArtifact < BaseArtifact
6
8
  class << self
7
- def versions(overrides={}, ssl_verify=true)
8
-
9
- coordinate_map = {:group_id => KPM::BaseArtifact::KAUI_GROUP_ID, :artifact_id => KPM::BaseArtifact::KAUI_ARTIFACT_ID, :packaging => KPM::BaseArtifact::KAUI_PACKAGING, :classifier => KPM::BaseArtifact::KAUI_CLASSIFIER}
9
+ def versions(overrides = {}, ssl_verify = true)
10
+ coordinate_map = { group_id: KPM::BaseArtifact::KAUI_GROUP_ID, artifact_id: KPM::BaseArtifact::KAUI_ARTIFACT_ID, packaging: KPM::BaseArtifact::KAUI_PACKAGING, classifier: KPM::BaseArtifact::KAUI_CLASSIFIER }
10
11
 
11
12
  coordinates = KPM::Coordinates.build_coordinates(coordinate_map)
12
13
  response = REXML::Document.new nexus_remote(overrides, ssl_verify).search_for_artifacts(coordinates)
@@ -1,23 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rexml/document'
2
4
  require 'set'
3
5
 
4
6
  module KPM
5
7
  class KillbillPluginArtifact < BaseArtifact
6
8
  class << self
7
- def pull(logger, group_id, artifact_id, packaging='jar', classifier=nil, version='LATEST', plugin_name=nil, destination_path=nil, sha1_file=nil, force_download=false, verify_sha1=true, overrides={}, ssl_verify=true)
8
- coordinate_map = {:group_id => group_id, :artifact_id => artifact_id, :packaging => packaging, :classifier => classifier, :version => version}
9
- pull_and_put_in_place(logger, coordinate_map, plugin_name, destination_path, is_ruby_plugin_and_should_skip_top_dir(group_id, artifact_id), sha1_file, force_download, verify_sha1, overrides, ssl_verify)
9
+ def pull(logger, group_id, artifact_id, packaging = 'jar', classifier = nil, version = 'LATEST', plugin_name = nil, destination_path = nil, sha1_file = nil, force_download = false, verify_sha1 = true, overrides = {}, ssl_verify = true)
10
+ coordinate_map = { group_id: group_id, artifact_id: artifact_id, packaging: packaging, classifier: classifier, version: version }
11
+ pull_and_put_in_place(logger, coordinate_map, plugin_name, destination_path, ruby_plugin_and_should_skip_top_dir?(group_id, artifact_id), sha1_file, force_download, verify_sha1, overrides, ssl_verify)
10
12
  end
11
13
 
12
- def versions(overrides={}, ssl_verify=true)
13
- plugins = {:java => {}, :ruby => {}}
14
+ def versions(overrides = {}, ssl_verify = true)
15
+ plugins = { java: {}, ruby: {} }
14
16
 
15
17
  nexus = nexus_remote(overrides, ssl_verify)
16
18
 
17
19
  [[:java, KPM::BaseArtifact::KILLBILL_JAVA_PLUGIN_GROUP_ID], [:ruby, KPM::BaseArtifact::KILLBILL_RUBY_PLUGIN_GROUP_ID]].each do |type_and_group_id|
18
20
  response = REXML::Document.new nexus.search_for_artifacts(type_and_group_id[1])
19
21
  response.elements.each('searchNGResponse/data/artifact') do |element|
20
- artifact_id = element.elements['artifactId'].text
22
+ artifact_id = element.elements['artifactId'].text
21
23
  plugins[type_and_group_id[0]][artifact_id] ||= SortedSet.new
22
24
  plugins[type_and_group_id[0]][artifact_id] << element.elements['version'].text
23
25
  end
@@ -27,9 +29,10 @@ module KPM
27
29
  end
28
30
 
29
31
  protected
32
+
30
33
  # Magic methods...
31
34
 
32
- def is_ruby_plugin_and_should_skip_top_dir(group_id, artifact_id)
35
+ def ruby_plugin_and_should_skip_top_dir?(group_id, artifact_id)
33
36
  # The second check is for custom ruby plugins
34
37
  group_id == KPM::BaseArtifact::KILLBILL_RUBY_PLUGIN_GROUP_ID || artifact_id.include?('plugin')
35
38
  end
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rexml/document'
2
4
  require 'set'
3
5
 
4
6
  module KPM
5
7
  class KillbillServerArtifact < BaseArtifact
6
8
  class << self
7
- def versions(artifact_id, packaging=KPM::BaseArtifact::KILLBILL_PACKAGING, classifier=KPM::BaseArtifact::KILLBILL_CLASSIFIER, overrides={}, ssl_verify=true)
8
- coordinate_map = {:group_id => KPM::BaseArtifact::KILLBILL_GROUP_ID, :artifact_id => artifact_id, :packaging => packaging, :classifier => classifier}
9
+ def versions(artifact_id, packaging = KPM::BaseArtifact::KILLBILL_PACKAGING, classifier = KPM::BaseArtifact::KILLBILL_CLASSIFIER, overrides = {}, ssl_verify = true)
10
+ coordinate_map = { group_id: KPM::BaseArtifact::KILLBILL_GROUP_ID, artifact_id: artifact_id, packaging: packaging, classifier: classifier }
9
11
  coordinates = KPM::Coordinates.build_coordinates(coordinate_map)
10
12
  response = REXML::Document.new nexus_remote(overrides, ssl_verify).search_for_artifacts(coordinates)
11
13
  versions = SortedSet.new
@@ -13,14 +15,15 @@ module KPM
13
15
  versions
14
16
  end
15
17
 
16
- def info(version='LATEST', sha1_file=nil, force_download=false, verify_sha1=true, overrides={}, ssl_verify=true)
18
+ def info(version = 'LATEST', sha1_file = nil, force_download = false, verify_sha1 = true, overrides = {}, ssl_verify = true)
17
19
  logger = Logger.new(STDOUT)
18
20
  logger.level = Logger::ERROR
19
21
 
20
- version = KPM::Installer.get_kb_latest_stable_version if version == 'LATEST'
21
-
22
+ # Initialize as early as possible (used in rescue block below)
22
23
  sha1_checker = sha1_file ? Sha1Checker.from_file(sha1_file) : nil
23
24
 
25
+ version = KPM::Installer.get_kb_latest_stable_version if version == 'LATEST'
26
+
24
27
  versions = {}
25
28
  Dir.mktmpdir do |dir|
26
29
  # Retrieve the main Kill Bill pom
@@ -61,7 +64,7 @@ module KPM
61
64
 
62
65
  pom = REXML::Document.new(File.new(oss_pom_info[:file_path]))
63
66
  properties_element = pom.root.elements['properties']
64
- %w(killbill-api killbill-plugin-api killbill-commons killbill-platform).each do |property|
67
+ %w[killbill-api killbill-plugin-api killbill-commons killbill-platform].each do |property|
65
68
  versions[property] = properties_element.elements["#{property}.version"].text
66
69
  end
67
70
 
@@ -71,12 +74,10 @@ module KPM
71
74
  rescue StandardError => e
72
75
  # Network down? Hopefully, we have something in the cache
73
76
  cached_version = sha1_checker ? sha1_checker.killbill_info(version) : nil
74
- if force_download || !cached_version
75
- raise e
76
- else
77
- # Use the cache
78
- return cached_version
79
- end
77
+ raise e if force_download || !cached_version
78
+
79
+ # Use the cache
80
+ cached_version
80
81
  end
81
82
  end
82
83
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'base64'
2
4
  require 'json'
3
5
  require 'logger'
@@ -6,10 +8,9 @@ require 'pathname'
6
8
 
7
9
  module KPM
8
10
  class Migrations
9
-
10
- KILLBILL_MIGRATION_PATH = /src\/main\/resources\/org\/killbill\/billing\/[a-z]+\/migration\/(V[0-9a-zA-Z_]+.sql)/
11
- JAVA_PLUGIN_MIGRATION_PATH = /src\/main\/resources\/migration\/(V[0-9a-zA-Z_]+.sql)/
12
- RUBY_PLUGIN_MIGRATION_PATH = /db\/migrate\/([0-9a-zA-Z_]+.rb)/
11
+ KILLBILL_MIGRATION_PATH = %r{src/main/resources/org/killbill/billing/[a-z]+/migration/(V[0-9a-zA-Z_]+.sql)}.freeze
12
+ JAVA_PLUGIN_MIGRATION_PATH = %r{src/main/resources/migration/(V[0-9a-zA-Z_]+.sql)}.freeze
13
+ RUBY_PLUGIN_MIGRATION_PATH = %r{db/migrate/([0-9a-zA-Z_]+.rb)}.freeze
13
14
 
14
15
  # Go to https://github.com/settings/tokens to generate a token
15
16
  def initialize(from_version, to_version = nil, repository = 'killbill/killbill', oauth_token = nil, logger = Logger.new(STDOUT))
@@ -34,7 +35,7 @@ module KPM
34
35
  end
35
36
 
36
37
  def save(dir = nil)
37
- return nil if migrations.size == 0
38
+ return nil if migrations.empty?
38
39
 
39
40
  dir ||= Dir.mktmpdir
40
41
  @logger.debug("Storing migrations to #{dir}")
@@ -71,8 +72,8 @@ module KPM
71
72
  end
72
73
 
73
74
  migrations << {
74
- :name => migration_name,
75
- :sql => sql
75
+ name: migration_name,
76
+ sql: sql
76
77
  }
77
78
  end
78
79
 
@@ -1,9 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'nexus_api_calls_v2'
2
- #require_relative 'nexus_api_calls_v3'
4
+ # require_relative 'nexus_api_calls_v3'
3
5
 
4
6
  module KPM
5
7
  module NexusFacade
6
8
  class Actions
9
+ DEFAULT_RETRIES = 3
10
+ DEFAULT_CONNECTION_ERRORS = {
11
+ EOFError => 'The remote server dropped the connection',
12
+ Errno::ECONNREFUSED => 'The remote server refused the connection',
13
+ Errno::ECONNRESET => 'The remote server reset the connection',
14
+ Timeout::Error => 'The connection to the remote server timed out',
15
+ Errno::ETIMEDOUT => 'The connection to the remote server timed out',
16
+ SocketError => 'The connection to the remote server could not be established',
17
+ OpenSSL::X509::CertificateError => 'The remote server did not accept the provided SSL certificate',
18
+ OpenSSL::SSL::SSLError => 'The SSL connection to the remote server could not be established',
19
+ Zlib::BufError => 'The remote server replied with an invalid response',
20
+ KPM::NexusFacade::UnexpectedStatusCodeException => nil
21
+ }.freeze
22
+
7
23
  attr_reader :nexus_api_call
8
24
 
9
25
  def initialize(overrides, ssl_verify, logger)
@@ -11,24 +27,47 @@ module KPM
11
27
  overrides[:url] ||= 'https://oss.sonatype.org'
12
28
  overrides[:repository] ||= 'releases'
13
29
 
14
- #this is where the version is verified
15
- #example if
16
- #@nexus_api_call = overrides['version'] == '3' ? NexusApiCallsV3.new(overrides, ssl_verify) : NexusApiCallsV2.new(overrides, ssl_verify)
30
+ @logger = logger
31
+
32
+ # this is where the version is verified
33
+ # example if
34
+ # @nexus_api_call = overrides['version'] == '3' ? NexusApiCallsV3.new(overrides, ssl_verify) : NexusApiCallsV2.new(overrides, ssl_verify)
17
35
  @nexus_api_call = NexusApiCallsV2.new(overrides, ssl_verify, logger)
18
36
  end
19
37
 
20
- def pull_artifact(coordinates, destination=nil)
21
- nexus_api_call.pull_artifact(coordinates, destination)
38
+ def pull_artifact(coordinates, destination = nil)
39
+ retry_exceptions("pull_artifact #{coordinates}") { nexus_api_call.pull_artifact(coordinates, destination) }
22
40
  end
23
41
 
24
42
  def get_artifact_info(coordinates)
25
- nexus_api_call.get_artifact_info(coordinates)
43
+ retry_exceptions("get_artifact_info #{coordinates}") { nexus_api_call.get_artifact_info(coordinates) }
26
44
  end
27
45
 
28
46
  def search_for_artifacts(coordinates)
29
- nexus_api_call.search_for_artifacts(coordinates)
47
+ retry_exceptions("search_for_artifacts #{coordinates}") { nexus_api_call.search_for_artifacts(coordinates) }
48
+ end
49
+
50
+ private
51
+
52
+ def retry_exceptions(tag)
53
+ retries = DEFAULT_RETRIES
54
+
55
+ begin
56
+ yield
57
+ rescue *DEFAULT_CONNECTION_ERRORS.keys => e
58
+ retries -= 1
59
+
60
+ @logger.warn(format('Transient error during %<tag>s, retrying (attempt=%<attempt>d): %<msg>s', tag: tag, attempt: DEFAULT_RETRIES - retries, msg: derived_error_message(DEFAULT_CONNECTION_ERRORS, e)))
61
+ retry unless retries.zero?
62
+
63
+ raise
64
+ end
30
65
  end
31
66
 
67
+ def derived_error_message(errors, exception)
68
+ key = (errors.keys & exception.class.ancestors).first
69
+ (key ? errors[key] : nil) || exception.message
70
+ end
32
71
  end
33
72
  end
34
73
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'net/http'
2
4
  require 'uri'
3
5
  require 'rexml/document'
@@ -5,13 +7,12 @@ require 'openssl'
5
7
 
6
8
  module KPM
7
9
  module NexusFacade
8
-
9
10
  class UnexpectedStatusCodeException < StandardError
10
11
  def initialize(code)
11
12
  @code = code
12
13
  end
13
14
 
14
- def message
15
+ def message
15
16
  "The server responded with a #{@code} status code which is unexpected."
16
17
  end
17
18
  end
@@ -34,7 +35,6 @@ module KPM
34
35
  OPEN_TIMEOUT_DEFAULT = 60
35
36
 
36
37
  ERROR_MESSAGE_404 = 'The artifact you requested information for could not be found. Please ensure it exists inside the Nexus.'
37
- ERROR_MESSAGE_503 = 'Could not connect to Nexus. Please ensure the url you are using is reachable.'
38
38
 
39
39
  attr_reader :version
40
40
  attr_reader :configuration
@@ -49,14 +49,16 @@ module KPM
49
49
 
50
50
  def search_for_artifacts(coordinates)
51
51
  logger.debug "Entered - Search for artifact, coordinates: #{coordinates}"
52
- response = get_response(coordinates, SEARCH_FOR_ARTIFACT_ENDPOINT, [:g, :a])
52
+ response = get_response(coordinates, SEARCH_FOR_ARTIFACT_ENDPOINT, %i[g a])
53
53
 
54
54
  case response.code
55
- when '200'
56
- logger.debug "response body: #{response.body}"
57
- return response.body
58
- else
59
- raise UnexpectedStatusCodeException.new(response.code)
55
+ when '200'
56
+ logger.debug "response body: #{response.body}"
57
+ return response.body
58
+ when '404'
59
+ raise StandardError, ERROR_MESSAGE_404
60
+ else
61
+ raise UnexpectedStatusCodeException, response.code
60
62
  end
61
63
  end
62
64
 
@@ -65,125 +67,116 @@ module KPM
65
67
  response = get_response(coordinates, GET_ARTIFACT_INFO_ENDPOINT, nil)
66
68
 
67
69
  case response.code
68
- when '200'
69
- logger.debug "response body: #{response.body}"
70
- return response.body
71
- when '404'
72
- raise StandardError.new(ERROR_MESSAGE_404)
73
- when '503'
74
- raise StandardError.new(ERROR_MESSAGE_503)
75
- else
76
- raise UnexpectedStatusCodeException.new(response.code)
70
+ when '200'
71
+ logger.debug "response body: #{response.body}"
72
+ return response.body
73
+ when '404'
74
+ raise StandardError, ERROR_MESSAGE_404
75
+ else
76
+ raise UnexpectedStatusCodeException, response.code
77
77
  end
78
78
  end
79
79
 
80
- def pull_artifact(coordinates ,destination)
80
+ def pull_artifact(coordinates, destination)
81
81
  logger.debug "Entered - Pull artifact, coordinates: #{coordinates}"
82
82
  file_name = get_file_name(coordinates)
83
- destination = File.join(File.expand_path(destination || "."), file_name)
83
+ destination = File.join(File.expand_path(destination || '.'), file_name)
84
84
  logger.debug "destination: #{destination}"
85
85
  response = get_response(coordinates, PULL_ARTIFACT_ENDPOINT, nil)
86
86
 
87
87
  case response.code
88
- when '301', '307'
89
- location = response['Location'].gsub!(configuration[:url],'')
90
- logger.debug 'fetching artifact'
91
- file_response = get_response(nil,location, nil)
92
-
93
- File.open(destination, "wb") do |io|
94
- io.write(file_response.body)
95
- end
96
- when 404
97
- raise StandardError.new(ERROR_MESSAGE_404)
98
- else
99
- raise UnexpectedStatusCodeException.new(response.code)
88
+ when '301', '307'
89
+ location = response['Location'].gsub!(configuration[:url], '')
90
+ logger.debug 'fetching artifact'
91
+ file_response = get_response(nil, location, nil)
92
+
93
+ File.open(destination, 'wb') do |io|
94
+ io.write(file_response.body)
95
+ end
96
+ when 404
97
+ raise StandardError, ERROR_MESSAGE_404
98
+ else
99
+ raise UnexpectedStatusCodeException, response.code
100
100
  end
101
101
  {
102
- :file_name => file_name,
103
- :file_path => File.expand_path(destination),
104
- :version => version,
105
- :size => File.size(File.expand_path(destination))
102
+ file_name: file_name,
103
+ file_path: File.expand_path(destination),
104
+ version: version,
105
+ size: File.size(File.expand_path(destination))
106
106
  }
107
107
  end
108
108
 
109
109
  private
110
- def parse_coordinates(coordinates)
111
110
 
112
- if coordinates.nil?
113
- raise ArtifactMalformedException
114
- end
111
+ def parse_coordinates(coordinates)
112
+ raise ArtifactMalformedException if coordinates.nil?
115
113
 
116
- split_coordinates = coordinates.split(":")
117
- if (split_coordinates.size == 0 or split_coordinates.size > 5)
118
- raise ArtifactMalformedException
119
- end
114
+ split_coordinates = coordinates.split(':')
115
+ raise ArtifactMalformedException if split_coordinates.empty? || (split_coordinates.size > 5)
120
116
 
121
- artifact = Hash.new
117
+ artifact = {}
122
118
 
123
- artifact[:group_id] = split_coordinates[0]
124
- artifact[:artifact_id] = split_coordinates[1]
125
- artifact[:extension] = split_coordinates.size > 3 ? split_coordinates[2] : "jar"
126
- artifact[:classifier] = split_coordinates.size > 4 ? split_coordinates[3] : nil
127
- artifact[:version] = split_coordinates[-1]
119
+ artifact[:group_id] = split_coordinates[0]
120
+ artifact[:artifact_id] = split_coordinates[1]
121
+ artifact[:extension] = split_coordinates.size > 3 ? split_coordinates[2] : 'jar'
122
+ artifact[:classifier] = split_coordinates.size > 4 ? split_coordinates[3] : nil
123
+ artifact[:version] = split_coordinates[-1]
128
124
 
129
- artifact[:version].upcase! if version == "latest"
125
+ artifact[:version].upcase! if version == 'latest'
130
126
 
131
- return artifact
132
- end
127
+ artifact
128
+ end
133
129
 
134
- def get_file_name(coordinates)
135
- artifact = parse_coordinates(coordinates)
130
+ def get_file_name(coordinates)
131
+ artifact = parse_coordinates(coordinates)
136
132
 
137
- if artifact[:version].casecmp("latest")
138
- artifact[:version] = REXML::Document.new(get_artifact_info(coordinates)).elements["//version"].text
139
- end
133
+ artifact[:version] = REXML::Document.new(get_artifact_info(coordinates)).elements['//version'].text if artifact[:version].casecmp('latest')
140
134
 
141
- if artifact[:classifier].nil?
142
- "#{artifact[:artifact_id]}-#{artifact[:version]}.#{artifact[:extension]}"
143
- else
144
- "#{artifact[:artifact_id]}-#{artifact[:version]}-#{artifact[:classifier]}.#{artifact[:extension]}"
145
- end
135
+ if artifact[:classifier].nil?
136
+ "#{artifact[:artifact_id]}-#{artifact[:version]}.#{artifact[:extension]}"
137
+ else
138
+ "#{artifact[:artifact_id]}-#{artifact[:version]}-#{artifact[:classifier]}.#{artifact[:extension]}"
146
139
  end
140
+ end
147
141
 
148
- def get_query_params(coordinates, what_parameters = nil)
149
- artifact = parse_coordinates(coordinates)
150
- @version = artifact[:version].to_s.upcase
151
-
152
- query = {:g => artifact[:group_id], :a => artifact[:artifact_id], :e => artifact[:extension], :v => version, :r => configuration[:repository]}
153
- query.merge!({:c => artifact[:classifier]}) unless artifact[:classifier].nil?
142
+ def build_query_params(coordinates, what_parameters = nil)
143
+ artifact = parse_coordinates(coordinates)
144
+ @version = artifact[:version].to_s.upcase
154
145
 
155
- params = what_parameters.nil? ? query : Hash.new
156
- what_parameters.each {|key| params[key] = query[key] unless query[key].nil? } unless what_parameters.nil?
146
+ query = { g: artifact[:group_id], a: artifact[:artifact_id], e: artifact[:extension], v: version, r: configuration[:repository] }
147
+ query.merge!(c: artifact[:classifier]) unless artifact[:classifier].nil?
157
148
 
158
- params.map{|key,value| "#{key}=#{value}"}.join('&')
159
- end
149
+ params = what_parameters.nil? ? query : {}
150
+ what_parameters.each { |key| params[key] = query[key] unless query[key].nil? } unless what_parameters.nil?
160
151
 
161
- def get_response(coordinates, endpoint, what_parameters)
162
- http = get_http
163
- query_params = get_query_params(coordinates, what_parameters) unless coordinates.nil?
164
- endpoint = get_endpoint_with_params(endpoint, query_params) unless coordinates.nil?
165
- request = Net::HTTP::Get.new(endpoint)
152
+ params.map { |key, value| "#{key}=#{value}" }.join('&')
153
+ end
166
154
 
167
- logger.debug "request endpoint: #{endpoint}"
155
+ def get_response(coordinates, endpoint, what_parameters)
156
+ http = build_http
157
+ query_params = build_query_params(coordinates, what_parameters) unless coordinates.nil?
158
+ endpoint = endpoint_with_params(endpoint, query_params) unless coordinates.nil?
159
+ request = Net::HTTP::Get.new(endpoint)
168
160
 
169
- response = http.request(request)
170
- response
171
- end
161
+ logger.debug "request endpoint: #{endpoint}"
172
162
 
173
- def get_http
174
- uri = URI.parse(configuration[:url])
175
- http = Net::HTTP.new(uri.host,uri.port)
176
- http.open_timeout = configuration[:open_timeout] || OPEN_TIMEOUT_DEFAULT #seconds
177
- http.read_timeout = configuration[:read_timeout] || READ_TIMEOUT_DEFAULT #seconds
178
- http.use_ssl = (ssl_verify != false)
179
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE unless ssl_verify
180
- http
181
- end
163
+ response = http.request(request)
164
+ response
165
+ end
182
166
 
183
- def get_endpoint_with_params(endpoint,query_params)
184
- "#{endpoint}?#{URI::DEFAULT_PARSER.escape(query_params)}"
185
- end
167
+ def build_http
168
+ uri = URI.parse(configuration[:url])
169
+ http = Net::HTTP.new(uri.host, uri.port)
170
+ http.open_timeout = configuration[:open_timeout] || OPEN_TIMEOUT_DEFAULT # seconds
171
+ http.read_timeout = configuration[:read_timeout] || READ_TIMEOUT_DEFAULT # seconds
172
+ http.use_ssl = (ssl_verify != false)
173
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE unless ssl_verify
174
+ http
175
+ end
186
176
 
177
+ def endpoint_with_params(endpoint, query_params)
178
+ "#{endpoint}?#{URI::DEFAULT_PARSER.escape(query_params)}"
179
+ end
187
180
  end
188
181
  end
189
182
  end