nexus_cli 0.7.3 → 0.8.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.
@@ -1,11 +1,10 @@
1
- require 'restclient'
1
+ require 'httpclient'
2
2
  require 'nokogiri'
3
3
  require 'yaml'
4
4
 
5
5
  module NexusCli
6
6
  class Factory
7
7
  class << self
8
-
9
8
  def create(overrides)
10
9
  @configuration = Configuration::parse(overrides)
11
10
  running_nexus_pro? ? ProRemote.new(overrides) : OSSRemote.new(overrides)
@@ -16,22 +15,41 @@ module NexusCli
16
15
  end
17
16
 
18
17
  def nexus
19
- RestClient::Resource.new configuration["url"], :user => configuration["username"], :password => configuration["password"]
18
+ client = HTTPClient.new
19
+ # https://github.com/nahi/httpclient/issues/63
20
+ client.set_auth(nil, configuration['username'], configuration['password'])
21
+ client.www_auth.basic_auth.challenge(configuration['url'])
22
+ return client
23
+ end
24
+
25
+ def nexus_url(url)
26
+ File.join(configuration['url'], url)
20
27
  end
21
28
 
22
29
  def status
23
- doc = Nokogiri::XML(nexus['service/local/status'].get).xpath("/status/data")
24
- data = Hash.new
25
- data['app_name'] = doc.xpath("appName")[0].text
26
- data['version'] = doc.xpath("version")[0].text
27
- data['edition_long'] = doc.xpath("editionLong")[0].text
28
- data['state'] = doc.xpath("state")[0].text
29
- data['started_at'] = doc.xpath("startedAt")[0].text
30
- data['base_url'] = doc.xpath("baseUrl")[0].text
31
- return data
30
+ response = nexus.get(nexus_url("service/local/status"))
31
+ case response.status
32
+ when 200
33
+ doc = Nokogiri::XML(response.content).xpath("/status/data")
34
+ data = Hash.new
35
+ data['app_name'] = doc.xpath("appName")[0].text
36
+ data['version'] = doc.xpath("version")[0].text
37
+ data['edition_long'] = doc.xpath("editionLong")[0].text
38
+ data['state'] = doc.xpath("state")[0].text
39
+ data['started_at'] = doc.xpath("startedAt")[0].text
40
+ data['base_url'] = doc.xpath("baseUrl")[0].text
41
+ return data
42
+ when 401
43
+ raise PermissionsException
44
+ when 503
45
+ raise CouldNotConnectToNexusException
46
+ else
47
+ raise UnexpectedStatusCodeException.new(response.status)
48
+ end
32
49
  end
33
50
 
34
51
  private
52
+
35
53
  def running_nexus_pro?
36
54
  return status['edition_long'] == "Professional" ? true : false
37
55
  end
@@ -11,11 +11,10 @@ module NexusCli
11
11
  map 'push' => :push_artifact
12
12
  map 'info' => :get_artifact_info
13
13
  map 'custom' => :get_artifact_custom_info
14
- map 'custom_raw' => :get_artifact_custom_info_n3
15
14
  map 'config' => :get_nexus_configuration
16
15
  map 'status' => :get_nexus_status
17
16
  map 'search' => :search_for_artifacts
18
- map 'search_custom' => :search_artifacts
17
+ map 'search_custom' => :search_artifacts_custom
19
18
 
20
19
  class_option :overrides,
21
20
  :type => :hash,
@@ -60,13 +59,8 @@ module NexusCli
60
59
 
61
60
  desc "get_artifact_custom_info artifact", "Gets and returns the custom metadata in XML format about a particular artifact."
62
61
  def get_artifact_custom_info(artifact)
63
- say @nexus_remote.get_artifact_custom_info(artifact), :green
64
- end
65
-
66
- desc "get_artifact_custom_info_n3 artifact", "Gets and returns the custom metadata in Nexus n3 format about a particular artifact."
67
- def get_artifact_custom_info_n3(artifact)
68
62
  raise NotNexusProException unless @nexus_remote.kind_of? ProRemote
69
- say @nexus_remote.get_artifact_custom_info_n3(artifact), :green
63
+ say @nexus_remote.get_artifact_custom_info(artifact), :green
70
64
  end
