r10k 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTFjN2Q4ODIzMTI4MDAzZjc3MzI4MzA0ZDJlMzhmMDI0ODIyMDFiMQ==
4
+ MjNhZTM2NGM2Y2I5ZWVjMmM3NjZjMTkzZTY4ZjhkNWRmZjNiODA2Nw==
5
5
  data.tar.gz: !binary |-
6
- YWZhNDNlN2RmMmFhNjRhMTNlNTJmZGExZDdkMmVjYjA3YTRkY2ZjMw==
6
+ MzY0NGYyYTM3YzdlMDhjZWU2MDkyM2NiMmZlNmYyNzU1ZWZiMDc3ZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZGVjY2M1MDg2NTQ1NTRiZDViY2VmMTQxYTBjNDk4ZDM2NmNmY2YyODcyMWI0
10
- NjMzYzcwNzQ5NzhlMTEwY2ZlOTNkYjUzYThiNGNhY2NhMzAxNzk2MzA3M2E1
11
- YjYyMWJhZjJkMjZiZmIzOWI0MjVmZWE0MzI2M2ZkOGYxYWY3MmU=
9
+ YjUyYjMwOWJhOGY2MWI0OWFmYjUyYmY3OGE5NjI4MTE1YjMzMjUzZjgyOTY5
10
+ OGY3NTIxYWNhMWUyMWY5ZDEwZmM5MGI1NjFkZDJjZjRmYzU3NmZhZmVlNzM0
11
+ NTgzMjM0ZTM5NGY0OTJjNWJmOWQ1YjJhMTlkOWZiZjNhYThhM2M=
12
12
  data.tar.gz: !binary |-
13
- NjZjYzFkNTkyYWY0MmIwMWQzODI4NzE5YmM5YmZjYWY4NTVjZmUzZWYxMGE2
14
- MWE2YzViZWVhNDc1NmMxYWQzYzE5OTExMTQ4MTBiYjdjMTQ3ZWY3ZWM3YTMz
15
- NTg1OTgzYjE2Mzc4MzFiZGNhZDJhNjkzY2I2M2FkYjNlNWQxMmY=
13
+ ZGE4NmFlMTU3YTE2NDY5NTMyYzNmOWNhMjhlNGYzYmQzNjU5MWQwYzNjMDNi
14
+ NzhmOGQ2YTMyYWM0ZWM3MTk4ZWJhZWQ5OTJjZDYyZDcxMmJiZTA1NjA0NzY0
15
+ NjMyMTk4Njk0YzBlM2Q3ODI5YWEyZDMxYzU0NTBkZDgxYjU4Mzk=
data/CHANGELOG.mkd CHANGED
@@ -1,6 +1,32 @@
1
1
  CHANGELOG
2
2
  =========
3
3
 
4
+ 2.0.2
5
+ -----
6
+
7
+ 2015/06/18
8
+
9
+ This is a maintenance release that improves error messages around installing
10
+ modules from the Puppet Forge.
11
+
12
+ ### User notes
13
+
14
+ (RK-109) Add context to connection failure errors
15
+
16
+ If a connection to the Puppet Forge failed for any reason, the resulting
17
+ exception would indicate the error type but not the host or proxy host. This
18
+ made it hard to understand why connections were failing. This has been fixed so
19
+ that r10k will include the host and optional proxy host in error messages when
20
+ connections fail.
21
+
22
+ (RK-121) Improve error handling for nonexistent Forge modules
23
+
24
+ The r10k Puppet Forge connection error handling reports when HTTP requests fail,
25
+ but would simply print the HTTP status code on failure. For cases where a
26
+ nonexistent module or module release was queried, r10k now specially handles
27
+ HTTP 404 status codes and indicates that the module/module release is missing
28
+ instead of just throwing a generic HTTP error.
29
+
4
30
  2.0.1
5
31
  -----
6
32
 
data/lib/r10k/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module R10K
2
- VERSION = '2.0.1'
2
+ VERSION = '2.0.2'
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'shared/puppet_forge/version'
2
+ require 'shared/puppet_forge/connection/connection_failure'
2
3
 
3
4
  require 'faraday'
4
5
  require 'faraday_middleware'
@@ -54,6 +55,7 @@ module PuppetForge
54
55
  Faraday.new(url, options) do |builder|
55
56
  builder.response(:json, :content_type => /\bjson$/)
56
57
  builder.response(:raise_error)
58
+ builder.use(:connection_failure)
57
59
 
58
60
  builder.adapter(*adapter_args)
59
61
  end
