artifactory-ruby 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a79eac0819c280d08856922ddfa8650b5e928c68
4
- data.tar.gz: 776d6e71a1b66adb4802f7553c3261b45aba82ca
3
+ metadata.gz: e7fb4a1236baecc54d9ab25da7b99660644dd021
4
+ data.tar.gz: 3e334fcd05595c34cb74568107545f5aa103923f
5
5
  SHA512:
6
- metadata.gz: fa79e9c9ab2eb105952adefc80b3d5ae7c5d98b288464f22a08bb1cadb047eeea01eb7258da1884c490ce12d8e2a39a445454317b90d4aad6724724265457f31
7
- data.tar.gz: 5f3bc6db1d365a00204de5bc5f6e072e6f10372c6c1ea68b25cde2497b92f60c742245ba5f5c06407f2309e4d566e2672a37d738083deac71c7d581ee100b19b
6
+ metadata.gz: 2612da8023f66c6fba9efc1a85d322756bf378420a0bee1bcdd8efca5ddd969f9f58256c1c8a5e70389f2d8f061fa57f2d140c44b19a3bbb73a90a767f77c5b5
7
+ data.tar.gz: d47ed4e9cd064ca90f1061a010165a1085b15f8b37e1bc9bedf67a45353e00fde235ef99f99828d8398fb47ff9eab1ecde0056555b2c698d6ab447b29544a325
@@ -175,10 +175,11 @@ module Artifactory
175
175
  # @return [Hash] File statistics
176
176
  #
177
177
  def file_stat(repo_key:, path:)
178
+ ret = {}
179
+
178
180
  p = File.join("/storage", repo_key, path).chomp('/')
179
181
  params = ['stats']
180
182
 
181
- ret = {}
182
183
  api_get([p, params.join('&')].join('?')).tap { |h| h.delete('uri') }.each do |k, v|
183
184
  case k
184
185
  when "lastDownloaded", "remoteLastDownloaded"
@@ -201,6 +202,130 @@ module Artifactory
201
202
  api_delete(File.join(repo_key, path))
202
203
  end
203
204
 
205
+ # Retrieve all artifacts not downloaded since the specified Java epoch in milliseconds
206
+ #
207
+ # @param repo_key [String, Array<String>] Repository key(s)
208
+ # @param not_used_since [Time] Return artifacts that have not been used since the given date
209
+ # @param created_before [Time] Return artifacts that have been created before the given date
210
+ # @return [Hash] Artifacts matching search criteria
211
+ #
212
+ def search_usage(repo_key:, not_used_since:, created_before: nil)
213
+ ret = {}
214
+
215
+ path = File.join("/search", "usage")
216
+ params = []
217
+ params << "notUsedSince=#{(not_used_since.to_f.round(3) * 1000).to_i}"
218
+ params << "createdBefore=#{(created_before.to_f.round(3) * 1000).to_i}" if created_before
219
+ params << "repos=#{repo_key.is_a?(Array) ? repo_key.join(',') : repo_key}"
220
+
221
+ api_get([path, params.join('&')].join('?'))['results'].each do |result|
222
+ result.each do |k, v|
223
+ case k
224
+ when "lastDownloaded", "remoteLastDownloaded"
225
+ ret[result['uri']] = Time.parse(v)
226
+
227
+ when "uri"
228
+ next
229
+
230
+ else
231
+ ret[result['uri']] = v
232
+ end
233
+ end
234
+ end
235
+
236
+ ret
237
+ end
238
+
239
+ # Get all artifacts with specified dates within the given range
240
+ #
241
+ # @param repo_key [String, Array<String>] Repository key(s)
242
+ # @param from_date [Time] Return artifacts that have not been used since the given date
243
+ # @param to_date [Time] Return artifacts that have been created before the given date
244
+ # @param fields [created, lastModified, lastDownloaded] Date fields that specify which fields the from_date and to_date values should be applied to
245
+ # @return [Hash] Artifacts matching search criteria
246
+ #
247
+ def search_dates(repo_key:, from_date: nil, to_date: Time.now, date_fields:)
248
+ ret = {}
249
+
250
+ valid_date_fields = ["created", "lastModified", "lastDownloaded"]
251
+
252
+ date_fields.each do |date_field|
253
+ raise ValueError, "Not a valid date field '#{date_field}'" unless valid_date_fields.include?(date_field)
254
+ end
255
+
256
+ path = File.join("/search", "dates")
257
+ params = []
258
+ params << "from=#{(from_date.to_f.round(3) * 1000).to_i}" if from_date
259
+ params << "to=#{(to_date.to_f.round(3) * 1000).to_i}"
260
+ params << "repos=#{repo_key.is_a?(Array) ? repo_key.join(',') : repo_key}"
261
+ params << "dateFields=#{date_fields.join(',')}"
262
+
263
+ puts([path, params.join('&')].join('?'))
264
+ api_get([path, params.join('&')].join('?'))['results'].each do |result|
265
+ result.each do |k, v|
266
+ case k
267
+ when *valid_date_fields
268
+ ret[result['uri']] = Time.parse(v)
269
+
270
+ when "uri"
271
+ next
272
+
273
+ else
274
+ ret[result['uri']] = v
275
+ end
276
+ end
277
+ end
278
+
279
+ ret
280
+ end
281
+
282
+ # Get all artifacts created in date range
283
+ #
284
+ # @param repo_key [String, Array<String>] Repository key(s)
285
+ # @param from_date [Time] Return artifacts that have not been used since the given date
286
+ # @param to_date [Time] Return artifacts that have been created before the given date
287
+ # @return [Hash] Artifacts matching search criteria
288
+ #
289
+ def search_creation(repo_key:, from_date: nil, to_date: Time.now)
290
+ ret = {}
291
+
292
+ path = File.join("/search", "creation")
293
+ params = []
294
+ params << "from=#{(from_date.to_f.round(3) * 1000).to_i}" if from_date
295
+ params << "to=#{(to_date.to_f.round(3) * 1000).to_i}"
296
+ params << "repos=#{repo_key.is_a?(Array) ? repo_key.join(',') : repo_key}"
297
+
298
+ api_get([path, params.join('&')].join('?'))['results'].each do |result|
299
+ result.each do |k, v|
300
+ case k
301
+ when "created"
302
+ ret[result['uri']] = Time.parse(v)
303
+
304
+ when "uri"
305
+ next
306
+
307
+ else
308
+ ret[result['uri']] = v
309
+ end
310
+ end
311
+ end
312
+
313
+ ret
314
+ end
315
+
316
+ # Get all artifacts matching the given path pattern
317
+ #
318
+ # @param repo_key [String] Repository key
319
+ # @param pattern [String] File pattern
320
+ # @return [Hash] Artifacts matching search pattern
321
+ #
322
+ def search_pattern(repo_key:, pattern:)
323
+ path = File.join("/search", "pattern")
324
+ params = ["pattern=#{repo_key}:#{pattern}"]
325
+
326
+ api_get([path, params].join('?'))['files']
327
+ end
328
+
204
329
  private
205
330
  # Dispatch a GET request to the Artifactory API interface
206
331
  #
@@ -3,7 +3,7 @@
3
3
  #
4
4
 
5
5
  module Artifactory
6
- VERSION = "0.0.2"
6
+ VERSION = "0.0.3"
7
7
 
8
8
  def self.version
9
9
  VERSION
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: artifactory-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matteo Cerutti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-19 00:00:00.000000000 Z
11
+ date: 2017-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -24,7 +24,7 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.7.0
27
- description: Ruby client library for Kapacitor JSON REST API
27
+ description: Ruby client library for Artifactory REST API
28
28
  email: matteo.cerutti@hotmail.co.uk
29
29
  executables: []
30
30
  extensions: []