puppet_forge 2.3.3 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 14fb262a13e9382bc404ebf162e70c8fa48ccd73f33f53113e75524da106bed9
|
4
|
+
data.tar.gz: 0316cbac8bd7c7d3dc18d792a0dfc25a4cca095fce0974a5f54a50e546ef1c92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f909a3a4b8bf942f104f1a9f5a798edeb8a29e03adaaa24dbd4170efd97f2e09c23ef44b3b88ad406d32d5d10aba98d382d21ce10e1db115ee5c87d8cd01e30f
|
7
|
+
data.tar.gz: 2da931edf4e563a6e0962d834c9e3db3dec6ff33fd9a172f5d50a12066863b336fae173c8ad860d6c85f6df1ef02da4e1e0fc61e0a3182e92552ac988db3ce7b
|
@@ -3,10 +3,10 @@ name: ruby-rspec
|
|
3
3
|
on:
|
4
4
|
push:
|
5
5
|
branches:
|
6
|
-
-
|
6
|
+
- main
|
7
7
|
pull_request:
|
8
8
|
branches:
|
9
|
-
-
|
9
|
+
- main
|
10
10
|
|
11
11
|
jobs:
|
12
12
|
test:
|
@@ -14,14 +14,14 @@ jobs:
|
|
14
14
|
runs-on: ubuntu-latest
|
15
15
|
strategy:
|
16
16
|
matrix:
|
17
|
-
|
17
|
+
ruby: [2.7, 2.6, 2.5]
|
18
18
|
|
19
19
|
steps:
|
20
20
|
- uses: actions/checkout@v1
|
21
|
-
- name: Set up Ruby ${{ matrix.
|
22
|
-
uses:
|
21
|
+
- name: Set up Ruby ${{ matrix.ruby }}
|
22
|
+
uses: ruby/setup-ruby@v1
|
23
23
|
with:
|
24
|
-
ruby-version: ${{ matrix.
|
24
|
+
ruby-version: ${{ matrix.ruby }}
|
25
25
|
|
26
26
|
- name: Build and test with Rspec
|
27
27
|
run: |
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,30 @@
|
|
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.2.0 - 2021-11-09
|
7
|
+
|
8
|
+
* Allow requests to follow redirects
|
9
|
+
* Remove the `gettext-setup` gem dependency, which was unused
|
10
|
+
|
11
|
+
## v3.1.0 - 2021-08-20
|
12
|
+
|
13
|
+
### Changed
|
14
|
+
|
15
|
+
* Update `PuppetForge::Connection.authorization` so that it prepends the
|
16
|
+
required `Bearer ` string automatically to values that look like Forge API
|
17
|
+
keys. This won't affect values that already include `Bearer `.
|
18
|
+
|
19
|
+
## v3.0.0 - 2021-01-28
|
20
|
+
|
21
|
+
* Breaking: The `puppet_forge` gem now requires at least Ruby 2.4.0.
|
22
|
+
* Update `faraday` and `faraday_middleware` gem dependencies to 1.x series.
|
23
|
+
* Update optional `typhoeus` dependency to `>= 1.4` to maintain compatibility with `faraday`.
|
24
|
+
|
25
|
+
## v2.3.4 - 2020-03-31
|
26
|
+
|
27
|
+
* Update the forge API url to `forgeapi.puppet.com` (instead of using the older puppetlabs.com domain).
|
28
|
+
* Allow versions of the `faraday_middleware` dependency up to 0.15.
|
29
|
+
|
6
30
|
## v2.3.3 - 2020-02-20
|
7
31
|
|
8
32
|
### Changed
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Puppet Forge
|
2
2
|
|
3
|
-
Access and manipulate the [Puppet Forge API](https://forgeapi.
|
3
|
+
Access and manipulate the [Puppet Forge API](https://forgeapi.puppet.com)
|
4
4
|
from Ruby.
|
5
5
|
|
6
6
|
## Installation
|
@@ -81,13 +81,14 @@ resource model are documented on the [Resource Reference][resource_ref] page.
|
|
81
81
|
Each of the models uses ActiveRecord-like REST functionality to map over the Forge API endpoints.
|
82
82
|
Most simple ActiveRecord-style interactions function as intended.
|
83
83
|
|
84
|
-
Currently, only
|
84
|
+
Currently, only read-only actions are supported.
|
85
85
|
|
86
86
|
The methods find, where, and all immediately make one API request.
|
87
87
|
|
88
88
|
```ruby
|
89
89
|
# Find a Resource by Slug
|
90
|
-
PuppetForge::User.find('puppetlabs') # => #<
|
90
|
+
PuppetForge::User.find('puppetlabs') # => #<PuppetForge::V3::User(/v3/users/puppetlabs)>
|
91
|
+
PuppetForge::Module.find('puppetlabs-stdlib') # => #<PuppetForge::V3::Module(/v3/modules/puppetlabs-stdlib)>
|
91
92
|
|
92
93
|
# Find All Resources
|
93
94
|
PuppetForge::Module.all # See "Paginated Collections" below for important info about enumerating resource sets.
|
@@ -109,7 +110,7 @@ PuppetForge::Module.where(query: 'apache').all # This method is deprecated and n
|
|
109
110
|
All API Requests (whether via find, where, or all) will raise a Faraday::ResourceNotFound error if the request fails.
|
110
111
|
|
111
112
|
|
112
|
-
###
|
113
|
+
### Downloading and installing a module release
|
113
114
|
|
114
115
|
A release tarball can be downloaded and installed by following the steps below.
|
115
116
|
|
@@ -186,26 +187,24 @@ user.username # => "puppetlabs"
|
|
186
187
|
user.created_at # => "2010-05-19 05:46:26 -0700"
|
187
188
|
```
|
188
189
|
|
189
|
-
###
|
190
|
+
### Configuration
|
190
191
|
|
191
|
-
|
192
|
-
[writing translatable code](https://github.com/puppetlabs/gettext-setup-gem#writing-translatable-code).
|
193
|
-
|
194
|
-
The PuppetForge gem will default to outputing all error messages in English, but you may set the locale
|
195
|
-
using the `FastGettext.set_locale` method. If translations do not exist for the language you request then the gem will
|
196
|
-
default to English. The `set_locale` method will return the locale, as a string, that FastGettext will now
|
197
|
-
use to report PuppetForge errors.
|
192
|
+
To overwrite the default of `https://forgeapi.puppet.com` and set a custom url for the Forge API:
|
198
193
|
|
199
194
|
```ruby
|
200
|
-
|
201
|
-
|
195
|
+
PuppetForge.host = "https://your-own-api.url/"
|
196
|
+
```
|
197
|
+
|
198
|
+
### Authorization
|
202
199
|
|
203
|
-
|
200
|
+
To authorize your requests with an API key from a Forge user account:
|
204
201
|
|
205
|
-
|
206
|
-
|
202
|
+
```ruby
|
203
|
+
PuppetForge::Connection.authorization = "<your-api-key-here>"
|
207
204
|
```
|
208
205
|
|
206
|
+
You can generate API keys on your user profile page once you've [logged into the Forge website](https://forge.puppet.com/login).
|
207
|
+
|
209
208
|
## Caveats
|
210
209
|
|
211
210
|
This library currently does no response caching of its own, instead opting to
|
data/Rakefile
CHANGED
@@ -9,21 +9,11 @@ module PuppetForge
|
|
9
9
|
@app.call(env)
|
10
10
|
rescue Faraday::ConnectionFailed, Faraday::TimeoutError => e
|
11
11
|
baseurl = env[:url].dup
|
12
|
+
errmsg = "Unable to connect to %{scheme}://%{host}" % { scheme: baseurl.scheme, host: baseurl.host }
|
12
13
|
if proxy = env[:request][:proxy]
|
13
|
-
errmsg
|
14
|
-
scheme: baseurl.scheme,
|
15
|
-
host: baseurl.host,
|
16
|
-
proxy: proxy.uri.to_s,
|
17
|
-
path_query: baseurl.request_uri,
|
18
|
-
}
|
19
|
-
else
|
20
|
-
errmsg = _("Unable to connect to %{scheme}://%{host} (for request %{path_query})") % {
|
21
|
-
scheme: baseurl.scheme,
|
22
|
-
host: baseurl.host,
|
23
|
-
path_query: baseurl.request_uri,
|
24
|
-
}
|
14
|
+
errmsg << " (using proxy %{proxy})" % { proxy: proxy.uri.to_s }
|
25
15
|
end
|
26
|
-
errmsg << ":
|
16
|
+
errmsg << " (for request %{path_query}): %{message}" % { message: e.message, path_query: baseurl.request_uri }
|
27
17
|
m = Faraday::ConnectionFailed.new(errmsg)
|
28
18
|
m.set_backtrace(e.backtrace)
|
29
19
|
raise m
|
@@ -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.
|
@@ -24,6 +23,8 @@ module PuppetForge
|
|
24
23
|
|
25
24
|
attr_writer :conn
|
26
25
|
|
26
|
+
AUTHORIZATION_TOKEN_REGEX = /^[a-f0-9]{64}$/
|
27
|
+
|
27
28
|
USER_AGENT = "#{PuppetForge.user_agent} PuppetForge.gem/#{PuppetForge::VERSION} Faraday/#{Faraday::VERSION} Ruby/#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} (#{RUBY_PLATFORM})".strip
|
28
29
|
|
29
30
|
def self.authorization=(token)
|
@@ -81,7 +82,7 @@ module PuppetForge
|
|
81
82
|
|
82
83
|
begin
|
83
84
|
# Use Typhoeus if available.
|
84
|
-
Gem::Specification.find_by_name('typhoeus', '~> 1.
|
85
|
+
Gem::Specification.find_by_name('typhoeus', '~> 1.4')
|
85
86
|
require 'typhoeus/adapters/faraday'
|
86
87
|
adapter = :typhoeus
|
87
88
|
rescue Gem::LoadError
|
@@ -102,7 +103,7 @@ module PuppetForge
|
|
102
103
|
options = { :headers => { :user_agent => USER_AGENT } }.merge(opts)
|
103
104
|
|
104
105
|
if token = PuppetForge::Connection.authorization
|
105
|
-
options[:headers][:authorization] = token
|
106
|
+
options[:headers][:authorization] = token =~ AUTHORIZATION_TOKEN_REGEX ? "Bearer #{token}" : token
|
106
107
|
end
|
107
108
|
|
108
109
|
if lang = PuppetForge::Connection.accept_language
|
@@ -114,8 +115,8 @@ module PuppetForge
|
|
114
115
|
end
|
115
116
|
|
116
117
|
Faraday.new(url, options) do |builder|
|
117
|
-
builder.use
|
118
|
-
builder.response(:json, :content_type => /\bjson
|
118
|
+
builder.use FaradayMiddleware::FollowRedirects
|
119
|
+
builder.response(:json, :content_type => /\bjson$/, :parser_options => { :symbolize_names => true })
|
119
120
|
builder.response(:raise_error)
|
120
121
|
builder.use(:connection_failure)
|
121
122
|
|
data/lib/puppet_forge/error.rb
CHANGED
@@ -16,11 +16,15 @@ module PuppetForge
|
|
16
16
|
def initialize(options)
|
17
17
|
@entry_path = options[:entry_path]
|
18
18
|
@directory = options[:directory]
|
19
|
-
super
|
19
|
+
super "Attempt to install file into #{@entry_path.inspect} under #{@directory.inspect}"
|
20
20
|
end
|
21
21
|
|
22
22
|
def multiline
|
23
|
-
|
23
|
+
<<-MSG.strip
|
24
|
+
Could not install package
|
25
|
+
Package attempted to install file into
|
26
|
+
#{@entry_path.inspect} under #{@directory.inspect}.
|
27
|
+
MSG
|
24
28
|
end
|
25
29
|
end
|
26
30
|
|
@@ -24,7 +24,7 @@ module PuppetForge
|
|
24
24
|
version = class_name.split("::")[-2]
|
25
25
|
|
26
26
|
if version.nil?
|
27
|
-
raise RuntimeError,
|
27
|
+
raise RuntimeError, "Unable to determine the parent PuppetForge version module"
|
28
28
|
end
|
29
29
|
|
30
30
|
PuppetForge.const_get(version)
|
@@ -39,7 +39,7 @@ module PuppetForge
|
|
39
39
|
begin
|
40
40
|
PuppetForge::Tar.instance.unpack(@filename, @tmpdir)
|
41
41
|
rescue PuppetForge::ExecutionFailure => e
|
42
|
-
raise RuntimeError,
|
42
|
+
raise RuntimeError, "Could not extract contents of module archive: #{e.message}"
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -61,7 +61,7 @@ module PuppetForge
|
|
61
61
|
if metadata_file
|
62
62
|
@root_dir = Pathname.new(metadata_file).dirname
|
63
63
|
else
|
64
|
-
raise
|
64
|
+
raise "No valid metadata.json found!"
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
data/lib/puppet_forge/v3/base.rb
CHANGED
@@ -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
|
|
@@ -63,7 +63,7 @@ module PuppetForge
|
|
63
63
|
validate_version_range(version_requirement) if version_requirement
|
64
64
|
|
65
65
|
if dup = @data['dependencies'].find { |d| d.full_module_name == name && d.version_requirement != version_requirement }
|
66
|
-
raise ArgumentError,
|
66
|
+
raise ArgumentError, "Dependency conflict for #{full_module_name}: Dependency #{name} was given conflicting version requirements #{version_requirement} and #{dup.version_requirement}. Verify that there are no duplicates in the metadata.json or the Modulefile."
|
67
67
|
end
|
68
68
|
|
69
69
|
dep = Dependency.new(name, version_requirement, repository)
|
@@ -165,30 +165,31 @@ module PuppetForge
|
|
165
165
|
|
166
166
|
err = case modname
|
167
167
|
when nil, '', :namespace_missing
|
168
|
-
|
168
|
+
"the field must be a namespaced module name"
|
169
169
|
when /[^a-z0-9_]/i
|
170
|
-
|
170
|
+
"the module name contains non-alphanumeric (or underscore) characters"
|
171
171
|
when /^[^a-z]/i
|
172
|
-
|
172
|
+
"the module name must begin with a letter"
|
173
173
|
else
|
174
|
-
|
174
|
+
"the namespace contains non-alphanumeric characters"
|
175
175
|
end
|
176
176
|
|
177
|
-
raise ArgumentError,
|
177
|
+
raise ArgumentError, "Invalid 'name' field in metadata.json: #{err}"
|
178
178
|
end
|
179
179
|
|
180
180
|
# Validates that the version string can be parsed by SemanticPuppet.
|
181
181
|
def validate_version(version)
|
182
182
|
return if SemanticPuppet::Version.valid?(version)
|
183
183
|
|
184
|
-
|
184
|
+
err = "version string cannot be parsed as a valid Semantic Version"
|
185
|
+
raise ArgumentError, "Invalid 'version' field in metadata.json: #{err}"
|
185
186
|
end
|
186
187
|
|
187
188
|
# Validates that the version range can be parsed by SemanticPuppet.
|
188
189
|
def validate_version_range(version_range)
|
189
190
|
SemanticPuppet::VersionRange.parse(version_range)
|
190
191
|
rescue ArgumentError => e
|
191
|
-
raise ArgumentError,
|
192
|
+
raise ArgumentError, "Invalid 'version_range' field in metadata.json: #{e}"
|
192
193
|
end
|
193
194
|
end
|
194
195
|
end
|
@@ -29,7 +29,7 @@ module PuppetForge
|
|
29
29
|
resp = self.class.conn.get(download_url)
|
30
30
|
path.open('wb') { |fh| fh.write(resp.body) }
|
31
31
|
rescue Faraday::ResourceNotFound => e
|
32
|
-
raise PuppetForge::ReleaseNotFound,
|
32
|
+
raise PuppetForge::ReleaseNotFound, "The module release #{slug} does not exist on #{self.class.conn.url_prefix}.", e.backtrace
|
33
33
|
rescue Faraday::ClientError => e
|
34
34
|
if e.response && e.response[:status] == 403
|
35
35
|
raise PuppetForge::ReleaseForbidden.from_response(e.response)
|
data/lib/puppet_forge/version.rb
CHANGED
data/lib/puppet_forge.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'puppet_forge/version'
|
2
|
-
require 'gettext-setup'
|
3
2
|
|
4
3
|
module PuppetForge
|
5
4
|
class << self
|
@@ -15,9 +14,7 @@ module PuppetForge
|
|
15
14
|
end
|
16
15
|
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
DEFAULT_FORGE_HOST = 'https://forgeapi.puppetlabs.com/'
|
17
|
+
DEFAULT_FORGE_HOST = 'https://forgeapi.puppet.com/'
|
21
18
|
|
22
19
|
self.host = DEFAULT_FORGE_HOST
|
23
20
|
|
data/puppet_forge.gemspec
CHANGED
@@ -18,13 +18,12 @@ 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 = '>=
|
21
|
+
spec.required_ruby_version = '>= 2.4.0'
|
22
22
|
|
23
|
-
spec.add_runtime_dependency "faraday",
|
24
|
-
spec.add_runtime_dependency "faraday_middleware",
|
25
|
-
spec.add_dependency
|
26
|
-
spec.add_dependency
|
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"
|
28
27
|
|
29
28
|
spec.add_development_dependency "rake"
|
30
29
|
spec.add_development_dependency "rspec", "~> 3.0"
|