kpm 0.5.3 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,34 @@
1
+ require_relative 'nexus_api_calls_v2'
2
+ #require_relative 'nexus_api_calls_v3'
3
+
4
+ module KPM
5
+ module NexusFacade
6
+ class Actions
7
+ attr_reader :nexus_api_call
8
+
9
+ def initialize(overrides, ssl_verify, logger)
10
+ overrides ||= {}
11
+ overrides[:url] ||= 'https://oss.sonatype.org'
12
+ overrides[:repository] ||= 'releases'
13
+
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)
17
+ @nexus_api_call = NexusApiCallsV2.new(overrides, ssl_verify, logger)
18
+ end
19
+
20
+ def pull_artifact(coordinates, destination=nil)
21
+ nexus_api_call.pull_artifact(coordinates, destination)
22
+ end
23
+
24
+ def get_artifact_info(coordinates)
25
+ nexus_api_call.get_artifact_info(coordinates)
26
+ end
27
+
28
+ def search_for_artifacts(coordinates)
29
+ nexus_api_call.search_for_artifacts(coordinates)
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,188 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'rexml/document'
4
+
5
+ module KPM
6
+ module NexusFacade
7
+
8
+ class UnexpectedStatusCodeException < StandardError
9
+ def initialize(code)
10
+ @code = code
11
+ end
12
+
13
+ def message
14
+ "The server responded with a #{@code} status code which is unexpected."
15
+ end
16
+ end
17
+
18
+ class ArtifactMalformedException < StandardError
19
+ class << self
20
+ def message
21
+ 'Please submit your request using 4 colon-separated values. `groupId:artifactId:version:extension`'
22
+ end
23
+ end
24
+ end
25
+
26
+ # This is an extract and slim down of functions needed from nexus_cli to maintain the response expected by the base_artifact.
27
+ class NexusApiCallsV2
28
+ PULL_ARTIFACT_ENDPOINT = '/service/local/artifact/maven/redirect'
29
+ GET_ARTIFACT_INFO_ENDPOINT = '/service/local/artifact/maven/resolve'
30
+ SEARCH_FOR_ARTIFACT_ENDPOINT = '/service/local/lucene/search'
31
+
32
+ READ_TIMEOUT_DEFAULT = 60
33
+ OPEN_TIMEOUT_DEFAULT = 60
34
+
35
+ ERROR_MESSAGE_404 = 'The artifact you requested information for could not be found. Please ensure it exists inside the Nexus.'
36
+ ERROR_MESSAGE_503 = 'Could not connect to Nexus. Please ensure the url you are using is reachable.'
37
+
38
+ attr_reader :version
39
+ attr_reader :configuration
40
+ attr_reader :ssl_verify
41
+ attr_accessor :logger
42
+
43
+ def initialize(configuration, ssl_verify, logger)
44
+ @configuration = configuration
45
+ @ssl_verify = ssl_verify
46
+ @logger = logger
47
+ end
48
+
49
+ def search_for_artifacts(coordinates)
50
+ logger.debug "Entered - Search for artifact, coordinates: #{coordinates}"
51
+ response = get_response(coordinates, SEARCH_FOR_ARTIFACT_ENDPOINT, [:g, :a])
52
+
53
+ case response.code
54
+ when '200'
55
+ logger.debug "response body: #{response.body}"
56
+ return response.body
57
+ else
58
+ raise UnexpectedStatusCodeException.new(response.code)
59
+ end
60
+ end
61
+
62
+ def get_artifact_info(coordinates)
63
+ logger.debug "Entered - Get artifact info, coordinates: #{coordinates}"
64
+ response = get_response(coordinates, GET_ARTIFACT_INFO_ENDPOINT, nil)
65
+
66
+ case response.code
67
+ when '200'
68
+ logger.debug "response body: #{response.body}"
69
+ return response.body
70
+ when '404'
71
+ raise StandardError.new(ERROR_MESSAGE_404)
72
+ when '503'
73
+ raise StandardError.new(ERROR_MESSAGE_503)
74
+ else
75
+ raise UnexpectedStatusCodeException.new(response.code)
76
+ end
77
+ end
78
+
79
+ def pull_artifact(coordinates ,destination)
80
+ logger.debug "Entered - Pull artifact, coordinates: #{coordinates}"
81
+ file_name = get_file_name(coordinates)
82
+ destination = File.join(File.expand_path(destination || "."), file_name)
83
+ logger.debug "destination: #{destination}"
84
+ response = get_response(coordinates, PULL_ARTIFACT_ENDPOINT, nil)
85
+
86
+ case response.code
87
+ when '301', '307'
88
+ location = response['Location'].gsub!(configuration[:url],'')
89
+ logger.debug 'fetching artifact'
90
+ file_response = get_response(nil,location, nil)
91
+
92
+ File.open(destination, "wb") do |io|
93
+ io.write(file_response.body)
94
+ end
95
+ when 404
96
+ raise StandardError.new(ERROR_MESSAGE_404)
97
+ else
98
+ raise UnexpectedStatusCodeException.new(response.code)
99
+ end
100
+ {
101
+ :file_name => file_name,
102
+ :file_path => File.expand_path(destination),
103
+ :version => version,
104
+ :size => File.size(File.expand_path(destination))
105
+ }
106
+ end
107
+
108
+ private
109
+ def parse_coordinates(coordinates)
110
+
111
+ if coordinates.nil?
112
+ raise ArtifactMalformedException
113
+ end
114
+
115
+ split_coordinates = coordinates.split(":")
116
+ if (split_coordinates.size == 0 or split_coordinates.size > 5)
117
+ raise ArtifactMalformedException
118
+ end
119
+
120
+ artifact = Hash.new
121
+
122
+ artifact[:group_id] = split_coordinates[0]
123
+ artifact[:artifact_id] = split_coordinates[1]
124
+ artifact[:extension] = split_coordinates.size > 3 ? split_coordinates[2] : "jar"
125
+ artifact[:classifier] = split_coordinates.size > 4 ? split_coordinates[3] : nil
126
+ artifact[:version] = split_coordinates[-1]
127
+
128
+ artifact[:version].upcase! if version == "latest"
129
+
130
+ return artifact
131
+ end
132
+
133
+ def get_file_name(coordinates)
134
+ artifact = parse_coordinates(coordinates)
135
+
136
+ if artifact[:version].casecmp("latest")
137
+ artifact[:version] = REXML::Document.new(get_artifact_info(coordinates)).elements["//version"].text
138
+ end
139
+
140
+ if artifact[:classifier].nil?
141
+ "#{artifact[:artifact_id]}-#{artifact[:version]}.#{artifact[:extension]}"
142
+ else
143
+ "#{artifact[:artifact_id]}-#{artifact[:version]}-#{artifact[:classifier]}.#{artifact[:extension]}"
144
+ end
145
+ end
146
+
147
+ def get_query_params(coordinates, what_parameters = nil)
148
+ artifact = parse_coordinates(coordinates)
149
+ @version = artifact[:version].to_s.upcase
150
+
151
+ query = {:g => artifact[:group_id], :a => artifact[:artifact_id], :e => artifact[:extension], :v => version, :r => configuration[:repository]}
152
+ query.merge!({:c => artifact[:classifier]}) unless artifact[:classifier].nil?
153
+
154
+ params = what_parameters.nil? ? query : Hash.new
155
+ what_parameters.each {|key| params[key] = query[key] unless query[key].nil? } unless what_parameters.nil?
156
+
157
+ params.map{|key,value| "#{key}=#{value}"}.join('&')
158
+ end
159
+
160
+ def get_response(coordinates, endpoint, what_parameters)
161
+ http = get_http
162
+ query_params = get_query_params(coordinates, what_parameters) unless coordinates.nil?
163
+ endpoint = get_endpoint_with_params(endpoint, query_params) unless coordinates.nil?
164
+ request = Net::HTTP::Get.new(endpoint)
165
+
166
+ logger.debug "request endpoint: #{endpoint}"
167
+
168
+ response = http.request(request)
169
+ response
170
+ end
171
+
172
+ def get_http
173
+ uri = URI.parse(configuration[:url])
174
+ http = Net::HTTP.new(uri.host,uri.port)
175
+ http.open_timeout = configuration[:open_timeout] || OPEN_TIMEOUT_DEFAULT #seconds
176
+ http.read_timeout = configuration[:read_timeout] || READ_TIMEOUT_DEFAULT #seconds
177
+ http.use_ssl = true
178
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE unless ssl_verify
179
+ http
180
+ end
181
+
182
+ def get_endpoint_with_params(endpoint,query_params)
183
+ "#{endpoint}?#{URI::DEFAULT_PARSER.escape(query_params)}"
184
+ end
185
+
186
+ end
187
+ end
188
+ end
@@ -0,0 +1,20 @@
1
+ require_relative 'actions'
2
+ module KPM
3
+ module NexusFacade
4
+ class << self
5
+ def logger
6
+ logger = ::Logger.new(STDOUT)
7
+ logger.level = Logger::INFO
8
+ logger
9
+ end
10
+ end
11
+
12
+ class RemoteFactory
13
+ class << self
14
+ def create(overrides, ssl_verify=true, logger=nil)
15
+ Actions.new(overrides, ssl_verify,logger || NexusFacade.logger)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -16,7 +16,7 @@
16
16
  :0.15: 0.2.1
