puppet-resource_api 1.8.3 → 1.8.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42a8295bef7527d8b9a309e22c9b650bf2f0e62213be3bba7cca506ecd5b745b
4
- data.tar.gz: b1630d97f5a1c13f5377f67e30818dbcd41cc31c6f1c0cbc5e8dd75acff51cb2
3
+ metadata.gz: 2f6caa565c4c74ffa60028baa93976517fe6a6677e1265e29b164b91c1b8ddf7
4
+ data.tar.gz: 0d88b19fa67188d50658428a3a1a22fd3012831b2e7552fbf2d9dd5a546b2b52
5
5
  SHA512:
6
- metadata.gz: 8d3741e8c50ecaa89ccc3e7dd6f8e0a926602427731d1a4755377e45ab8aab1de46ed2c2c020d455516825509cf9e4159e9890c86d4b11ddbe8236b734a41486
7
- data.tar.gz: 4c55d2a4b01c0dd1675c49c42752643c037b68eb5fd0c66ce65a152d1d93129a09cb33bdb967ad81eef36d7622c5a7a66d9642d86753d6e807135895af17e07c
6
+ metadata.gz: 12df0d25e70620dbc247bd26b4705c39d5b0d4341606d828f1aed79a152bd67934b2704b20dd29805955240e3dd972bce8f7586bf3719bdd509afe7fd1a6a219
7
+ data.tar.gz: fc3e433a2a5a2c218a64dbcb2dab12af8aa96d36ed458b9607bf997cb470afce3352d0ed966e69ee03d0c7037bc738e713aab9ad8940560c9b7a6a59f8df5c2f
@@ -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
- Please note that within the transport schema, the following keywords are reserved words:
243
-
244
- #### Usable within the schema
245
-
246
- The following keywords are encouraged within the Transport schema:
247
-
248
- * `uri` - Use when you need to specify a specific URL to connect to. All of the following keys will be computed from the `uri` if possible. In the future more url parts may be computed from the URI as well.
249
- * `host` - Use to specify and IP or address to connect to.
250
- * `protocol` - Use to specify which protocol the transport should use for example `http`, `https`, `ssh` or `tcp`
251
- * `user` - The user the transport should connect as.
252
- * `port` - The port the transport should connect to.
253
-
254
- #### Non-Usable within the schema
255
-
256
- The following keywords are keywords that must not be used by the transport schema:
257
-
258
- * `name` - transports should use `uri` instead of name.
259
- * `path` - reserved as a uri part
260
- * `query` - reserved as a uri part
261
- * `run-on` - This is used by bolt to determine which target to proxy to. Transports should not rely on this key.
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
- init_transports
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: @environment,
15
+ environment: current_environment,
17
16
  }
18
17
  end
19
- @transports[@environment][schema[:name]] = Puppet::ResourceApi::TransportSchemaDef.new(schema)
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
- init_transports
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
- init_transports
51
- require "puppet/transport/schema/#{name}" unless @transports[@environment].key? name
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: @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(@transports[@environment][name])
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 = @transports[@environment][name]
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
@@ -1,5 +1,5 @@
1
1
  module Puppet
2
2
  module ResourceApi
3
- VERSION = '1.8.3'.freeze
3
+ VERSION = '1.8.4'.freeze
4
4
  end
5
5
  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.3
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-10 00:00:00.000000000 Z
11
+ date: 2019-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hocon