nexus_cli 0.9.1 → 1.0.0

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.1
1
+ 1.0.0
@@ -5,7 +5,10 @@ require 'json'
5
5
  require 'jsonpath'
6
6
 
7
7
  module NexusCli
8
+ # @author Kyle Allan <kallan@riotgames.com>
8
9
  class OSSRemote
10
+ # @param [Hash] overrides
11
+ # @param [Boolean] ssl_verify
9
12
  def initialize(overrides, ssl_verify=true)
10
13
  @configuration = Configuration::parse(overrides)
11
14
  @ssl_verify = ssl_verify
@@ -15,6 +18,10 @@ module NexusCli
15
18
  return @configuration if @configuration
16
19
  end
17
20
 
21
+ # Returns an HTTPClient instance with settings to connect
22
+ # to a Nexus server.
23
+ #
24
+ # @return [HTTPClient]
18
25
  def nexus
19
26
  client = HTTPClient.new
20
27
  client.send_timeout = 600
@@ -26,10 +33,20 @@ module NexusCli
26
33
  return client
27
34
  end
28
35
 
36
+ # Joins a given url to the current url stored in the configuraiton
37
+ # and returns the combined String.
38
+ #
39
+ # @param [String] url
40
+ #
41
+ # @return [String]
29
42
  def nexus_url(url)
30
43
  File.join(configuration['url'], url)
31
44
  end
32
45
 
46
+ # Gets that current status of the Nexus server. On a non-error
47
+ # status code, returns a Hash of values from the server.
48
+ #
49
+ # @return [Hash]
33
50
  def status
34
51
  response = nexus.get(nexus_url("service/local/status"))
35
52
  case response.status
@@ -52,17 +69,26 @@ module NexusCli
52
69
  end
53
70
  end
54
71
 
72
+ # Determines whether or not the Nexus server being
73
+ # connected to is running Nexus Pro.
55
74
  def running_nexus_pro?
56
75
  status['edition_long'] == "Professional"
57
76
  end
58
77
 
78
+ # Retrieves a file from the Nexus server using the given [String] artifact
79
+ # identifier. Optionally provide a destination [String].
80
+ #
81
+ # @param [String] artifact
82
+ # @param [String] destination
83
+ #
84
+ # @return [File]
59
85
  def pull_artifact(artifact, destination=nil)
60
86
  group_id, artifact_id, version, extension = parse_artifact_string(artifact)
61
87
  version = Nokogiri::XML(get_artifact_info(artifact)).xpath("//version").first.content() if version.casecmp("latest")
62
88
  destination = File.join(File.expand_path(destination || "."), "#{artifact_id}-#{version}.#{extension}")
63
89
  response = nexus.get(nexus_url("service/local/artifact/maven/redirect"), :query => {:g => group_id, :a => artifact_id, :v => version, :e => extension, :r => configuration['repository']})
64
90
  case response.status
65
- when 301
91
+ when 301, 307
66
92
  # Follow redirect and stream in chunks.
67
93
  artifact_file = File.open(destination, "wb") do |io|
68
94
  nexus.get(response.content.gsub(/If you are not automatically redirected use this url: /, "")) do |chunk|
@@ -77,6 +103,14 @@ module NexusCli
77
103
  File.expand_path(destination)
78
104
  end
79
105
 
106
+
107
+ # Pushes the given [file] to the Nexus server
108
+ # under the given [artifact] identifier.
109
+ #
110
+ # @param artifact [String] the Maven identifier
111
+ # @param file [type] the path to the file
112
+ #
113
+ # @return [Boolean] returns true when successful
80
114
  def push_artifact(artifact, file)
81
115
  group_id, artifact_id, version, extension = parse_artifact_string(artifact)
82
116
  response = nexus.post(nexus_url("service/local/artifact/maven/content"), {:hasPom => false, :g => group_id, :a => artifact_id, :v => version, :e => extension, :p => extension, :r => configuration['repository'], :file => File.open(file)})
