puppet-resource_api 1.8.10 → 1.8.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23c38c650148fd1697a642774a4b470e208f1f45c3e47dc75c1d93795be7bb38
4
- data.tar.gz: 884337cc89bd510169e9822982fbed68866dff0d9f30c027b3ebfca600670ce1
3
+ metadata.gz: a97a74d2743c8dd71ef34a5ad182d3946464b0ee9ab3b0dc9fb9d084b1c0dbb2
4
+ data.tar.gz: 4440e7664869083fb353cb7ffd32e60e948ba99dee07fab5fb19ea58ded52bb6
5
5
  SHA512:
6
- metadata.gz: 721c4d232ba09cef37c387bfec47d557de2873f858bbf7a3e72a9b7f66ef993e0298eb954cdd1864ad4d5091b9aa2fe83480f51a5324255861cd7fa2df80a6c2
7
- data.tar.gz: af6b72118cc710bac4eec4b4fbae849f5620f1fc29b949afb0dd2baca5ebc2237b55ccf76c696ab6a5be8e534f7d3fbaead41829e256926a07791fc6a064c8e3
6
+ metadata.gz: b491366c3ee28299ee4c56745f8606d3f257e4f814367a97694f9b363b68f6f9bb4de02d9f743eb3272a7a432b47175c1fa10804fc6d55df001480ce10289768
7
+ data.tar.gz: 0e426a40343d84d3a9cca300b9f7fe45aa0ad35925c2b9c3b39facb07d7152b352e60a9e5fa7b91a98c4637ab2bb4264c7a12a1ccc309bb4d930928c9e9ff3b6
data/Gemfile CHANGED
@@ -15,6 +15,8 @@ group :tests do
15
15
  # load a rubocop version that works on java for the Rakefile
16
16
  gem 'parser', '2.3.3.1'
17
17
  gem 'rubocop', '0.41.2'
18
+ # JRuby 1.7 does not like json 2.3.0, jruby 9.1.9.0 has RUBY_VERSION == '2.3.3'
19
+ gem 'json', '2.2.0' if Gem::Version.new(RUBY_VERSION) <= Gem::Version.new('2.3.0')
18
20
  elsif Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2.0')
19
21
  gem 'rubocop', '0.57.2'
20
22
  # the last version of parallel to support ruby 2.1
@@ -35,7 +35,8 @@ module Puppet::ResourceApi
35
35
  end
36
36
 
37
37
  Puppet::Type.newtype(definition[:name].to_sym) do
38
- @docs = definition[:desc]
38
+ # The :desc value is already cleaned up by the TypeDefinition validation
39
+ @doc = definition[:desc]
39
40
  @type_definition = type_def
40
41
 
41
42
  # Keeps a copy of the provider around. Weird naming to avoid clashes with puppet's own `provider` member
@@ -260,7 +261,7 @@ module Puppet::ResourceApi
260
261
 
261
262
  if @rsapi_current_state
262
263
  type_definition.check_schema(@rsapi_current_state)
263
- strict_check(@rsapi_current_state) if type_definition.feature?('canonicalize')
264
+ strict_check(@rsapi_current_state)
264
265
  else
265
266
  @rsapi_current_state = if rsapi_title.is_a? Hash
266
267
  rsapi_title.dup
@@ -274,7 +275,7 @@ module Puppet::ResourceApi
274
275
  # Use this to set the current state from the `instances` method
275
276
  def cache_current_state(resource_hash)
276
277
  @rsapi_current_state = resource_hash
277
- strict_check(@rsapi_current_state) if type_definition.feature?('canonicalize')
278
+ strict_check(@rsapi_current_state)
278
279
  end
279
280
 
280
281
  def retrieve
@@ -353,6 +354,22 @@ module Puppet::ResourceApi
353
354
  def strict_check(current_state)
354
355
  return if Puppet.settings[:strict] == :off
355
356
 
357
+ strict_check_canonicalize(current_state) if type_definition.feature?('canonicalize')
358
+ strict_check_title_parameter(current_state) if type_definition.namevars.size > 1 && !type_definition.title_patterns.empty?
359
+
360
+ nil
361
+ end
362
+
363
+ def strict_message(message)
364
+ case Puppet.settings[:strict]
365
+ when :warning
366
+ Puppet.warning(message)
367
+ when :error
368
+ raise Puppet::DevError, message
369
+ end
370
+ end
371
+
372
+ def strict_check_canonicalize(current_state)
356
373
  # if strict checking is on we must notify if the values are changed by canonicalize
357
374
  # make a deep copy to perform the operation on and to compare against later
358
375
  state_clone = Marshal.load(Marshal.dump(current_state))
@@ -369,15 +386,43 @@ Returned values: #{current_state.inspect}
369
386
  Canonicalized values: #{state_clone.inspect}
370
387
  MESSAGE
371
388
  #:nocov:
389
+ strict_message(message)
390
+ end
372
391
 
373
- case Puppet.settings[:strict]
374
- when :warning
375
- Puppet.warning(message)
376
- when :error
377
- raise Puppet::DevError, message
392
+ def strict_check_title_parameter(current_state)
393
+ unless current_state.key?(:title)
394
+ strict_message("#{type_definition.name}[#{@title}]#get has not provided a title attribute.")
395
+ return
378
396
  end
379
397
 
380
- nil
398
+ # Logic borrowed from Puppet::Resource.parse_title
399
+ title_hash = {}
400
+ self.class.title_patterns.each do |regexp, symbols|
401
+ captures = regexp.match(current_state[:title])
402
+ next if captures.nil?
403
+ symbols.zip(captures[1..-1]).each do |symbol_and_lambda, capture|
404
+ # The Resource API does not support passing procs in title_patterns
405
+ # so, unlike Puppet::Resource, we do not need to handle that here.
406
+ symbol = symbol_and_lambda[0]
407
+ title_hash[symbol] = capture
408
+ end
409
+ break
410
+ end
411
+
412
+ return if title_hash == rsapi_title
413
+
414
+ namevars = type_definition.namevars.reject { |namevar| title_hash[namevar] == rsapi_title[namevar] }
415
+
416
+ #:nocov:
417
+ # codecov fails to register this multiline as covered, even though simplecov does.
418
+ message = <<MESSAGE.strip
419
+ #{type_definition.name}[#{@title}]#get has provided a title attribute which does not match all namevars.
420
+ Namevars which do not match: #{namevars.inspect}
421
+ Returned parsed title hash: #{title_hash.inspect}
422
+ Expected hash: #{rsapi_title.inspect}
423
+ MESSAGE
424
+ #:nocov:
425
+ strict_message(message)
381
426
  end
382
427
 
383
428
  define_singleton_method(:context) do
@@ -18,6 +18,10 @@ module Puppet::ResourceApi
18
18
  (definition[:features] && definition[:features].include?(feature))
19
19
  end
20
20
 
21
+ def title_patterns
22
+ definition[:title_patterns] ||= []
23
+ end
24
+
21
25
  def validate_schema(definition, attr_key)
22
26
  super(definition, attr_key)
23
27
  [:title, :provider, :alias, :audit, :before, :consume, :export, :loglevel, :noop, :notify, :require, :schedule, :stage, :subscribe, :tag].each do |name|
@@ -1,5 +1,5 @@
1
1
  module Puppet
2
2
  module ResourceApi
3
- VERSION = '1.8.10'.freeze
3
+ VERSION = '1.8.11'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-resource_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.10
4
+ version: 1.8.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Schmitt