nexus_cli 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -5,4 +5,5 @@
5
5
  Gemfile.lock
6
6
  tmp/
7
7
  pkg/
8
- *.gem
8
+ *.gem
9
+ global_settings.json
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
@@ -2,4 +2,9 @@
2
2
  $:.push File.expand_path("../../lib", __FILE__)
3
3
  require 'nexus_cli'
4
4
 
5
- NexusCli::Cli.start
5
+ begin
6
+ NexusCli::Cli.start
7
+ rescue NexusCli::NexusCliError => e
8
+ NexusCli.ui.say e.message, :red
9
+ exit e.status_code
10
+ end
@@ -0,0 +1,102 @@
1
+ Feature: Use the Nexus CLI
2
+ As a CLI user
3
+ I need commands to get Nexus status, push, pull
4
+
5
+ Scenario: Get Nexus Status
6
+ When I call the nexus "status" command
7
+ Then the output should contain:
8
+ """
9
+ Application Name: Sonatype Nexus
10
+ """
11
+ And the exit status should be 0
12
+
13
+ @push
14
+ Scenario: Push an Artifact
15
+ When I push an artifact with the GAV of "com.test:mytest:1.0.0:tgz"
16
+ Then the output should contain:
17
+ """
18
+ Artifact com.test:mytest:1.0.0:tgz has been successfully pushed to Nexus.
19
+ """
20
+ And the exit status should be 0
21
+
22
+ Scenario: Pull an artifact
23
+ When I call the nexus "pull com.test:mytest:1.0.0:tgz" command
24
+ Then the output should contain:
25
+ """
26
+ Artifact has been retrived and can be found at path:
27
+ """
28
+ And the exit status should be 0
29
+
30
+ Scenario: Pull the LATEST of an artifact
31
+ When I pull an artifact with the GAV of "com.test:mytest:latest:tgz" to a temp directory
32
+ Then I should have a copy of the "mytest-1.0.0.tgz" artifact in a temp directory
33
+ And the exit status should be 0
34
+
35
+ Scenario: Pull an artifact to a specific place
36
+ When I pull an artifact with the GAV of "com.test:mytest:1.0.0:tgz" to a temp directory
37
+ Then I should have a copy of the "mytest-1.0.0.tgz" artifact in a temp directory
38
+ And the exit status should be 0
39
+
40
+ Scenario: Get an artifact's info
41
+ When I call the nexus "info com.test:mytest:1.0.0:tgz" command
42
+ Then the output should contain:
43
+ """
44
+ <groupId>com.test</groupId>
45
+ """
46
+ And the exit status should be 0
47
+
48
+ Scenario: Search for artifacts
49
+ When I call the nexus "search_for_artifacts com.test:mytest" command
50
+ Then the output should contain:
51
+ """
52
+ Found Versions:
53
+ 1.0.0: `nexus-cli pull com.test:mytest:1.0.0:tgz`
54
+ """
55
+ And the exit status should be 0
56
+
57
+ @delete
58
+ Scenario: Attempt to delete an artifact
59
+ When I delete an artifact with the GAV of "com.test:mytest:1.0.0:tgz"
60
+ And I call the nexus "info com.test:mytest:1.0.0:tgz" command
61
+ Then the output should contain:
62
+ """
63
+ The artifact you requested information for could not be found. Please ensure it exists inside the Nexus.
64
+ """
65
+ And the exit status should be 101
66
+
67
+ Scenario: Get the current global settings of Nexus
68
+ When I call the nexus "get_global_settings" command
69
+ Then the output should contain:
70
+ """
71
+ Your current Nexus global settings have been written to the file: global_settings.json
72
+ """
73
+ And a file named "global_settings.json" should exist
74
+ And the exit status should be 0
75
+
76
+ Scenario: Update the global settings of Nexus
77
+ When I call the nexus "get_global_settings" command
78
+ And I edit the "global_settings.json" files "forceBaseUrl" field to true
79
+ And I call the nexus "upload_global_settings" command
80
+ Then the output should contain:
81
+ """
82
+ Your global_settings.json file has been uploaded to Nexus
83
+ """
84
+ When I call the nexus "get_global_settings" command
85
+ Then the file "global_settings.json" should contain:
86
+ """
87
+ "forceBaseUrl": true
88
+ """
89
+ And the exit status should be 0
90
+
91
+ Scenario: Reset the global settings of Nexus
92
+ When I call the nexus "reset_global_settings" command
93
+ Then the output should contain:
94
+ """
95
+ Your Nexus global settings have been reset to their default values
96
+ """
97
+ When I call the nexus "get_global_settings" command
98
+ Then the file "global_settings.json" should contain:
99
+ """
100
+ "forceBaseUrl": false
101
+ """
102
+ And the exit status should be 0
@@ -1,8 +1,9 @@
1
1
  require 'aruba/api'