17
17
  :0.16: 0.3.2
18
18
  :0.17: 0.4.10
19
- :0.18: 0.5.4
19
+ :0.18: 0.5.5
20
20
  :require:
21
21
  - :org.killbill.billing.plugin.adyen.merchantAccount
22
22
  - :org.killbill.billing.plugin.adyen.username
@@ -182,6 +182,11 @@
182
182
  - :api_key
183
183
  - :country_account_id
184
184
  - :merchant_id
185
+ :payment-test:
186
+ :type: :ruby
187
+ :artifact_id: payment-test-plugin
188
+ :versions:
189
+ :0.18: 4.3.0
185
190
  :securenet:
186
191
  :type: :ruby
187
192
  :versions:
data/lib/kpm/system.rb CHANGED
@@ -1,25 +1,7 @@
1
1
  require 'yaml'
2
+ require_relative 'system_helpers/system_proxy'
2
3
 
3
4
  module KPM
4
-
5
- module OS
6
- def OS.windows?
7
- (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RbConfig::CONFIG["host_os"]) != nil
8
- end
9
-
10
- def OS.mac?
11
- (/darwin/ =~ RbConfig::CONFIG["host_os"]) != nil
12
- end
13
-
14
- def OS.unix?
15
- !OS.windows?
16
- end
17
-
18
- def OS.linux?
19
- OS.unix? and not OS.mac?
20
- end
21
- end
22
-
23
5
  class System
