puppet_forge 2.1.4 → 2.1.5

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: f48d6266af226aa37df713b0e1e3f72d44dc574e
4
- data.tar.gz: 70d063373704bfed1c60455cc305a67daa61bb23
3
+ metadata.gz: 4c540e2e0483e80b517b23ef6a5160d30173e302
4
+ data.tar.gz: 0d5de65b3c5654e78459d03efdf33368834848dd
5
5
  SHA512:
6
- metadata.gz: a23339d6b315cd7415c5b7421a16df9aaee54c4dc3940f5b803cc8a6896356bf984a8c01ce4cda19bd25ad94d08683569f50420837cb052478cbd0afd22b20ae
7
- data.tar.gz: f13dc0acd460860e8d9f94d99206c93305abce3a87bebaaf60845a423d4a173018da8a813e39aa0f40bbfbf728fbe4d08ab7c0a04f77dcb4e9378afe62b7fb30
6
+ metadata.gz: 8662c9f01abfd72337a3b0bea60157b7d33487b8de862be41e705de6f343d05eb8477432a827fcf99688b9a32ce5a6cf850a9362601c7211d6cf808652f9f1f5
7
+ data.tar.gz: f91538968a8fa53c87236b54d029f6dd549d68887c6fdc3e1bd1468ee7f9ac66789e4ffc6a64bea29a72d842abe39953d00b80c459f32cb20af024d57c3efcfc
@@ -3,6 +3,16 @@
3
3
  Starting with v2.0.0, all notable changes to this project will be documented in this file.