2
+ require 'json'
2
3
  World(Aruba::Api)
3
4
 
4
5
  When /^I call the nexus "(.*?)" command$/ do |command|
5
- step "I run `nexus-cli #{command} --overrides=#{get_overrides}`"
6
+ step "I run `nexus-cli #{command} --overrides=#{get_overrides_string}`"
6
7
  end
7
8
 
8
9
  When /^I push an artifact with the GAV of "(.*)"$/ do |gav|
@@ -10,11 +11,11 @@ When /^I push an artifact with the GAV of "(.*)"$/ do |gav|
10
11
  file = File.new(File.join(temp_dir, "#{artifactId}-#{version}.#{extension}"), 'w')
11
12
  file.puts "some data"
12
13
  file.close
13
- step "I run `nexus-cli push #{gav} #{file.path}`"
14
+ step "I run `nexus-cli push #{gav} #{file.path} --overrides=#{get_overrides_string}`"
14
15
  end
15
16
 
16
17
  When /^I pull an artifact with the GAV of "(.*?)" to a temp directory$/ do |gav|
17
- step "I run `nexus-cli pull #{gav} --destination #{temp_dir}`"
18
+ step "I run `nexus-cli pull #{gav} --destination #{temp_dir} --overrides=#{get_overrides_string}`"
18
19
  end
19
20
 
20
21
  Then /^I should have a copy of the "(.*?)" artifact in a temp directory$/ do |fileName|
@@ -23,4 +24,18 @@ end
23
24
 
24
25
  When /^I delete an artifact with the GAV of "(.*)"$/ do |gav|
25
26
  nexus_remote.delete_artifact(gav)
26
- end
27
+ end
28
+
29
+ When /^I edit the "(.*?)" files "(.*?)" field to true$/ do |file, field|
30
+ Dir.chdir('tmp/aruba') do
31
+ json = JSON.parse(File.read(File.join(File.expand_path("."), file)))
32
+ File.open(File.join(File.expand_path("."), file), "w+") do |opened|
33
+ json["data"]["globalRestApiSettings"][field] = true
34
+ opened.write(JSON.pretty_generate(json))
35
+ end
36
+ end
37
+ end
38
+
39
+ Then /^the file "([^"]*)" should contain:$/ do |file, partial_content|
40
+ check_file_content(file, partial_content, true)
41
+ end
@@ -3,8 +3,28 @@ $:.push "#{File.dirname(__FILE__)}/../../lib/"
3
3
  require 'nexus_cli'
4
4
  require 'rspec'
5
5
 
6
+ module ArubaOverrides
7
+ def detect_ruby(cmd)
8
+ processor, platform, *rest = RUBY_PLATFORM.split("-")
9
+ if platform =~ /w32$/ && cmd =~ /^nexus-cli /
10
+ "ruby -I../../lib -S ../../bin/#{cmd}"
11
+ else
12
+ "#{cmd}"
13
+ end
14
+ end
15
+ end
16
+
17
+ World(ArubaOverrides)
18
+
19
+ Before do
20
+ @aruba_timeout_seconds = 5
21
+ end
22
+ def get_overrides_string
23
+ @overrides_string ||= "url:http://localhost:8081/nexus repository:releases username:admin password:admin123"
24
+ end
25
+
6
26
  def get_overrides
7
- @overrides ||= {:url => 'http://localhost:8081/nexus', :repository => 'releases', :username => 'deployment', :password => 'deployment123'}
27
+ @overrides ||= {'url' => 'http://localhost:8081/nexus', 'repository' => 'releases', 'username' => 'deployment', 'password' => 'deployment123'}
8
28
  end
9
29
 
10
30
  def temp_dir
@@ -5,11 +5,16 @@ require 'nexus_cli/kernel'
5
5
  require 'nexus_cli/nexus_remote_factory'
6
6
  require 'nexus_cli/nexus_oss_remote'
7
7
  require 'nexus_cli/nexus_pro_remote'
8
+ require 'nexus_cli/configuration'
8
9
 
9
10
  module NexusCli
10
11
  class << self
11
12
  def root
12
13
  @root ||= Pathname.new(File.expand_path('../', File.dirname(__FILE__)))
13
14
  end
15
+
16
+ def ui
17
+ @ui ||= Thor::Shell::Color.new
18
+ end
14
19
  end
15
20
  end
