nexus 1.2.3 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3bebf90c036e91a7bf8f68ab2bf40e1ed2979ecd
4
- data.tar.gz: 5c42f749fe16cf437c4c292da178d6c2d58ece12
3
+ metadata.gz: c390f45bd0c31e68df98712adf0b1fdde32c2fe8
4
+ data.tar.gz: 9dc8685041e8fcd7ae302321015676e45d3db73a
5
5
  SHA512:
6
- metadata.gz: e64101606a5ea82066c58f3c526d4dd8ac6a8390a3a289e12c90454b8ebab665db7c42acedc4af484e198be90fdeacc07b9cda4218d3d245b55dd9282bbbaf1d
7
- data.tar.gz: 0302bbdd6654fe2203ceff3ff3dba0e5085588fc66cc3a165d42cd0ea5229bd9414d322e840c4c16e4040a2fdff4b61dbedbd9c8284a69c7d4b4386843d60c38
6
+ metadata.gz: 6726114873b1ea9aa57c74bc9a4391ed8e5f077fe50ce21334f1cb35589712c23a1eb727940e3415d7a9aecb5a6dae44487f97fe4c35a7ab247e1f06856357a3
7
+ data.tar.gz: e768d7cec487c0176392bc4e4c537b759ee93fe0d744ccebaec92a9f570c96f0b846f3c4d82b7d6f7bead46b91d284b931309e0340f11701f7c7322bec4987bb
@@ -23,6 +23,11 @@ class Gem::AbstractCommand < Gem::Command
23
23
  "File location of nexus config to use.\n default #{Nexus::Config.default_file}" ) do |value, options|
24
24
  options[ :nexus_config ] = File.expand_path( value )
25
25
  end
26
+
27
+ add_option( '--ignore-ssl-errors',
28
+ "No check certificate." ) do |value, options|
29
+ options[ :ssl_verify_mode ] = OpenSSL::SSL::VERIFY_NONE
30
+ end
26
31
  end
27
32
 
28
33
  def url
@@ -109,6 +114,8 @@ class Gem::AbstractCommand < Gem::Command
109
114
 
110
115
  if url.scheme == 'https'
111
116
  http.use_ssl = true
117
+ http.verify_mode =
118
+ options[ :ssl_verify_mode ] || config.ssl_verify_mode || OpenSSL::SSL::VERIFY_PEER
112
119
  end
113
120
 
114
121
  #Because sometimes our gems are huge and our people are on vpns
@@ -9,7 +9,7 @@ class Gem::Commands::NexusCommand < Gem::AbstractCommand
9
9
  end
10
10
 
11
11
  def usage
12
- "#{program_name} GEM"
12
+ "#{program_name} GEM [GEM [...]]"
13
13
  end
14
14
 
15
15
  def list_repos
@@ -55,17 +55,17 @@ class Gem::Commands::NexusCommand < Gem::AbstractCommand
55
55
  'encrypt/decrypt the credentials with a master password.' ) do |value, options|
56
56
  options[ :nexus_encrypt ] = value
57
57
  end
58
-
58
+
59
59
  end
60
60
 
61
61
  def execute
