puppet-resource_api 1.4.2 → 1.5.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 +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +17 -0
- data/Gemfile +1 -5
- data/README.md +4 -1
- data/appveyor.yml +2 -1
- data/lib/puppet/resource_api.rb +54 -28
- data/lib/puppet/resource_api/type_definition.rb +1 -1
- 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: 9e2e55069c15f749148ae6c4a9fc626e77191f0ebba51123893f5d82c6d22a9d
|
4
|
+
data.tar.gz: 7add3eb881e226501009caf3150001ee7d83891e301a5d41081fffe3dd77d4cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d34e5647c07817985e6ec9029e2e7635dc94f0873943af524ae737d27166fe5da76a7bbc8649785d46f7aa0a99097c97e70478a6d797b0cb28562734d1d478d7
|
7
|
+
data.tar.gz: 1341a7774319c44650747f1ccba7178e70db1dff676c019d7614ae1ee8fa94af5f33ecaff8eb51ad2942b6a97252e25c8c381f12088b7fd33f8bf07ebdce91d2
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,23 @@
|
|
3
3
|
All significant changes to this repo will be summarized in this file.
|
4
4
|
|
5
5
|
|
6
|
+
## [v1.5.0](https://github.com/puppetlabs/puppet-resource_api/tree/v1.5.0) (2018-09-12)
|
7
|
+
[Full Changelog](https://github.com/puppetlabs/puppet-resource_api/compare/v1.4.2...v1.5.0)
|
8
|
+
|
9
|
+
**Implemented enhancements:**
|
10
|
+
|
11
|
+
- \(PDK-1150\) Allow providers to override :title when retrieving resources [\#115](https://github.com/puppetlabs/puppet-resource_api/pull/115) ([da-ar](https://github.com/da-ar))
|
12
|
+
|
13
|
+
**Fixed bugs:**
|
14
|
+
|
15
|
+
- \(maint\) create a new default value instance on every access [\#118](https://github.com/puppetlabs/puppet-resource_api/pull/118) ([DavidS](https://github.com/DavidS))
|
16
|
+
- \(PDK-1091\) Fix Sensitive value handling [\#117](https://github.com/puppetlabs/puppet-resource_api/pull/117) ([DavidS](https://github.com/DavidS))
|
17
|
+
- \(MODULES-7679\) correctly handle simple\_get\_filter providers [\#113](https://github.com/puppetlabs/puppet-resource_api/pull/113) ([da-ar](https://github.com/da-ar))
|
18
|
+
|
19
|
+
**Merged pull requests:**
|
20
|
+
|
21
|
+
- Release prep for v1.4.2 [\#112](https://github.com/puppetlabs/puppet-resource_api/pull/112) ([DavidS](https://github.com/DavidS))
|
22
|
+
|
6
23
|
## [v1.4.2](https://github.com/puppetlabs/puppet-resource_api/tree/v1.4.2) (2018-08-09)
|
7
24
|
[Full Changelog](https://github.com/puppetlabs/puppet-resource_api/compare/v1.4.1...v1.4.2)
|
8
25
|
|
data/Gemfile
CHANGED
@@ -45,8 +45,4 @@ def location_for(place_or_version, fake_version = nil)
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
|
49
|
-
gem 'puppet', *location_for(ENV['PUPPET_GEM_VERSION'])
|
50
|
-
else
|
51
|
-
gem 'puppet', github: 'DavidS/puppet', ref: 'device-apply'
|
52
|
-
end
|
48
|
+
gem 'puppet', *location_for(ENV['PUPPET_GEM_VERSION'])
|
data/README.md
CHANGED
@@ -179,6 +179,10 @@ After this, `puppet device` will be able to use the new provider, and supply it
|
|
179
179
|
|
180
180
|
The [Resource API](https://github.com/puppetlabs/puppet-specifications/blob/master/language/resource-api/README.md) describes details of all the capabilities of this gem.
|
181
181
|
|
182
|
+
The [hue_rsapi module](https://github.com/da-ar/hue_rsapi) is a very simple example for using the Resource API for remote resources.
|
183
|
+
|
184
|
+
The [meraki module](https://github.com/meraki/puppet-module) is a full example for using the Resource API for remote resources.
|
185
|
+
|
182
186
|
This [Introduction to Testing Puppet Modules](https://www.netways.de/index.php?id=3445#c44135) talk describes rspec usage in more detail.
|
183
187
|
|
184
188
|
The [RSpec docs](https://relishapp.com/rspec) provide an overview of the capabilities of rspec.
|
@@ -215,7 +219,6 @@ Restrictions of puppet:
|
|
215
219
|
* Attributes cannot be called `title`, `provider`, or any of the [metaparameters](https://puppet.com/docs/puppet/5.5/metaparameter.html), as those are reserved by puppet itself.
|
216
220
|
|
217
221
|
Future possibilities:
|
218
|
-
* [Composite Namevars](https://tickets.puppetlabs.com/browse/PDK-531)
|
219
222
|
* [Multiple Providers](https://tickets.puppetlabs.com/browse/PDK-530)
|
220
223
|
* [Commands API](https://tickets.puppetlabs.com/browse/PDK-847)
|
221
224
|
|
data/appveyor.yml
CHANGED
@@ -7,7 +7,8 @@ branches:
|
|
7
7
|
environment:
|
8
8
|
matrix:
|
9
9
|
- RUBY_VERSION: 24-x64
|
10
|
-
-
|
10
|
+
- PUPPET_GEM_VERSION: '~> 4.0'
|
11
|
+
RUBY_VERSION: 21-x64
|
11
12
|
|
12
13
|
install:
|
13
14
|
- set PATH=C:\Ruby%RUBY_VERSION%\bin;C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin;%PATH%
|
data/lib/puppet/resource_api.rb
CHANGED
@@ -79,10 +79,21 @@ module Puppet::ResourceApi
|
|
79
79
|
if attributes.is_a? Puppet::Resource
|
80
80
|
@title = attributes.title
|
81
81
|
@catalog = attributes.catalog
|
82
|
+
sensitives = attributes.sensitive_parameters
|
82
83
|
attributes = attributes.to_hash
|
83
84
|
else
|
84
85
|
@ral_find_absent = true
|
86
|
+
sensitives = []
|
85
87
|
end
|
88
|
+
|
89
|
+
# undo puppet's unwrapping of Sensitive values to provide a uniform experience for providers
|
90
|
+
# See https://tickets.puppetlabs.com/browse/PDK-1091 for investigation and background
|
91
|
+
sensitives.each do |name|
|
92
|
+
if attributes.key?(name) && !attributes[name].is_a?(Puppet::Pops::Types::PSensitiveType::Sensitive)
|
93
|
+
attributes[name] = Puppet::Pops::Types::PSensitiveType::Sensitive.new(attributes[name])
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
86
97
|
# $stderr.puts "B: #{attributes.inspect}"
|
87
98
|
if type_definition.feature?('canonicalize')
|
88
99
|
attributes = my_provider.canonicalize(context, [attributes])[0]
|
@@ -188,9 +199,13 @@ module Puppet::ResourceApi
|
|
188
199
|
# work around https://tickets.puppetlabs.com/browse/PUP-2368
|
189
200
|
defaultto :true # rubocop:disable Lint/BooleanSymbol
|
190
201
|
else
|
191
|
-
|
202
|
+
# marshal the default option to decouple that from the actual value.
|
203
|
+
# we cache the dumped value in `marshalled`, but use a block to unmarshal
|
204
|
+
# everytime the value is requested. Objects that can't be marshalled
|
205
|
+
# See https://stackoverflow.com/a/8206537/4918
|
206
|
+
marshalled = Marshal.dump(options[:default])
|
207
|
+
defaultto { Marshal.load(marshalled) } # rubocop:disable Security/MarshalLoad
|
192
208
|
end
|
193
|
-
# defaultto options[:default]
|
194
209
|
end
|
195
210
|
end
|
196
211
|
|
@@ -301,42 +316,53 @@ module Puppet::ResourceApi
|
|
301
316
|
# force autoloading of the provider
|
302
317
|
provider(type_definition.name)
|
303
318
|
|
304
|
-
|
319
|
+
initial_fetch = if type_definition.feature?('simple_get_filter')
|
320
|
+
my_provider.get(context, [])
|
321
|
+
else
|
322
|
+
my_provider.get(context)
|
323
|
+
end
|
324
|
+
|
325
|
+
initial_fetch.map do |resource_hash|
|
305
326
|
type_definition.check_schema(resource_hash)
|
306
|
-
|
327
|
+
# allow a :title from the provider to override the default
|
328
|
+
result = if resource_hash.key? :title
|
329
|
+
new(title: resource_hash[:title])
|
330
|
+
else
|
331
|
+
new(title: resource_hash[type_definition.namevars.first])
|
332
|
+
end
|
307
333
|
result.cache_current_state(resource_hash)
|
308
334
|
result
|
309
335
|
end
|
310
336
|
end
|
311
337
|
|
312
338
|
define_method(:refresh_current_state) do
|
313
|
-
@
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
if @
|
320
|
-
type_definition.check_schema(@
|
321
|
-
strict_check(@
|
339
|
+
@rsapi_current_state = if type_definition.feature?('simple_get_filter')
|
340
|
+
my_provider.get(context, [title]).find { |h| namevar_match?(h) }
|
341
|
+
else
|
342
|
+
my_provider.get(context).find { |h| namevar_match?(h) }
|
343
|
+
end
|
344
|
+
|
345
|
+
if @rsapi_current_state
|
346
|
+
type_definition.check_schema(@rsapi_current_state)
|
347
|
+
strict_check(@rsapi_current_state) if type_definition.feature?('canonicalize')
|
322
348
|
else
|
323
|
-
@
|
324
|
-
@
|
349
|
+
@rsapi_current_state = { title: title }
|
350
|
+
@rsapi_current_state[:ensure] = :absent if type_definition.ensurable?
|
325
351
|
end
|
326
352
|
end
|
327
353
|
|
328
354
|
# Use this to set the current state from the `instances` method
|
329
355
|
def cache_current_state(resource_hash)
|
330
|
-
@
|
331
|
-
strict_check(@
|
356
|
+
@rsapi_current_state = resource_hash
|
357
|
+
strict_check(@rsapi_current_state) if type_definition.feature?('canonicalize')
|
332
358
|
end
|
333
359
|
|
334
360
|
define_method(:retrieve) do
|
335
|
-
refresh_current_state unless @
|
361
|
+
refresh_current_state unless @rsapi_current_state
|
336
362
|
|
337
|
-
Puppet.debug("Current State: #{@
|
363
|
+
Puppet.debug("Current State: #{@rsapi_current_state.inspect}")
|
338
364
|
|
339
|
-
result = Puppet::Resource.new(self.class, title, parameters: @
|
365
|
+
result = Puppet::Resource.new(self.class, title, parameters: @rsapi_current_state)
|
340
366
|
# puppet needs ensure to be a symbol
|
341
367
|
result[:ensure] = result[:ensure].to_sym if type_definition.ensurable? && result[:ensure].is_a?(String)
|
342
368
|
|
@@ -360,17 +386,17 @@ module Puppet::ResourceApi
|
|
360
386
|
target_state = Hash[actual_params.map { |k, v| [k, v.rs_value] }]
|
361
387
|
target_state = my_provider.canonicalize(context, [target_state]).first if type_definition.feature?('canonicalize')
|
362
388
|
|
363
|
-
retrieve unless @
|
389
|
+
retrieve unless @rsapi_current_state
|
364
390
|
|
365
|
-
return if @
|
391
|
+
return if @rsapi_current_state == target_state
|
366
392
|
|
367
393
|
Puppet.debug("Target State: #{target_state.inspect}")
|
368
394
|
|
369
395
|
# enforce init_only attributes
|
370
|
-
if Puppet.settings[:strict] != :off && @
|
396
|
+
if Puppet.settings[:strict] != :off && @rsapi_current_state && (@rsapi_current_state[:ensure] == 'present' && target_state[:ensure] == 'present')
|
371
397
|
target_state.each do |name, value|
|
372
|
-
next unless definition[:attributes][name][:behaviour] == :init_only && value != @
|
373
|
-
message = "Attempting to change `#{name}` init_only attribute value from `#{@
|
398
|
+
next unless definition[:attributes][name][:behaviour] == :init_only && value != @rsapi_current_state[name]
|
399
|
+
message = "Attempting to change `#{name}` init_only attribute value from `#{@rsapi_current_state[name]}` to `#{value}`"
|
374
400
|
case Puppet.settings[:strict]
|
375
401
|
when :warning
|
376
402
|
Puppet.warning(message)
|
@@ -381,14 +407,14 @@ module Puppet::ResourceApi
|
|
381
407
|
end
|
382
408
|
|
383
409
|
if type_definition.feature?('supports_noop')
|
384
|
-
my_provider.set(context, { title => { is: @
|
410
|
+
my_provider.set(context, { title => { is: @rsapi_current_state, should: target_state } }, noop: noop?)
|
385
411
|
else
|
386
|
-
my_provider.set(context, title => { is: @
|
412
|
+
my_provider.set(context, title => { is: @rsapi_current_state, should: target_state }) unless noop?
|
387
413
|
end
|
388
414
|
raise 'Execution encountered an error' if context.failed?
|
389
415
|
|
390
416
|
# remember that we have successfully reached our desired state
|
391
|
-
@
|
417
|
+
@rsapi_current_state = target_state
|
392
418
|
end
|
393
419
|
|
394
420
|
define_method(:raise_missing_attrs) do
|
@@ -74,7 +74,7 @@ class Puppet::ResourceApi::TypeDefinition
|
|
74
74
|
# Modifies the resource passed in, leaving only valid attributes
|
75
75
|
def check_schema_keys(resource)
|
76
76
|
rejected = []
|
77
|
-
resource.reject! { |key| rejected << key
|
77
|
+
resource.reject! { |key| rejected << key if key != :title && attributes.key?(key) == false }
|
78
78
|
rejected
|
79
79
|
end
|
80
80
|
|
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.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Schmitt
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hocon
|