@@ -0,0 +1,24 @@
1
+ require 'extlib'
2
+
3
+ module NexusCli
4
+ module Configuration
5
+ class << self
6
+ def parse(overrides)
7
+ config_path = File.expand_path("~/.nexus_cli")
8
+ config = File.exists?(config_path) ? YAML::load_file(config_path) : Hash.new
9
+ if config.nil? && (overrides.nil? || overrides.empty?)
10
+ raise MissingSettingsFileException
11
+ end
12
+ overrides.each{|key, value| config[key] = value} unless overrides.nil? || overrides.empty?
13
+ validate_config(config)
14
+ config
15
+ end
16
+
17
+ def validate_config(configuration)
18
+ ["url", "repository", "username","password"].each do |key|
19
+ raise InvalidSettingsException.new(key) if configuration[key].blank?
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,5 @@
1
+ require 'json'
2
+
1
3
  module NexusCli
2
4
  class NexusCliError < StandardError
3
5
  class << self
@@ -90,4 +92,17 @@ This could mean several things:
90
92
  end
91
93
  status_code(110)
92
94
  end
95
+
96
+ class BadSettingsException < NexusCliError
97
+ def initialize(body)
98
+ @server_response = JSON.pretty_generate(JSON.parse(body))
99
+ end
100
+
101
+ def message
102
+ %{Your global_settings.json file is malformed and could not be uploaded to Nexus.
103
+ The output from the server was:
104
+ #{@server_response}}
105
+ end
106
+ status_code(111)
107
+ end
93
108
  end
@@ -1,12 +1,13 @@
1
1
  require 'restclient'
2
2
  require 'nokogiri'
3
3
  require 'yaml'
4
+ require 'json'
4
5
 
5
6
  module NexusCli
6
7
  class OSSRemote
7
8
 
8
9
  def initialize(overrides)
9
- @configuration = parse_configuration(overrides)
10
+ @configuration = Configuration::parse(overrides)
10
11
  end
11
12
 
12
13
  def configuration
@@ -14,7 +15,7 @@ module NexusCli
14
15
  end
15
16
 
16
17
  def nexus
17
- @nexus ||= RestClient::Resource.new configuration["url"], :user => configuration["username"], :password => configuration["password"]
18
+ @nexus ||= RestClient::Resource.new configuration["url"], :user => configuration["username"], :password => configuration["password"], :timeout => 1000000, :open_timeout => 1000000
18
19
  end
19
20
 
20
21
  def status
@@ -36,18 +37,21 @@ module NexusCli
36
37
  rescue RestClient::ResourceNotFound
37
38
  raise ArtifactNotFoundException
38
39
  end
39
- artifact = nil
40
+ if version.casecmp("latest")
41
+ doc = Nokogiri::XML(get_artifact_info(artifact))
42
+ version = doc.xpath("//version").first.content()
43
+ end
40
44
  destination = File.join(File.expand_path(destination || "."), "#{artifact_id}-#{version}.#{extension}")
41
- artifact = File.open(destination, 'w')
42
- artifact.write(fileData)
43
- artifact.close()
44
- File.expand_path(artifact.path)
45
+ artifact_file = File.open(destination, 'wb')
46
+ artifact_file.write(fileData)
47
+ artifact_file.close()
48
+ File.expand_path(artifact_file.path)
45
49
  end
46
50
 
47
51
  def push_artifact(artifact, file)
48
52
  group_id, artifact_id, version, extension = parse_artifact_string(artifact)
49
53
  nexus['service/local/artifact/maven/content'].post({:hasPom => false, :g => group_id, :a => artifact_id, :v => version, :e => extension, :p => extension, :r => configuration['repository'],
50
- :file => File.new(file)}) do |response, request, result, &block|
54
+ :file => File.new(file)}) do |response|
51
55
  case response.code
52
56
  when 400
53
57
  raise BadUploadRequestException
@@ -78,32 +82,58 @@ module NexusCli
78
82
  end
79
83
  end
80
84
 
81
- private
82
- def parse_artifact_string(artifact)
83
- split_artifact = artifact.split(":")
84
- if(split_artifact.size < 4)
85
- raise ArtifactMalformedException
86
- end
87
- return split_artifact
85
+ def search_for_artifacts(artifact)
86
+ group_id, artifact_id = artifact.split(":")
87
+ nexus['service/local/data_index'].get({:params => {:g => group_id, :a => artifact_id}}) do |response|
88
+ doc = Nokogiri::XML(response.body)
89
+ return format_search_results(doc, group_id, artifact_id)
88
90
  end