@@ -0,0 +1,26 @@
1
+ require 'faraday'
2
+
3
+ module PuppetForge
4
+ module Connection
5
+ # Wrap Faraday connection failures to include the host and optional proxy
6
+ # in use for the failed connection.
7
+ class ConnectionFailure < Faraday::Middleware
8
+ def call(env)
9
+ @app.call(env)
10
+ rescue Faraday::ConnectionFailed => e
11
+ baseurl = env[:url].dup
12
+ baseurl.path = ''
13
+ errmsg = "Unable to connect to #{baseurl.to_s}"
14
+ if proxy = env[:request][:proxy]
15
+ errmsg << " (using proxy #{proxy.uri.to_s})"
16
+ end
17
+ errmsg << ": #{e.message}"
18
+ m = Faraday::ConnectionFailed.new(errmsg)
19
+ m.set_backtrace(e.backtrace)
20
+ raise m
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ Faraday::Middleware.register_middleware(:connection_failure => lambda { PuppetForge::Connection::ConnectionFailure })
@@ -25,4 +25,10 @@ Could not install package
25
25
  MSG
26
26
  end
27
27
  end
28
+
29
+ class ModuleNotFound < PuppetForge::Error
30
+ end
31
+
32
+ class ModuleReleaseNotFound < PuppetForge::Error
33
+ end
28
34
  end
@@ -1,6 +1,7 @@
1
1
  require 'shared/puppet_forge/v3'
2
2
  require 'shared/puppet_forge/v3/module_release'
3
3
  require 'shared/puppet_forge/connection'
4
+ require 'shared/puppet_forge/error'
4
5
 
5
6
  module PuppetForge
6
7
  module V3
@@ -41,6 +42,8 @@ module PuppetForge
41
42
  end
42
43
 
43
44
  releases.reverse
45
+ rescue Faraday::ResourceNotFound => e
46
+ raise PuppetForge::ModuleNotFound, "The module #{@full_name} does not exist on #{conn.url_prefix}.", e.backtrace
44
47
  end
45
48
 
46
49
  # Get all released versions of this module
@@ -1,5 +1,6 @@
1
1
  require 'shared/puppet_forge/v3'
2
2
  require 'shared/puppet_forge/connection'
3
+ require 'shared/puppet_forge/error'
3
4
 
4
5
  module PuppetForge
5
6
  module V3
@@ -24,9 +25,11 @@ module PuppetForge
24
25
  @version = version
25
26
  end
26
27
 
27
- # @return [Hash] The complete Forge resposne for this release.
28
+ # @return [Hash] The complete Forge response for this release.
28
29
  def data
29
30
  @data ||= conn.get(resource_url).body
31
+ rescue Faraday::ResourceNotFound => e
32
+ raise PuppetForge::ModuleReleaseNotFound, "The module release #{slug} does not exist on #{conn.url_prefix}.", e.backtrace
30
33
  end
31
34
 
32
35
  # @return [String] The unique identifier for this module release.
@@ -41,6 +44,8 @@ module PuppetForge
41
44
  def download(path)
42
45
  resp = conn.get(file_url)
43
46
  path.open('wb') { |fh| fh.write(resp.body) }
47
+ rescue Faraday::ResourceNotFound => e
48
+ raise PuppetForge::ModuleReleaseNotFound, "The module release #{slug} does not exist on #{conn.url_prefix}.", e.backtrace
44
49
  end
45
50
 
46
51
  # Verify that a downloaded module matches the checksum in the metadata for this release.
@@ -56,6 +56,7 @@ describe R10K::Forge::ModuleRelease do
56
56
 
57
57
  describe '#verify' do
58
58
  it "verifies the module checksum based on the Forge file checksum" do
59
+ allow(subject.forge_release).to receive(:data).and_return('file_md5' => 'something')
59
60
  expect(subject.forge_release).to receive(:verify).with(download_path)
60
61
  subject.verify
61
62
  end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+ require 'shared/puppet_forge/connection/connection_failure'
3
+
4
+ describe PuppetForge::Connection::ConnectionFailure do
5
+
6
+ subject do
7
+ Faraday.new('https://my-site.url/some-path') do |builder|
8
+ builder.use(:connection_failure)
9
+
10
+ builder.adapter :test do |stub|
11
+ stub.get('/connectfail') { raise Faraday::ConnectionFailed.new(SocketError.new("getaddrinfo: Name or service not known"), :hi) }
12
+ end
13
+ end
14
+ end
15
+
16
+ it "includes the base URL in the error message" do
17
+ expect {
18
+ subject.get('/connectfail')
19
+ }.to raise_error(Faraday::ConnectionFailed, "Unable to connect to https://my-site.url: getaddrinfo: Name or service not known")
20
+ end
21
+
22
+ it "includes the proxy host in the error message when set" do
23
+ subject.proxy('https://some-unreachable.proxy:3128')
24
+ expect {
25
+ subject.get('/connectfail')
26
+ }.to raise_error(Faraday::ConnectionFailed, "Unable to connect to https://my-site.url (using proxy https://some-unreachable.proxy:3128): getaddrinfo: Name or service not known")
27
+ end
28
+ end
@@ -8,6 +8,7 @@ describe PuppetForge::V3::ModuleRelease do
8
8
 
