puppet-resource_api 1.8.3 → 1.8.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/Gemfile +4 -3
- data/README.md +20 -25
- data/lib/puppet/resource_api/glue.rb +11 -0
- data/lib/puppet/resource_api/transport.rb +62 -24
- data/lib/puppet/resource_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f6caa565c4c74ffa60028baa93976517fe6a6677e1265e29b164b91c1b8ddf7
|
4
|
+
data.tar.gz: 0d88b19fa67188d50658428a3a1a22fd3012831b2e7552fbf2d9dd5a546b2b52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12df0d25e70620dbc247bd26b4705c39d5b0d4341606d828f1aed79a152bd67934b2704b20dd29805955240e3dd972bce8f7586bf3719bdd509afe7fd1a6a219
|
7
|
+
data.tar.gz: fc3e433a2a5a2c218a64dbcb2dab12af8aa96d36ed458b9607bf997cb470afce3352d0ed966e69ee03d0c7037bc738e713aab9ad8940560c9b7a6a59f8df5c2f
|
data/.travis.yml
CHANGED
@@ -20,7 +20,7 @@ matrix:
|
|
20
20
|
cache:
|
21
21
|
bundler: true
|
22
22
|
directories: ~/.rvm
|
23
|
-
before_install: rvm use jruby-1.7.26 --install --binary --fuzzy
|
23
|
+
before_install: rvm use jruby-1.7.26 --install --binary --fuzzy && gem install bundler -v '~> 1.7.0'
|
24
24
|
# disable coverage on jruby9k as this confuses codecov
|
25
25
|
- env: RVM="jruby-9.1.9.0" PUPPET_GEM_VERSION='~> 5' JRUBY_OPTS="--debug"
|
26
26
|
before_cache: pushd ~/.rvm && rm -rf archives rubies/ruby-2.2.7 rubies/ruby-2.3.4 && popd
|
data/Gemfile
CHANGED
@@ -7,15 +7,13 @@ gemspec
|
|
7
7
|
|
8
8
|
group :tests do
|
9
9
|
gem 'codecov'
|
10
|
-
# license_finder does not install on windows using older versions of rubygems.
|
11
|
-
# ruby 2.4 is confirmed working on appveyor.
|
12
|
-
gem 'license_finder' if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.4.0')
|
13
10
|
gem 'rake', '~> 10.0'
|
14
11
|
gem 'rspec', '~> 3.0'
|
15
12
|
# rubocop 0.58 throws when testing against ruby 2.1, so pin to the latest,
|
16
13
|
# unless we're dealing with jruby...
|
17
14
|
if RUBY_PLATFORM == 'java'
|
18
15
|
# load any rubocop version that works on java for the Rakefile
|
16
|
+
gem 'parser', '2.3.3.1'
|
19
17
|
gem 'rubocop', '0.41.2'
|
20
18
|
elsif Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2.0')
|
21
19
|
gem 'rubocop', '0.57.2'
|
@@ -27,6 +25,9 @@ group :tests do
|
|
27
25
|
# This needs to be removed once we drop puppet4 support.
|
28
26
|
gem 'rubocop', '~> 0.57.0'
|
29
27
|
gem 'rubocop-rspec'
|
28
|
+
# license_finder does not install on windows using older versions of rubygems.
|
29
|
+
# ruby 2.4 is confirmed working on appveyor.
|
30
|
+
gem 'license_finder' if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.4.0')
|
30
31
|
end
|
31
32
|
gem 'simplecov-console'
|
32
33
|
# the test gems required for module testing
|
data/README.md
CHANGED
@@ -239,31 +239,26 @@ Puppet::ResourceAPI.register_transport(
|
|
239
239
|
|
240
240
|
### Transport Schema keywords
|
241
241
|
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
* `
|
249
|
-
* `
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
* `
|
259
|
-
* `
|
260
|
-
|
261
|
-
|
262
|
-
* `remote-transport` - This is used to determine which transport to load. It should always be the transport class name "declassified".
|
263
|
-
* `remote-*` Any key starting with `remote-` is reserved for future use.
|
264
|
-
* `implementations`: reserved by bolt
|
265
|
-
|
266
|
-
Note: Currently bolt inventory requires that a name be set for every target and always uses that name as the URI. This means there is no way to specify `host` separately from the host section of the `name` when parsed as a URI.
|
242
|
+
To align with [Bolt's inventory file](https://puppet.com/docs/bolt/latest/inventory_file.html), a transport schema prefers the following keywords (when relevant):
|
243
|
+
|
244
|
+
* `uri`: use when you need to specify a specific URL to connect to. Bolt will compute the following keys from the `uri` when possible. In the future more url parts may be computed from the URI.
|
245
|
+
* `protocol`: use to specify which protocol the transport should use for example `http`, `https`, `ssh` or `tcp`.
|
246
|
+
* `host`: use to specify an IP or address to connect to.
|
247
|
+
* `port`: the port the transport should connect to.
|
248
|
+
* `user`: the user the transport should connect as.
|
249
|
+
* `password`: the password for the specified user.
|
250
|
+
|
251
|
+
Do not use the following keywords when writing a schema:
|
252
|
+
|
253
|
+
* `implementations`: reserved by Bolt.
|
254
|
+
* `name`: transports should use `uri` instead of name.
|
255
|
+
* `path`: reserved as a uri part.
|
256
|
+
* `query`: reserved as a uri part.
|
257
|
+
* `remote-*`: any key starting with `remote-` is reserved for future use.
|
258
|
+
* `remote-transport`: determines which transport to load. It is always the transport class named "declassified".
|
259
|
+
* `run-on`: Bolt uses this keyword to determine which target to proxy to. Transports should not rely on this key.
|
260
|
+
|
261
|
+
> Note: Bolt inventory requires you to set a name for every target and always use it for the URI. This means that there is no way to specify `host` separately from the host section of the `name` when parsed as a URI.
|
267
262
|
|
268
263
|
After the device class, transport class and transport schema have been implemented, `puppet device` will be able to use the new provider, and supply it (through the device class) with the URL specified in the [`device.conf`](https://puppet.com/docs/puppet/5.3/config_file_device.html).
|
269
264
|
|
@@ -41,6 +41,17 @@ module Puppet::ResourceApi
|
|
41
41
|
YAML.dump('type' => { title => attributes }).split("\n").drop(2).join("\n") + "\n"
|
42
42
|
end
|
43
43
|
|
44
|
+
def to_json(*)
|
45
|
+
attrs = filtered_keys.map { |k| [k.to_s, values[k]] unless values[k].nil? }
|
46
|
+
attributes = Hash[*attrs.compact.flatten]
|
47
|
+
resource = { title => attributes }
|
48
|
+
resource.to_json
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_hash
|
52
|
+
values
|
53
|
+
end
|
54
|
+
|
44
55
|
# attribute names that are not title or namevars
|
45
56
|
def filtered_keys
|
46
57
|
values.keys.reject { |k| k == :title || !attr_def[k] || (attr_def[k][:behaviour] == :namevar && @namevars.size == 1) }
|
@@ -9,21 +9,19 @@ module Puppet::ResourceApi::Transport
|
|
9
9
|
raise Puppet::DevError, 'requires `:connection_info`' unless schema.key? :connection_info
|
10
10
|
raise Puppet::DevError, '`:connection_info` must be a hash, not `%{other_type}`' % { other_type: schema[:connection_info].class } unless schema[:connection_info].is_a?(Hash)
|
11
11
|
|
12
|
-
|
13
|
-
unless @transports[@environment][schema[:name]].nil?
|
12
|
+
unless transports[schema[:name]].nil?
|
14
13
|
raise Puppet::DevError, 'Transport `%{name}` is already registered for `%{environment}`' % {
|
15
14
|
name: schema[:name],
|
16
|
-
environment:
|
15
|
+
environment: current_environment,
|
17
16
|
}
|
18
17
|
end
|
19
|
-
|
18
|
+
transports[schema[:name]] = Puppet::ResourceApi::TransportSchemaDef.new(schema)
|
20
19
|
end
|
21
20
|
module_function :register # rubocop:disable Style/AccessModifierDeclarations
|
22
21
|
|
23
22
|
# retrieve a Hash of transport schemas, keyed by their name.
|
24
23
|
def list
|
25
|
-
|
26
|
-
Marshal.load(Marshal.dump(@transports[@environment]))
|
24
|
+
Marshal.load(Marshal.dump(transports))
|
27
25
|
end
|
28
26
|
module_function :list # rubocop:disable Style/AccessModifierDeclarations
|
29
27
|
|
@@ -47,15 +45,19 @@ module Puppet::ResourceApi::Transport
|
|
47
45
|
module_function :inject_device # rubocop:disable Style/AccessModifierDeclarations
|
48
46
|
|
49
47
|
def self.validate(name, connection_info)
|
50
|
-
|
51
|
-
|
52
|
-
transport_schema = @transports[@environment][name]
|
48
|
+
require "puppet/transport/schema/#{name}" unless transports.key? name
|
49
|
+
transport_schema = transports[name]
|
53
50
|
if transport_schema.nil?
|
54
51
|
raise Puppet::DevError, 'Transport for `%{target}` not registered with `%{environment}`' % {
|
55
52
|
target: name,
|
56
|
-
environment:
|
53
|
+
environment: current_environment,
|
57
54
|
}
|
58
55
|
end
|
56
|
+
|
57
|
+
if connection_info.key?(:"remote-transport")
|
58
|
+
clean_bolt_attributes(transport_schema, connection_info)
|
59
|
+
end
|
60
|
+
|
59
61
|
message_prefix = 'The connection info provided does not match the Transport Schema'
|
60
62
|
transport_schema.check_schema(connection_info, message_prefix)
|
61
63
|
transport_schema.validate(connection_info)
|
@@ -64,24 +66,12 @@ module Puppet::ResourceApi::Transport
|
|
64
66
|
|
65
67
|
def self.get_context(name)
|
66
68
|
require 'puppet/resource_api/puppet_context'
|
67
|
-
Puppet::ResourceApi::PuppetContext.new(
|
69
|
+
Puppet::ResourceApi::PuppetContext.new(transports[name])
|
68
70
|
end
|
69
71
|
private_class_method :get_context
|
70
72
|
|
71
|
-
def self.init_transports
|
72
|
-
lookup = Puppet.lookup(:current_environment) if Puppet.respond_to? :lookup
|
73
|
-
@environment = if lookup.nil?
|
74
|
-
:transports_default
|
75
|
-
else
|
76
|
-
lookup.name
|
77
|
-
end
|
78
|
-
@transports ||= {}
|
79
|
-
@transports[@environment] ||= {}
|
80
|
-
end
|
81
|
-
private_class_method :init_transports
|
82
|
-
|
83
73
|
def self.wrap_sensitive(name, connection_info)
|
84
|
-
transport_schema =
|
74
|
+
transport_schema = transports[name]
|
85
75
|
if transport_schema
|
86
76
|
transport_schema.definition[:connection_info].each do |attr_name, options|
|
87
77
|
if options.key?(:sensitive) && (options[:sensitive] == true) && connection_info.key?(attr_name)
|
@@ -92,4 +82,52 @@ module Puppet::ResourceApi::Transport
|
|
92
82
|
connection_info
|
93
83
|
end
|
94
84
|
private_class_method :wrap_sensitive
|
85
|
+
|
86
|
+
def self.transports
|
87
|
+
@transports ||= {}
|
88
|
+
@transports[current_environment] ||= {}
|
89
|
+
end
|
90
|
+
private_class_method :transports
|
91
|
+
|
92
|
+
def self.current_environment
|
93
|
+
if Puppet.respond_to? :lookup
|
94
|
+
env = Puppet.lookup(:current_environment)
|
95
|
+
env.nil? ? :transports_default : env.name
|
96
|
+
else
|
97
|
+
:transports_default
|
98
|
+
end
|
99
|
+
end
|
100
|
+
private_class_method :current_environment
|
101
|
+
|
102
|
+
def self.clean_bolt_attributes(transport_schema, connection_info)
|
103
|
+
context = get_context(transport_schema.name)
|
104
|
+
|
105
|
+
# Attributes we expect from bolt, but want to ignore if the transport does not expect them
|
106
|
+
[:uri, :host, :protocol, :user, :port, :password].each do |attribute_name|
|
107
|
+
if connection_info.key?(attribute_name) && !transport_schema.attributes.key?(attribute_name)
|
108
|
+
context.info('Discarding superfluous bolt attribute: %{attribute_name}' % { attribute_name: attribute_name })
|
109
|
+
connection_info.delete(attribute_name)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# Attributes that bolt emits, but we want to ignore if the transport does not expect them
|
114
|
+
([:name, :path, :query, :"run-on", :"remote-transport", :implementations] + connection_info.keys.select { |k| k.to_s.start_with? 'remote-' }).each do |attribute_name|
|
115
|
+
if connection_info.key?(attribute_name) && !transport_schema.attributes.key?(attribute_name)
|
116
|
+
context.debug('Discarding bolt metaparameter: %{attribute_name}' % { attribute_name: attribute_name })
|
117
|
+
connection_info.delete(attribute_name)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# remove any other attributes the transport is not prepared to handle
|
122
|
+
connection_info.keys.each do |attribute_name|
|
123
|
+
if connection_info.key?(attribute_name) && !transport_schema.attributes.key?(attribute_name)
|
124
|
+
context.warning('Discarding unknown attribute: %{attribute_name}' % { attribute_name: attribute_name })
|
125
|
+
connection_info.delete(attribute_name)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
# don't return a value as we've already modified the hash
|
130
|
+
nil
|
131
|
+
end
|
132
|
+
private_class_method :clean_bolt_attributes
|
95
133
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-resource_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Schmitt
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06-
|
11
|
+
date: 2019-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hocon
|