nexus_cli 0.8.4 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.4
1
+ 0.9.0
@@ -55,6 +55,15 @@ Feature: Use the Nexus CLI
55
55
  """
56
56
  And the exit status should be 0
57
57
 
58
+ @transfer
59
+ Scenario: Transfer an artifact between repositories
60
+ When I call the nexus "transfer com.test:mytest:1.0.0:tgz releases thirdparty" command
61
+ Then the output should contain:
62
+ """
63
+ The artifact com.test:mytest:1.0.0:tgz has been transferred from releases to thirdparty.
64
+ """
65
+ And the exit status should be 0
66
+
58
67
  @delete
59
68
  Scenario: Attempt to delete an artifact
60
69
  When I delete an artifact with the GAV of "com.test:mytest:1.0.0:tgz"
@@ -65,6 +74,17 @@ Feature: Use the Nexus CLI
65
74
  """
66
75
  And the exit status should be 101
67
76
 
77
+ @delete
78
+ Scenario: Attempt to delete another artifact
79
+ When I delete an artifact with the GAV of "com.test:mytest:1.0.0:tgz" from the "thirdparty" repository
80
+ And I call the nexus "info com.test:mytest:1.0.0:tgz" command overriding "repository:thirdparty"
81
+ Then the output should contain:
82
+ """
83
+ The artifact you requested information for could not be found. Please ensure it exists inside the Nexus.
84
+ """
85
+ And the exit status should be 101
86
+
87
+
68
88
  Scenario: Get the current global settings of Nexus
69
89
  When I call the nexus "get_global_settings" command
70
90
  Then the output should contain:
@@ -7,6 +7,11 @@ When /^I call the nexus "(.*?)" command$/ do |command|
7
7
  step "I run `nexus-cli #{command} --overrides=#{get_overrides_string}`"
8
8
  end
9
9
 
10
+ When /^I call the nexus "(.*?)" command overriding "(.*?)"$/ do |command, overrides|
11
+
12
+ step "I run `nexus-cli #{command} --overrides=#{create_step_overrides(overrides)}`"
13
+ end
14
+
10
15
  When /^I call the nexus "(.*?)" command as the "(.*?)" user with password "(.*?)"$/ do |command, username, password|
11
16
  overrides = get_overrides_string.gsub('username:admin', "username:#{username}")
12
17
  overrides.gsub!('password:admin123', "password:#{password}")
@@ -33,6 +38,11 @@ When /^I delete an artifact with the GAV of "(.*)"$/ do |gav|
33
38
  nexus_remote.delete_artifact(gav)
34
39
  end
35
40
 
41
+ When /^I delete an artifact with the GAV of "(.*?)" from the "(.*?)" repository$/ do |gav, repository|
42
+ nexus_remote.configuration["repository"] = repository
43
+ nexus_remote.delete_artifact(gav)
44
+ end
45
+
36
46
  When /^I edit the "(.*?)" files "(.*?)" field to true$/ do |file, field|
37
47
  Dir.chdir('tmp/aruba') do
38
48
  json = JSON.parse(File.read(File.join(File.expand_path("~/.nexus"), file)))
@@ -28,6 +28,20 @@ def get_overrides
28
28
  @overrides ||= {'url' => 'http://localhost:8081/nexus', 'repository' => 'releases', 'username' => 'admin', 'password' => 'admin123'}
29
29
  end
30
30
 
31
+ def create_step_overrides(overrides)
32
+ overrides_hash = overrides.split(" ").inject({}) do |overrides_hash, override|
33
+ key, value = override.split(":")
34
+ overrides_hash[key] = value
35
+ overrides_hash
36
+ end
37
+
38
+ step_overrides = get_overrides.merge(overrides_hash)
39
+ step_overrides.to_a.inject("") do |overrides_string, pair|
40
+ overrides_string << pair.join(":")
41
+ overrides_string << " "
42
+ end
43
+ end
44
+
31
45
  def temp_dir
32
46
  @tmpdir ||= Dir.mktmpdir
33
47
  end
@@ -38,4 +52,4 @@ end
38
52
 
39
53
  at_exit do
40
54
  FileUtils.rm_rf(temp_dir)
41
- end
55
+ end
@@ -11,6 +11,7 @@ module NexusCli
11
11
  end
12
12
  overrides.each{|key, value| config[key] = value} unless overrides.nil? || overrides.empty?
13
13
  validate_config(config)
14
+ config["repository"] = config["repository"].gsub(" ", "_").downcase
14
15
  config
15
16
  end
16
17
 
@@ -244,5 +244,16 @@ The output from the server was:
244
244
  end
245
245
  status_code(127)
246
246
  end
247
+
248
+ class NexusHTTP404 < NexusCliError
249
+ def initialize(body)
250
+ @server_response = body
251
+ end
247
252
 