71
65
 
72
66
  desc "update_artifact_custom_info artifact param1 param2 ...", "Updates the artifact custom metadata with the given key-value pairs."
@@ -76,13 +70,6 @@ module NexusCli
76
70
  say "Custom metadata for artifact #{artifact} has been successfully pushed to Nexus.", :green
77
71
  end
78
72
 
79
- desc "update_artifact_custom_info_n3 artifact file", "Updates the artifact custom metadata by pushing the Nexus custom artifact file (n3) from your machine onto the Nexus."
80
- def update_artifact_custom_info_n3(artifact, file)
81
- raise NotNexusProException unless @nexus_remote.kind_of? ProRemote
82
- @nexus_remote.update_artifact_custom_info_n3(artifact, file)
83
- say "Custom metadata for artifact #{artifact} has been successfully pushed to Nexus.", :green
84
- end
85
-
86
73
  desc "clear_artifact_custom_info artifact", "Clears the artifact custom metadata."
87
74
  def clear_artifact_custom_info(artifact)
88
75
  raise NotNexusProException unless @nexus_remote.kind_of? ProRemote
@@ -90,10 +77,10 @@ module NexusCli
90
77
  say "Custom metadata for artifact #{artifact} has been successfully cleared.", :green
91
78
  end
92
79
 
93
- desc "search_artifacts param1 param2 ... ", "Searches for artifacts using artifact metadata and returns the result as a list with items in XML format."
94
- def search_artifacts(*params)
80
+ desc "search_artifacts_custom param1 param2 ... ", "Searches for artifacts using artifact metadata and returns the result as a list with items in XML format."
81
+ def search_artifacts_custom(*params)
95
82
  raise NotNexusProException unless @nexus_remote.kind_of? ProRemote
96
- say (s = @nexus_remote.search_artifacts(*params)) == "" ? "No search results." : s, :green
83
+ say (s = @nexus_remote.search_artifacts_custom(*params)) == "" ? "No search results." : s, :green
97
84
  end
98
85
 
99
86
  desc "get_nexus_configuration", "Prints out configuration from the .nexus_cli file that helps inform where artifacts will be uploaded."
@@ -379,6 +366,18 @@ module NexusCli
379
366
  @nexus_remote.install_license(license_file)
380
367
  end
381
368
 
369
+ desc "get_logging_info", "Gets the log4j Settings of the Nexus server."
370
+ def get_logging_info
371
+ say @nexus_remote.get_logging_info, :green
372
+ end
373
+
374
+ desc "set_logger_level level", "Updates the log4j logging level to a new value."
375
+ def set_logger_level(level)
376
+ if @nexus_remote.set_logger_level(level)
377
+ say "The logging level of Nexus has been set to #{level.upcase}", :blue
378
+ end
379
+ end
380
+
382
381
  private
383
382
 
384
383
  def ask_user(params, ask_username=true, ask_password=true)
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.require_paths = ["lib"]
18
18
 
19
19
  s.add_dependency 'thor'
20
- s.add_dependency 'rest-client'
20
+ s.add_dependency 'httpclient'
21
21
  s.add_dependency 'nokogiri'
22
22
  s.add_dependency 'extlib'
23
23
  s.add_dependency 'json'