24
6
 
25
7
  MAX_VALUE_COLUMN_WIDTH = 60
@@ -32,7 +14,6 @@ module KPM
32
14
  end
33
15
 
34
16
  def information(bundles_dir = nil, output_as_json = false, config_file = nil, kaui_web_path = nil, killbill_web_path = nil)
35
- puts 'Retrieving system information'
36
17
  set_config(config_file)
37
18
  killbill_information = show_killbill_information(kaui_web_path,killbill_web_path,output_as_json)
38
19
 
@@ -40,6 +21,10 @@ module KPM
40
21
 
41
22
  environment_information = show_environment_information(java_version, output_as_json)
42
23
  os_information = show_os_information(output_as_json)
24
+ cpu_information = show_cpu_information(output_as_json)
25
+ memory_information = show_memory_information(output_as_json)
26
+ disk_space_information = show_disk_space_information(output_as_json)
27
+ entropy_available = show_entropy_available(output_as_json)
43
28
 
44
29
  if not java_version.nil?
45
30
  command = get_command
@@ -48,16 +33,18 @@ module KPM
48
33
 
49
34
  plugin_information = show_plugin_information(get_plugin_path || bundles_dir || DEFAULT_BUNDLE_DIR, output_as_json)
50
35
 
51
- if output_as_json
52
- json_data = Hash.new
53
- json_data[:killbill_information] = killbill_information
54
- json_data[:environment_information] = environment_information
55
- json_data[:os_information] = os_information
56
- json_data[:java_system_information] = java_system_information
57
- json_data[:plugin_information] = plugin_information
58
-
59
- puts json_data.to_json
60
- end
36
+ json_data = Hash.new
37
+ json_data[:killbill_information] = killbill_information
38
+ json_data[:environment_information] = environment_information
39
+ json_data[:os_information] = os_information
40
+ json_data[:cpu_information] = cpu_information
41
+ json_data[:memory_information] = memory_information
42
+ json_data[:disk_space_information] = disk_space_information
43
+ json_data[:entropy_available] = entropy_available
44
+ json_data[:java_system_information] = java_system_information
45
+ json_data[:plugin_information] = plugin_information
46
+
47
+ json_data.to_json
61
48
  end