62
- name = get_one_gem_name rescue nil
63
- if( name && ( options[ :nexus_all_repos ] != nil ||
62
+ names = get_all_gem_names rescue nil
63
+ if( names && ( options[ :nexus_all_repos ] != nil ||
64
64
  options[ :nexus_clear_all ] != nil ||
65
65
  options[ :nexus_prompt_all ] != nil ||
66
66
  options[ :nexus_encrypt ] != nil ||
67
67
  options[ :nexus_secrets ] != nil ) )
68
- warn "given gemfile #{name} get ignored due to the options used"
68
+ warn "given gemfile(s) #{names.join(' ')} get ignored due to the options used"
69
69
  end
70
70
 
71
71
  if options[ :nexus_all_repos ]
@@ -99,26 +99,32 @@ class Gem::Commands::NexusCommand < Gem::AbstractCommand
99
99
  end
100
100
 
101
101
  def send_gem
102
- say "Uploading gem to Nexus..."
102
+ gems = get_all_gem_names
103
103
 
104
- path = get_one_gem_name
104
+ say "Uploading #{gems.size} gem#{'s' if gems.size != 1} to Nexus..."
105
105
 
106
- response = make_request(:put, "gems/#{File.basename(path)}") do |request|
107
- request.body = Gem.read_binary(path)
108
- request.add_field("Content-Length", request.body.size)
109
- request.add_field("Content-Type", "application/octet-stream")
110
- request.add_field("Authorization", authorization.strip) if authorization
111
- end
106
+ gems.each do |path|
107
+ response = make_request(:put, "gems/#{File.basename(path)}") do |request|
108
+ request.body = Gem.read_binary(path)
109
+ request.add_field("Content-Length", request.body.size)
110
+ request.add_field("Content-Type", "application/octet-stream")
111
+ request.add_field("Authorization", authorization.strip) if authorization
112
+ end
112
113
 
113
- case response.code
114
- when "401"
115
- say "Unauthorized"
116
- when "400"
117
- say "something went wrong - maybe (re)deployment is not allowed"
118
- when "500"
119
- say "something went wrong"
120
- else
121
- say response.message
114
+ case response.code
115
+ when "400"
116
+ say "something went wrong - maybe (re)deployment is not allowed"
117
+ when "401"
118
+ say "Unauthorized"
119
+ when "500"
120
+ say "something went wrong"
121
+ else
122
+ say "#{response.message} #{path.split(/\//).last}"
123
+ end
124
+
125
+ if !response.kind_of? Net::HTTPSuccess
126
+ exit 1
127
+ end
122
128
  end
123
129
  end
124
130
  end
data/lib/nexus/config.rb CHANGED
@@ -190,6 +190,10 @@ module Nexus
190
190
  @conf.store
191
191
  end
192
192
 
193
+ def ssl_verify_mode
194
+ @conf[ :ssl_verify_mode, @repo ]
195
+ end
196
+
193
197
  def to_s
194
198
  config.file
195
199
  end
data/lib/nexus/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nexus
2
- VERSION = '1.2.3'.freeze
2
+ VERSION = '1.3.0'.freeze
3
3
  end
@@ -222,5 +222,27 @@ class AbstractCommandTest < CommandTest
222
222
  assert_equal( @command.config.url, "http://url" )
223
223
  end
224
224
  end
225
+
226
+ context "SSL verification" do
227
+ setup do
228
+ @url = "https://url"
229
+ @connection = Net::HTTP.new("host", 443)
230
+ stub(@connection).request
231
+ stub(Net::HTTP).new { @connection }
232
+ @command.config.url = @url
233
+ end
234
+
235
+ should "disable SSL verification" do
236
+ stub(@command.config).ssl_verify_mode { OpenSSL::SSL::VERIFY_NONE }
237
+ stub(Gem.configuration).verbose { 0 }
238
+ @command.make_request(:put, "gems/gem")
239
+ assert_equal( @connection.verify_mode, OpenSSL::SSL::VERIFY_NONE )
240
+ end
241
+
242
+ should "verify SSL" do
243
+ @command.make_request(:put, "gems/gem")
244
+ assert_equal( @connection.verify_mode, OpenSSL::SSL::VERIFY_PEER )
245
+ end
246
+ end
225
247
  end
226
248
  end
@@ -47,7 +47,7 @@ class NexusCommandTest < CommandTest
47
47
  @command.options[ :nexus_encrypt ] = true
48
48
  mock(@command).ask( "Enter your Nexus encryption credentials (no prompt)" ) { 'behappy' }
49
49
  @command.execute
50
- assert_equal( File.read( @with + ".config" ),
50
+ assert_equal( File.read( @with + ".config" ),
51
51
  File.read( @from + ".config" ) )
52
52
  assert_equal( File.read( @with + ".secrets" ) != File.read( @from + ".secrets" ), true )
53
53
 
@@ -80,13 +80,13 @@ class NexusCommandTest < CommandTest
80
80
  config_path = File.join( 'pkg', 'encconfig_prompt')
81
81
  File.open( config_path, 'w') do |f|
82
82
  h = { :url => 'http://example.com',
83
- :authorization => 'something',
83
+ :authorization => 'something',
84
84
  :token => 'pe/ty1I5sl7qD5drdsSXOBi0peRYOqdhhvRXJBjzzNY=' }
85
85
  f.write h.to_yaml
86
86
  end
87
87
  stub(@command).options { {:nexus_config => config_path } }
88
88
  stub(@command).ask_for_password { "behappy" }
89
-
89
+
90
90
  @command.setup
91
91
  assert_equal @command.config.encrypted?, true
92
92
  end
@@ -109,7 +109,7 @@ class NexusCommandTest < CommandTest
109
109
  @command.options[ :nexus_encrypt ] = false
110
110
  mock(@command).ask( "Enter your Nexus encryption credentials (no prompt)" ) { 'behappy' }
111
111
  @command.execute
112
- assert_equal( File.read( @with + ".config" ),
112
+ assert_equal( File.read( @with + ".config" ),
113
113
  File.read( @from + ".config" ) )
114
114
  assert_equal( File.read( @with + ".secrets" ) != File.read( @from + ".secrets" ), true )
115
115
 
@@ -304,14 +304,13 @@ class NexusCommandTest < CommandTest
304
304
  obj
305
305
  end
306
306
  stub_request(:put, @url).to_return(:status => 201)
307
-
308
307
  @command.send_gem
309
308
  end
310
309
 
311
310
  should "say push was successful" do
312
- assert_received(@command) { |command| command.say("Uploading gem to Nexus...") }
311
+ assert_received(@command) { |command| command.say("Uploading 1 gem to Nexus...") }
313
312
  # due to webmock there is no status message
314
- assert_received(@command) { |command| command.say("") }
313
+ assert_received(@command) { |command| command.say(" foo-0.0.0.gem") }
315
314
  end
316
315
 
317
316
  should "put to api" do
@@ -321,10 +320,46 @@ class NexusCommandTest < CommandTest
321
320
  assert_requested(:put, @url,
322
321
  :body => @gem_binary,
323
322
  :headers => {
324
- 'Authorization' => 'key',
323
+ 'Authorization' => 'key',
325
324
  'Content-Type' => 'application/octet-stream'
326
325
  })
327
326
  end
327
+
328
+ context "non-successful push" do
329
+ should "say something went wrong - maybe (re)deployment is not allowed when receiving a 400 reponse" do
330
+ stub_request(:put, @url).to_return(:status => 400)
331
+ begin
332
+ @command.send_gem
333
+ rescue SystemExit => e
334
+ @exit_code = e.status
335
+ msg = "something went wrong - maybe (re)deployment is not allowed"
336
+ assert_received(@command) { |command| command.say(msg) }
337
+ assert_equal 1, @exit_code
338
+ end
339
+ end
340
+
341
+ should "say unauthorized when receiving a 401 response" do
342
+ stub_request(:put, @url).to_return(:status => 401)
343
+ begin
344
+ @command.send_gem
345
+ rescue SystemExit => e
346
+ @exit_code = e.status
347
+ assert_received(@command) { |command| command.say("Unauthorized") }
348
+ assert_equal 1, @exit_code
349
+ end
350
+ end
351
+
352
+ should "say something went wrong when receiving a 500 response" do
353
+ stub_request(:put, @url).to_return(:status => 500)
354
+ begin
355
+ @exit_code = @command.send_gem
356
+ rescue SystemExit => e
357
+ @exit_code = e.status
358
+ assert_received(@command) { |command| command.say("something went wrong") }
359
+ assert_equal 1, @exit_code
360
+ end
361
+ end
362
+ end
328
363
  end
329
364
  end
330
365
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Quaranto
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-08-15 00:00:00.000000000 Z
12
+ date: 2017-03-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -101,6 +101,20 @@ dependencies:
101
101
  - - "<"
102
102
  - !ruby/object:Gem::Version
103
103
  version: '1.16'
104
+ - !ruby/object:Gem::Dependency
105
+ name: addressable
106
+ requirement: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 2.4.0
111
+ type: :development
112
+ prerelease: false
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 2.4.0
104
118
  description: Adds a command to RubyGems for uploading gems to a nexus server.
105
119
  email:
106
120
  - nick@quaran.to
@@ -130,12 +144,24 @@ homepage: https://github.com/sonatype/nexus-gem
130
144
  licenses:
131
145
  - MIT-LICENSE
132
146
  metadata: {}
133
- post_install_message: "\n========================================================================\n\n
134
- \ Thanks for installing Nexus gem! You can now run:\n\n gem nexus publish
135
- your gems onto Nexus server\n\n nbundle a bundler fork with mirror
136
- support. for bundler before 1.5.0\n \nadd a mirror with:\n\n
137
- \ bundle config mirror.http://rubygems.org http://localhost:8081/nexus/content/repositories/rubygems.org\n\nfor
138
- bundler before 1.5.0 use 'nbundle' instead of 'bundle' to use the mirror\n\n========================================================================\n\n"
147
+ post_install_message: |2+
148
+
149
+ ========================================================================
150
+
151
+ Thanks for installing Nexus gem! You can now run:
152
+
153
+ gem nexus publish your gems onto Nexus server
154
+
155
+ nbundle a bundler fork with mirror support. for bundler before 1.5.0
156
+
157
+ add a mirror with:
158
+
159
+ bundle config mirror.http://rubygems.org http://localhost:8081/nexus/content/repositories/rubygems.org
160
+
161
+ for bundler before 1.5.0 use 'nbundle' instead of 'bundle' to use the mirror
162
+
163
+ ========================================================================
164
+
139
165
  rdoc_options: []
140
166
  require_paths:
141
167
  - lib