@@ -0,0 +1,97 @@
1
+ Feature: Use the Nexus Pro CLI
2
+ As a Pro CLI user
3
+ I need commands to get, update, search, and delete Nexus artifact custom metadata
4
+
5
+ Scenario: Push an artifact
6
+ When I push an artifact with the GAV of "com.test:myprotest:1.0.0:tgz"
7
+ Then the output should contain:
8
+ """
9
+ Artifact com.test:myprotest:1.0.0:tgz has been successfully pushed to Nexus.
10
+ """
11
+ And the exit status should be 0
12
+
13
+ Scenario: Update an artifact's custom metadata
14
+ When I call the nexus "update_artifact_custom_info com.test:myprotest:1.0.0:tgz somekey:somevalue" command
15
+ Then the output should contain:
16
+ """
17
+ Custom metadata for artifact com.test:myprotest:1.0.0:tgz has been successfully pushed to Nexus.
18
+ """
19
+ And the exit status should be 0
20
+
21
+ Scenario: Update an artifact's custom metadata with multiple parameters
22
+ When I call the nexus "update_artifact_custom_info com.test:myprotest:1.0.0:tgz somekey:somevalue_1! \"someotherkey:some other value\" tempkey:tempvalue" command
23
+ Then the output should contain:
24
+ """
25
+ Custom metadata for artifact com.test:myprotest:1.0.0:tgz has been successfully pushed to Nexus.
26
+ """
27
+ And the exit status should be 0
28
+
29
+ Scenario: Update an artifact's custom metadata and remove a key
30
+ When I call the nexus "update_artifact_custom_info com.test:myprotest:1.0.0:tgz tempkey:" command
31
+ Then the output should contain:
32
+ """
33
+ Custom metadata for artifact com.test:myprotest:1.0.0:tgz has been successfully pushed to Nexus.
34
+ """
35
+ And the exit status should be 0
36
+
37
+ Scenario: Get an artifact's custom metadata
38
+ When I call the nexus "custom com.test:myprotest:1.0.0:tgz" command
39
+ Then the output should contain:
40
+ """
41
+ <somekey>somevalue_1!</somekey>
42
+ """
43
+ And the output should contain:
44
+ """
45
+ <someotherkey>some other value</someotherkey>
46
+ """
47
+ And the exit status should be 0
48
+
49
+ Scenario: Search for artifacts by custom metadata using matches
50
+ When I call the nexus "search_custom somekey:matches:*value*" command
51
+ Then the output should contain:
52
+ """
53
+ <artifactId>myprotest</artifactId>
54
+ """
55
+ And the exit status should be 0
56
+
57
+ Scenario: Search for artifacts by custom metadata using equal
58
+ When I call the nexus "search_custom somekey:equal:somevalue_1!" command
59
+ Then the output should contain:
60
+ """
61
+ <artifactId>myprotest</artifactId>
62
+ """
63
+ And the exit status should be 0
64
+
65
+ Scenario: Search for artifacts by custom metadata using multiple parameters
66
+ When I call the nexus "search_custom somekey:matches:*value* somekey:equal:somevalue_1!" command
67
+ Then the output should contain:
68
+ """
69
+ <artifactId>myprotest</artifactId>
70
+ """
71
+ And the exit status should be 0
72
+
73
+ Scenario: Search for artifacts by custom metadata that return an empty result set
74
+ When I call the nexus "search_custom fakekey:equal:fakevalue" command
75
+ Then the output should contain:
76
+ """
77
+ No search results.
78
+ """
79
+ And the exit status should be 0
80
+
81
+ Scenario: Clear an artifact's custom metadata
82
+ When I call the nexus "clear_artifact_custom_info com.test:myprotest:1.0.0:tgz" command
83
+ Then the output should contain:
84
+ """
85
+ Custom metadata for artifact com.test:myprotest:1.0.0:tgz has been successfully cleared.
86
+ """
87
+ And the exit status should be 0
88
+
89
+ @delete
90
+ Scenario: Attempt to delete an artifact
91
+ When I delete an artifact with the GAV of "com.test:myprotest:1.0.0:tgz"
92
+ And I call the nexus "info com.test:myprotest:1.0.0:tgz" command
93
+ Then the output should contain:
94
+ """
95
+ The artifact you requested information for could not be found. Please ensure it exists inside the Nexus.
96
+ """
97
+ And the exit status should be 101
@@ -10,105 +10,6 @@ Feature: Use the Nexus Pro CLI
10
10
  """
11
11
  And the exit status should be 0
12
12
 
13
- @push
14
- Scenario: Push an artifact
15
- When I push an artifact with the GAV of "com.test:myprotest:1.0.0:tgz"
16
- Then the output should contain:
17
- """
18
- Artifact com.test:myprotest:1.0.0:tgz has been successfully pushed to Nexus.
19
- """
20
- And the exit status should be 0
21
-
22
- Scenario: Update an artifact's custom metadata
23
- When I call the nexus "update_artifact_custom_info com.test:myprotest:1.0.0:tgz teemoHat:equipped" command
24
- Then the output should contain:
25
- """
26
- Custom metadata for artifact com.test:myprotest:1.0.0:tgz has been successfully pushed to Nexus.
27
- """
28
- And the exit status should be 0
29
-
30
- Scenario: Update an artifact's custom metadata with multiple parameters
31
- When I call the nexus "update_artifact_custom_info com.test:myprotest:1.0.0:tgz teemoHat:equipped_ \"teemoSkins:many skins!!1\"" command
32
- Then the output should contain:
33
- """
34
- Custom metadata for artifact com.test:myprotest:1.0.0:tgz has been successfully pushed to Nexus.
35
- """
36
- And the exit status should be 0
37
-
38
- Scenario: Get an artifact's custom metadata
39
- When I call the nexus "custom com.test:myprotest:1.0.0:tgz" command
40
- Then the output should contain:
41
- """
42
- <teemoHat>equipped_</teemoHat>
43
- """
44
- And the output should contain:
45
- """
46
- <teemoSkins>many skins!!1</teemoSkins>
47
- """
48
- And the exit status should be 0
49
-
50
- Scenario: Get an artifact's raw custom metadata
51
- When I call the nexus "custom_raw com.test:myprotest:1.0.0:tgz" command
52
- Then the output should contain:
53
- """
54
- <urn:nexus/user#teemoHat> "equipped_"
55
- """
56
- And the output should contain:
57
- """
58
- <urn:nexus/user#teemoSkins> "many skins!!1"
59
- """
60
- And the exit status should be 0
61
-
62
- Scenario: Search for artifacts by custom metadata using matches
63
- When I call the nexus "search_custom teemoHat:matches:equip*" command
64
- Then the output should contain:
65
- """
66
- <artifactId>myprotest</artifactId>
67
- """
68
- And the exit status should be 0
69
-
70
- Scenario: Search for artifacts by custom metadata using equal
71
- When I call the nexus "search_custom teemoHat:equal:equipped_" command
72
- Then the output should contain:
73
- """
74
- <artifactId>myprotest</artifactId>
75
- """
76
- And the exit status should be 0
77
-
78
- Scenario: Search for artifacts by custom metadata using multiple parameters
79
- When I call the nexus "search_custom teemoHat:matches:equip* teemoHat:equal:equipped_" command
80
- Then the output should contain:
81
- """
82
- <artifactId>myprotest</artifactId>
83
- """
84
- And the exit status should be 0
85
-
86
- Scenario: Search for artifacts by custom metadata that return an empty result set
87
- When I call the nexus "search_custom bestTeemo:equal:malady" command
88
- Then the output should contain:
89
- """
90
- No search results.
91
- """
92
- And the exit status should be 0
93
-
94
- Scenario: Clear an artifact's custom metadata
95
- When I call the nexus "clear_artifact_custom_info com.test:myprotest:1.0.0:tgz" command
96
- Then the output should contain:
97
- """
98
- Custom metadata for artifact com.test:myprotest:1.0.0:tgz has been successfully cleared.
99
- """
100
- And the exit status should be 0
101
-
102
- @delete
103
- Scenario: Attempt to delete an artifact
104
- When I delete an artifact with the GAV of "com.test:myprotest:1.0.0:tgz"
105
- And I call the nexus "info com.test:myprotest:1.0.0:tgz" command
106
- Then the output should contain:
107
- """
108
- The artifact you requested information for could not be found. Please ensure it exists inside the Nexus.
109
- """
110
- And the exit status should be 101
111
-
112
13
  Scenario: Set a repository to publish updates
113
14
  When I call the nexus "enable_artifact_publish releases" command
114
15
  And I call the nexus "get_pub_sub releases" command
@@ -12,12 +12,12 @@ describe NexusCli do
12
12
  end
13
13
 
14
14
  it "gives you errors when you attempt to pull an artifact and it cannot be found" do
15
- RestClient::Resource.any_instance.stub(:get).and_raise(RestClient::ResourceNotFound)
15
+ HTTPClient.any_instance.stub(:get).and_raise(NexusCli::ArtifactNotFoundException)
16
16
  expect {remote.pull_artifact "com.something:something:1.0.0:tgz", nil}.to raise_error(NexusCli::ArtifactNotFoundException)
17
17
  end
18
18
 
19
19
  it "gives you errors when you attempt to get an artifact's info and it cannot be found" do
20
- RestClient::Resource.any_instance.stub(:get).and_raise(RestClient::ResourceNotFound)
20
+ HTTPClient.any_instance.stub(:get).and_raise(NexusCli::ArtifactNotFoundException)
21
21
  expect {remote.get_artifact_info "com.something:something:1.0.0:tgz"}.to raise_error(NexusCli::ArtifactNotFoundException)
22
22
  end
23
23
 
@@ -27,4 +27,8 @@ describe NexusCli do
27
27
  to_return(:status => 404, :body => "", :headers => {})
28
28
  expect {remote.update_user(:userId => "qwertyasdf")}.to raise_error(NexusCli::UserNotFoundException)
29
29
  end
30
+
31
+ it "gives you an error when you try to set the logging level to something weird" do
32
+ expect {remote.set_logger_level("weird")}.to raise_error(NexusCli::InvalidLoggingLevelException)
33
+ end
30
34
  end
@@ -8,7 +8,7 @@ describe NexusCli do
8
8
  end
9
9
 
10
10
  it "gives you errors when you attempt to get an artifact's custom info and it cannot be found" do
11
- RestClient::Resource.any_instance.stub(:get).and_raise(RestClient::ResourceNotFound)
11
+ HTTPClient.any_instance.stub(:get).and_raise(NexusCli::ArtifactNotFoundException)
12
12
  expect {remote.get_artifact_custom_info("com.something:something:1.0.0:tgz")}.to raise_error(NexusCli::ArtifactNotFoundException)
13
13
  end
14
14
 
@@ -21,23 +21,83 @@ describe NexusCli do
21
21
  end
22
22
 
23
23
  it "gives you errors when you attempt to clear an artifact's custom info and it cannot be found" do
24
- RestClient::Resource.any_instance.stub(:get).and_raise(RestClient::ResourceNotFound)
24
+ HTTPClient.any_instance.stub(:get).and_raise(NexusCli::ArtifactNotFoundException)
25
25
  expect {remote.clear_artifact_custom_info("com.something:something:1.0.0:tgz")}.to raise_error(NexusCli::ArtifactNotFoundException)
26
26
  end
27
27
 
28
28
  it "gives you errors when you attempt to search for artifacts using custom info and don't give valid key" do
29
- expect {remote.search_artifacts("somekey_:equal:somevalue")}.to raise_error(NexusCli::SearchParameterMalformedException)
29
+ expect {remote.search_artifacts_custom("somekey_:equal:somevalue")}.to raise_error(NexusCli::SearchParameterMalformedException)
30
30
  end
31
31
 
32
32
  it "gives you errors when you attempt to search for artifacts using custom info and don't give valid value" do
33
- expect {remote.search_artifacts("somekey:equal:somevalue \"\'\\/")}.to raise_error(NexusCli::SearchParameterMalformedException)
33
+ expect {remote.search_artifacts_custom("somekey:equal:somevalue \"\'\\/")}.to raise_error(NexusCli::SearchParameterMalformedException)
34
34
  end
35
35
 
36
36
  it "gives you errors when you attempt to search for artifacts using custom info and don't give valid search type" do
37
- expect {remote.search_artifacts("somekey:equals:somevalue")}.to raise_error(NexusCli::SearchParameterMalformedException)
37
+ expect {remote.search_artifacts_custom("somekey:equals:somevalue")}.to raise_error(NexusCli::SearchParameterMalformedException)
38
38
  end
39
39
 
40
40
  it "gives you errors when you attempt to search for artifacts using custom info and don't give valid parameters" do
41
- expect {remote.search_artifacts("somekey")}.to raise_error(NexusCli::SearchParameterMalformedException)
41
+ expect {remote.search_artifacts_custom("somekey")}.to raise_error(NexusCli::SearchParameterMalformedException)
42
+ end
43
+
44
+ describe "tests for custom metadata private helper methods" do
45
+ it "gives you errors when you attempt to parse custom metadata with bad update keys" do
46
+ expect {NexusCli::ProRemote.new(nil).send(:parse_custom_metadata_update_params, "goodkey:goodvalue", "badkey_:goodvalue")}.to raise_error(NexusCli::N3ParameterMalformedException)
47
+ end
48
+
49
+ it "gives you errors when you attempt to parse custom metadata with missing update keys" do
50
+ expect {NexusCli::ProRemote.new(nil).send(:parse_custom_metadata_update_params, ":goodvalue")}.to raise_error(NexusCli::N3ParameterMalformedException)
51
+ end
52
+
53
+ it "gives you errors when you attempt to parse custom metadata with typo" do
54
+ expect {NexusCli::ProRemote.new(nil).send(:parse_custom_metadata_update_params, "goodkeygoodvalue")}.to raise_error(NexusCli::N3ParameterMalformedException)
55
+ end
56
+
57
+ it "gives you errors when you attempt to parse custom metadata with bad update values" do
58
+ expect {NexusCli::ProRemote.new(nil).send(:parse_custom_metadata_update_params, "goodkey:goodvalue", "goodkey:badvalue\"'\\")}.to raise_error(NexusCli::N3ParameterMalformedException)
59
+ end
60
+
61
+ it "gives you errors when you attempt to parse custom metadata with missing search type and value" do
62
+ expect {NexusCli::ProRemote.new(nil).send(:parse_custom_metadata_search_params, "goodkey")}.to raise_error(NexusCli::SearchParameterMalformedException)
63
+ end
64
+
65
+ it "gives you errors when you attempt to parse custom metadata with bad search type" do
66
+ expect {NexusCli::ProRemote.new(nil).send(:parse_custom_metadata_search_params, "goodkey:eq:goodvalue")}.to raise_error(NexusCli::SearchParameterMalformedException)
67
+ end
68
+
69
+ it "gives you errors when you attempt to parse custom metadata with bad search value" do
70
+ expect {NexusCli::ProRemote.new(nil).send(:parse_custom_metadata_search_params, "goodkey:equals:badvalue\"'\\")}.to raise_error(NexusCli::SearchParameterMalformedException)
71
+ end
72
+ end
73
+
74
+ describe "tests for custom metadata private helper methods" do
75
+ it "gives you errors when you attempt to parse custom metadata with bad update keys" do
76
+ expect {NexusCli::ProRemote.new(nil).send(:parse_custom_metadata_update_params, "goodkey:goodvalue", "badkey_:goodvalue")}.to raise_error(NexusCli::N3ParameterMalformedException)
77
+ end
78
+
79
+ it "gives you errors when you attempt to parse custom metadata with missing update keys" do
80
+ expect {NexusCli::ProRemote.new(nil).send(:parse_custom_metadata_update_params, ":goodvalue")}.to raise_error(NexusCli::N3ParameterMalformedException)
81
+ end
82
+
83
+ it "gives you errors when you attempt to parse custom metadata with typo" do
84
+ expect {NexusCli::ProRemote.new(nil).send(:parse_custom_metadata_update_params, "goodkeygoodvalue")}.to raise_error(NexusCli::N3ParameterMalformedException)
85
+ end
86
+
87
+ it "gives you errors when you attempt to parse custom metadata with bad update values" do
88
+ expect {NexusCli::ProRemote.new(nil).send(:parse_custom_metadata_update_params, "goodkey:goodvalue", "goodkey:badvalue\"'\\")}.to raise_error(NexusCli::N3ParameterMalformedException)
89
+ end
90
+
91
+ it "gives you errors when you attempt to parse custom metadata with missing search type and value" do
92
+ expect {NexusCli::ProRemote.new(nil).send(:parse_custom_metadata_search_params, "goodkey")}.to raise_error(NexusCli::SearchParameterMalformedException)
93
+ end
94
+
95
+ it "gives you errors when you attempt to parse custom metadata with bad search type" do
96
+ expect {NexusCli::ProRemote.new(nil).send(:parse_custom_metadata_search_params, "goodkey:eq:goodvalue")}.to raise_error(NexusCli::SearchParameterMalformedException)
97
+ end
98
+
99
+ it "gives you errors when you attempt to parse custom metadata with bad search value" do
100
+ expect {NexusCli::ProRemote.new(nil).send(:parse_custom_metadata_search_params, "goodkey:equals:badvalue\"'\\")}.to raise_error(NexusCli::SearchParameterMalformedException)
101
+ end
42
102
  end
43
103
  end