62
49
 
63
50
  def show_killbill_information(kaui_web_path, killbill_web_path, output_as_json)
@@ -65,9 +52,11 @@ module KPM
65
52
  kpm_version = KPM::VERSION
66
53
  kaui_version = get_kaui_version(get_kaui_web_path || kaui_web_path)
67
54
  killbill_version = get_killbill_version(get_killbill_web_path || killbill_web_path)
55
+ kaui_standalone_version = get_kaui_standalone_version(get_kaui_web_path || kaui_web_path)
68
56
 
69
57
  environment = Hash[:kpm => {:system=>'KPM',:version => kpm_version},
70
58
  :kaui => {:system=>'Kaui',:version => kaui_version.nil? ? 'not found' : kaui_version},
59
+ :kaui_standalone => {:system=>'Kaui standalone',:version => kaui_standalone_version.nil? ? 'not found' : kaui_standalone_version},
71
60
  :killbill => {:system=>'Killbill',:version => killbill_version.nil? ? 'not found' : killbill_version}]
72
61
 
73
62
  labels = [{:label => :system},
@@ -95,38 +84,59 @@ module KPM
95
84
  environment
96
85
  end
97
86
 
98
- def show_os_information(output_as_json)
99
- os = Hash.new
100
- os_data = nil
87
+ def show_cpu_information(output_as_json)
88
+ cpu_info = KPM::SystemProxy::CpuInformation.fetch
89
+ labels = KPM::SystemProxy::CpuInformation.get_labels
101
90
 
102
- if OS.windows?
103
- os_data = `systeminfo | findstr /C:"OS"`
91
+ unless output_as_json
92
+ @formatter.format(cpu_info,labels)
93
+ end
104
94
 
105
- elsif OS.linux?
106
- os_data = `lsb_release -a 2>&1`
95
+ cpu_info
96
+ end
107
97
 
108
- elsif OS.mac?
109
- os_data = `sw_vers`
98
+ def show_memory_information(output_as_json)
99
+ memory_info = KPM::SystemProxy::MemoryInformation.fetch
100
+ labels = KPM::SystemProxy::MemoryInformation.get_labels
110
101
 
102
+ unless output_as_json
103
+ @formatter.format(memory_info,labels)
111
104
  end
112
105
 
113
- if os_data != nil
114
- os_data.split("\n").each do |info|
106
+ memory_info
107
+ end
115
108
 
116
- infos = info.split(':')
117
- os[infos[0]] = {:os_detail => infos[0], :value => infos[1].to_s.strip}
109
+ def show_disk_space_information(output_as_json)
110
+ disk_space_info = KPM::SystemProxy::DiskSpaceInformation.fetch
111
+ labels = KPM::SystemProxy::DiskSpaceInformation.get_labels
118
112
 
119
- end
113
+ unless output_as_json
114
+ @formatter.format(disk_space_info,labels)
120
115
  end
121
116
 
122
- labels = [{:label => :os_detail},
123
- {:label => :value}]
117
+ disk_space_info
118
+ end
124
119
 
125
- if not output_as_json
126
- @formatter.format(os,labels)
120
+ def show_entropy_available(output_as_json)
121
+ entropy_available = KPM::SystemProxy::EntropyAvailable.fetch
122
+ labels = KPM::SystemProxy::EntropyAvailable.get_labels
123
+
124
+ unless output_as_json
125
+ @formatter.format(entropy_available,labels)
127
126
  end
128
127
 
129
- os
128
+ entropy_available
129
+ end
130
+
131
+ def show_os_information(output_as_json)
132
+ os_information = KPM::SystemProxy::OsInformation.fetch
133
+ labels = KPM::SystemProxy::OsInformation.get_labels
134
+
135
+ unless output_as_json
136
+ @formatter.format(os_information,labels)
137
+ end
138
+
139
+ os_information
130
140
  end
131
141
 
132
142
  def show_java_system_information(command, output_as_json)
@@ -195,7 +205,7 @@ module KPM
195
205
  all_plugins = inspector.inspect(bundles_dir)
196
206
  end
197
207
 
198
- if not output_as_json
208
+ unless output_as_json
199
209
  if all_plugins.nil? || all_plugins.size == 0
200
210
  puts "\e[91;1mNo KB plugin information available\e[0m\n\n"
201
211
  else
@@ -209,9 +219,24 @@ module KPM
209
219
  all_plugins
210
220
  end
211
221
 
222
+ def get_kaui_standalone_version(kaui_web_path = nil)
223
+ kaui_search_default_dir = kaui_web_path.nil? ? DEFAULT_KAUI_SEARCH_BASE_DIR : Dir[kaui_web_path][0]
224
+ kaui_search_default_dir.gsub!('.war','')
225
+ version = nil
226
+
227
+ yaml_file = kaui_search_default_dir + File::SEPARATOR + 'WEB-INF' + File::SEPARATOR + 'version.yml'
228
+ unless Dir[yaml_file][0].nil?
229
+ yml_data = YAML::load_file(yaml_file)
230
+
231
+ version = yml_data['version']
232
+ end
233
+
234
+ version
235
+ end
236
+
212
237
  def get_kaui_version(kaui_web_path = nil)
213
- puts kaui_web_path
214
- kaui_search_default_dir = Dir[kaui_web_path.nil? ? '' : kaui_web_path][0] || DEFAULT_KAUI_SEARCH_BASE_DIR
238
+ kaui_search_default_dir = kaui_web_path.nil? ? DEFAULT_KAUI_SEARCH_BASE_DIR : Dir[kaui_web_path][0]
239
+ kaui_search_default_dir.gsub!('.war','')
215
240
  version = nil
216
241
 
217
242
  gemfile = Dir[kaui_search_default_dir + File::SEPARATOR + 'WEB-INF' + File::SEPARATOR + 'Gemfile']
@@ -238,7 +263,9 @@ module KPM
238
263
  end
239
264
 
240
265
  def get_killbill_version(killbill_web_path = nil)
241
- killbill_search_default_dir = Dir[killbill_web_path.nil? ? '' : killbill_web_path][0] || DEFAULT_KILLBILL_SEARCH_BASE_DIR
266
+ killbill_search_default_dir = killbill_web_path.nil? ? DEFAULT_KILLBILL_SEARCH_BASE_DIR : Dir[killbill_web_path][0]
267
+ killbill_search_default_dir.gsub!('.war','')
268
+ killbill_search_default_dir.gsub!('webapps','**')
242
269
 
243
270
  file = Dir[killbill_search_default_dir + File::SEPARATOR + 'META-INF' + File::SEPARATOR + '**' + File::SEPARATOR + 'pom.properties']
244
271
  version = nil