4
4
  This project adheres to [Semantic Versioning](http://semver.org/).
5
5
 
6
+ ## v2.1.5 - 2016-04-13
7
+
8
+ ### Added
9
+
10
+ * PuppetForge::Connection now has .proxy and .proxy= class methods providing a more reliable way of configuring an HTTP proxy.
11
+
12
+ ### Changed
13
+
14
+ * Cached connection objects will now be automatically discarded when proxy or authorization config has changed.
15
+
6
16
  ## v2.1.4 - 2016-04-01
7
17
 
8
18
  ### Changed
@@ -28,18 +28,37 @@ module PuppetForge
28
28
 
29
29
  def self.authorization=(token)
30
30
  @authorization = token
31
+
32
+ # RK-229 Specific Workaround
33
+ # Capture instance specific proxy setting if defined.
34
+ if defined?(PuppetForge::V3::Base)
35
+ if old_conn = PuppetForge::V3::Base.instance_variable_get(:@conn)
36
+ self.proxy = old_conn.proxy.uri.to_s if old_conn.proxy
37
+ end
38
+ end
31
39
  end
32
40
 
33
41
  def self.authorization
34
42
  @authorization
35
43
  end
36
44
 
45
+ def self.proxy=(url)
46
+ @proxy = url
47
+ end
48
+
49
+ def self.proxy
50
+ @proxy
51
+ end
52
+
37
53
  # @param reset_connection [Boolean] flag to create a new connection every time this is called
38
54
  # @param opts [Hash] Hash of connection options for Faraday
39
55
  # @return [Faraday::Connection] An existing Faraday connection if one was
40
56
  # already set, otherwise a new Faraday connection.
41
57
  def conn(reset_connection = nil, opts = {})
42
- if reset_connection
58
+ new_auth = @conn && @conn.headers['Authorization'] != PuppetForge::Connection.authorization
59
+ new_proxy = @conn && ((@conn.proxy.nil? && PuppetForge::Connection.proxy) || (@conn.proxy && @conn.proxy.uri.to_s != PuppetForge::Connection.proxy))
60
+
61
+ if new_auth || new_proxy || reset_connection
43
62
  default_connection(opts)
44
63
  else
45
64
  @conn ||= default_connection(opts)
@@ -75,6 +94,10 @@ module PuppetForge
75
94
  options[:headers][:authorization] = token
76
95
  end
77
96
 
97
+ if proxy = PuppetForge::Connection.proxy
98
+ options[:proxy] = proxy
99
+ end
100
+
78
101
  Faraday.new(url, options) do |builder|
79
102
  builder.use PuppetForge::Middleware::SymbolifyJson
80
103
  builder.response(:json, :content_type => /\bjson$/)
@@ -1,3 +1,3 @@
1
1
  module PuppetForge
2
- VERSION = '2.1.4' # Library version
2
+ VERSION = '2.1.5' # Library version
3
3
  end
@@ -1,6 +1,45 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe PuppetForge::V3::Base do
4
+ context 'connection management' do
5
+ before(:each) do
6
+ PuppetForge::Connection.authorization = nil
7
+ PuppetForge::Connection.proxy = nil
8
+ described_class.conn = nil
9
+ end
10
+
11
+ after(:each) do
12
+ PuppetForge::Connection.authorization = nil
13
+ PuppetForge::Connection.proxy = nil
14
+ described_class.conn = nil
15
+ end
16
+
17
+ describe 'setting authorization value after a connection is created' do
18
+ it 'should reset connection' do
19
+ old_conn = described_class.conn
20
+
21
+ PuppetForge::Connection.authorization = 'post-init auth value'
22
+ new_conn = described_class.conn
23
+
24
+ expect(new_conn).to_not eq(old_conn)
25
+ expect(new_conn.headers).to include(:authorization => 'post-init auth value')
26
+ end
27
+ end
28
+
29
+ describe 'setting proxy value after a connection is created' do
30
+ it 'should reset connection' do
31
+ old_conn = described_class.conn
32
+
33
+ PuppetForge::Connection.proxy = 'http://proxy.example.com:8888'
34
+ new_conn = described_class.conn
35
+
36
+ expect(new_conn).to_not eq(old_conn)
37
+ expect(new_conn.proxy).to_not be_nil
38
+ expect(new_conn.proxy.uri.to_s).to eq('http://proxy.example.com:8888')
39
+ end
40
+ end
41
+ end
42
+
4
43
  describe '::new_collection' do
5
44
  it 'should handle responses with no results' do
6
45
  response_data = { data: {}, errors: "Something bad happened!" }
@@ -2,91 +2,132 @@ require 'spec_helper'
2
2
  require 'fileutils'
3
3
 
4
4
  describe PuppetForge::V3::Release do
5
- before do
6
- stub_api_for(PuppetForge::V3::Base) do |stubs|
7
- stub_fixture(stubs, :get, '/v3/releases/puppetlabs-apache-0.0.1')
8
- stub_fixture(stubs, :get, '/v3/releases/absent-apache-0.0.1')
9
- stub_fixture(stubs, :get, '/v3/files/puppetlabs-apache-0.0.1.tar.gz')
10
- stub_fixture(stubs, :get, '/v3/modules/puppetlabs-apache')
11
- stub_fixture(stubs, :get, '/v3/releases?module=puppetlabs-apache')
5
+ context 'connection management' do
6
+ before(:each) do
7
+ PuppetForge::Connection.authorization = nil
8
+ PuppetForge::Connection.proxy = nil
9
+ described_class.conn = PuppetForge::V3::Base.conn(true)
12
10
  end
13
- end
14
-
15
- describe '::find' do
16
- let(:release) { PuppetForge::V3::Release.find('puppetlabs-apache-0.0.1') }
17
- let(:missing_release) { PuppetForge::V3::Release.find('absent-apache-0.0.1') }
18
11
 
19
- it 'can find releases that exist' do
20
- expect(release.version).to eql('0.0.1')
12
+ after(:each) do
13
+ PuppetForge::Connection.authorization = nil
14
+ PuppetForge::Connection.proxy = nil
15
+ described_class.conn = nil
21
16
  end
22
17
 
23
- it 'raises Faraday::ResourceNotFound for non-existent releases' do
24
- expect { missing_release }.to raise_error(Faraday::ResourceNotFound)
18
+ describe 'setting authorization value after a connection is created' do
19
+ it 'should reset connection' do
20
+ old_conn = described_class.conn
21
+
22
+ PuppetForge::Connection.authorization = 'post-init auth value'
23
+ new_conn = described_class.conn
24
+
25
+ expect(new_conn).to_not eq(old_conn)
26
+ expect(new_conn.headers).to include(:authorization => 'post-init auth value')
27
+ end
25
28
  end
26
- end
27
29
 
28
- describe '#module' do
29
- let(:release) { PuppetForge::V3::Release.find('puppetlabs-apache-0.0.1') }
30
+ describe 'setting proxy value after a connection is created' do
31
+ it 'should reset connection' do
32
+ old_conn = described_class.conn
30
33
 
31
- it 'exposes the related module as a property' do
32
- expect(release.module).to_not be nil
34
+ PuppetForge::Connection.proxy = 'http://proxy.example.com:8888'
35
+ new_conn = described_class.conn
36
+
37
+ expect(new_conn).to_not eq(old_conn)
38
+ expect(new_conn.proxy).to_not be_nil
39
+ expect(new_conn.proxy.uri.to_s).to eq('http://proxy.example.com:8888')
40
+ end
33
41
  end
42
+ end
34
43
 
35
- it 'grants access to module attributes without an API call' do
36
- expect(PuppetForge::V3::Module).not_to receive(:request)
37
- expect(release.module.name).to eql('apache')
44
+ context 'with stubbed connection' do
45
+ before do
46
+ stub_api_for(PuppetForge::V3::Base) do |stubs|
47
+ stub_fixture(stubs, :get, '/v3/releases/puppetlabs-apache-0.0.1')
48
+ stub_fixture(stubs, :get, '/v3/releases/absent-apache-0.0.1')
49
+ stub_fixture(stubs, :get, '/v3/files/puppetlabs-apache-0.0.1.tar.gz')
50
+ stub_fixture(stubs, :get, '/v3/modules/puppetlabs-apache')
51
+ stub_fixture(stubs, :get, '/v3/releases?module=puppetlabs-apache')
52
+ end
38
53
  end
39
54
 
40
- it 'transparently makes API calls for other attributes' do
41
- expect(PuppetForge::V3::Module).to receive(:request).once.and_call_original
42
- expect(release.module.created_at).to_not be nil
55
+ describe '::find' do
56
+ let(:release) { PuppetForge::V3::Release.find('puppetlabs-apache-0.0.1') }
57
+ let(:missing_release) { PuppetForge::V3::Release.find('absent-apache-0.0.1') }
58
+
59
+ it 'can find releases that exist' do
60
+ expect(release.version).to eql('0.0.1')
61
+ end
62
+
63
+ it 'raises Faraday::ResourceNotFound for non-existent releases' do
64
+ expect { missing_release }.to raise_error(Faraday::ResourceNotFound)
65
+ end
43
66
  end
44
- end
45
67
 
46
- describe '#download_url' do
47
- let(:release) { PuppetForge::V3::Release.find('puppetlabs-apache-0.0.1') }
68
+ describe '#module' do
69
+ let(:release) { PuppetForge::V3::Release.find('puppetlabs-apache-0.0.1') }
48
70
 
49
- it 'handles an API response that does not include a scheme and host' do
50
- release.file_uri = '/v3/files/puppetlabs-apache-0.0.1.tar.gz'
51
- uri_with_host = URI.join(PuppetForge.host, '/v3/files/puppetlabs-apache-0.0.1.tar.gz').to_s
52
- expect(release.download_url).to eql(uri_with_host)
71
+ it 'exposes the related module as a property' do
72
+ expect(release.module).to_not be nil
73
+ end
74
+
75
+ it 'grants access to module attributes without an API call' do
76
+ expect(PuppetForge::V3::Module).not_to receive(:request)
77
+ expect(release.module.name).to eql('apache')
78
+ end
79
+
80
+ it 'transparently makes API calls for other attributes' do
81
+ expect(PuppetForge::V3::Module).to receive(:request).once.and_call_original
82
+ expect(release.module.created_at).to_not be nil
83
+ end
53
84
  end
54
85
 
55
- it 'handles an API response that includes a scheme and host' do
56
- release.file_uri = 'https://example.com/v3/files/puppetlabs-apache-0.0.1.tar.gz'
57
- expect(release.download_url).to eql('https://example.com/v3/files/puppetlabs-apache-0.0.1.tar.gz')
86
+ describe '#download_url' do
87
+ let(:release) { PuppetForge::V3::Release.find('puppetlabs-apache-0.0.1') }
88
+
89
+ it 'handles an API response that does not include a scheme and host' do
90
+ release.file_uri = '/v3/files/puppetlabs-apache-0.0.1.tar.gz'
91
+ uri_with_host = URI.join(PuppetForge.host, '/v3/files/puppetlabs-apache-0.0.1.tar.gz').to_s
92
+ expect(release.download_url).to eql(uri_with_host)
93
+ end
94
+
95
+ it 'handles an API response that includes a scheme and host' do
96
+ release.file_uri = 'https://example.com/v3/files/puppetlabs-apache-0.0.1.tar.gz'
97
+ expect(release.download_url).to eql('https://example.com/v3/files/puppetlabs-apache-0.0.1.tar.gz')
98
+ end
58
99
  end
59
- end
60
100
 
61
- describe '#download' do
62
- let(:release) { PuppetForge::V3::Release.find('puppetlabs-apache-0.0.1') }
63
- let(:tarball) { "#{PROJECT_ROOT}/spec/tmp/module.tgz" }
101
+ describe '#download' do
102
+ let(:release) { PuppetForge::V3::Release.find('puppetlabs-apache-0.0.1') }
103
+ let(:tarball) { "#{PROJECT_ROOT}/spec/tmp/module.tgz" }
64
104
 
65
- before { FileUtils.rm tarball rescue nil }
66
- after { FileUtils.rm tarball rescue nil }
105
+ before { FileUtils.rm tarball rescue nil }
106
+ after { FileUtils.rm tarball rescue nil }
67
107
 
68
- it 'downloads the file to the specified location' do
69
- expect(File.exist?(tarball)).to be false
70
- release.download(Pathname.new(tarball))
71
- expect(File.exist?(tarball)).to be true
108
+ it 'downloads the file to the specified location' do
109
+ expect(File.exist?(tarball)).to be false
110
+ release.download(Pathname.new(tarball))
111
+ expect(File.exist?(tarball)).to be true
112
+ end
72
113
  end
73
- end
74
114
 
75
- describe '#metadata' do
76
- let(:release) { PuppetForge::V3::Release.find('puppetlabs-apache-0.0.1') }
115
+ describe '#metadata' do
116
+ let(:release) { PuppetForge::V3::Release.find('puppetlabs-apache-0.0.1') }
77
117
 
78
- it 'is lazy and repeatable' do
79
- 3.times do
80
- expect(release.module.releases.last.metadata).to_not be_nil
118
+ it 'is lazy and repeatable' do
119
+ 3.times do
120
+ expect(release.module.releases.last.metadata).to_not be_nil
121
+ end
81
122
  end
82
123
  end
83
- end
84
124
 
85
- describe 'instance properies' do
86
- let(:release) { PuppetForge::V3::Release.find('puppetlabs-apache-0.0.1') }
125
+ describe 'instance properies' do
126
+ let(:release) { PuppetForge::V3::Release.find('puppetlabs-apache-0.0.1') }
87
127
 
88
- example 'are easily accessible' do
89
- expect(release.created_at).to_not be nil
128
+ example 'are easily accessible' do
129
+ expect(release.created_at).to_not be nil
130
+ end
90
131
  end
91
132
  end
92
133
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet_forge
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.4
4
+ version: 2.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet Labs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-01 00:00:00.000000000 Z
11
+ date: 2016-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -269,7 +269,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
269
269
  version: '0'
270
270
  requirements: []
271
271
  rubyforge_project:
272
- rubygems_version: 2.2.5
272
+ rubygems_version: 2.4.5.1
273
273
  signing_key:
274
274
  specification_version: 4
275
275
  summary: Access the Puppet Forge API from Ruby for resource information and to download
@@ -320,3 +320,4 @@ test_files:
320
320
  - spec/unit/forge/v3/module_spec.rb
321
321
  - spec/unit/forge/v3/release_spec.rb
322
322
  - spec/unit/forge/v3/user_spec.rb
323
+ has_rdoc: