kpm 0.7.0 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +73 -0
- data/Gemfile +2 -0
- data/README.adoc +111 -109
- data/Rakefile +2 -1
- data/bin/kpm +4 -2
- data/kpm.gemspec +8 -6
- data/lib/kpm.rb +3 -0
- data/lib/kpm/account.rb +268 -337
- data/lib/kpm/base_artifact.rb +40 -36
- data/lib/kpm/base_installer.rb +71 -84
- data/lib/kpm/blob.rb +29 -0
- data/lib/kpm/cli.rb +3 -1
- data/lib/kpm/coordinates.rb +6 -9
- data/lib/kpm/database.rb +92 -103
- data/lib/kpm/diagnostic_file.rb +126 -146
- data/lib/kpm/formatter.rb +74 -46
- data/lib/kpm/inspector.rb +22 -32
- data/lib/kpm/installer.rb +53 -46
- data/lib/kpm/kaui_artifact.rb +4 -3
- data/lib/kpm/killbill_plugin_artifact.rb +10 -7
- data/lib/kpm/killbill_server_artifact.rb +24 -10
- data/lib/kpm/migrations.rb +8 -7
- data/lib/kpm/nexus_helper/actions.rb +47 -8
- data/lib/kpm/nexus_helper/nexus_api_calls_v2.rb +87 -94
- data/lib/kpm/nexus_helper/nexus_facade.rb +5 -3
- data/lib/kpm/plugins_directory.rb +14 -9
- data/lib/kpm/plugins_directory.yml +16 -175
- data/lib/kpm/plugins_manager.rb +29 -24
- data/lib/kpm/sha1_checker.rb +56 -15
- data/lib/kpm/system.rb +104 -135
- data/lib/kpm/system_helpers/cpu_information.rb +56 -55
- data/lib/kpm/system_helpers/disk_space_information.rb +60 -63
- data/lib/kpm/system_helpers/entropy_available.rb +37 -39
- data/lib/kpm/system_helpers/memory_information.rb +52 -51
- data/lib/kpm/system_helpers/os_information.rb +45 -47
- data/lib/kpm/system_helpers/system_proxy.rb +10 -10
- data/lib/kpm/tasks.rb +370 -443
- data/lib/kpm/tenant_config.rb +68 -83
- data/lib/kpm/tomcat_manager.rb +9 -8
- data/lib/kpm/trace_logger.rb +18 -16
- data/lib/kpm/uninstaller.rb +81 -14
- data/lib/kpm/utils.rb +13 -14
- data/lib/kpm/version.rb +3 -1
- data/packaging/Gemfile +2 -0
- data/pom.xml +1 -1
- data/spec/kpm/remote/base_artifact_spec.rb +26 -12
- data/spec/kpm/remote/base_installer_spec.rb +30 -29
- data/spec/kpm/remote/installer_spec.rb +74 -72
- data/spec/kpm/remote/kaui_artifact_spec.rb +7 -6
- data/spec/kpm/remote/killbill_plugin_artifact_spec.rb +19 -24
- data/spec/kpm/remote/killbill_server_artifact_spec.rb +30 -13
- data/spec/kpm/remote/migrations_spec.rb +12 -11
- data/spec/kpm/remote/nexus_facade_spec.rb +30 -26
- data/spec/kpm/remote/tenant_config_spec.rb +27 -26
- data/spec/kpm/remote/tomcat_manager_spec.rb +2 -1
- data/spec/kpm/unit/actions_spec.rb +52 -0
- data/spec/kpm/unit/base_artifact_spec.rb +17 -16
- data/spec/kpm/unit/cpu_information_spec.rb +67 -0
- data/spec/kpm/unit/disk_space_information_spec.rb +47 -0
- data/spec/kpm/unit/entropy_information_spec.rb +36 -0
- data/spec/kpm/unit/formatter_spec.rb +163 -0
- data/spec/kpm/unit/inspector_spec.rb +34 -42
- data/spec/kpm/unit/installer_spec.rb +5 -4
- data/spec/kpm/unit/memory_information_spec.rb +102 -0
- data/spec/kpm/unit/os_information_spec.rb +38 -0
- data/spec/kpm/unit/plugins_directory_spec.rb +34 -18
- data/spec/kpm/unit/plugins_manager_spec.rb +61 -65
- data/spec/kpm/unit/sha1_checker_spec.rb +107 -60
- data/spec/kpm/unit/uninstaller_spec.rb +107 -61
- data/spec/kpm/unit_mysql/account_spec.rb +137 -136
- data/spec/spec_helper.rb +19 -17
- data/tasks/package.rake +18 -18
- metadata +19 -34
data/lib/kpm/kaui_artifact.rb
CHANGED
@@ -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 = {:
|
9
|
-
pull_and_put_in_place(logger, coordinate_map, plugin_name, destination_path,
|
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 = {:
|
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
|
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
|
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 = {:
|
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,10 +15,13 @@ module KPM
|
|
13
15
|
versions
|
14
16
|
end
|
15
17
|
|
16
|
-
def info(version='LATEST', 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
|
|
22
|
+
# Initialize as early as possible (used in rescue block below)
|
23
|
+
sha1_checker = sha1_file ? Sha1Checker.from_file(sha1_file) : nil
|
24
|
+
|
20
25
|
version = KPM::Installer.get_kb_latest_stable_version if version == 'LATEST'
|
21
26
|
|
22
27
|
versions = {}
|
@@ -29,9 +34,9 @@ module KPM
|
|
29
34
|
nil,
|
30
35
|
version,
|
31
36
|
dir,
|
32
|
-
|
33
|
-
|
34
|
-
|
37
|
+
sha1_file,
|
38
|
+
force_download,
|
39
|
+
verify_sha1,
|
35
40
|
overrides,
|
36
41
|
ssl_verify)
|
37
42
|
|
@@ -51,19 +56,28 @@ module KPM
|
|
51
56
|
nil,
|
52
57
|
oss_parent_version,
|
53
58
|
dir,
|
54
|
-
|
55
|
-
|
56
|
-
|
59
|
+
sha1_file,
|
60
|
+
force_download,
|
61
|
+
verify_sha1,
|
57
62
|
overrides,
|
58
63
|
ssl_verify)
|
59
64
|
|
60
65
|
pom = REXML::Document.new(File.new(oss_pom_info[:file_path]))
|
61
66
|
properties_element = pom.root.elements['properties']
|
62
|
-
%w
|
67
|
+
%w[killbill-api killbill-plugin-api killbill-commons killbill-platform].each do |property|
|
63
68
|
versions[property] = properties_element.elements["#{property}.version"].text
|
64
69
|
end
|
70
|
+
|
71
|
+
sha1_checker.cache_killbill_info(version, versions) if sha1_checker
|
65
72
|
end
|
66
73
|
versions
|
74
|
+
rescue StandardError => e
|
75
|
+
# Network down? Hopefully, we have something in the cache
|
76
|
+
cached_version = sha1_checker ? sha1_checker.killbill_info(version) : nil
|
77
|
+
raise e if force_download || !cached_version
|
78
|
+
|
79
|
+
# Use the cache
|
80
|
+
cached_version
|
67
81
|
end
|
68
82
|
end
|
69
83
|
end
|
data/lib/kpm/migrations.rb
CHANGED
@@ -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
|
-
|
11
|
-
|
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.
|
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
|
-
|
75
|
-
|
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
|
-
|
15
|
-
|
16
|
-
|
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
|
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, [
|
52
|
+
response = get_response(coordinates, SEARCH_FOR_ARTIFACT_ENDPOINT, %i[g a])
|
53
53
|
|
54
54
|
case response.code
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
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
|
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 ||
|
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
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
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
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
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
|
-
|
113
|
-
|
114
|
-
end
|
111
|
+
def parse_coordinates(coordinates)
|
112
|
+
raise ArtifactMalformedException if coordinates.nil?
|
115
113
|
|
116
|
-
|
117
|
-
|
118
|
-
raise ArtifactMalformedException
|
119
|
-
end
|
114
|
+
split_coordinates = coordinates.split(':')
|
115
|
+
raise ArtifactMalformedException if split_coordinates.empty? || (split_coordinates.size > 5)
|
120
116
|
|
121
|
-
|
117
|
+
artifact = {}
|
122
118
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
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
|
-
|
125
|
+
artifact[:version].upcase! if version == 'latest'
|
130
126
|
|
131
|
-
|
132
|
-
|
127
|
+
artifact
|
128
|
+
end
|
133
129
|
|
134
|
-
|
135
|
-
|
130
|
+
def get_file_name(coordinates)
|
131
|
+
artifact = parse_coordinates(coordinates)
|
136
132
|
|
137
|
-
|
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
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
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
|
-
|
149
|
-
|
150
|
-
|
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
|
-
|
156
|
-
|
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
|
-
|
159
|
-
|
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
|
-
|
162
|
-
|
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
|
-
|
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
|
-
|
170
|
-
response
|
171
|
-
end
|
161
|
+
logger.debug "request endpoint: #{endpoint}"
|
172
162
|
|
173
|
-
|
174
|
-
|
175
|
-
|
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
|
-
|
184
|
-
|
185
|
-
|
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
|