@@ -122,6 +156,12 @@ module NexusCli
122
156
  end
123
157
  end
124
158
 
159
+
160
+ # Searches for an artifact using the given identifier.
161
+ #
162
+ # @param artifact [String] the Maven identifier
163
+ #
164
+ # @return [Array<String>] a formatted Array of results
125
165
  def search_for_artifacts(artifact)
126
166
  group_id, artifact_id = artifact.split(":")
127
167
  response = nexus.get(nexus_url("service/local/data_index"), :query => {:g => group_id, :a => artifact_id})
@@ -134,6 +174,10 @@ module NexusCli
134
174
  end
135
175
  end
136
176
 
177
+
178
+ # Retrieves the global settings of the Nexus server
179
+ #
180
+ # @return [File] a File with the global settings.
137
181
  def get_global_settings
138
182
  json = get_global_settings_json
139
183
  pretty_json = JSON.pretty_generate(JSON.parse(json))
@@ -188,6 +232,14 @@ module NexusCli
188
232
  end
189
233
  end
190
234
 
235
+
236
+ # Creates a repository that the Nexus uses to hold artifacts.
237
+ #
238
+ # @param name [String] the name of the repository to create
239
+ # @param proxy [Boolean] true if this is a proxy repository
240
+ # @param url [String] the url for the proxy repository to point to
241
+ #
242
+ # @return [Boolean] returns true on success
191
243
  def create_repository(name, proxy, url)
192
244
  json = if proxy
193
245
  create_proxy_repository_json(name, url)
@@ -285,6 +337,12 @@ module NexusCli
285
337
  end
286
338
  end
287
339
 
340
+
341
+ # Changes the password of a user
342
+ #
343
+ # @param params [Hash] a hash given to update the users password
344
+ #
345
+ # @return [type] [description]
288
346
  def change_password(params)
289
347
  response = nexus.post(nexus_url("service/local/users_changepw"), :body => create_change_password_json(params), :header => DEFAULT_CONTENT_TYPE_HEADER)
290
348
  case response.status
@@ -403,10 +461,26 @@ module NexusCli
403
461
 
404
462
  private
405
463
 
464
+
465
+ # Transforms a given [String] into a sanitized version by
466
+ # replacing spaces with underscores and downcasing.
467
+ #
468
+ # @param unsanitized_string [String] the String to sanitize
469
+ #
470
+ # @return [String] the sanitized String
406
471
  def sanitize_for_id(unsanitized_string)
407
472
  unsanitized_string.gsub(" ", "_").downcase
408
473
  end
409
474
 
475
+
476
+ # Transfers an artifact from one repository
477
+ # to another. Sometimes called a `promotion`
478
+ #
479
+ # @param artifact [String] a Maven identifier
480
+ # @param from_repository [String] the name of the from repository
481
+ # @param to_repository [String] the name of the to repository
482
+ #
483
+ # @return [Boolean] returns true when successful
410
484
  def do_transfer_artifact(artifact, from_repository, to_repository)
411
485
  Dir.mktmpdir do |temp_dir|
412
486
  configuration["repository"] = sanitize_for_id(from_repository)
@@ -416,6 +490,15 @@ module NexusCli
416
490
  end
417
491
  end
418
492
 
493
+
494
+ # Formats the given XML into an [Array<String>] so it
495
+ # can be displayed nicely.
496
+ #
497
+ # @param doc [Nokogiri::XML] the xml search results
498
+ # @param group_id [String] the group id
499
+ # @param artifact_id [String] the artifact id
500
+ #
501
+ # @return [type] [description]
419
502
  def format_search_results(doc, group_id, artifact_id)
420
503
  versions = doc.xpath("//version").inject([]) {|array,node| array << "#{node.content()}"}
421
504
  indent_size = versions.max{|a,b| a.length <=> b.length}.size+4
@@ -426,6 +509,13 @@ module NexusCli
426
509
  end
427
510
  end
428
511
 
