nexus_cli_sb 4.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.travis.yml +4 -0
  4. data/CHANGELOG.md +14 -0
  5. data/Gemfile +42 -0
  6. data/Guardfile +27 -0
  7. data/LICENSE +15 -0
  8. data/README.md +121 -0
  9. data/Rakefile +1 -0
  10. data/Thorfile +66 -0
  11. data/VERSION +1 -0
  12. data/bin/nexus-cli +10 -0
  13. data/data/pom.xml.erb +13 -0
  14. data/features/nexus_oss.feature +251 -0
  15. data/features/pro/nexus_custom_metadata.feature +116 -0
  16. data/features/pro/nexus_pro.feature +101 -0
  17. data/features/step_definitions/cli_steps.rb +105 -0
  18. data/features/support/env.rb +64 -0
  19. data/lib/nexus_cli/artifact.rb +44 -0
  20. data/lib/nexus_cli/base_remote.rb +16 -0
  21. data/lib/nexus_cli/cli.rb +7 -0
  22. data/lib/nexus_cli/configuration.rb +102 -0
  23. data/lib/nexus_cli/connection.rb +84 -0
  24. data/lib/nexus_cli/errors.rb +259 -0
  25. data/lib/nexus_cli/mixins/artifact_actions.rb +194 -0
  26. data/lib/nexus_cli/mixins/global_settings_actions.rb +64 -0
  27. data/lib/nexus_cli/mixins/logging_actions.rb +45 -0
  28. data/lib/nexus_cli/mixins/pro/custom_metadata_actions.rb +176 -0
  29. data/lib/nexus_cli/mixins/pro/smart_proxy_actions.rb +219 -0
  30. data/lib/nexus_cli/mixins/repository_actions.rb +245 -0
  31. data/lib/nexus_cli/mixins/user_actions.rb +125 -0
  32. data/lib/nexus_cli/n3_metadata.rb +77 -0
  33. data/lib/nexus_cli/remote/oss_remote.rb +11 -0
  34. data/lib/nexus_cli/remote/pro_remote.rb +59 -0
  35. data/lib/nexus_cli/remote_factory.rb +30 -0
  36. data/lib/nexus_cli/tasks.rb +496 -0
  37. data/lib/nexus_cli/version.rb +6 -0
  38. data/lib/nexus_cli.rb +44 -0
  39. data/nexus_cli.gemspec +31 -0
  40. data/spec/fixtures/metadata_search.xml +10 -0
  41. data/spec/fixtures/nexus.config +4 -0
  42. data/spec/spec_helper.rb +22 -0
  43. data/spec/unit/nexus_cli/artifact_spec.rb +82 -0
  44. data/spec/unit/nexus_cli/configuration_spec.rb +137 -0
  45. data/spec/unit/nexus_cli/mixins/pro/custom_metadata_actions_spec.rb +21 -0
  46. data/spec/unit/nexus_cli/oss_remote_spec.rb +78 -0
  47. data/spec/unit/nexus_cli/pro_remote_spec.rb +110 -0
  48. data/spec/unit/nexus_cli/remote_factory_spec.rb +42 -0
  49. metadata +259 -0
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+
3
+ describe NexusCli::Artifact do
4
+
5
+ describe "#new" do
6
+ it "gives you errors when you under specify" do
7
+ expect { described_class.new("group:artifact") }.to raise_error(NexusCli::ArtifactMalformedException)
8
+ end
9
+
10
+ it "gives you errors when you over specify" do
11
+ expect { described_class.new("group:artifact:extension:classifier:version:garbage") }.to raise_error(NexusCli::ArtifactMalformedException)
12
+ end
13
+
14
+ context "when extension and classifier are omitted" do
15
+ subject { new_artifact }
16
+ let(:new_artifact) { described_class.new("group:artifact:version") }
17
+
18
+ it "creates a new Artifact object" do
19
+ expect(new_artifact).to be_a(NexusCli::Artifact)
20
+ end
21
+
22
+ it "has the correct attributes" do
23
+ expect(new_artifact.group_id).to eq("group")
24
+ expect(new_artifact.artifact_id).to eq("artifact")
25
+ expect(new_artifact.extension).to eq("jar")
26
+ expect(new_artifact.classifier).to be_nil
27
+ expect(new_artifact.version).to eq("version")
28
+ expect(new_artifact.file_name).to eq("artifact-version.jar")
29
+ end
30
+ end
31
+
32
+ context "when just extension is specified" do
33
+ subject { new_artifact }
34
+ let(:new_artifact) { described_class.new("group:artifact:extension:version") }
35
+
36
+ it "creates a new Artifact object" do
37
+ expect(new_artifact).to be_a(NexusCli::Artifact)
38
+ end
39
+
40
+ it "has the correct attributes" do
41
+ expect(new_artifact.group_id).to eq("group")
42
+ expect(new_artifact.artifact_id).to eq("artifact")
43
+ expect(new_artifact.extension).to eq("extension")
44
+ expect(new_artifact.classifier).to be_nil
45
+ expect(new_artifact.version).to eq("version")
46
+ expect(new_artifact.file_name).to eq("artifact-version.extension")
47
+ end
48
+ end
49
+
50
+ context "when both extension and classifer are specified" do
51
+ subject { new_artifact }
52
+ let(:new_artifact) { described_class.new("group:artifact:extension:classifier:version") }
53
+
54
+ it "creates a new Artifact object" do
55
+ expect(new_artifact).to be_a(NexusCli::Artifact)
56
+ end
57
+
58
+ it "has the correct attributes" do
59
+ expect(new_artifact.group_id).to eq("group")
60
+ expect(new_artifact.artifact_id).to eq("artifact")
61
+ expect(new_artifact.extension).to eq("extension")
62
+ expect(new_artifact.classifier).to eq("classifier")
63
+ expect(new_artifact.version).to eq("version")
64
+ expect(new_artifact.file_name).to eq("artifact-version-classifier.extension")
65
+ end
66
+ end
67
+
68
+ context "when you specify latest as the version" do
69
+ subject { new_artifact }
70
+ let(:new_artifact) { described_class.new("group:artifact:latest") }
71
+
72
+ it "upper cases version" do
73
+ expect(new_artifact.group_id).to eq("group")
74
+ expect(new_artifact.artifact_id).to eq("artifact")
75
+ expect(new_artifact.extension).to eq("jar")
76
+ expect(new_artifact.classifier).to be_nil
77
+ expect(new_artifact.version).to eq("LATEST")
78
+ expect(new_artifact.file_name).to eq("artifact-LATEST.jar")
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,137 @@
1
+ require 'spec_helper'
2
+
3
+ describe NexusCli::Configuration do
4
+ subject { configuration }
5
+ let(:configuration) { described_class }
6
+ let(:config_instance) { configuration.from_overrides(valid_config) }
7
+ let(:url) { "http://some-url.com" }
8
+ let(:repository) { "releases" }
9
+ let(:username) { "kallan" }
10
+ let(:password) { "password" }
11
+
12
+ let(:valid_config) do
13
+ {
14
+ "url" => "http://somewebsite.com",
15
+ "repository" => "foo",
16
+ "username" => "admin",
17
+ "password" => "password"
18
+ }
19
+ end
20
+
21
+ describe "::from_overrides" do
22
+ subject { from_overrides }
23
+ let(:from_overrides) { configuration.from_overrides(valid_config) }
24
+
25
+ it "returns a new Configuration object" do
26
+ expect(from_overrides).to be_a(NexusCli::Configuration)
27
+ end
28
+
29
+ context "without username and password" do
30
+ let(:valid_config) do
31
+ {
32
+ "url" => "http://somewebsite.com",
33
+ "repository" => "foo"
34
+ }
35
+ end
36
+
37
+ it "should not raise an exception" do
38
+ expect { from_overrides.validate! }.not_to raise_error
39
+ end
40
+ end
41
+ end
42
+
43
+ describe "::from_file" do
44
+ subject { from_file }
45
+ let(:from_file) { configuration.from_file }
46
+
47
+ before do
48
+ YAML.stub(:load_file).and_return(valid_config)
49
+ end
50
+
51
+ context "when the NEXUS_CONFIG environment variable exists" do
52
+ let(:nexus_config_path) { "/home/var/nexus_cli" }
53
+
54
+ before do
55
+ ENV['NEXUS_CONFIG'] = nexus_config_path
56
+ end
57
+
58
+ it "loads the config file from NEXUS_CONFIG" do
59
+ YAML.should_receive(:load_file).with(nexus_config_path)
60
+ from_file
61
+ end
62
+ end
63
+
64
+ context "when the NEXUS_CONFIG environment variable does not exist" do
65
+ let(:nexus_config_path) { File.expand_path(NexusCli::Configuration::DEFAULT_FILE) }
66
+
67
+ before do
68
+ ENV['NEXUS_CONFIG'] = nil
69
+ end
70
+
71
+ it "loads the config file from DEFAULT_FILE" do
72
+ YAML.should_receive(:load_file).with(nexus_config_path)
73
+ from_file
74
+ end
75
+ end
76
+
77
+ it "returns a new Configuration object" do
78
+ expect(from_file).to be_a(NexusCli::Configuration)
79
+ end
80
+ end
81
+
82
+ describe "::validate!" do
83
+ subject { validate! }
84
+ let(:validate!) {described_class.validate!(invalid_config)}
85
+ let(:invalid_config) do
86
+ described_class.new(url: nil, repository: "something", username: "someone", password: "somepass")
87
+ end
88
+
89
+ context "when the object is invalide" do
90
+ it "raises an error" do
91
+ expect { validate! }.to raise_error(NexusCli::InvalidSettingsException)
92
+ end
93
+ end
94
+ end
95
+
96
+ describe "#new" do
97
+ subject { new_config }
98
+ let(:new_config) { described_class.new(url: url, repository: repository, username: username, password: password) }
99
+
100
+ it "creates a new Configuration object" do
101
+ expect(new_config).to be_a(NexusCli::Configuration)
102
+ end
103
+ end
104
+
105
+ describe "#url" do
106
+ it "returns the url" do
107
+ expect(config_instance.url).to eq("http://somewebsite.com")
108
+ end
109
+ end
110
+
111
+ describe "#repository" do
112
+ let(:repository_config) { described_class.new(url: url, repository: repository, username: username, password: password) }
113
+
114
+ it "returns the repository" do
115
+ expect(config_instance.repository).to eq("foo")
116
+ end
117
+
118
+ context "when repository has illegal values" do
119
+ let(:repository) { "ILLEGAL VALUE" }
120
+ it "makes it legal" do
121
+ expect(repository_config.repository).to eq("illegal_value")
122
+ end
123
+ end
124
+ end
125
+
126
+ describe "#username" do
127
+ it "returns the username" do
128
+ expect(config_instance.username).to eq("admin")
129
+ end
130
+ end
131
+
132
+ describe "#password" do
133
+ it "returns the password" do
134
+ expect(config_instance.password).to eq("password")
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe NexusCli::CustomMetadataActions do
4
+ let(:custom_metadata_actions) { injected_module.new }
5
+ let(:injected_module) do
6
+ Class.new {
7
+ include NexusCli::CustomMetadataActions
8
+ }
9
+ end
10
+ let(:document) { REXML::Document.new(File.read(fixtures_path.join('metadata_search.xml'))) }
11
+
12
+ describe "::get_artifact_array" do
13
+ subject { get_artifact_array }
14
+ let(:get_artifact_array) { custom_metadata_actions.send(:get_artifact_array, document) }
15
+
16
+ it "returns an array of strings" do
17
+ get_artifact_array.should be_a(Array)
18
+ get_artifact_array.each { |element| element.should be_a(String) }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ remote = NexusCli::OSSRemote.new(
4
+ 'url' => 'http://localhost:8081/nexus',
5
+ 'repository' => 'releases',
6
+ 'username' => 'admin',
7
+ 'password' => 'admin123'
8
+ )
9
+
10
+
11
+ fake_xml = <<EOS
12
+ <search-results>
13
+ <totalCount>1</totalCount>
14
+ <from>-1</from>
15
+ <count>-1</count>
16
+ <tooManyResults>false</tooManyResults>
17
+ <data>
18
+ <artifact>
19
+ <resourceURI>https://someuri.com/com/something/thing.tgz</resourceURI>
20
+ <groupId>com.something</groupId>
21
+ <artifactId>thing-stuff</artifactId>
22
+ <version>0.4.0</version>
23
+ <packaging>tgz</packaging>
24
+ <extension>tgz</extension>
25
+ <repoId>company_artifact</repoId>
26
+ <contextId>Company Replicated Artifacts</contextId>
27
+ <pomLink>https://somedomain.com/nexus/service/local/artifact/maven/redirect?r=company_artifact&amp;g=com.something&amp;a=thing-stuff&amp;v=0.4.0&amp;e=pom</pomLink>
28
+ <artifactLink>https://somedomain/nexus/service/local/artifact/maven/redirect?r=ompany_artifact&amp;g=com.something&amp;a=thing-stuff&amp;v=0.4.0&amp;e=tgz</artifactLink>
29
+ </artifact>
30
+ </data>
31
+ </search-results>
32
+ EOS
33
+
34
+ describe NexusCli do
35
+ it "gives you errors when you attempt to pull an artifact don't give a valid artifact name" do
36
+ expect {remote.pull_artifact "com.something:something", nil}.to raise_error(NexusCli::ArtifactMalformedException)
37
+ end
38
+
39
+ it "gives you errors when you attempt to get an artifact's info and don't give a valid artifact name" do
40
+ expect {remote.get_artifact_info "com.something:something"}.to raise_error(NexusCli::ArtifactMalformedException)
41
+ end
42
+
43
+ it "gives you errors when you attempt to pull an artifact and it cannot be found" do
44
+ HTTPClient.any_instance.stub(:get).and_raise(NexusCli::ArtifactNotFoundException)
45
+ expect {remote.pull_artifact "com.something:something:tgz:1.0.0", nil}.to raise_error(NexusCli::ArtifactNotFoundException)
46
+ end
47
+
48
+ it "gives you errors when you attempt to get an artifact's info and it cannot be found" do
49
+ HTTPClient.any_instance.stub(:get).and_raise(NexusCli::ArtifactNotFoundException)
50
+ expect {remote.get_artifact_info "com.something:something:tgz:1.0.0"}.to raise_error(NexusCli::ArtifactNotFoundException)
51
+ end
52
+
53
+ it "gives you errors when you attempt to pull an artifact with classifier and it cannot be found" do
54
+ HTTPClient.any_instance.stub(:get).and_raise(NexusCli::ArtifactNotFoundException)
55
+ expect {remote.pull_artifact "com.something:something:tgz:x64:1.0.0", nil}.to raise_error(NexusCli::ArtifactNotFoundException)
56
+ end
57
+
58
+ it "gives you an error when you try to update a user that doesnt exist" do
59
+ stub_request(:get, "http://admin:admin123@localhost:8081/nexus/service/local/users/qwertyasdf").
60
+ with(:headers => {
61
+ 'Accept' => 'application/json',
62
+ 'Authorization' => 'Basic YWRtaW46YWRtaW4xMjM='
63
+ }).to_return(:status => 404, :body => "", :headers => {})
64
+
65
+ expect {
66
+ remote.update_user(:userId => "qwertyasdf")
67
+ }.to raise_error(NexusCli::UserNotFoundException)
68
+ end
69
+
70
+ it "gives you an error when you try to set the logging level to something weird" do
71
+ expect {remote.set_logger_level("weird")}.to raise_error(NexusCli::InvalidLoggingLevelException)
72
+ end
73
+
74
+ it "will return raw xml from the search command" do
75
+ stub_request(:get, "http://admin:admin123@localhost:8081/nexus/service/local/data_index?a=something&g=com.something").to_return(:status => 200, :body => fake_xml, :headers => {})
76
+ remote.search_for_artifacts("com.something:something").should eq fake_xml
77
+ end
78
+ end
@@ -0,0 +1,110 @@
1
+ require 'nexus_cli'
2
+
3
+ describe NexusCli::ProRemote do
4
+ let(:remote) do
5
+ NexusCli::ProRemote.new(
6
+ 'url' => 'http://localhost:8081/nexus',
7
+ 'repository' => 'releases',
8
+ 'username' => 'admin',
9
+ 'password' => 'admin123'
10
+ )
11
+ end
12
+
13
+ it "gives you errors when you attempt to get an artifact's custom info and don't give a valid artifact name" do
14
+ expect {remote.get_artifact_custom_info("com.something:something")}.to raise_error(NexusCli::ArtifactMalformedException)
15
+ end
16
+
17
+ it "gives you errors when you attempt to get an artifact's custom info and it cannot be found" do
18
+ HTTPClient.any_instance.stub(:get).and_raise(NexusCli::ArtifactNotFoundException)
19
+ expect {remote.get_artifact_custom_info("com.something:something:tgz:1.0.0")}.to raise_error(NexusCli::ArtifactNotFoundException)
20
+ end
21
+
22
+ it "gives you errors when you attempt to update an artifact's custom info and don't give valid parameters" do
23
+ expect {remote.update_artifact_custom_info("com.something:something:tgz:1.0.0", "_somebadkey:_somebadvalue")}.to raise_error(NexusCli::N3ParameterMalformedException)
24
+ end
25
+
26
+ it "gives you errors when you attempt to update an artifact's custom info and don't give valid parameters" do
27
+ expect {remote.update_artifact_custom_info("com.something:something:tgz:1.0.0", "_somebadkey")}.to raise_error(NexusCli::N3ParameterMalformedException)
28
+ end
29
+
30
+ it "gives you errors when you attempt to clear an artifact's custom info and it cannot be found" do
31
+ HTTPClient.any_instance.stub(:get).and_raise(NexusCli::ArtifactNotFoundException)
32
+ expect {remote.clear_artifact_custom_info("com.something:something:tgz:1.0.0")}.to raise_error(NexusCli::ArtifactNotFoundException)
33
+ end
34
+
35
+ it "gives you errors when you attempt to search for artifacts using custom info and don't give valid key" do
36
+ expect {remote.search_artifacts_custom("somekey_:equal:somevalue")}.to raise_error(NexusCli::SearchParameterMalformedException)
37
+ end
38
+
39
+ it "gives you errors when you attempt to search for artifacts using custom info and don't give valid value" do
40
+ expect {remote.search_artifacts_custom("somekey:equal:somevalue \"\'\\/")}.to raise_error(NexusCli::SearchParameterMalformedException)
41
+ end
42
+
43
+ it "gives you errors when you attempt to search for artifacts using custom info and don't give valid search type" do
44
+ expect {remote.search_artifacts_custom("somekey:equals:somevalue")}.to raise_error(NexusCli::SearchParameterMalformedException)
45
+ end
46
+
47
+ it "gives you errors when you attempt to search for artifacts using custom info and don't give valid parameters" do
48
+ expect {remote.search_artifacts_custom("somekey")}.to raise_error(NexusCli::SearchParameterMalformedException)
49
+ end
50
+
51
+ describe "tests for custom metadata private helper methods" do
52
+ it "gives you errors when you attempt to parse custom metadata with bad update keys" do
53
+ expect {remote.send(:parse_custom_metadata_update_params, "goodkey:goodvalue", "badkey_:goodvalue")}.to raise_error(NexusCli::N3ParameterMalformedException)
54
+ end
55
+
56
+ it "gives you errors when you attempt to parse custom metadata with missing update keys" do
57
+ expect {remote.send(:parse_custom_metadata_update_params, ":goodvalue")}.to raise_error(NexusCli::N3ParameterMalformedException)
58
+ end
59
+
60
+ it "gives you errors when you attempt to parse custom metadata with typo" do
61
+ expect {remote.send(:parse_custom_metadata_update_params, "goodkeygoodvalue")}.to raise_error(NexusCli::N3ParameterMalformedException)
62
+ end
63
+
64
+ it "gives you errors when you attempt to parse custom metadata with bad update values" do
65
+ expect {remote.send(:parse_custom_metadata_update_params, "goodkey:goodvalue", "goodkey:badvalue\"'\\")}.to raise_error(NexusCli::N3ParameterMalformedException)
66
+ end
67
+
68
+ it "gives you errors when you attempt to parse custom metadata with missing search type and value" do
69
+ expect {remote.send(:parse_custom_metadata_search_params, "goodkey")}.to raise_error(NexusCli::SearchParameterMalformedException)
70
+ end
71
+
72
+ it "gives you errors when you attempt to parse custom metadata with bad search type" do
73
+ expect {remote.send(:parse_custom_metadata_search_params, "goodkey:eq:goodvalue")}.to raise_error(NexusCli::SearchParameterMalformedException)
74
+ end
75
+
76
+ it "gives you errors when you attempt to parse custom metadata with bad search value" do
77
+ expect {remote.send(:parse_custom_metadata_search_params, "goodkey:equals:badvalue\"'\\")}.to raise_error(NexusCli::SearchParameterMalformedException)
78
+ end
79
+ end
80
+
81
+ describe "tests for custom metadata private helper methods" do
82
+ it "gives you errors when you attempt to parse custom metadata with bad update keys" do
83
+ expect {remote.send(:parse_custom_metadata_update_params, "goodkey:goodvalue", "badkey_:goodvalue")}.to raise_error(NexusCli::N3ParameterMalformedException)
84
+ end
85
+
86
+ it "gives you errors when you attempt to parse custom metadata with missing update keys" do
87
+ expect {remote.send(:parse_custom_metadata_update_params, ":goodvalue")}.to raise_error(NexusCli::N3ParameterMalformedException)
88
+ end
89
+
90
+ it "gives you errors when you attempt to parse custom metadata with typo" do
91
+ expect {remote.send(:parse_custom_metadata_update_params, "goodkeygoodvalue")}.to raise_error(NexusCli::N3ParameterMalformedException)
92
+ end
93
+
94
+ it "gives you errors when you attempt to parse custom metadata with bad update values" do
95
+ expect {remote.send(:parse_custom_metadata_update_params, "goodkey:goodvalue", "goodkey:badvalue\"'\\")}.to raise_error(NexusCli::N3ParameterMalformedException)
96
+ end
97
+
98
+ it "gives you errors when you attempt to parse custom metadata with missing search type and value" do
99
+ expect {remote.send(:parse_custom_metadata_search_params, "goodkey")}.to raise_error(NexusCli::SearchParameterMalformedException)
100
+ end
101
+
102
+ it "gives you errors when you attempt to parse custom metadata with bad search type" do
103
+ expect {remote.send(:parse_custom_metadata_search_params, "goodkey:eq:goodvalue")}.to raise_error(NexusCli::SearchParameterMalformedException)
104
+ end
105
+
106
+ it "gives you errors when you attempt to parse custom metadata with bad search value" do
107
+ expect {remote.send(:parse_custom_metadata_search_params, "goodkey:equals:badvalue\"'\\")}.to raise_error(NexusCli::SearchParameterMalformedException)
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe NexusCli::RemoteFactory do
4
+ subject { remote_factory }
5
+ let(:remote_factory) { described_class }
6
+
7
+ describe "::create" do
8
+ subject { create }
9
+ let(:create) { remote_factory.create(overrides) }
10
+
11
+ before do
12
+ NexusCli::Connection.stub(:new)
13
+ remote_factory.stub(:running_nexus_pro?).and_return(false)
14
+ NexusCli::OSSRemote.stub(:new)
15
+ end
16
+
17
+ context "when overrides are passed in" do
18
+ let(:overrides) {
19
+ {
20
+ "url" => "http://somewebsite.com",
21
+ "repository" => "foo",
22
+ "username" => "admin",
23
+ "password" => "password"
24
+ }
25
+ }
26
+
27
+ it "loads configuration from the overrides" do
28
+ NexusCli::Configuration.should_receive(:from_overrides).with(overrides)
29
+ create
30
+ end
31
+ end
32
+
33
+ context "when no overrides are passed in" do
34
+ let(:overrides) { nil }
35
+
36
+ it "loads configuration from the config file" do
37
+ NexusCli::Configuration.should_receive(:from_file)
38
+ create
39
+ end
40
+ end
41
+ end
42
+ end