89
-
90
- def parse_configuration(overrides)
91
- begin
92
- config = YAML::load_file(File.expand_path("~/.nexus_cli"))
93
- rescue
94
- end
95
- if config.nil? && (overrides.nil? || overrides.empty?)
96
- raise MissingSettingsFileException
91
+ end
92
+
93
+ def get_global_settings
94
+ nexus['service/local/global_settings/current'].get({:accept => "application/json"}) do |response|
95
+ pretty_json = JSON.pretty_generate(JSON.parse(response.body))
96
+ destination = File.join(File.expand_path("."), "global_settings.json")
97
+ artifact_file = File.open(destination, 'wb') do |file|
98
+ file.write(pretty_json)
97
99
  end
98
- overrides.each{|key, value| config[key] = value} unless overrides.nil? || overrides.empty?
99
- validate_config(config)
100
- config
101
100
  end
102
-
103
- def validate_config(configuration)
104
- ["url", "repository", "username","password"].each do |key|
105
- raise InvalidSettingsException.new(key) unless configuration.has_key?(key)
101
+ end
102
+
103
+ def upload_global_settings
104
+ global_settings_file = File.join(File.expand_path("."), "global_settings.json")
105
+ nexus['service/local/global_settings/current'].put(File.read(global_settings_file), {:content_type => "application/json"}) do |response|
106
+ case response.code
107
+ when 400
108
+ raise BadSettingsException.new(response.body)
106
109
  end
107
110
  end
108
- end
109
- end
111
+ end
112
+
113
+ def reset_global_settings
114
+ default_json = nexus['service/local/global_settings/default'].get({:accept => "application/json"})
115
+ nexus['service/local/global_settings/current'].put(default_json, {:content_type => "application/json"})
116
+ end
117
+
118
+ private
119
+ def format_search_results(doc, group_id, artifact_id)
120
+ versions = doc.xpath("//version").inject([]) {|array,node| array << "#{node.content()}"}
121
+ indent_size = versions.max{|a,b| a.length <=> b.length}.size+4
122
+ formated_results = ['Found Versions:']
123
+ versions.inject(formated_results) do |array,version|
124
+ temp_version = version + ":"
125
+ array << "#{temp_version.ljust(indent_size)} `nexus-cli pull #{group_id}:#{artifact_id}:#{version}:tgz`"
126
+ end
127
+ end
128
+
129
+ def parse_artifact_string(artifact)
130
+ split_artifact = artifact.split(":")
131
+ if(split_artifact.size < 4)
132
+ raise ArtifactMalformedException
133
+ end
134
+ group_id, artifact_id, version, extension = split_artifact
135
+ version.upcase! if version.casecmp("latest")
136
+ return group_id, artifact_id, version, extension
137
+ end
138
+ end
139
+ end
@@ -21,7 +21,7 @@ module NexusCli
21
21
  end
22
22
  end
23
23
 
24
- def update_artifact_custom_info(artifact, file, insecure)
24
+ def update_artifact_custom_info(artifact, file)
25
25
  # Check if artifact exists before posting custom metadata.
26
26
  get_artifact_info(artifact)
27
27
  # Update the custom metadata using the n3 file.
@@ -7,7 +7,7 @@ module NexusCli
7
7
  class << self
8
8
 
9
9
  def create(overrides)
10
- @configuration = parse_configuration(overrides)
10
+ @configuration = Configuration::parse(overrides)
11
11
  running_nexus_pro? ? ProRemote.new(overrides) : OSSRemote.new(overrides)
12
12
  end
13
13
 
@@ -35,25 +35,6 @@ module NexusCli
35
35
  def running_nexus_pro?
36
36
  return status['edition_long'] == "Professional" ? true : false
37
37
  end
38
-
39
- def parse_configuration(overrides)
40
- begin
41
- config = YAML::load_file(File.expand_path("~/.nexus_cli"))
42
- rescue
43
- end
44
- if config.nil? && (overrides.nil? || overrides.empty?)
45
- raise MissingSettingsFileException
46
- end
47
- overrides.each{|key, value| config[key] = value} unless overrides.nil? || overrides.empty?
48
- validate_config(config)
49
- config
50
- end
51
-
52
- def validate_config(configuration)
53
- ["url", "repository", "username","password"].each do |key|
54
- raise InvalidSettingsException.new(key) unless configuration.has_key?(key)
55
- end
56
- end
57
38
  end
58
39
  end
59
40
  end
@@ -12,6 +12,7 @@ module NexusCli
12
12
  map 'custom' => :get_artifact_custom_info
13
13
  map 'config' => :get_nexus_configuration