9
9
  let(:conn) do
10
10
  Faraday.new do |builder|
11
+ builder.response(:raise_error)
11
12
  builder.adapter :test, faraday_stubs
12
13
  end
13
14
  end
@@ -26,6 +27,13 @@ describe PuppetForge::V3::ModuleRelease do
26
27
  faraday_stubs.get('/v3/releases/username-modulename-3.1.4') { [200, {}, {'metadata' => 'yep'}] }
27
28
  expect(subject.data).to eq('metadata' => 'yep')
28
29
  end
30
+
31
+ it 'raises an error if the module release does not exist' do
32
+ faraday_stubs.get('/v3/releases/username-modulename-3.1.4') { [404, {}, {'metadata' => 'yep'}] }
33
+ expect {
34
+ subject.data
35
+ }.to raise_error(PuppetForge::ModuleReleaseNotFound, /The module release username-modulename-3\.1\.4 does not exist/)
36
+ end
29
37
  end
30
38
 
31
39
  describe '#download' do
@@ -40,6 +48,13 @@ describe PuppetForge::V3::ModuleRelease do
40
48
 
41
49
  subject.download(path)
42
50
  end
51
+
52
+ it 'raises an error if the module release does not exist' do
53
+ faraday_stubs.get('/v3/files/username-modulename-3.1.4.tar.gz') { [404, {}, 'not found'] }
54
+ expect {
55
+ subject.download(Pathname.new('/some/path'))
56
+ }.to raise_error(PuppetForge::ModuleReleaseNotFound, /The module release username-modulename-3\.1\.4 does not exist/)
57
+ end
43
58
  end
44
59
 
45
60
  describe '#verify' do
@@ -7,6 +7,7 @@ describe PuppetForge::V3::Module do
7
7
 
8
8
  let(:conn) do
9
9
  Faraday.new do |builder|
10
+ builder.response(:raise_error)
10
11
  builder.adapter :test, faraday_stubs
11
12
  end
12
13
  end
@@ -56,6 +57,13 @@ describe PuppetForge::V3::Module do
56
57
  faraday_stubs.get('/v3/modules/authorname-modulename') { [200, {}, releases_with_deletions] }
57
58
  expect(subject.versions).to eq ["0.3.0"]
58
59
  end
60
+
61
+ it "raises an error when the module does not exist" do
62
+ faraday_stubs.get('/v3/modules/authorname-modulename') { [404, {}, ''] }
63
+ expect {
64
+ subject.versions
65
+ }.to raise_error(PuppetForge::ModuleNotFound, /The module authorname-modulename does not exist/)
66
+ end
59
67
  end
60
68
 
61
69
  describe '#latest_version' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r10k
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrien Thebo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-09 00:00:00.000000000 Z
11
+ date: 2015-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored
@@ -400,6 +400,7 @@ files:
400
400
  - lib/r10k/version.rb
401
401
  - lib/shared/puppet/module_tool/metadata.rb
402
402
  - lib/shared/puppet_forge/connection.rb
403
+ - lib/shared/puppet_forge/connection/connection_failure.rb
403
404
  - lib/shared/puppet_forge/error.rb
404
405
  - lib/shared/puppet_forge/tar.rb
405
406
  - lib/shared/puppet_forge/tar/mini.rb
@@ -470,6 +471,7 @@ files:
470
471
  - spec/unit/module_repository/forge_spec.rb
471
472
  - spec/unit/module_spec.rb
472
473
  - spec/unit/puppet/module_tool/metadata_spec.rb
474
+ - spec/unit/puppet_forge/connection/connection_failure_spec.rb
473
475
  - spec/unit/puppet_forge/connection_spec.rb
474
476
  - spec/unit/puppet_forge/tar/mini_spec.rb
475
477
  - spec/unit/puppet_forge/tar_spec.rb
@@ -577,6 +579,7 @@ test_files:
577
579
  - spec/unit/module/git_spec.rb
578
580
  - spec/unit/logging_spec.rb
579
581
  - spec/unit/puppet_forge/tar_spec.rb
582
+ - spec/unit/puppet_forge/connection/connection_failure_spec.rb
580
583
  - spec/unit/puppet_forge/v3/module_spec.rb
581
584
  - spec/unit/puppet_forge/v3/module_release_spec.rb
582
585
  - spec/unit/puppet_forge/unpacker_spec.rb