puppet_forge 2.3.3 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/workflows/ruby-rspec.yml +6 -6
- data/.gitignore +0 -1
- data/CHANGELOG.md +24 -0
- data/README.md +16 -17
- data/Rakefile +0 -6
- data/lib/puppet_forge/connection/connection_failure.rb +3 -13
- data/lib/puppet_forge/connection.rb +6 -5
- data/lib/puppet_forge/error.rb +6 -2
- data/lib/puppet_forge/lazy_relations.rb +1 -1
- data/lib/puppet_forge/unpacker.rb +2 -2
- data/lib/puppet_forge/v3/base.rb +1 -1
- data/lib/puppet_forge/v3/metadata.rb +9 -8
- data/lib/puppet_forge/v3/release.rb +1 -1
- data/lib/puppet_forge/version.rb +1 -1
- data/lib/puppet_forge.rb +1 -4
- data/puppet_forge.gemspec +5 -6
- data/spec/fixtures/v3/modules/puppetlabs-apache.json +1 -1
- data/spec/fixtures/v3/modules.json +19 -19
- data/spec/fixtures/v3/modules__owner=puppetlabs.json +19 -19
- data/spec/fixtures/v3/modules__query=apache.json +6 -6
- data/spec/fixtures/v3/releases/puppetlabs-apache-0.1.1.json +2 -2
- data/spec/fixtures/v3/releases.json +14 -14
- data/spec/fixtures/v3/releases__module=puppetlabs-apache.json +14 -14
- data/spec/spec_helper.rb +1 -2
- data/spec/unit/forge/connection_spec.rb +36 -7
- data/spec/unit/forge/v3/metadata_spec.rb +0 -40
- metadata +12 -49
- data/lib/puppet_forge/middleware/symbolify_json.rb +0 -72
- data/locales/config.yaml +0 -21
- data/spec/unit/forge/middleware/symbolify_json_spec.rb +0 -63
data/spec/spec_helper.rb
CHANGED
@@ -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.
|
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
|
|
@@ -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.
|
5
|
+
PuppetForge.host = "https://forgeapi.puppet.com"
|
6
6
|
end
|
7
7
|
|
8
8
|
let(:test_conn) do
|
@@ -88,16 +88,45 @@ describe PuppetForge::Connection do
|
|
88
88
|
|
89
89
|
expect {
|
90
90
|
subject.get('/error')
|
91
|
-
}.to raise_error(Faraday::
|
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
|
95
|
-
|
96
|
-
|
95
|
+
let(:key) { "abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789" }
|
96
|
+
let(:prepended_key) { "Bearer #{key}" }
|
97
|
+
|
98
|
+
context 'when the key already includes the Bearer prefix as expected' do
|
99
|
+
before(:each) do
|
100
|
+
allow(described_class).to receive(:authorization).and_return(prepended_key)
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'does not prepend it again' do
|
104
|
+
expect(subject.headers).to include(:authorization => prepended_key)
|
105
|
+
end
|
97
106
|
end
|
98
107
|
|
99
|
-
|
100
|
-
|
108
|
+
context 'when the key does not includ the Bearer prefix' do
|
109
|
+
context 'when the value looks like a Forge API key' do
|
110
|
+
before(:each) do
|
111
|
+
allow(described_class).to receive(:authorization).and_return(key)
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'prepends "Bearer"' do
|
115
|
+
expect(subject.headers).to include(:authorization => prepended_key)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context 'when the value does not look like a Forge API key' do
|
120
|
+
let(:key) { "auth-test value" }
|
121
|
+
|
122
|
+
before(:each) do
|
123
|
+
allow(described_class).to receive(:authorization).and_return(key)
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'does not alter the value' do
|
127
|
+
expect(subject.headers).to include(:authorization => key)
|
128
|
+
end
|
129
|
+
end
|
101
130
|
end
|
102
131
|
end
|
103
132
|
|
@@ -115,7 +144,7 @@ describe PuppetForge::Connection do
|
|
115
144
|
describe 'creating a default connection' do
|
116
145
|
it 'creates a connection with the PuppetForge host' do
|
117
146
|
conn = test_conn.default_connection
|
118
|
-
expect(conn.url_prefix.to_s).to eq 'https://forgeapi.
|
147
|
+
expect(conn.url_prefix.to_s).to eq 'https://forgeapi.puppet.com/'
|
119
148
|
end
|
120
149
|
end
|
121
150
|
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,61 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet_forge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 3.2.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:
|
11
|
+
date: 2021-11-09 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
|
-
- - "<"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 0.18.0
|
23
|
-
- - "!="
|
17
|
+
- - "~>"
|
24
18
|
- !ruby/object:Gem::Version
|
25
|
-
version:
|
19
|
+
version: '1.3'
|
26
20
|
type: :runtime
|
27
21
|
prerelease: false
|
28
22
|
version_requirements: !ruby/object:Gem::Requirement
|
29
23
|
requirements:
|
30
|
-
- - "
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 0.9.0
|
33
|
-
- - "<"
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
version: 0.18.0
|
36
|
-
- - "!="
|
24
|
+
- - "~>"
|
37
25
|
- !ruby/object:Gem::Version
|
38
|
-
version:
|
26
|
+
version: '1.3'
|
39
27
|
- !ruby/object:Gem::Dependency
|
40
28
|
name: faraday_middleware
|
41
29
|
requirement: !ruby/object:Gem::Requirement
|
42
30
|
requirements:
|
43
|
-
- - "
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: 0.9.0
|
46
|
-
- - "<"
|
31
|
+
- - "~>"
|
47
32
|
- !ruby/object:Gem::Version
|
48
|
-
version:
|
33
|
+
version: '1.0'
|
49
34
|
type: :runtime
|
50
35
|
prerelease: false
|
51
36
|
version_requirements: !ruby/object:Gem::Requirement
|
52
37
|
requirements:
|
53
|
-
- - "
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: 0.9.0
|
56
|
-
- - "<"
|
38
|
+
- - "~>"
|
57
39
|
- !ruby/object:Gem::Version
|
58
|
-
version:
|
40
|
+
version: '1.0'
|
59
41
|
- !ruby/object:Gem::Dependency
|
60
42
|
name: semantic_puppet
|
61
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,20 +66,6 @@ dependencies:
|
|
84
66
|
- - ">="
|
85
67
|
- !ruby/object:Gem::Version
|
86
68
|
version: '0'
|
87
|
-
- !ruby/object:Gem::Dependency
|
88
|
-
name: gettext-setup
|
89
|
-
requirement: !ruby/object:Gem::Requirement
|
90
|
-
requirements:
|
91
|
-
- - "~>"
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
version: '0.11'
|
94
|
-
type: :runtime
|
95
|
-
prerelease: false
|
96
|
-
version_requirements: !ruby/object:Gem::Requirement
|
97
|
-
requirements:
|
98
|
-
- - "~>"
|
99
|
-
- !ruby/object:Gem::Version
|
100
|
-
version: '0.11'
|
101
69
|
- !ruby/object:Gem::Dependency
|
102
70
|
name: rake
|
103
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -218,7 +186,6 @@ files:
|
|
218
186
|
- lib/puppet_forge/error.rb
|
219
187
|
- lib/puppet_forge/lazy_accessors.rb
|
220
188
|
- lib/puppet_forge/lazy_relations.rb
|
221
|
-
- lib/puppet_forge/middleware/symbolify_json.rb
|
222
189
|
- lib/puppet_forge/tar.rb
|
223
190
|
- lib/puppet_forge/tar/mini.rb
|
224
191
|
- lib/puppet_forge/unpacker.rb
|
@@ -231,7 +198,6 @@ files:
|
|
231
198
|
- lib/puppet_forge/v3/release.rb
|
232
199
|
- lib/puppet_forge/v3/user.rb
|
233
200
|
- lib/puppet_forge/version.rb
|
234
|
-
- locales/config.yaml
|
235
201
|
- puppet_forge.gemspec
|
236
202
|
- spec/fixtures/uri/prefix/v3/bases/puppet.headers
|
237
203
|
- spec/fixtures/uri/prefix/v3/bases/puppet.json
|
@@ -269,7 +235,6 @@ files:
|
|
269
235
|
- spec/unit/forge/connection_spec.rb
|
270
236
|
- spec/unit/forge/lazy_accessors_spec.rb
|
271
237
|
- spec/unit/forge/lazy_relations_spec.rb
|
272
|
-
- spec/unit/forge/middleware/symbolify_json_spec.rb
|
273
238
|
- spec/unit/forge/tar/mini_spec.rb
|
274
239
|
- spec/unit/forge/tar_spec.rb
|
275
240
|
- spec/unit/forge/unpacker_spec.rb
|
@@ -293,15 +258,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
293
258
|
requirements:
|
294
259
|
- - ">="
|
295
260
|
- !ruby/object:Gem::Version
|
296
|
-
version:
|
261
|
+
version: 2.4.0
|
297
262
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
298
263
|
requirements:
|
299
264
|
- - ">="
|
300
265
|
- !ruby/object:Gem::Version
|
301
266
|
version: '0'
|
302
267
|
requirements: []
|
303
|
-
|
304
|
-
rubygems_version: 2.6.14
|
268
|
+
rubygems_version: 3.1.6
|
305
269
|
signing_key:
|
306
270
|
specification_version: 4
|
307
271
|
summary: Access the Puppet Forge API from Ruby for resource information and to download
|
@@ -343,7 +307,6 @@ test_files:
|
|
343
307
|
- spec/unit/forge/connection_spec.rb
|
344
308
|
- spec/unit/forge/lazy_accessors_spec.rb
|
345
309
|
- spec/unit/forge/lazy_relations_spec.rb
|
346
|
-
- spec/unit/forge/middleware/symbolify_json_spec.rb
|
347
310
|
- spec/unit/forge/tar/mini_spec.rb
|
348
311
|
- spec/unit/forge/tar_spec.rb
|
349
312
|
- spec/unit/forge/unpacker_spec.rb
|
@@ -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
|
-
|
data/locales/config.yaml
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
---
|
2
|
-
# This is the project-specific configuration file for setting up
|
3
|
-
# fast_gettext for your project.
|
4
|
-
gettext:
|
5
|
-
# This is used for the name of the .pot and .po files; they will be
|
6
|
-
# called <project_name>.pot?
|
7
|
-
project_name: 'forge-ruby'
|
8
|
-
# This is used in comments in the .pot and .po files to indicate what
|
9
|
-
# project the files belong to and should bea little more desctiptive than
|
10
|
-
# <project_name>
|
11
|
-
package_name: Puppet Forge Gem
|
12
|
-
# The locale that the default messages in the .pot file are in
|
13
|
-
default_locale: en
|
14
|
-
# The email used for sending bug reports.
|
15
|
-
bugs_address: docs@puppetlabs.com
|
16
|
-
# The holder of the copyright.
|
17
|
-
copyright_holder: Puppet, Inc.
|
18
|
-
# Patterns for +Dir.glob+ used to find all files that might contain
|
19
|
-
# translatable content, relative to the project root directory
|
20
|
-
source_files:
|
21
|
-
- 'lib/**/*.rb'
|
@@ -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
|
-
|