14
14
  map 'status' => :get_nexus_status
15
+ map 'search' => :search_for_artifacts
15
16
 
16
17
  class_option :overrides,
17
18
  :type => :hash,
@@ -34,112 +35,86 @@ module NexusCli
34
35
  :desc => "A different folder other than the current working directory."
35
36
  desc "pull_artifact artifact", "Pulls an artifact from Nexus and places it on your machine."
36
37
  def pull_artifact(artifact)
37
- begin
38
- path_to_artifact = @nexus_remote.pull_artifact(artifact, options[:destination])
39
- say "Artifact has been retrived and can be found at path: #{path_to_artifact}", :green
40
- rescue NexusCliError => e
41
- say e.message, :red
42
- exit e.status_code
43
- end
38
+ path_to_artifact = @nexus_remote.pull_artifact(artifact, options[:destination])
39
+ say "Artifact has been retrived and can be found at path: #{path_to_artifact}", :green
44
40
  end
45
41
 
46
42
  desc "push_artifact artifact file", "Pushes an artifact from your machine onto the Nexus."
47
43
  def push_artifact(artifact, file)
48
- begin
49
- @nexus_remote.push_artifact(artifact, file)
50
- say "Artifact #{artifact} has been successfully pushed to Nexus.", :green
51
- rescue NexusCliError => e
52
- say e.message, :red
53
- exit e.status_code
54
- end
44
+ @nexus_remote.push_artifact(artifact, file)
45
+ say "Artifact #{artifact} has been successfully pushed to Nexus.", :green
55
46
  end
56
47
 
57
48
  desc "get_artifact_info artifact", "Gets and returns the metadata in XML format about a particular artifact."
58
49
  def get_artifact_info(artifact)
59
- begin
60
- say @nexus_remote.get_artifact_info(artifact), :green
61
- rescue NexusCliError => e
62
- say e.message, :red
63
- exit e.status_code
64
- end
50
+ say @nexus_remote.get_artifact_info(artifact), :green
51
+ end
52
+
53
+ desc "search_for_artifacts", "Prints out some information about some junk."
54
+ def search_for_artifacts(artifact)
55
+ @nexus_remote.search_for_artifacts(artifact).each{|output| say output, :green}
65
56
  end
66
57
 
67
58
  desc "get_artifact_custom_info artifact", "Gets and returns the custom metadata in XML format about a particular artifact."
68
59
  def get_artifact_custom_info(artifact)
69
- begin
70
- say @nexus_remote.get_artifact_custom_info(artifact), :green
71
- rescue NexusCliError => e
72
- say e.message, :red
73
- exit e.status_code
74
- end
60
+ say @nexus_remote.get_artifact_custom_info(artifact), :green
75
61
  end
76
62
 
77
63
  desc "get_artifact_custom_info_n3 artifact", "Gets and returns the custom metadata in Nexus n3 format about a particular artifact."
78
- def get_artifact_custom_info_n3(artifact)
79
- begin
80
- raise NotNexusProException unless @nexus_remote.kind_of? ProRemote
81
- say @nexus_remote.get_artifact_custom_info_n3(artifact), :green
82
- rescue NexusCliError => e
83
- say e.message, :red
84
- exit e.status_code
85
- end
64
+ def get_artifact_custom_info_n3(artifact)
65
+ raise NotNexusProException unless @nexus_remote.kind_of? ProRemote
66
+ say @nexus_remote.get_artifact_custom_info_n3(artifact), :green
86
67
  end
87
68
 
88
- method_option :insecure,
89
- :type => :boolean,
90
- :default => false,
91
- :desc => "Overrides any failures because of an 'insecure' SSL connection."
92
69
  desc "update_artifact_custom_info artifact file", "Updates the artifact custom metadata by pushing the Nexus custom artifact file (n3) from your machine onto the Nexus."
93
70
  def update_artifact_custom_info(artifact, file)
94
- begin
95
- raise NotNexusProException unless @nexus_remote.kind_of? ProRemote
96
- @nexus_remote.update_artifact_custom_info(artifact, file, options[:insecure])
97
- say "Custom metadata for artifact #{artifact} has been successfully pushed to Nexus.", :green
98
- rescue NexusCliError => e
99
- say e.message, :red
100
- exit e.status_code
101
- end
71
+ raise NotNexusProException unless @nexus_remote.kind_of? ProRemote
72
+ @nexus_remote.update_artifact_custom_info(artifact, file)
73
+ say "Custom metadata for artifact #{artifact} has been successfully pushed to Nexus.", :green
102
74
  end
103
75
 
