puppet_forge 2.3.0 → 3.0.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
  SHA256:
3
- metadata.gz: d72d1609cb7e736e7bb0ef08ac3e1525be1a30da2510a47e6c61540ee916eee8
4
- data.tar.gz: 8d9eed220d7aa2b64cde494812aeda1dd8a1a0113244284992900cd6386db72a
3
+ metadata.gz: 04e64600a52c57a9fef2dce82516632a77e196b1778b2082c925def0ecdbf734
4
+ data.tar.gz: 660cb79c76d923bbe6f101f68f01d913800625688ba59f61152d697054f967bc
5
5
  SHA512:
6
- metadata.gz: 7515c022ac7cbf70b2e1837b9066c76c80fd73ad17c86877df30c259dee0b34666528f33c235fa49914ae6a8760cca803322df746cc3bb9f0247224efd71841e
7
- data.tar.gz: 281871d896280738fa16fff39ebafc33c3fed460e82e34dd94c0409fd99f2585f903ed0098cbbda30465d5d06cd855538f9342e3b75e4d6364dadfc908a31e37
6
+ metadata.gz: 2199cd27949a3de2c7869bcffea4b489b03aee703b5a1fdb9cac4b9447a90160ecf731cd549b1c8edcfeeb560a6352c0df3836daf2e22d2fdf5290f95f6f9f0b
7
+ data.tar.gz: 2a0053e71e9bccd6cb9cb2168618344426ca9e829f1328f5ff97b1d7d644a164e2a3077f483f2bc0ce2a41078e7daeefaf2d3016730ded51fd24a6cca9b82750
@@ -0,0 +1,30 @@
1
+ name: ruby-rspec
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+ branches:
9
+ - main
10
+
11
+ jobs:
12
+ test:
13
+ name: Test with Ruby ${{ matrix.ruby_version }}
14
+ runs-on: ubuntu-latest
15
+ strategy:
16
+ matrix:
17
+ ruby_version: ['2.7.x', '2.6.x', '2.5.x', '2.4.x']
18
+
19
+ steps:
20
+ - uses: actions/checkout@v1
21
+ - name: Set up Ruby ${{ matrix.ruby_version }}
22
+ uses: actions/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby_version }}
25
+
26
+ - name: Build and test with Rspec
27
+ run: |
28
+ gem install bundler
29
+ bundle install --jobs 4 --retry 3
30
+ bundle exec rspec
@@ -3,6 +3,42 @@
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
+ ## v3.0.0 - 2021-01-28
7
+
8
+ * Breaking: The `puppet_forge` gem now requires at least Ruby 2.4.0.
9
+ * Update `faraday` and `faraday_middleware` gem dependencies to 1.x series.
10
+ * Update optional `typhoeus` dependency to `>= 1.4` to maintain compatibility with `faraday`.
11
+
12
+ ## v2.3.4 - 2020-03-31
13
+
14
+ * Update the forge API url to `forgeapi.puppet.com` (instead of using the older puppetlabs.com domain).
15
+ * Allow versions of the `faraday_middleware` dependency up to 0.15.
16
+
17
+ ## v2.3.3 - 2020-02-20
18
+
19
+ ### Changed
20
+
21
+ * Allow versions of faraday up to 0.18
22
+
23
+ ## v2.3.2 - 2020-02-05
24
+
25
+ ### Fixed
26
+
27
+ * Catch and handle the new `Faraday::TimeoutError`s which are occasionally
28
+ surfaced by the the typheous adapter with more recent verions of libcurl, and
29
+ log them the same way that `Faraday::ConnectionFailed` errors are already
30
+ logged.
31
+
32
+ ### Changed
33
+
34
+ * Allow for using `faraday_middleware` versions in the 0.13.x series.
35
+
36
+ ## v2.3.1 - 2019-11-15
37
+
38
+ ### Fixed
39
+
40
+ * Fixed an issue where proxy configurations were being ignored by expanding the range of acceptable versions of the `faraday` gem dependency and specifically excluding the version that was ignoring proxy configuration options.
41
+
6
42
  ## v2.3.0 - 2019-07-09
7
43
 
8
44
  ### Changed
@@ -0,0 +1 @@
1
+ * @puppetlabs/forge-team
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Puppet Forge
2
2
 
3
- Access and manipulate the [Puppet Forge API](https://forgeapi.puppetlabs.com)
3
+ Access and manipulate the [Puppet Forge API](https://forgeapi.puppet.com)
4
4
  from Ruby.
5
5
 
6
6
  ## Installation
@@ -17,7 +17,7 @@ module PuppetForge
17
17
 
18
18
  GettextSetup.initialize(File.absolute_path('../locales', File.dirname(__FILE__)))
19
19
 
20
- DEFAULT_FORGE_HOST = 'https://forgeapi.puppetlabs.com/'
20
+ DEFAULT_FORGE_HOST = 'https://forgeapi.puppet.com/'
21
21
 
22
22
  self.host = DEFAULT_FORGE_HOST
23
23
 
@@ -2,7 +2,6 @@ require 'puppet_forge/connection/connection_failure'
2
2
 
3
3
  require 'faraday'
4
4
  require 'faraday_middleware'
5
- require 'puppet_forge/middleware/symbolify_json'
6
5
 
7
6
  module PuppetForge
8
7
  # Provide a common mixin for adding a HTTP connection to classes.
@@ -81,7 +80,7 @@ module PuppetForge
81
80
 
82
81
  begin
83
82
  # Use Typhoeus if available.
84
- Gem::Specification.find_by_name('typhoeus', '~> 1.0.1')
83
+ Gem::Specification.find_by_name('typhoeus', '~> 1.4')
85
84
  require 'typhoeus/adapters/faraday'
86
85
  adapter = :typhoeus
87
86
  rescue Gem::LoadError
@@ -114,8 +113,7 @@ module PuppetForge
114
113
  end
115
114
 
116
115
  Faraday.new(url, options) do |builder|
117
- builder.use PuppetForge::Middleware::SymbolifyJson
118
- builder.response(:json, :content_type => /\bjson$/)
116
+ builder.response(:json, :content_type => /\bjson$/, :parser_options => { :symbolize_names => true })
119
117
  builder.response(:raise_error)
120
118
  builder.use(:connection_failure)
121
119
 
@@ -7,7 +7,7 @@ module PuppetForge
7
7
  class ConnectionFailure < Faraday::Middleware
8
8
  def call(env)
9
9
  @app.call(env)
10
- rescue Faraday::ConnectionFailed => e
10
+ rescue Faraday::ConnectionFailed, Faraday::TimeoutError => e
11
11
  baseurl = env[:url].dup
12
12
  if proxy = env[:request][:proxy]
13
13
  errmsg = _("Unable to connect to %{scheme}://%{host} (using proxy %{proxy}) (for request %{path_query})") % {
@@ -56,7 +56,7 @@ module PuppetForge
56
56
  # @private
57
57
  def request(resource, item = nil, params = {}, reset_connection = false, conn_opts = {})
58
58
  conn(reset_connection, conn_opts) if reset_connection
59
- unless conn.url_prefix =~ /^#{PuppetForge.host}/
59
+ unless conn.url_prefix.to_s =~ /^#{PuppetForge.host}/
60
60
  conn.url_prefix = "#{PuppetForge.host}"
61
61
  end
62
62
 
@@ -1,3 +1,3 @@
1
1
  module PuppetForge
2
- VERSION = '2.3.0' # Library version
2
+ VERSION = '3.0.0' # Library version
3
3
  end
@@ -18,15 +18,14 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.required_ruby_version = '>= 1.9.3'
21
+ spec.required_ruby_version = '>= 2.4.0'
22
22
 
23
- spec.add_runtime_dependency "faraday", [">= 0.9.0", "< 0.14.0"]
24
- spec.add_runtime_dependency "faraday_middleware", [">= 0.9.0", "< 0.13.0"]
25
- spec.add_dependency 'semantic_puppet', '~> 1.0'
26
- spec.add_dependency 'minitar'
27
- spec.add_dependency 'gettext-setup', '~> 0.11'
23
+ spec.add_runtime_dependency "faraday", "~> 1.3"
24
+ spec.add_runtime_dependency "faraday_middleware", "~> 1.0"
25
+ spec.add_dependency "semantic_puppet", "~> 1.0"
26
+ spec.add_dependency "minitar"
27
+ spec.add_dependency "gettext-setup", "~> 0.11"
28
28
 
29
- spec.add_development_dependency "bundler", "~> 1.6"
30
29
  spec.add_development_dependency "rake"
31
30
  spec.add_development_dependency "rspec", "~> 3.0"
32
31
  spec.add_development_dependency "simplecov"
@@ -15,8 +15,7 @@ module StubbingFaraday
15
15
  def stub_api_for(klass, base_url = "http://api.example.com")
16
16
  allow(klass).to receive(:conn) do
17
17
  Faraday.new :url => base_url do |builder|
18
- builder.use PuppetForge::Middleware::SymbolifyJson
19
- builder.response(:json, :content_type => /\bjson$/)
18
+ builder.response(:json, :content_type => /\bjson$/, :parser_options => { :symbolize_names => true })
20
19
  builder.response(:raise_error)
21
20
  builder.use(:connection_failure)
22
21
 
@@ -11,6 +11,7 @@ describe PuppetForge::Connection::ConnectionFailure do
11
11
 
12
12
  builder.adapter :test do |stub|
13
13
  stub.get('/connectfail') { raise Faraday::ConnectionFailed.new(SocketError.new("getaddrinfo: Name or service not known"), :hi) }
14
+ stub.get('/timeout') { raise Faraday::TimeoutError, "request timed out" }
14
15
  end
15
16
  end
16
17
  end
@@ -21,6 +22,12 @@ describe PuppetForge::Connection::ConnectionFailure do
21
22
  }.to raise_error(Faraday::ConnectionFailed, /unable to connect to.*\/connectfail.*name or service not known/i)
22
23
  end
23
24
 
25
+ it "logs for timeout errors" do
26
+ expect {
27
+ subject.get('/timeout')
28
+ }.to raise_error(Faraday::ConnectionFailed, /unable to connect to.*\/timeout.*request timed out/i)
29
+ end
30
+
24
31
  it "includes the proxy host in the error message when set" do
25
32
  if subject.respond_to?(:proxy=)
26
33
  subject.proxy = 'https://some-unreachable.proxy:3128'
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe PuppetForge::Connection do
4
4
  before(:each) do
5
- PuppetForge.host = "https://forgeapi.puppetlabs.com"
5
+ PuppetForge.host = "https://forgeapi.puppet.com"
6
6
  end
7
7
 
8
8
  let(:test_conn) do
@@ -88,7 +88,7 @@ describe PuppetForge::Connection do
88
88
 
89
89
  expect {
90
90
  subject.get('/error')
91
- }.to raise_error(Faraday::ClientError, "the server responded with status 503")
91
+ }.to raise_error(Faraday::ServerError, "the server responded with status 503")
92
92
  end
93
93
 
94
94
  context 'when an authorization value is provided' do
@@ -115,7 +115,7 @@ describe PuppetForge::Connection do
115
115
  describe 'creating a default connection' do
116
116
  it 'creates a connection with the PuppetForge host' do
117
117
  conn = test_conn.default_connection
118
- expect(conn.url_prefix.to_s).to eq 'https://forgeapi.puppetlabs.com/'
118
+ expect(conn.url_prefix.to_s).to eq 'https://forgeapi.puppet.com/'
119
119
  end
120
120
  end
121
121
  end
@@ -168,14 +168,6 @@ describe PuppetForge::Metadata do
168
168
 
169
169
  end
170
170
 
171
- context "with a valid dependency", :pending => "dependency resolution is not yet in scope" do
172
- let(:data) { {'dependencies' => [{'name' => 'puppetlabs-goodmodule'}] }}
173
-
174
- it "adds the dependency" do
175
- expect(subject.dependencies.size).to eq(1)
176
- end
177
- end
178
-
179
171
  context "with a invalid dependency name" do
180
172
  let(:data) { {'dependencies' => [{'name' => 'puppetlabsbadmodule'}] }}
181
173
 
@@ -184,14 +176,6 @@ describe PuppetForge::Metadata do
184
176
  end
185
177
  end
186
178
 
187
- context "with a valid dependency version range", :pending => "dependency resolution is not yet in scope" do
188
- let(:data) { {'dependencies' => [{'name' => 'puppetlabs-badmodule', 'version_requirement' => '>= 2.0.0'}] }}
189
-
190
- it "adds the dependency" do
191
- expect(subject.dependencies.size).to eq(1)
192
- end
193
- end
194
-
195
179
  context "with a invalid version range" do
196
180
  let(:data) { {'dependencies' => [{'name' => 'puppetlabsbadmodule', 'version_requirement' => '>= banana'}] }}
197
181
 
@@ -199,30 +183,6 @@ describe PuppetForge::Metadata do
199
183
  expect { subject }.to raise_error(ArgumentError)
200
184
  end
201
185
  end
202
-
203
- context "with duplicate dependencies", :pending => "dependency resolution is not yet in scope" do
204
- let(:data) { {'dependencies' => [{'name' => 'puppetlabs-dupmodule', 'version_requirement' => '1.0.0'},
205
- {'name' => 'puppetlabs-dupmodule', 'version_requirement' => '0.0.1'}] }
206
- }
207
-
208
- it "raises an exception" do
209
- expect { subject }.to raise_error(ArgumentError)
210
- end
211
- end
212
-
213
- context "adding a duplicate dependency", :pending => "dependency resolution is not yet in scope" do
214
- let(:data) { {'dependencies' => [{'name' => 'puppetlabs-origmodule', 'version_requirement' => '1.0.0'}] }}
215
-
216
- it "with a different version raises an exception" do
217
- metadata.add_dependency('puppetlabs-origmodule', '>= 0.0.1')
218
- expect { subject }.to raise_error(ArgumentError)
219
- end
220
-
221
- it "with the same version does not add another dependency" do
222
- metadata.add_dependency('puppetlabs-origmodule', '1.0.0')
223
- expect(subject.dependencies.size).to eq(1)
224
- end
225
- end
226
186
  end
227
187
 
228
188
  describe '#dashed_name' do
metadata CHANGED
@@ -1,55 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet_forge
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet Labs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-10 00:00:00.000000000 Z
11
+ date: 2021-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 0.9.0
20
- - - "<"
17
+ - - "~>"
21
18
  - !ruby/object:Gem::Version
22
- version: 0.14.0
19
+ version: '1.3'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- version: 0.9.0
30
- - - "<"
24
+ - - "~>"
31
25
  - !ruby/object:Gem::Version
32
- version: 0.14.0
26
+ version: '1.3'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: faraday_middleware
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- version: 0.9.0
40
- - - "<"
31
+ - - "~>"
41
32
  - !ruby/object:Gem::Version
42
- version: 0.13.0
33
+ version: '1.0'
43
34
  type: :runtime
44
35
  prerelease: false
45
36
  version_requirements: !ruby/object:Gem::Requirement
46
37
  requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- version: 0.9.0
50
- - - "<"
38
+ - - "~>"
51
39
  - !ruby/object:Gem::Version
52
- version: 0.13.0
40
+ version: '1.0'
53
41
  - !ruby/object:Gem::Dependency
54
42
  name: semantic_puppet
55
43
  requirement: !ruby/object:Gem::Requirement
@@ -92,20 +80,6 @@ dependencies:
92
80
  - - "~>"
93
81
  - !ruby/object:Gem::Version
94
82
  version: '0.11'
95
- - !ruby/object:Gem::Dependency
96
- name: bundler
97
- requirement: !ruby/object:Gem::Requirement
98
- requirements:
99
- - - "~>"
100
- - !ruby/object:Gem::Version
101
- version: '1.6'
102
- type: :development
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- requirements:
106
- - - "~>"
107
- - !ruby/object:Gem::Version
108
- version: '1.6'
109
83
  - !ruby/object:Gem::Dependency
110
84
  name: rake
111
85
  requirement: !ruby/object:Gem::Requirement
@@ -212,12 +186,12 @@ executables: []
212
186
  extensions: []
213
187
  extra_rdoc_files: []
214
188
  files:
189
+ - ".github/workflows/ruby-rspec.yml"
215
190
  - ".gitignore"
216
- - ".travis.yml"
217
191
  - CHANGELOG.md
192
+ - CODEOWNERS
218
193
  - Gemfile
219
194
  - LICENSE.txt
220
- - MAINTAINERS
221
195
  - README.md
222
196
  - Rakefile
223
197
  - lib/puppet_forge.rb
@@ -226,7 +200,6 @@ files:
226
200
  - lib/puppet_forge/error.rb
227
201
  - lib/puppet_forge/lazy_accessors.rb
228
202
  - lib/puppet_forge/lazy_relations.rb
229
- - lib/puppet_forge/middleware/symbolify_json.rb
230
203
  - lib/puppet_forge/tar.rb
231
204
  - lib/puppet_forge/tar/mini.rb
232
205
  - lib/puppet_forge/unpacker.rb
@@ -271,16 +244,12 @@ files:
271
244
  - spec/fixtures/v3/releases__module=puppetlabs-apache.json
272
245
  - spec/fixtures/v3/users/puppetlabs.headers
273
246
  - spec/fixtures/v3/users/puppetlabs.json
274
- - spec/integration/forge/v3/module_spec.rb
275
- - spec/integration/forge/v3/release_spec.rb
276
- - spec/integration/forge/v3/user_spec.rb
277
247
  - spec/spec_helper.rb
278
248
  - spec/tmp/.gitkeep
279
249
  - spec/unit/forge/connection/connection_failure_spec.rb
280
250
  - spec/unit/forge/connection_spec.rb
281
251
  - spec/unit/forge/lazy_accessors_spec.rb
282
252
  - spec/unit/forge/lazy_relations_spec.rb
283
- - spec/unit/forge/middleware/symbolify_json_spec.rb
284
253
  - spec/unit/forge/tar/mini_spec.rb
285
254
  - spec/unit/forge/tar_spec.rb
286
255
  - spec/unit/forge/unpacker_spec.rb
@@ -304,15 +273,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
304
273
  requirements:
305
274
  - - ">="
306
275
  - !ruby/object:Gem::Version
307
- version: 1.9.3
276
+ version: 2.4.0
308
277
  required_rubygems_version: !ruby/object:Gem::Requirement
309
278
  requirements:
310
279
  - - ">="
311
280
  - !ruby/object:Gem::Version
312
281
  version: '0'
313
282
  requirements: []
314
- rubyforge_project:
315
- rubygems_version: 2.7.7
283
+ rubygems_version: 3.0.8
316
284
  signing_key:
317
285
  specification_version: 4
318
286
  summary: Access the Puppet Forge API from Ruby for resource information and to download
@@ -348,16 +316,12 @@ test_files:
348
316
  - spec/fixtures/v3/releases__module=puppetlabs-apache.json
349
317
  - spec/fixtures/v3/users/puppetlabs.headers
350
318
  - spec/fixtures/v3/users/puppetlabs.json
351
- - spec/integration/forge/v3/module_spec.rb
352
- - spec/integration/forge/v3/release_spec.rb
353
- - spec/integration/forge/v3/user_spec.rb
354
319
  - spec/spec_helper.rb
355
320
  - spec/tmp/.gitkeep
356
321
  - spec/unit/forge/connection/connection_failure_spec.rb
357
322
  - spec/unit/forge/connection_spec.rb
358
323
  - spec/unit/forge/lazy_accessors_spec.rb
359
324
  - spec/unit/forge/lazy_relations_spec.rb
360
- - spec/unit/forge/middleware/symbolify_json_spec.rb
361
325
  - spec/unit/forge/tar/mini_spec.rb
362
326
  - spec/unit/forge/tar_spec.rb
363
327
  - spec/unit/forge/unpacker_spec.rb
@@ -1,22 +0,0 @@
1
- dist: xenial
2
- language: ruby
3
- rvm:
4
- - 2.6
5
- - 2.5
6
- - 2.3
7
- - 2.1
8
- # TODO: enable integration testing
9
- script: bundle exec rspec spec/unit
10
- jobs:
11
- include:
12
- - stage: deploy
13
- if: tag IS present
14
- rvm: 2.6
15
- script: echo "Deploying to rubygems.org..."
16
- deploy:
17
- on:
18
- all_branches: true
19
- provider: rubygems
20
- gem: puppet_forge
21
- api_key:
22
- secure: 066s1nJoYzCPzujfTAZ1OiDbbHghLIfW2SxZ/xTom7SbtYlb4SVOUkzOr6dLMysUBAWLQRwiFvgNij+iWwHoNEPqNA+JeGZIiL32ShQI0NW+lTcjPzeAe8Ppy/1pxgXFSJAPHLzdpdgiK91eM4vMWHIaOqPeT/4+X2+kmWbg71E=
@@ -1,13 +0,0 @@
1
- If you'd like to make a change to this library, you should contact at least one
2
- of the maintainers listed below. They will be able to discuss the change with
3
- you and decide the next best step. The maintainers will also be notified of pull
4
- requests as described in the README. This maintainers file should be kept up to
5
- date with the current maintainers of the project.
6
-
7
- If you need to contact the maintainers of this project you should email
8
- info@puppetlabs.com.
9
-
10
- Alex Dreyer, Puppet Labs
11
- Anderson Mills, Puppet Labs
12
- Jesse Scott, Puppet Labs
13
-
@@ -1,72 +0,0 @@
1
- module PuppetForge
2
- module Middleware
3
-
4
- # SymbolifyJson is a Faraday Middleware that will process any response formatted as a hash
5
- # and change all the keys into symbols (as long as they respond to the method #to_sym.
6
- #
7
- # This middleware makes no changes to the values of the hash.
8
- # If the response is not a hash, no changes will be made.
9
- class SymbolifyJson < Faraday::Middleware
10
-
11
- # Processes an array
12
- #
13
- # @return an array with any hash's keys turned into symbols if possible
14
- def process_array(array)
15
- array.map do |arg|
16
- # Search any arrays and hashes for hash keys
17
- if arg.is_a? Hash
18
- process_hash(arg)
19
- elsif arg.is_a? Array
20
- process_array(arg)
21
- else
22
- arg
23
- end
24
- end
25
- end
26
-
27
- # Processes a hash
28
- #
29
- # @return a hash with all keys turned into symbols if possible
30
- def process_hash(hash)
31
-
32
- # hash.map returns an array in the format
33
- # [ [key, value], [key2, value2], ... ]
34
- # Hash[] converts that into a hash in the format
35
- # { key => value, key2 => value2, ... }
36
- Hash[hash.map do |key, val|
37
- # Convert to a symbol if possible
38
- if key.respond_to? :to_sym
39
- new_key = key.to_sym
40
- else
41
- new_key = key
42
- end
43
-
44
- # If value is a hash or array look for more hash keys inside.
45
- if val.is_a?(Hash)
46
- [new_key, process_hash(val)]
47
- elsif val.is_a?(Array)
48
- [new_key, process_array(val)]
49
- else
50
- [new_key, val]
51
- end
52
- end]
53
- end
54
-
55
- def process_response(env)
56
- if !env["body"].nil? && env["body"].is_a?(Hash)
57
- process_hash(env.body)
58
- else
59
- env.body
60
- end
61
- end
62
-
63
- def call(environment)
64
- @app.call(environment).on_complete do |env|
65
- env.body = process_response(env)
66
- end
67
- end
68
-
69
- end
70
- end
71
- end
72
-
@@ -1,119 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe PuppetForge::V3::Module do
4
- before do
5
- PuppetForge.host = "https://forge-aio01-petest.puppetlabs.com/"
6
- PuppetForge::V3::Base.conn = PuppetForge::Connection.make_connection(PuppetForge.host, nil, {:ssl => {:verify => false} })
7
- end
8
-
9
- context "::find" do
10
- context "gets information on an existing module and" do
11
- let (:mod) { PuppetForge::V3::Module.find('puppetforgegemtesting-thorin') }
12
- let (:mod_stateless) { PuppetForge::V3::Module.find_stateless('puppetforgegemtesting-thorin') }
13
-
14
- it "returns a PuppetForge::V3::Module." do
15
- expect(mod).to be_a(PuppetForge::V3::Module)
16
- end
17
-
18
- it "returns a PuppetForge::V3::Module from a stateless call." do
19
- expect(mod_stateless).to be_a(PuppetForge::V3::Module)
20
- end
21
-
22
- it "exposes the API information." do
23
- expect(mod).to respond_to(:uri)
24
- expect(mod).to respond_to(:owner)
25
- expect(mod).to respond_to(:current_release)
26
- expect(mod).to respond_to(:releases)
27
-
28
- expect(mod.uri).to be_a(String)
29
- expect(mod.owner).to be_a(PuppetForge::V3::User)
30
- expect(mod.current_release).to be_a(PuppetForge::V3::Release)
31
- expect(mod.releases.first).to be_a(PuppetForge::V3::Release)
32
- end
33
-
34
- end
35
-
36
- context "raises Faraday::ResourceNotFound when" do
37
- let (:mod) { PuppetForge::V3::Module.find('puppetforgegemtesting-bilbo') }
38
-
39
- it "the module does not exist" do
40
- expect { mod }.to raise_error(Faraday::ResourceNotFound)
41
- end
42
-
43
- end
44
-
45
- end
46
-
47
- context "::where" do
48
- context "finds matching resources" do
49
-
50
- it "only returns modules that match the query" do
51
- modules = PuppetForge::V3::Module.where(:owner => 'puppetforgegemtesting')
52
-
53
- expect(modules).to be_a(PuppetForge::V3::Base::PaginatedCollection)
54
- modules.each do |mod|
55
- expect(mod.owner.username).to eq('puppetforgegemtesting')
56
- end
57
-
58
- end
59
-
60
- it "returns a paginated response" do
61
- modules = PuppetForge::V3::Module.where(:owner => 'puppetforgegemtesting', :limit => 1)
62
-
63
- expect(modules.limit).to eq(1)
64
- expect(modules.total).to eq(2)
65
-
66
- expect(modules.next).not_to be_nil
67
- end
68
-
69
- end
70
-
71
- context "does not find matching resources" do
72
- it "returns an empty PaginatedCollection" do
73
- modules = PuppetForge::V3::Module.where(:owner => 'absentuser')
74
-
75
- expect(modules).to be_a(PuppetForge::V3::Base::PaginatedCollection)
76
-
77
- expect(modules.size).to eq(0)
78
- expect(modules.empty?).to be(true)
79
- end
80
- end
81
- end
82
-
83
- context "::where_stateless" do
84
- context "finds matching resources" do
85
-
86
- it "only returns modules that match the query" do
87
- modules = PuppetForge::V3::Module.where_stateless(:owner => 'puppetforgegemtesting')
88
-
89
- expect(modules).to be_a(PuppetForge::V3::Base::PaginatedCollection)
90
- modules.each do |mod|
91
- expect(mod.owner.username).to eq('puppetforgegemtesting')
92
- end
93
-
94
- end
95
-
96
- it "returns a paginated response" do
97
- modules = PuppetForge::V3::Module.where_stateless(:owner => 'puppetforgegemtesting', :limit => 1)
98
-
99
- expect(modules.limit).to eq(1)
100
- expect(modules.total).to eq(2)
101
-
102
- expect(modules.next).not_to be_nil
103
- end
104
-
105
- end
106
-
107
- context "does not find matching resources" do
108
- it "returns an empty PaginatedCollection" do
109
- modules = PuppetForge::V3::Module.where_stateless(:owner => 'absentuser')
110
-
111
- expect(modules).to be_a(PuppetForge::V3::Base::PaginatedCollection)
112
-
113
- expect(modules.size).to eq(0)
114
- expect(modules.empty?).to be(true)
115
- end
116
- end
117
- end
118
- end
119
-
@@ -1,75 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe PuppetForge::V3::Release do
4
- before do
5
- PuppetForge.host = "https://forge-aio01-petest.puppetlabs.com/"
6
- PuppetForge::V3::Base.conn = PuppetForge::Connection.make_connection(PuppetForge.host, nil, {:ssl => {:verify => false} })
7
- end
8
-
9
- context "#find" do
10
- context "when the release exists," do
11
-
12
- it "find returns a PuppetForge::V3::Release." do
13
- release = PuppetForge::V3::Release.find('puppetforgegemtesting-thorin-0.0.1')
14
-
15
- expect(release).to be_a(PuppetForge::V3::Release)
16
- end
17
-
18
- it "it exposes the API information." do
19
- release = PuppetForge::V3::Release.find('puppetforgegemtesting-thorin-0.0.1')
20
-
21
- expect(release).to respond_to(:uri)
22
-
23
- expect(release.uri).to be_a(String)
24
- end
25
-
26
- end
27
-
28
- context "when the release doesn't exist," do
29
- let (:release) { PuppetForge::V3::Release.find('puppetforgegemtesting-bilbo-0.0.1') }
30
-
31
- it "find returns nil." do
32
- expect { release }.to raise_error(Faraday::ResourceNotFound)
33
- end
34
-
35
- end
36
-
37
- end
38
-
39
- context "::where" do
40
- context "finds matching resources" do
41
-
42
- it "only returns releases that match the query" do
43
- releases = PuppetForge::V3::Release.where(:module => 'puppetforgegemtesting-thorin')
44
-
45
- expect(releases).to be_a(PuppetForge::V3::Base::PaginatedCollection)
46
-
47
- expect(releases.first.version).to eq("0.0.2")
48
- expect(releases[1].version).to eq("0.0.1")
49
-
50
- end
51
-
52
- it "returns a paginated response" do
53
- releases = PuppetForge::V3::Release.where(:module => 'puppetforgegemtesting-thorin', :limit => 1)
54
-
55
- expect(releases.limit).to eq(1)
56
- expect(releases.total).to eq(2)
57
-
58
- expect(releases.next).not_to be_nil
59
- end
60
-
61
- end
62
-
63
- context "does not find matching resources" do
64
- it "returns an empty PaginatedCollection" do
65
- releases = PuppetForge::V3::Release.where(:module => 'puppetforgegemtesting-notamodule')
66
-
67
- expect(releases).to be_a(PuppetForge::V3::Base::PaginatedCollection)
68
-
69
- expect(releases.size).to eq(0)
70
- expect(releases.empty?).to be(true)
71
- end
72
- end
73
- end
74
- end
75
-
@@ -1,70 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe PuppetForge::V3::User do
4
- before do
5
- PuppetForge.host = "https://forge-aio01-petest.puppetlabs.com/"
6
- PuppetForge::V3::Base.conn = PuppetForge::Connection.make_connection(PuppetForge.host, nil, {:ssl => {:verify => false} })
7
- end
8
-
9
- context "#find" do
10
- context "when the user exists," do
11
-
12
- it "find returns a PuppetForge::V3::User." do
13
- user = PuppetForge::V3::User.find('puppetforgegemtesting')
14
- expect(user).to be_a(PuppetForge::V3::User)
15
- end
16
-
17
- it "it exposes the API information." do
18
- user = PuppetForge::V3::User.find('puppetforgegemtesting')
19
-
20
- expect(user).to respond_to(:uri)
21
- expect(user).to respond_to(:modules)
22
-
23
- expect(user.uri).to be_a(String)
24
- expect(user.modules).to be_a(PuppetForge::V3::Base::PaginatedCollection)
25
- end
26
-
27
- end
28
-
29
- context "when the user doesn't exists," do
30
- let (:user) { PuppetForge::V3::User.find('notauser') }
31
-
32
- it "find returns nil." do
33
- expect { user }.to raise_error(Faraday::ResourceNotFound)
34
- end
35
-
36
- end
37
- end
38
-
39
- context "::where" do
40
- context "finds matching resources" do
41
-
42
- it "returns sorted users" do
43
- users = PuppetForge::V3::User.where(:sort_by => 'releases')
44
-
45
- expect(users).to be_a(PuppetForge::V3::Base::PaginatedCollection)
46
-
47
- previous_releases = users.first.release_count
48
- users.each do |user|
49
- expect(user.release_count).to be <= previous_releases
50
- previous_releases = user.release_count
51
- end
52
-
53
- end
54
-
55
- it "returns a paginated response" do
56
- users = PuppetForge::V3::User.where(:limit => 1)
57
-
58
- expect(users.limit).to eq(1)
59
-
60
- 2.times do
61
- expect(users).not_to be_nil
62
- users = users.next
63
- end
64
- end
65
-
66
- end
67
-
68
- end
69
- end
70
-
@@ -1,63 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe PuppetForge::Middleware::SymbolifyJson do
4
- let(:basic_array) { [1, "two", 3] }
5
- let(:basic_hash) { { "id" => 1, "data" => "x" } }
6
- let(:symbolified_hash) { { :id => 1, :data => "x" } }
7
- let(:internal_hash) { { :id => 2, :data => basic_hash } }
8
-
9
- let(:hash_with_array) { { "id" => 3, "data" => basic_array } }
10
- let(:array_with_hash) { [1, "two", basic_hash] }
11
-
12
- let(:complex_array) { [array_with_hash, hash_with_array] }
13
- let(:complex_hash) { { "id" => 4, "data" => [complex_array, basic_array], "more_data" => hash_with_array } }
14
- let(:complex_request) { { "id" => 5, "data" => complex_hash } }
15
-
16
- let(:middleware) { described_class.new() }
17
-
18
- context "#process_array" do
19
- it "doesn't change an array with no array or hash inside" do
20
- processed_array = middleware.process_array(basic_array)
21
- expect(processed_array).to eql( [1, "two", 3] )
22
- end
23
-
24
- it "changes all keys of a hash inside the array" do
25
- processed_array = middleware.process_array(array_with_hash)
26
- expect(processed_array).to eql( [ 1, "two", { :id => 1, :data => "x" } ] )
27
- end
28
- end
29
-
30
- context "#process_hash" do
31
- it "changes all keys that respond to :to_sym into Symbols and doesn't change values." do
32
- processed_hash = middleware.process_hash(basic_hash)
33
- expect(processed_hash).to eql( { :id => 1, :data => "x" } )
34
- end
35
-
36
- it "doesn't change keys that don't respond to :to_sym" do
37
- processed_hash = middleware.process_hash(basic_hash.merge({ 1 => 2 }))
38
- expect(processed_hash).to eql( { :id => 1, :data => "x", 1 => 2 } )
39
- end
40
-
41
- it "can process a hash that is already symbolified" do
42
- processed_hash = middleware.process_hash(symbolified_hash)
43
- expect(processed_hash).to eql( { :id => 1, :data => "x" })
44
- end
45
-
46
- it "can process a hash with a hash inside of it" do
47
- processed_hash = middleware.process_hash(internal_hash)
48
- expect(processed_hash).to eql( {:id => 2, :data => { :id => 1, :data => "x" } })
49
- end
50
-
51
- it "can process a hash with an array inside of it" do
52
- processed_hash = middleware.process_hash(hash_with_array)
53
- expect(processed_hash).to eql( { :id => 3, :data => [1, "two", 3] } )
54
- end
55
-
56
- it "can handle extensively nested arrays and hashes" do
57
- processed_hash = middleware.process_hash(complex_request)
58
- expect(processed_hash).to eql( { :id => 5, :data => { :id => 4 , :data=>[ [ [1, "two", { :id => 1, :data => "x" } ], { :id=>3, :data => [1, "two", 3] } ], [1, "two", 3] ], :more_data => { :id => 3, :data => [1, "two", 3] } } } )
59
- end
60
- end
61
-
62
- end
63
-