512
+
513
+ # Parses a given artifact string into its
514
+ # four, distinct, Maven pieces.
515
+ #
516
+ # @param artifact [String] the Maven identifier
517
+ #
518
+ # @return [Array<String>] an Array with four elements
429
519
  def parse_artifact_string(artifact)
430
520
  split_artifact = artifact.split(":")
431
521
  if(split_artifact.size < 4)
@@ -105,7 +105,7 @@ module NexusCli
105
105
  end
106
106
 
107
107
  def artifact_publish(repository_id, params)
108
- response = nexus.put(nexus_url("service/local/smartproxy/pub-sub/#{repository_id}"), :body => create_pub_sub_json(params), :header => DEFAULT_CONTENT_TYPE_HEADER)
108
+ response = nexus.put(nexus_url("service/local/smartproxy/pub-sub/#{sanitize_for_id(repository_id)}"), :body => create_pub_sub_json(params), :header => DEFAULT_CONTENT_TYPE_HEADER)
109
109
  case response.status
110
110
  when 200
111
111
  return true
@@ -114,11 +114,12 @@ module NexusCli
114
114
  end
115
115
  end
116
116
 
117
- def enable_artifact_subscribe(repository_id)
117
+ def enable_artifact_subscribe(repository_id, preemptive_fetch)
118
118
  raise NotProxyRepositoryException.new(repository_id) unless Nokogiri::XML(get_repository_info(repository_id)).xpath("/repository/data/repoType").first.content == "proxy"
119
119
 
120
120
  params = {:repositoryId => repository_id}
121
121
  params[:subscribe] = true
122
+ params[:preemptiveFetch] = preemptive_fetch
122
123
  artifact_subscribe(repository_id, params)
123
124
  end
124
125
 
@@ -131,7 +132,7 @@ module NexusCli
131
132
  end
132
133
 
133
134
  def artifact_subscribe(repository_id, params)
134
- response = nexus.put(nexus_url("service/local/smartproxy/pub-sub/#{repository_id}"), :body => create_pub_sub_json(params), :header => DEFAULT_CONTENT_TYPE_HEADER)
135
+ response = nexus.put(nexus_url("service/local/smartproxy/pub-sub/#{sanitize_for_id(repository_id)}"), :body => create_pub_sub_json(params), :header => DEFAULT_CONTENT_TYPE_HEADER)
135
136
  case response.status
136
137
  when 200
137
138
  return true
@@ -282,10 +282,14 @@ module NexusCli
282
282
  end
283
283
  end
284
284
 
285
+ method_option :preemptive_fetch,
286
+ :type => :boolean,
287
+ :default => false,
288
+ :desc => "Subscribing repositories that preemtively fetch will grab artifacts as updates are received."
285
289
  desc "enable_artifact_subscribe repository_id", "Sets a repository to subscribe to updates about artifacts."
286
290
  def enable_artifact_subscribe(repository_id)
287
291
  raise NotNexusProException unless nexus_remote.kind_of? ProRemote
288
- if nexus_remote.enable_artifact_subscribe(repository_id)
292
+ if nexus_remote.enable_artifact_subscribe(repository_id, options[:preemptive_fetch])
289
293
  say "The repository #{repository_id} is now subscribed for artifact updates.", :blue
290
294
  end
291
295
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexus_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-04 00:00:00.000000000 Z
12
+ date: 2012-10-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -253,7 +253,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
253
253
  version: '0'
254
254
  segments:
255
255
  - 0
256
- hash: 1683805139971071117
256
+ hash: -2249648047035309885
257
257
  required_rubygems_version: !ruby/object:Gem::Requirement
258
258
  none: false
259
259
  requirements:
@@ -262,7 +262,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
262
262
  version: '0'
263
263
  segments:
264
264
  - 0
265
- hash: 1683805139971071117
265
+ hash: -2249648047035309885
266
266
  requirements: []
267
267
  rubyforge_project:
268
268
  rubygems_version: 1.8.21