104
76
  desc "search_artifacts key type value", "Searches for artifacts using artifact metadata and returns the result as a list with items in XML format."
105
77
  def search_artifacts(key, type, value)
106
- begin
107
- raise NotNexusProException unless @nexus_remote.kind_of? ProRemote
108
- say @nexus_remote.search_artifacts(key, type, value), :green
109
- rescue NexusCliError => e
110
- say e.message, :red
111
- exit e.status_code
112
- end
78
+ raise NotNexusProException unless @nexus_remote.kind_of? ProRemote
79
+ say @nexus_remote.search_artifacts(key, type, value), :green
113
80
  end
114
81
 
115
82
  desc "get_nexus_configuration", "Prints out configuration from the .nexus_cli file that helps inform where artifacts will be uploaded."
116
83
  def get_nexus_configuration
117
- begin
118
- config = @nexus_remote.configuration
119
- say "********* Reading CLI configuration from #{File.expand_path('~/.nexus_cli')} *********", :blue
120
- say "Nexus URL: #{config['url']}", :blue
121
- say "Nexus Repository: #{config['repository']}", :blue
122
- rescue NexusCliError => e
123
- say e.message, :red
124
- exit e.status_code
125
- end
84
+ config = @nexus_remote.configuration
85
+ say "********* Reading CLI configuration from #{File.expand_path('~/.nexus_cli')} *********", :blue
86
+ say "Nexus URL: #{config['url']}", :blue
87
+ say "Nexus Repository: #{config['repository']}", :blue
126
88
  end
127
89
 
128
90
  desc "get_nexus_status", "Prints out information about the Nexus instance."
129
91
  def get_nexus_status
130
- begin
131
- data = @nexus_remote.status
132
- say "********* Getting Nexus status from #{data['base_url']} *********", :blue
133
- say "Application Name: #{data['app_name']}", :blue
134
- say "Version: #{data['version']}", :blue
135
- say "Edition: #{data['edition_long']}", :blue
136
- say "State: #{data['state']}", :blue
137
- say "Started At: #{data['started_at']}", :blue
138
- say "Base URL: #{data['base_url']}", :blue
139
- rescue NexusCliError => e
140
- say e.message, :red
141
- exit e.status_code
142
- end
92
+ data = @nexus_remote.status
93
+ say "********* Getting Nexus status from #{data['base_url']} *********", :blue
94
+ say "Application Name: #{data['app_name']}", :blue
95
+ say "Version: #{data['version']}", :blue
96
+ say "Edition: #{data['edition_long']}", :blue
97
+ say "State: #{data['state']}", :blue
98
+ say "Started At: #{data['started_at']}", :blue
99
+ say "Base URL: #{data['base_url']}", :blue
100
+ end
101
+
102
+ desc "get_global_settings", "Prints out your Nexus' current setttings and saves them to a file."
103
+ def get_global_settings
104
+ @nexus_remote.get_global_settings
105
+ say "Your current Nexus global settings have been written to the file: global_settings.json", :blue
106
+ end
107
+
108
+ desc "upload_global_settings", "Uploads a global_settings.json file to your Nexus to update its settings."
109
+ def upload_global_settings
110
+ @nexus_remote.upload_global_settings
111
+ say "Your global_settings.json file has been uploaded to Nexus", :blue
112
+ end
113
+
114
+ desc "reset_global_settings", "Resets your Nexus global_settings to their out-of-the-box defaults."
115
+ def reset_global_settings
116
+ @nexus_remote.reset_global_settings
117
+ say "Your Nexus global settings have been reset to their default values", :blue
143
118
  end
144
119
  end
145
120
  end
@@ -19,6 +19,8 @@ Gem::Specification.new do |s|
19
19
  s.add_dependency 'thor'
20
20
  s.add_dependency 'rest-client'
21
21
  s.add_dependency 'nokogiri'
22
+ s.add_dependency 'extlib'
23
+ s.add_dependency 'json'
22
24
 
23
25
  s.add_development_dependency 'rspec'
24
26
  s.add_development_dependency 'aruba'
@@ -0,0 +1,23 @@
1
+ require 'nexus_cli'
2
+
3
+ describe NexusCli do
4
+ it "gives you errors when configuration has a blank password" do
5
+ overrides = {"url" => "http://somewebsite.com", "username" => "admin", "password" => ""}
6
+ expect {NexusCli::Configuration.parse(overrides)}.to raise_error(NexusCli::InvalidSettingsException)
7
+ end
8
+
9
+ it "gives you errors when configuration has a blank username" do
10
+ overrides = {"url" => "http://somewebsite.com", "username" => "", "password" => "admin"}
11
+ expect {NexusCli::Configuration.parse(overrides)}.to raise_error(NexusCli::InvalidSettingsException)
12
+ end
13
+
14
+ it "gives you errors when configuration has a blank url" do
15
+ overrides = {"url" => "", "username" => "admin", "password" => "admin"}
16
+ expect {NexusCli::Configuration.parse(overrides)}.to raise_error(NexusCli::InvalidSettingsException)
17
+ end
18
+
19
+ it "gives you errors when configuration has a blank repository" do
20
+ overrides = {"url" => "http://somewebsite.com", "repository" => ""}
21
+ expect {NexusCli::Configuration.parse(overrides)}.to raise_error(NexusCli::InvalidSettingsException)
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ require 'nexus_cli'
2
+
3
+ remote = NexusCli::OSSRemote.new(nil)
4
+
5
+ describe NexusCli do
6
+ it "gives you errors when you attempt to pull an artifact don't give a valid artifact name" do
7
+ expect {remote.pull_artifact "com.something:something:1.0.0", nil}.to raise_error(NexusCli::ArtifactMalformedException)
8
+ end
9
+
10
+ it "gives you errors when you attempt to get an artifact's info and don't give a valid artifact name" do
11
+ expect {remote.get_artifact_info "com.something:something:1.0.0"}.to raise_error(NexusCli::ArtifactMalformedException)
12
+ end
13
+
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)
16
+ expect {remote.pull_artifact "com.something:something:1.0.0:tgz", nil}.to raise_error(NexusCli::ArtifactNotFoundException)
17
+ end
18
+
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)
21
+ expect {remote.get_artifact_info "com.something:something:1.0.0:tgz"}.to raise_error(NexusCli::ArtifactNotFoundException)
22
+ end
23
+ 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.3.0
4
+ version: 0.4.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-07-28 00:00:00.000000000 Z
12
+ date: 2012-08-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -59,6 +59,38 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: extlib
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: json
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
62
94
  - !ruby/object:Gem::Dependency
63
95
  name: rspec
64
96
  requirement: !ruby/object:Gem::Requirement
@@ -138,11 +170,12 @@ files:
138
170
  - Rakefile
139
171
  - VERSION
140
172
  - bin/nexus-cli
141
- - features/cli/nexus_oss.feature
173
+ - features/nexus_oss.feature
142
174
  - features/step_definitions/cli_steps.rb
143
175
  - features/support/env.rb
144
176
  - lib/nexus_cli.rb
145
177
  - lib/nexus_cli/cli.rb
178
+ - lib/nexus_cli/configuration.rb
146
179
  - lib/nexus_cli/errors.rb
147
180
  - lib/nexus_cli/kernel.rb
148
181
  - lib/nexus_cli/nexus_oss_remote.rb
@@ -151,7 +184,8 @@ files:
151
184
  - lib/nexus_cli/tasks.rb
152
185
  - lib/nexus_cli/version.rb
153
186
  - nexus_cli.gemspec
154
- - spec/remote_spec.rb
187
+ - spec/configuration_spec.rb
188
+ - spec/oss_remote_spec.rb
155
189
  homepage: https://github.com/RiotGames/nexus_cli
156
190
  licenses: []
157
191
  post_install_message:
@@ -166,7 +200,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
166
200
  version: '0'
167
201
  segments:
168
202
  - 0
169
- hash: 3325532431441857534
203
+ hash: -589331205850929008
170
204
  required_rubygems_version: !ruby/object:Gem::Requirement
171
205
  none: false
172
206
  requirements:
@@ -175,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
209
  version: '0'
176
210
  segments:
177
211
  - 0
178
- hash: 3325532431441857534
212
+ hash: -589331205850929008
179
213
  requirements: []
180
214
  rubyforge_project:
181
215
  rubygems_version: 1.8.21
@@ -183,7 +217,8 @@ signing_key:
183
217
  specification_version: 3
184
218
  summary: A command-line wrapper for making REST calls to Sonatype Nexus.
185
219
  test_files:
186
- - features/cli/nexus_oss.feature
220
+ - features/nexus_oss.feature
187
221
  - features/step_definitions/cli_steps.rb
188
222
  - features/support/env.rb