253
+ def message
254
+ %{Your command failed and the server returned an error code. The output of the response was:
255
+ #{@server_response}}
256
+ end
257
+ status_code(128)
258
+ end
248
259
  end
@@ -56,7 +56,7 @@ module NexusCli
56
56
  status['edition_long'] == "Professional"
57
57
  end
58
58
 
59
- def pull_artifact(artifact, destination)
59
+ def pull_artifact(artifact, destination=nil)
60
60
  group_id, artifact_id, version, extension = parse_artifact_string(artifact)
61
61
  version = Nokogiri::XML(get_artifact_info(artifact)).xpath("//version").first.content() if version.casecmp("latest")
62
62
  destination = File.join(File.expand_path(destination || "."), "#{artifact_id}-#{version}.#{extension}")
@@ -90,7 +90,7 @@ module NexusCli
90
90
  when 403
91
91
  raise PermissionsException
92
92
  when 404
93
- raise CouldNotConnectToNexusException
93
+ raise NexusHTTP404.new(response.content)
94
94
  else
95
95
  raise UnexpectedStatusCodeException.new(response.status)
96
96
  end
@@ -206,7 +206,7 @@ module NexusCli
206
206
  end
207
207
 
208
208
  def delete_repository(name)
209
- response = nexus.delete(nexus_url("service/local/repositories/#{name.downcase}"))
209
+ response = nexus.delete(nexus_url("service/local/repositories/#{sanitize_for_id(name)}"))
210
210
  case response.status
211
211
  when 204
212
212
  return true
@@ -218,7 +218,7 @@ module NexusCli
218
218
  end
219
219
 
220
220
  def get_repository_info(name)
221
- response = nexus.get(nexus_url("service/local/repositories/#{name.gsub(" ", "_").downcase}"))
221
+ response = nexus.get(nexus_url("service/local/repositories/#{sanitize_for_id(name)}"))
222
222
  case response.status
223
223
  when 200
224
224
  return response.content
@@ -343,7 +343,7 @@ module NexusCli
343
343
  end
344
344
 
345
345
  def get_group_repository(group_id)
346
- response = nexus.get(nexus_url("service/local/repo_groups/#{group_id.gsub(" ", "_").downcase}"), :header => DEFAULT_ACCEPT_HEADER)
346
+ response = nexus.get(nexus_url("service/local/repo_groups/#{sanitize_for_id(group_id)}"), :header => DEFAULT_ACCEPT_HEADER)
347
347
  case response.status
348
348
  when 200
349
349
  return response.content
@@ -358,12 +358,12 @@ module NexusCli
358
358
  group_repository = JSON.parse(get_group_repository(group_id))
359
359
  repositories_in_group = group_repository["data"]["repositories"]
360
360
 
361
- repositories_in_group.find{|repository| repository["id"] == repository_to_check}
361
+ repositories_in_group.find{|repository| repository["id"] == sanitize_for_id(repository_to_check)}
362
362
  end
363
363
 
364
364
  def add_to_group_repository(group_id, repository_to_add_id)
365
365
  raise RepositoryInGroupException if repository_in_group?(group_id, repository_to_add_id)
366
- response = nexus.put(nexus_url("service/local/repo_groups/#{group_id.gsub(" ", "_").downcase}"), :body => create_add_to_group_repository_json(group_id, repository_to_add_id), :header => DEFAULT_CONTENT_TYPE_HEADER)
366
+ response = nexus.put(nexus_url("service/local/repo_groups/#{sanitize_for_id(group_id)}"), :body => create_add_to_group_repository_json(group_id, repository_to_add_id), :header => DEFAULT_CONTENT_TYPE_HEADER)
367
367
  case response.status
368
368
  when 200
369
369
  return true
@@ -376,7 +376,7 @@ module NexusCli
376
376
 
377
377
  def remove_from_group_repository(group_id, repository_to_remove_id)
378
378
  raise RepositoryNotInGroupException unless repository_in_group?(group_id, repository_to_remove_id)
379
- response = nexus.put(nexus_url("service/local/repo_groups/#{group_id.gsub(" ", "_").downcase}"), :body => create_remove_from_group_repository_json(group_id, repository_to_remove_id), :header => DEFAULT_CONTENT_TYPE_HEADER)
379
+ response = nexus.put(nexus_url("service/local/repo_groups/#{sanitize_for_id(group_id)}"), :body => create_remove_from_group_repository_json(group_id, repository_to_remove_id), :header => DEFAULT_CONTENT_TYPE_HEADER)
380
380
  case response.status
381
381
  when 200
382
382
  return true
@@ -386,7 +386,7 @@ module NexusCli
386
386
  end
387
387
 
388
388
  def delete_group_repository(group_id)
389
- response = nexus.delete(nexus_url("service/local/repo_groups/#{group_id.gsub(" ", "_").downcase}"))
389
+ response = nexus.delete(nexus_url("service/local/repo_groups/#{sanitize_for_id(group_id)}"))
390
390
  case response.status
391
391
  when 204
392
392
  return true
@@ -397,8 +397,25 @@ module NexusCli
397
397
  end
398
398
  end
399
399
 
400
+ def transfer_artifact(artifact, from_repository, to_repository)
401
+ do_transfer_artifact(artifact, from_repository, to_repository)
402
+ end
403
+
400
404
  private
401
405
 
406
+ def sanitize_for_id(unsanitized_string)
407
+ unsanitized_string.gsub(" ", "_").downcase
408
+ end
409
+
410
+ def do_transfer_artifact(artifact, from_repository, to_repository)
411
+ Dir.mktmpdir do |temp_dir|
412
+ configuration["repository"] = sanitize_for_id(from_repository)
413
+ artifact_file = pull_artifact(artifact, temp_dir)
414
+ configuration["repository"] = sanitize_for_id(to_repository)
415
+ push_artifact(artifact, artifact_file)
416
+ end
417
+ end
418
+
402
419
  def format_search_results(doc, group_id, artifact_id)
403
420
  versions = doc.xpath("//version").inject([]) {|array,node| array << "#{node.content()}"}
404
421
  indent_size = versions.max{|a,b| a.length <=> b.length}.size+4
@@ -423,10 +440,12 @@ module NexusCli
423
440
  params = {:provider => "maven2"}
424
441
  params[:providerRole] = "org.sonatype.nexus.proxy.repository.Repository"
425
442
  params[:exposed] = true
443
+ params[:browseable] = true
444
+ params[:indexable] = true
426
445
  params[:repoType] = "hosted"
427
446
  params[:repoPolicy] = "RELEASE"
428
447
  params[:name] = name
429
- params[:id] = name.gsub(" ", "_").downcase
448
+ params[:id] = sanitize_for_id(name)
430
449
  params[:format] = "maven2"
431
450
  JSON.dump(:data => params)
432
451
  end
@@ -435,6 +454,8 @@ module NexusCli
435
454
  params = {:provider => "maven2"}
436
455
  params[:providerRole] = "org.sonatype.nexus.proxy.repository.Repository"
437
456
  params[:exposed] = true
457
+ params[:browseable] = true
458
+ params[:indexable] = true
438
459
  params[:repoType] = "proxy"
439
460
  params[:repoPolicy] = "RELEASE"
440
461
  params[:checksumPolicy] = "WARN"
@@ -442,7 +463,7 @@ module NexusCli
442
463
  params[:downloadRemoteIndexes] = true
443
464
  params[:autoBlockActive] = true
444
465
  params[:name] = name
445
- params[:id] = name.gsub(" ", "_").downcase
466
+ params[:id] = sanitize_for_id(name)
446
467
  params[:remoteStorage] = {:remoteStorageUrl => url.nil? ? "http://change-me.com/" : url}
447
468
  JSON.dump(:data => params)
448
469
  end
@@ -461,7 +482,7 @@ module NexusCli
461
482
  end
462
483
 
463
484
  def create_group_repository_json(name)
464
- params = {:id => name.gsub(" ", "_").downcase}
485
+ params = {:id => sanitize_for_id(name)}
465
486
  params[:name] = name
466
487
  params[:provider] = "maven2"
467
488
  params[:exposed] = true
@@ -471,7 +492,7 @@ module NexusCli
471
492
  def create_add_to_group_repository_json(group_id, repository_to_add_id)
472
493
  group_repository_json = JSON.parse(get_group_repository(group_id))
473
494
  repositories = group_repository_json["data"]["repositories"]
474
- repositories << {:id => repository_to_add_id}
495
+ repositories << {:id => sanitize_for_id(repository_to_add_id)}
475
496
  params = {:repositories => repositories}
476
497
  params[:id] = group_repository_json["data"]["id"]
477
498
  params[:name] = group_repository_json["data"]["name"]
@@ -38,24 +38,9 @@ module NexusCli
38
38
  # @result [Integer] The resulting exit code of the operation
39
39
  def update_artifact_custom_info(artifact, *params)
40
40
  target_n3 = parse_custom_metadata_update_params(*params)
41
+ nexus_n3 = get_custom_metadata_hash(artifact)
41
42
 
42
- # Get all the urn:nexus/user# keys and consolidate.
43
- # Read in nexus n3 file. If this is a newly-added artifact, there will be no n3 file so escape the exception.
44
- begin
45
- nexus_n3 = N3Metadata::convert_result_to_hash(get_artifact_custom_info_raw(artifact))
46
- rescue N3NotFoundException
47
- nexus_n3 = {}
48
- end
49
-
50
- group_id, artifact_id, version, extension = parse_artifact_string(artifact)
51
- encoded_string = N3Metadata::create_base64_subject(group_id, artifact_id, version, extension)
52
- response = nexus.post(nexus_url("service/local/index/custom_metadata/#{configuration['repository']}/#{encoded_string}"), :body => create_custom_metadata_update_json(nexus_n3, target_n3), :header => DEFAULT_CONTENT_TYPE_HEADER)
53
- case response.code
54
- when 201
55
- return true
56
- else
57
- raise UnexpectedStatusCodeException.new(response.status)
58
- end
43
+ do_update_custom_metadata(artifact, nexus_n3, target_n3)
59
44
  end
60
45
 
61
46
  # Clears all custom metadata from an artifact
@@ -264,8 +249,40 @@ module NexusCli
264
249
  end
265
250
  end
266
251
 
252
+ def transfer_artifact(artifact, from_repository, to_repository)
253
+ do_transfer_artifact(artifact, from_repository, to_repository)
254
+
255
+ configuration["repository"] = from_repository
256
+ from_artifact_metadata = get_custom_metadata_hash(artifact)
257
+
258
+ configuration["repository"] = to_repository
259
+ to_artifact_metadata = get_custom_metadata_hash(artifact)
260
+
261
+ do_update_custom_metadata(artifact, from_artifact_metadata, to_artifact_metadata)
262
+ end
263
+
267
264
  private
268
265
 
266
+ def get_custom_metadata_hash(artifact)
267
+ begin
268
+ N3Metadata::convert_result_to_hash(get_artifact_custom_info_raw(artifact))
269
+ rescue N3NotFoundException
270
+ Hash.new
271
+ end
272
+ end
273
+
274
+ def do_update_custom_metadata(artifact, source_metadata, target_metadata)
275
+ group_id, artifact_id, version, extension = parse_artifact_string(artifact)
276
+ encoded_string = N3Metadata::create_base64_subject(group_id, artifact_id, version, extension)
277
+ response = nexus.post(nexus_url("service/local/index/custom_metadata/#{configuration['repository']}/#{encoded_string}"), :body => create_custom_metadata_update_json(source_metadata, target_metadata), :header => DEFAULT_CONTENT_TYPE_HEADER)
278
+ case response.code
279
+ when 201
280
+ return true
281
+ else
282
+ raise UnexpectedStatusCodeException.new(response.status)
283
+ end
284
+ end
285
+
269
286
  def create_add_trusted_key_json(params)
270
287
  JSON.dump(:data => params)
271
288
  end
@@ -15,6 +15,7 @@ module NexusCli
15
15
  map 'status' => :get_nexus_status
16
16
  map 'search' => :search_for_artifacts
17
17
  map 'search_custom' => :search_artifacts_custom
18
+ map 'transfer' => :transfer_artifact
18
19
 
19
20
  class_option :overrides,
20
21
  :type => :hash,
@@ -26,71 +27,61 @@ module NexusCli
26
27
  :default => true,
27
28
  :desc => "Set to false to disable SSL Verification."
28
29
 
29
- def initialize(*args)
30
- super
31
- begin
32
- @nexus_remote = Factory.create(options[:overrides], options[:ssl_verify])
33
- rescue NexusCliError => e
34
- say e.message, :red
35
- exit e.status_code
36
- end
37
- end
38
-
39
30
  method_option :destination,
40
31
  :type => :string,
41
32
  :default => nil,
42
33
  :desc => "A different folder other than the current working directory."
43
34
  desc "pull_artifact artifact", "Pulls an artifact from Nexus and places it on your machine."
44
35
  def pull_artifact(artifact)
45
- path_to_artifact = @nexus_remote.pull_artifact(artifact, options[:destination])
36
+ path_to_artifact = nexus_remote.pull_artifact(artifact, options[:destination])
46
37
  say "Artifact has been retrived and can be found at path: #{path_to_artifact}", :green
47
38
  end
48
39
 
49
40
  desc "push_artifact artifact file", "Pushes an artifact from your machine onto the Nexus."
50
41
  def push_artifact(artifact, file)
51
- @nexus_remote.push_artifact(artifact, file)
42
+ nexus_remote.push_artifact(artifact, file)
52
43
  say "Artifact #{artifact} has been successfully pushed to Nexus.", :green
53
44
  end
54
45
 
55
46
  desc "get_artifact_info artifact", "Gets and returns the metadata in XML format about a particular artifact."
56
47
  def get_artifact_info(artifact)
57
- say @nexus_remote.get_artifact_info(artifact), :green
48
+ say nexus_remote.get_artifact_info(artifact), :green
58
49
  end
59
50
 
60
51
  desc "search_for_artifacts", "Prints out some information about some junk."
61
52
  def search_for_artifacts(artifact)
62
- @nexus_remote.search_for_artifacts(artifact).each{|output| say output, :green}
53
+ nexus_remote.search_for_artifacts(artifact).each{|output| say output, :green}
63
54
  end
64
55
 
65
56
  desc "get_artifact_custom_info artifact", "Gets and returns the custom metadata in XML format about a particular artifact."
66
57
  def get_artifact_custom_info(artifact)
67
- raise NotNexusProException unless @nexus_remote.kind_of? ProRemote
68
- say @nexus_remote.get_artifact_custom_info(artifact), :green
58
+ raise NotNexusProException unless nexus_remote.kind_of? ProRemote
59
+ say nexus_remote.get_artifact_custom_info(artifact), :green
69
60
  end
70
61
 
71
62
  desc "update_artifact_custom_info artifact param1 param2 ...", "Updates the artifact custom metadata with the given key-value pairs."
72
63
  def update_artifact_custom_info(artifact, *params)
73
- raise NotNexusProException unless @nexus_remote.kind_of? ProRemote
74
- @nexus_remote.update_artifact_custom_info(artifact, *params)
64
+ raise NotNexusProException unless nexus_remote.kind_of? ProRemote
65
+ nexus_remote.update_artifact_custom_info(artifact, *params)
75
66
  say "Custom metadata for artifact #{artifact} has been successfully pushed to Nexus.", :green
76
67
  end
77
68
 
78
69
  desc "clear_artifact_custom_info artifact", "Clears the artifact custom metadata."
79
70
  def clear_artifact_custom_info(artifact)
80
- raise NotNexusProException unless @nexus_remote.kind_of? ProRemote
81
- @nexus_remote.clear_artifact_custom_info(artifact)
71
+ raise NotNexusProException unless nexus_remote.kind_of? ProRemote
72
+ nexus_remote.clear_artifact_custom_info(artifact)
82
73
  say "Custom metadata for artifact #{artifact} has been successfully cleared.", :green
83
74
  end
84
75
 
85
76
  desc "search_artifacts_custom param1 param2 ... ", "Searches for artifacts using artifact metadata and returns the result as a list with items in XML format."
86
77
  def search_artifacts_custom(*params)
87
- raise NotNexusProException unless @nexus_remote.kind_of? ProRemote
88
- say (s = @nexus_remote.search_artifacts_custom(*params)) == "" ? "No search results." : s, :green
78
+ raise NotNexusProException unless nexus_remote.kind_of? ProRemote
79
+ say (s = nexus_remote.search_artifacts_custom(*params)) == "" ? "No search results." : s, :green
89
80
  end
90
81
 
91
82
  desc "get_nexus_configuration", "Prints out configuration from the .nexus_cli file that helps inform where artifacts will be uploaded."
92
83
  def get_nexus_configuration
93
- config = @nexus_remote.configuration
84
+ config = nexus_remote.configuration
94
85
  say "********* Reading CLI configuration from #{File.expand_path('~/.nexus_cli')} *********", :blue
95
86
  say "Nexus URL: #{config['url']}", :blue
96
87
  say "Nexus Repository: #{config['repository']}", :blue
@@ -98,7 +89,7 @@ module NexusCli
98
89
 
99
90
  desc "get_nexus_status", "Prints out information about the Nexus instance."
100
91
  def get_nexus_status
101
- data = @nexus_remote.status
92
+ data = nexus_remote.status
102
93
  say "********* Getting Nexus status from #{data['base_url']} *********", :blue
103
94
  say "Application Name: #{data['app_name']}", :blue
104
95
  say "Version: #{data['version']}", :blue
@@ -110,7 +101,7 @@ module NexusCli
110
101
 
111
102
  desc "get_global_settings", "Prints out your Nexus' current setttings and saves them to a file."
112
103
  def get_global_settings
113
- @nexus_remote.get_global_settings
104
+ nexus_remote.get_global_settings
114
105
  say "Your current Nexus global settings have been written to the file: ~/.nexus/global_settings.json", :blue
115
106
  end
116
107
 
@@ -120,13 +111,13 @@ module NexusCli
120
111
  :desc => "A String of the JSON you wish to upload."
121
112
  desc "upload_global_settings", "Uploads a global_settings.json file to your Nexus to update its settings."
122
113
  def upload_global_settings
123
- @nexus_remote.upload_global_settings(options[:json])
114
+ nexus_remote.upload_global_settings(options[:json])
124
115
  say "Your global_settings.json file has been uploaded to Nexus", :blue
125
116
  end
126
117
 
127
118
  desc "reset_global_settings", "Resets your Nexus global_settings to their out-of-the-box defaults."
128
119
  def reset_global_settings
129
- @nexus_remote.reset_global_settings
120
+ nexus_remote.reset_global_settings
130
121
  say "Your Nexus global settings have been reset to their default values", :blue
131
122
  end
132
123
 
@@ -138,26 +129,26 @@ module NexusCli
138
129
  :desc => "The url of the actual repository for the proxy repository to use."
139
130
  desc "create_repository name", "Creates a new Repository with the provided name."
140
131
  def create_repository(name)
141
- if @nexus_remote.create_repository(name, options[:proxy], options[:url])
132
+ if nexus_remote.create_repository(name, options[:proxy], options[:url])
142
133
  say "A new Repository named #{name} has been created.", :blue
143
134
  end
144
135
  end
145
136
 
146
137
  desc "delete_repository name", "Deletes a Repository with the provided name."
147
138
  def delete_repository(name)
148
- if @nexus_remote.delete_repository(name)
139
+ if nexus_remote.delete_repository(name)
149
140
  say "The Repository named #{name} has been deleted.", :blue
150
141
  end
151
142
  end
152
143
 
153
144
  desc "get_repository_info name", "Finds and returns information about the provided Repository."
154
145
  def get_repository_info(name)
155
- say @nexus_remote.get_repository_info(name), :green
146
+ say nexus_remote.get_repository_info(name), :green
156
147
  end
157
148
 
158
149
  desc "get_users", "Returns XML representing the users in Nexus."
159
150
  def get_users
160
- say @nexus_remote.get_users, :green
151
+ say nexus_remote.get_users, :green
161
152
  end
162
153
 
163
154
  method_option :username,
@@ -193,7 +184,7 @@ module NexusCli
193
184
  def create_user
194
185
  params = ask_user(options)
195
186
 
196
- if @nexus_remote.create_user(params)
187
+ if nexus_remote.create_user(params)
197
188
  say "A user with the ID of #{params[:userId]} has been created.", :blue
198
189
  end
199
190
  end
@@ -228,14 +219,14 @@ module NexusCli
228
219
  params = ask_user(options, false, false)
229
220
  params[:userId] = user_id
230
221
 
231
- if @nexus_remote.update_user(params)
222
+ if nexus_remote.update_user(params)
232
223
  say "User #{user_id} has been updated.", :blue
233
224
  end
234
225
  end
235
226
 
236
227
  desc "delete_user user_id", "Deletes the user with the given id."
237
228
  def delete_user(user_id)
238
- if @nexus_remote.delete_user(user_id)
229
+ if nexus_remote.delete_user(user_id)
239
230
  say "User #{user_id} has been deleted.", :blue
240
231
  end
241
232
  end
@@ -264,45 +255,45 @@ module NexusCli
264
255
  params = {:userId => user_id}
265
256
  params[:oldPassword] = oldPassword
266
257
  params[:newPassword] = newPassword
267
- if @nexus_remote.change_password(params)
258
+ if nexus_remote.change_password(params)
268
259
  say "The password for user #{user_id} has been updated.", :blue
269
260
  end
270
261
  end
271
262
 
272
263
  desc "get_pub_sub repository_id", "Returns the publish/subscribe status of the given repository."
273
264
  def get_pub_sub(repository_id)
274
- raise NotNexusProException unless @nexus_remote.kind_of? ProRemote
275
- say @nexus_remote.get_pub_sub(repository_id), :green
265
+ raise NotNexusProException unless nexus_remote.kind_of? ProRemote
266
+ say nexus_remote.get_pub_sub(repository_id), :green
276
267
  end
277
268
 
278
269
  desc "enable_artifact_publish repository_id", "Sets a repository to enable the publishing of updates about its artifacts."
279
270
  def enable_artifact_publish(repository_id)
280
- raise NotNexusProException unless @nexus_remote.kind_of? ProRemote
281
- if @nexus_remote.enable_artifact_publish(repository_id)
271
+ raise NotNexusProException unless nexus_remote.kind_of? ProRemote
272
+ if nexus_remote.enable_artifact_publish(repository_id)
282
273
  say "The repository #{repository_id} will now publish updates.", :blue
283
274
  end
284
275
  end
285
276
 
286
277
  desc "disable_artifact_publish repository_id", "Sets a repository to disable the publishing of updates about its artifacts."
287
278
  def disable_artifact_publish(repository_id)
288
- raise NotNexusProException unless @nexus_remote.kind_of? ProRemote
289
- if @nexus_remote.disable_artifact_publish(repository_id)
279
+ raise NotNexusProException unless nexus_remote.kind_of? ProRemote
280
+ if nexus_remote.disable_artifact_publish(repository_id)
290
281
  say "The repository #{repository_id} is no longer publishing updates.", :blue
291
282
  end
292
283
  end
293
284
 
294
285
  desc "enable_artifact_subscribe repository_id", "Sets a repository to subscribe to updates about artifacts."
295
286
  def enable_artifact_subscribe(repository_id)
296
- raise NotNexusProException unless @nexus_remote.kind_of? ProRemote
297
- if @nexus_remote.enable_artifact_subscribe(repository_id)
287
+ raise NotNexusProException unless nexus_remote.kind_of? ProRemote
288
+ if nexus_remote.enable_artifact_subscribe(repository_id)
298
289
  say "The repository #{repository_id} is now subscribed for artifact updates.", :blue
299
290
  end
300
291
  end
301
292
 
302
293
  desc "disable_artifact_subscribe repository_id", "Sets a repository to stop subscribing to updates about artifacts."
303
294
  def disable_artifact_subscribe(repository_id)
304
- raise NotNexusProException unless @nexus_remote.kind_of? ProRemote
305
- if @nexus_remote.disable_artifact_subscribe(repository_id)
295
+ raise NotNexusProException unless nexus_remote.kind_of? ProRemote
296
+ if nexus_remote.disable_artifact_subscribe(repository_id)
306
297
  say "The repository #{repository_id} is no longer subscribed for artifact updates.", :blue
307
298
  end
308
299
  end
@@ -315,20 +306,20 @@ module NexusCli
315
306
  :desc => "An available port that will be used for Smart Proxy connections."
316
307
  desc "enable_smart_proxy", "Enables Smart Proxy on the server."
317
308
  def enable_smart_proxy
318
- raise NotNexusProException unless @nexus_remote.kind_of? ProRemote
319
- say @nexus_remote.enable_smart_proxy(options[:host], options[:port])
309
+ raise NotNexusProException unless nexus_remote.kind_of? ProRemote
310
+ say nexus_remote.enable_smart_proxy(options[:host], options[:port])
320
311
  end
321
312
 
322
313
  desc "disable_smart_proxy", "Disables Smart Proxy on the server."
323
314
  def disable_smart_proxy
324
- raise NotNexusProException unless @nexus_remote.kind_of? ProRemote
325
- say @nexus_remote.disable_smart_proxy
315
+ raise NotNexusProException unless nexus_remote.kind_of? ProRemote
316
+ say nexus_remote.disable_smart_proxy
326
317
  end
327
318
 
328
319
  desc "get_smart_proxy_settings", "Returns the Smart Proxy settings of the server."
329
320
  def get_smart_proxy_settings
330
- raise NotNexusProException unless @nexus_remote.kind_of? ProRemote
331
- say JSON.pretty_generate(JSON.parse(@nexus_remote.get_smart_proxy_settings)), :green
321
+ raise NotNexusProException unless nexus_remote.kind_of? ProRemote
322
+ say JSON.pretty_generate(JSON.parse(nexus_remote.get_smart_proxy_settings)), :green
332
323
  end
333
324
 
334
325
  method_option :certificate,
@@ -341,83 +332,99 @@ module NexusCli
341
332
  :desc => "A description to give to the trusted key. It is probably best to make this meaningful."
342
333
  desc "add_trusted_key", "Adds a new trusted key to the Smart Proxy configuration."
343
334
  def add_trusted_key
344
- raise NotNexusProException unless @nexus_remote.kind_of? ProRemote
345
- if @nexus_remote.add_trusted_key(options[:certificate], options[:description])
335
+ raise NotNexusProException unless nexus_remote.kind_of? ProRemote
336
+ if nexus_remote.add_trusted_key(options[:certificate], options[:description])
346
337
  say "A new trusted key has been added to the nexus.", :blue
347
338
  end
348
339
  end
349
340
 
350
341
  desc "delete_trusted_key key_id", "Deletes a trusted key using the given key_id."
351
342
  def delete_trusted_key(key_id)
352
- raise NotNexusProException unless @nexus_remote.kind_of? ProRemote
353
- if @nexus_remote.delete_trusted_key(key_id)
343
+ raise NotNexusProException unless nexus_remote.kind_of? ProRemote
344
+ if nexus_remote.delete_trusted_key(key_id)
354
345
  say "The trusted key with an id of #{key_id} has been deleted.", :blue
355
346
  end
356
347
  end
357
348
 
358
349
  desc "get_trusted_keys", "Returns the trusted keys of the server."
359
350
  def get_trusted_keys
360
- raise NotNexusProException unless @nexus_remote.kind_of? ProRemote
361
- say JSON.pretty_generate(JSON.parse(@nexus_remote.get_trusted_keys)), :green
351
+ raise NotNexusProException unless nexus_remote.kind_of? ProRemote
352
+ say JSON.pretty_generate(JSON.parse(nexus_remote.get_trusted_keys)), :green
362
353
  end
363
354
 
364
355
  desc "get_license_info", "Returns the license information of the server."
365
356
  def get_license_info
366
- say @nexus_remote.get_license_info, :green
357
+ say nexus_remote.get_license_info, :green
367
358
  end
368
359
 
369
360
  desc "install_license license_file", "Installs a license file into the server."
370
361
  def install_license(license_file)
371
- @nexus_remote.install_license(license_file)
362
+ nexus_remote.install_license(license_file)
372
363
  end
373
364
 
374
365
  desc "get_logging_info", "Gets the log4j Settings of the Nexus server."
375
366
  def get_logging_info
376
- say @nexus_remote.get_logging_info, :green
367
+ say nexus_remote.get_logging_info, :green
377
368
  end
378
369
 
379
370
  desc "set_logger_level level", "Updates the log4j logging level to a new value."
380
371
  def set_logger_level(level)
381
- if @nexus_remote.set_logger_level(level)
372
+ if nexus_remote.set_logger_level(level)
382
373
  say "The logging level of Nexus has been set to #{level.upcase}", :blue
383
374
  end
384
375
  end
385
376
 
386
377
  desc "create_group_repository name", "Creates a new repository group with the given name."
387
378
  def create_group_repository(name)
388
- if @nexus_remote.create_group_repository(name)
379
+ if nexus_remote.create_group_repository(name)
389
380
  say "A new group repository named #{name} has been created.", :blue
390
381
  end
391
382
  end
392
383
 
393
384
  desc "get_group_repository group_id", "Gets information about the given group repository."
394
385
  def get_group_repository(group_id)
395
- say @nexus_remote.get_group_repository(group_id), :green
386
+ say nexus_remote.get_group_repository(group_id), :green
396
387
  end
397
388
 
398
389
  desc "add_to_group_repository group_id repository_to_add_id", "Adds a repository with the given id into the group repository."
399
390
  def add_to_group_repository(group_id, repository_to_add_id)
400
- if @nexus_remote.add_to_group_repository(group_id, repository_to_add_id)
391
+ if nexus_remote.add_to_group_repository(group_id, repository_to_add_id)
401
392
  say "The repository #{repository_to_add_id} has been added to the repository group #{group_id}", :blue
402
393
  end
403
394
  end
404
395
 
405
396
  desc "remove_from_group_repository group_id repository_to_remove_id", "Remove a repository with the given id from the group repository."
406
397
  def remove_from_group_repository(group_id, repository_to_remove_id)
407
- if @nexus_remote.remove_from_group_repository(group_id, repository_to_remove_id)
398
+ if nexus_remote.remove_from_group_repository(group_id, repository_to_remove_id)
408
399
  say "The repository with an id of #{repository_to_remove_id} has been removed from the group repository, #{group_id}.", :blue
409
400
  end
410
401
  end
411
402
 
412
403
  desc "delete_group_repository group_id","Deletes a group repository based on the given id."
413
404
  def delete_group_repository(group_id)
414
- if @nexus_remote.delete_group_repository(group_id)
405
+ if nexus_remote.delete_group_repository(group_id)
415
406
  say "The group repository, #{group_id} has been deleted.", :blue
416
407
  end
417
408
  end
418
409
 
410
+ desc "transfer_artifact artifact from_repository to_repository", "Transfers a given artifact from one repository to another."
411
+ def transfer_artifact(artifact, from_repository, to_repository)
412
+ if nexus_remote.transfer_artifact(artifact, from_repository, to_repository)
413
+ say "The artifact #{artifact} has been transferred from #{from_repository} to #{to_repository}.", :blue
414
+ end
415
+ end
416
+
419
417
  private
420
418
 
419
+ def nexus_remote
420
+ begin
421
+ nexus_remote ||= Factory.create(options[:overrides], options[:ssl_verify])
422
+ rescue NexusCliError => e
423
+ say e.message, :red
424
+ exit e.status_code
425
+ end
426
+ end
427
+
421
428
  def ask_user(params, ask_username=true, ask_password=true)
422
429
  username = params[:username]
423
430
  first_name = params[:first_name]
@@ -1,7 +1,7 @@
1
1
  Feature: Use the Nexus Pro CLI
2
2
  As a Pro CLI user
3
3
  I need commands to get, update, search, and delete Nexus artifact custom metadata
4
-
4
+
5
5
  Scenario: Push an artifact
6
6
  When I push an artifact with the GAV of "com.test:myprotest:1.0.0:tgz"
7
7
  Then the output should contain:
@@ -10,7 +10,7 @@ Feature: Use the Nexus Pro CLI
10
10
  """
11
11
  And the exit status should be 0
12
12
 
13
- Scenario: Update an artifact's custom metadata
13
+ Scenario: Update an artifact's custom metadata
14
14
  When I call the nexus "update_artifact_custom_info com.test:myprotest:1.0.0:tgz somekey:somevalue" command
15
15
  Then the output should contain:
16
16
  """
@@ -78,6 +78,15 @@ Feature: Use the Nexus Pro CLI
78
78
  """
79
79
  And the exit status should be 0
80
80
 
81
+ Scenario: Transfer an artifact and ensure its metadata is also copied
82
+ When I call the nexus "transfer com.test:myprotest:1.0.0:tgz releases thirdparty" command
83
+ And I call the nexus "custom com.test:myprotest:1.0.0:tgz" command overriding "repository:thirdparty"
84
+ Then the output should contain:
85
+ """
86
+ <somekey>somevalue_1!</somekey>
87
+ """
88
+ And the exit status should be 0
89
+
81
90
  Scenario: Clear an artifact's custom metadata
82
91
  When I call the nexus "clear_artifact_custom_info com.test:myprotest:1.0.0:tgz" command
83
92
  Then the output should contain:
@@ -90,6 +99,16 @@ Feature: Use the Nexus Pro CLI
90
99
  Scenario: Attempt to delete an artifact
91
100
  When I delete an artifact with the GAV of "com.test:myprotest:1.0.0:tgz"
92
101
  And I call the nexus "info com.test:myprotest:1.0.0:tgz" command
102
+ Then the output should contain:
103
+ """
104
+ The artifact you requested information for could not be found. Please ensure it exists inside the Nexus.
105
+ """
106
+ And the exit status should be 101
107
+
108
+ @delete
109
+ Scenario: Attempt to delete another artifact
110
+ When I delete an artifact with the GAV of "com.test:myprotest:1.0.0:tgz" from the "thirdparty" repository
111
+ And I call the nexus "info com.test:myprotest:1.0.0:tgz" command overriding "repository:thirdparty"
93
112
  Then the output should contain:
94
113
  """
95
114
  The artifact you requested information for could not be found. Please ensure it exists inside the Nexus.
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.8.4
4
+ version: 0.9.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-09-26 00:00:00.000000000 Z
12
+ date: 2012-10-01 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: 25935714722440689
256
+ hash: 3447195715993783441
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: 25935714722440689
265
+ hash: 3447195715993783441
266
266
  requirements: []
267
267
  rubyforge_project:
268
268
  rubygems_version: 1.8.21