189
- - spec/remote_spec.rb
223
+ - spec/configuration_spec.rb
224
+ - spec/oss_remote_spec.rb
@@ -1,49 +0,0 @@
1
- Feature: Use the Nexus CLI
2
- As a CLI user
3
- I need commands to get Nexus status, push, pull
4
-
5
- Scenario: Get Nexus Status
6
- When I call the nexus "status" command
7
- Then the output should contain:
8
- """
9
- Application Name: Sonatype Nexus
10
- Version: 2.0.5
11
- """
12
- And the exit status should be 0
13
-
14
- Scenario: Push an Artifact
15
- When I push an artifact with the GAV of "com.test:mytest:1.0.0:tgz"
16
- Then the output should contain:
17
- """
18
- Artifact com.test:mytest:1.0.0:tgz has been successfully pushed to Nexus.
19
- """
20
- And the exit status should be 0
21
-
22
- Scenario: Pull an artifact
23
- When I call the nexus "pull com.test:mytest:1.0.0:tgz" command
24
- Then the output should contain:
25
- """
26
- Artifact has been retrived and can be found at path:
27
- """
28
- And the exit status should be 0
29
-
30
- Scenario: Pull an artifact to a specific place
31
- When I pull an artifact with the GAV of "com.test:mytest:1.0.0:tgz" to a temp directory
32
- Then I should have a copy of the "mytest-1.0.0.tgz" artifact in a temp directory
33
-
34
- Scenario: Get an artifact's info
35
- When I call the nexus "info com.test:mytest:1.0.0:tgz" command
36
- Then the output should contain:
37
- """
38
- <groupId>com.test</groupId>
39
- """
40
- And the exit status should be 0
41
-
42
- Scenario: Attempt to delete an artifact
43
- When I delete an artifact with the GAV of "com.test:mytest:1.0.0:tgz"
44
- And I call the nexus "info com.test:mytest:1.0.0:tgz" command
45
- Then the output should contain:
46
- """
47
- The artifact you requested information for could not be found. Please ensure it exists inside the Nexus.
48
- """
49
- And the exit status should be 101
@@ -1,43 +0,0 @@
1
- require 'nexus_cli'
2
- require 'restclient'
3
-
4
- describe NexusCli do
5
- it "gives you errors when configuration is missing a password" do
6
- expect {NexusCli::Remote.configuration = {url: "http://somewebsite.com", username: "admin"}}.to raise_error(NexusCli::InvalidSettingsException)
7
- end
8
-
9
- it "gives you errors when configuration is missing a username" do
10
- expect {NexusCli::Remote.configuration = {url: "http://somewebsite.com", password: "admin"}}.to raise_error(NexusCli::InvalidSettingsException)
11
- end
12
-
13
- it "gives you errors when you attempt to pull an artifact don't give a valid artifact name" do
14
- expect {NexusCli::Remote.pull_artifact "com.something:something:1.0.0", nil}.to raise_error(NexusCli::ArtifactMalformedException)
15
- end
16
-
17
- it "gives you errors when you attempt to push an artifact don't give a valid artifact name" do
18
- expect {NexusCli::Remote.push_artifact "com.something:something:1.0.0", nil}.to raise_error(NexusCli::ArtifactMalformedException)
19
- end
20
-
21
- it "gives you errors when you attempt to get an artifact's info and don't give a valid artifact name" do
22
- expect {NexusCli::Remote.get_artifact_info "com.something:something:1.0.0"}.to raise_error(NexusCli::ArtifactMalformedException)
23
- end
24
-
25
- it "gives you errors when you attempt to delete an artifact and don't give a valid artifact name" do
26
- expect {NexusCli::Remote.get_artifact_info "com.something:something:1.0.0"}.to raise_error(NexusCli::ArtifactMalformedException)
27
- end
28
-
29
- it "gives you errors when you attempt to pull an artifact and it cannot be found" do
30
- RestClient::Resource.any_instance.stub(:get).and_raise(RestClient::ResourceNotFound)
31
- expect {NexusCli::Remote.pull_artifact "com.something:something:1.0.0:tgz", nil}.to raise_error(NexusCli::ArtifactNotFoundException)
32
- end
33
-
34
- it "gives you errors when you attempt to get an artifact's info and it cannot be found" do
35
- RestClient::Resource.any_instance.stub(:get).and_raise(RestClient::ResourceNotFound)
36
- expect {NexusCli::Remote.get_artifact_info "com.something:something:1.0.0:tgz"}.to raise_error(NexusCli::ArtifactNotFoundException)
37
- end
38
-
39
- it "gives you errors when you attempt to get an artifact's custom info and it cannot be found" do
40
- RestClient::Resource.any_instance.stub(:get).and_raise(RestClient::ResourceNotFound)
41
- expect {NexusCli::Remote.get_artifact_custom_info "com.something:something:1.0.0:tgz"}.to raise_error(NexusCli::ArtifactNotFoundException)
42
- end
43
- end