puppet-resource_api 1.0.2 → 1.0.3

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: 8adaec9101c4bdf2bfaabfbb4ef87147d37c7360dd5008a8da7d0d653bd4071c
4
- data.tar.gz: a81e2f4b6e643587b74e7ae4313e9b011f76aeec10b09abc292d9bb65083df2a
3
+ metadata.gz: 3c0802c277632a57802c1b44466a56470474357dea596c39472c7e23a592aab9
4
+ data.tar.gz: 66b3de030a9a2b91a2abac411d46e803152e973a10235eaf09c1b3381b41a184
5
5
  SHA512:
6
- metadata.gz: f910f226a69685dcdadd6391b5ad4f2b5064f1861fdc06c8a7ed36d84f4da49d850983550809eb7053959d94799946c8c6109e0c3c848dbe9649d2bbc23f4f20
7
- data.tar.gz: 47ba949ac49e663add1eed1d9648d5b4642346ac4ecbf944447670352e9aa8f75813d5964cab7fd9f2793e1ae49b41153b24d54b0e9bb5884484284d101bb0ca
6
+ metadata.gz: c16aea1e79a69f0c6112812c1f5e89884899064ffdcf31c7c2a9567e776435244646a3d0111c3c29acf64cfee8ce061f3684ef012edb7af574615aef910b2cb2
7
+ data.tar.gz: 7e719c49452ddea14cabddaf3702eac1e15da5717138ce732be25c0f57b6c649df1f2702869adf3265b002fb83ca78f6df7b5671350119ea8b6fdc62f9eb2415
data/CHANGELOG.md CHANGED
@@ -3,6 +3,25 @@
3
3
  All significant changes to this repo will be summarized in this file.
4
4
 
5
5
 
6
+ ## [v1.0.3](https://github.com/puppetlabs/puppet-resource_api/tree/v1.0.3) (2018-04-06)
7
+ [Full Changelog](https://github.com/puppetlabs/puppet-resource_api/compare/v1.0.2...v1.0.3)
8
+
9
+ **Implemented enhancements:**
10
+
11
+ - \(PDK-887\) Add checks for read\_only values being set or modified [\#54](https://github.com/puppetlabs/puppet-resource_api/pull/54) ([da-ar](https://github.com/da-ar))
12
+ - \(PDK-885\) Add support for init\_only attributes [\#52](https://github.com/puppetlabs/puppet-resource_api/pull/52) ([da-ar](https://github.com/da-ar))
13
+
14
+ **Fixed bugs:**
15
+
16
+ - \(PDK-911\) Fix handling of `ensure` values from symbols to strings [\#55](https://github.com/puppetlabs/puppet-resource_api/pull/55) ([DavidS](https://github.com/DavidS))
17
+
18
+ **Merged pull requests:**
19
+
20
+ - Misc fixes [\#56](https://github.com/puppetlabs/puppet-resource_api/pull/56) ([DavidS](https://github.com/DavidS))
21
+ - \(PDK-890\) document current constraints on possible data types [\#53](https://github.com/puppetlabs/puppet-resource_api/pull/53) ([DavidS](https://github.com/DavidS))
22
+ - Update release prep notes [\#51](https://github.com/puppetlabs/puppet-resource_api/pull/51) ([DavidS](https://github.com/DavidS))
23
+ - Release prep for v1.0.2 [\#50](https://github.com/puppetlabs/puppet-resource_api/pull/50) ([DavidS](https://github.com/DavidS))
24
+
6
25
  ## [v1.0.2](https://github.com/puppetlabs/puppet-resource_api/tree/v1.0.2) (2018-03-26)
7
26
  [Full Changelog](https://github.com/puppetlabs/puppet-resource_api/compare/v1.0.1...v1.0.2)
8
27
 
data/README.md CHANGED
@@ -55,6 +55,8 @@ pdk (INFO): Creating '.../example/spec/unit/puppet/provider/foo/foo_spec.rb' fro
55
55
  $
56
56
  ```
57
57
 
58
+ Note that the templates released with PDK 1.4 suffer from the fallout of [PDK-911](https://tickets.puppetlabs.com/browse/PDK-911), and need all occurrences of `:present` changed to `'present'`. This will be fixed in PDK 1.5.
59
+
58
60
  The three generated files are the type, the implementation, and the unit tests. The default template contains an example that demonstrates the basic workings of the Resource API. This allows the unit tests to run immediately after creating the provider:
59
61
 
60
62
  ```
@@ -118,11 +120,11 @@ class Puppet::Provider::Foo::Foo < Puppet::ResourceApi::SimpleProvider
118
120
  [
119
121
  {
120
122
  name: 'foo',
121
- ensure: :present,
123
+ ensure: 'present',
122
124
  },
123
125
  {
124
126
  name: 'bar',
125
- ensure: :present,
127
+ ensure: 'present',
126
128
  },
127
129
  ]
128
130
  end
@@ -188,6 +190,12 @@ This gem is still under heavy development. This section is a living document of
188
190
 
189
191
  Currently working:
190
192
  * Basic type and provider definition, using `name`, `desc`, and `attributes`.
193
+ * Scalar puppet 4 [data types](https://puppet.com/docs/puppet/5.3/lang_data_type.html#core-data-types):
194
+ * String
195
+ * Integer, Float, Numeric
196
+ * Boolean
197
+ * Enum[absent, present]
198
+ * simple Optionals
191
199
  * The `canonicalize`, `simple_get_filter`, and `remote_resource` features.
192
200
  * All the logging facilities.
193
201
  * Executing the new provider under the following commands:
@@ -197,8 +205,8 @@ Currently working:
197
205
  * `puppet device` (if applicable)
198
206
 
199
207
  There are still a few notable gaps between the implementation and the specification:
208
+ * Complex data types, like Array, Hash, Tuple or Struct are not yet implemented.
200
209
  * Only a single runtime environment (the Puppet commands) is currently implemented.
201
- * The `:init_only` behaviour is not yet implemented ([PDK-885](https://tickets.puppetlabs.com/browse/PDK-885))
202
210
 
203
211
  Restrictions of running under puppet:
204
212
  * `supports_noop` is not effective, as puppet doesn't call into the type under noop.
@@ -222,6 +230,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/puppet
222
230
 
223
231
  To cut a new release, from a current `master` checkout:
224
232
 
233
+ * Start the release branch with `git checkout -b release-prep`
225
234
  * Update `lib/puppet/resource_api/version.rb` to the new version
226
235
  * Update the CHANGELOG
227
236
  * Have a [CHANGELOG_GITHUB_TOKEN](https://github.com/skywinder/github-changelog-generator#github-token) set in your environment
@@ -229,7 +238,9 @@ To cut a new release, from a current `master` checkout:
229
238
  * double check the PRs to make sure they're all tagged correctly (using the new CHANGELOG for cross-checking)
230
239
  * Check README and other materials for up-to-date-ness
231
240
  * Commit changes with title "Release prep for v<VERSION>"
232
- * Upload and PR the release prep to github as normal
241
+ * Upload and PR the release prep to github through the main repo starting with `git push upstream`
242
+ * make sure to use the name of your git remote pointing to main repo instead of "upstream"
233
243
  * Check that CI is green and merge the PR
234
244
  * Run `rake release[upstream]` to release from your checkout
235
245
  * make sure to use the name of your git remote pointing to main repo instead of "upstream"
246
+ * Remove the release-prep branch
@@ -85,7 +85,7 @@ module Puppet::ResourceApi
85
85
 
86
86
  # skip properties if the resource is being deleted
87
87
  next if definition[:attributes][:ensure] &&
88
- value(:ensure) == :absent &&
88
+ value(:ensure) == 'absent' &&
89
89
  options[:behaviour].nil?
90
90
 
91
91
  if value(name).nil? && !(type.instance_of? Puppet::Pops::Types::POptionalType)
@@ -96,7 +96,7 @@ module Puppet::ResourceApi
96
96
  missing_attrs -= [:ensure] if @called_from_resource
97
97
 
98
98
  if missing_attrs.any?
99
- error_msg = "The following mandatory attributes where not provided:\n * " + missing_attrs.join(", \n * ")
99
+ error_msg = "The following mandatory attributes were not provided:\n * " + missing_attrs.join(", \n * ")
100
100
  raise Puppet::ResourceError, error_msg
101
101
  end
102
102
  end
@@ -105,7 +105,7 @@ module Puppet::ResourceApi
105
105
  # puts "#{name}: #{options.inspect}"
106
106
 
107
107
  if options[:behaviour]
108
- unless [:read_only, :namevar, :parameter].include? options[:behaviour]
108
+ unless [:read_only, :namevar, :parameter, :init_only].include? options[:behaviour]
109
109
  raise Puppet::ResourceError, "`#{options[:behaviour]}` is not a valid behaviour value"
110
110
  end
111
111
  end
@@ -142,72 +142,80 @@ module Puppet::ResourceApi
142
142
  if options.key? :default
143
143
  defaultto options[:default]
144
144
  end
145
+ end
145
146
 
146
- type = Puppet::Pops::Types::TypeParser.singleton.parse(options[:type])
147
- validate do |value|
148
- return true if type.instance?(value)
147
+ type = Puppet::Pops::Types::TypeParser.singleton.parse(options[:type])
148
+ validate do |value|
149
+ if options[:behaviour] == :read_only
150
+ raise Puppet::ResourceError, "Attempting to set `#{name}` read_only attribute value to `#{value}`"
151
+ end
152
+
153
+ return true if type.instance?(value)
149
154
 
150
- if value.is_a? String
151
- # when running under `puppet resource`, we need to try to coerce from strings to the real type
152
- case value
153
- when %r{^-?\d+$}, Puppet::Pops::Patterns::NUMERIC
154
- value = Puppet::Pops::Utils.to_n(value)
155
- when %r{\Atrue|false\Z}
156
- value = value == 'true'
157
- end
158
- return true if type.instance?(value)
159
-
160
- inferred_type = Puppet::Pops::Types::TypeCalculator.infer_set(value)
161
- error_msg = Puppet::Pops::Types::TypeMismatchDescriber.new.describe_mismatch("#{definition[:name]}.#{name}", type, inferred_type)
162
- raise Puppet::ResourceError, error_msg
155
+ if value.is_a? String
156
+ # when running under `puppet resource`, we need to try to coerce from strings to the real type
157
+ case value
158
+ when %r{^-?\d+$}, Puppet::Pops::Patterns::NUMERIC
159
+ value = Puppet::Pops::Utils.to_n(value)
160
+ when %r{\Atrue|false\Z}
161
+ value = value == 'true'
163
162
  end
164
- end
163
+ return true if type.instance?(value)
165
164
 
166
- if type.instance_of? Puppet::Pops::Types::POptionalType
167
- type = type.type
165
+ inferred_type = Puppet::Pops::Types::TypeCalculator.infer_set(value)
166
+ error_msg = Puppet::Pops::Types::TypeMismatchDescriber.new.describe_mismatch("#{definition[:name]}.#{name}", type, inferred_type)
167
+ raise Puppet::ResourceError, error_msg
168
168
  end
169
+ end
169
170
 
170
- # provide better handling of the standard types
171
- case type
172
- when Puppet::Pops::Types::PStringType
173
- # require any string value
174
- Puppet::ResourceApi.def_newvalues(self, param_or_property, %r{})
175
- # rubocop:disable Lint/BooleanSymbol
176
- when Puppet::Pops::Types::PBooleanType
177
- Puppet::ResourceApi.def_newvalues(self, param_or_property, 'true', 'false')
178
- aliasvalue true, 'true'
179
- aliasvalue false, 'false'
180
- aliasvalue :true, 'true'
181
- aliasvalue :false, 'false'
182
-
183
- munge do |v|
184
- case v
185
- when 'true', :true
186
- true
187
- when 'false', :false
188
- false
189
- else
190
- v
191
- end
192
- end
193
- # rubocop:enable Lint/BooleanSymbol
194
- when Puppet::Pops::Types::PIntegerType
195
- Puppet::ResourceApi.def_newvalues(self, param_or_property, %r{^-?\d+$})
196
- munge do |v|
197
- Puppet::Pops::Utils.to_n(v)
198
- end
199
- when Puppet::Pops::Types::PFloatType, Puppet::Pops::Types::PNumericType
200
- Puppet::ResourceApi.def_newvalues(self, param_or_property, Puppet::Pops::Patterns::NUMERIC)
201
- munge do |v|
202
- Puppet::Pops::Utils.to_n(v)
171
+ if type.instance_of? Puppet::Pops::Types::POptionalType
172
+ type = type.type
173
+ end
174
+
175
+ # provide better handling of the standard types
176
+ case type
177
+ when Puppet::Pops::Types::PStringType
178
+ # require any string value
179
+ Puppet::ResourceApi.def_newvalues(self, param_or_property, %r{})
180
+ # rubocop:disable Lint/BooleanSymbol
181
+ when Puppet::Pops::Types::PBooleanType
182
+ Puppet::ResourceApi.def_newvalues(self, param_or_property, 'true', 'false')
183
+ aliasvalue true, 'true'
184
+ aliasvalue false, 'false'
185
+ aliasvalue :true, 'true'
186
+ aliasvalue :false, 'false'
187
+
188
+ munge do |v|
189
+ case v
190
+ when 'true', :true
191
+ true
192
+ when 'false', :false
193
+ false
194
+ else
195
+ v
203
196
  end
204
197
  end
205
-
206
- case options[:type]
207
- when 'Enum[present, absent]'
208
- Puppet::ResourceApi.def_newvalues(self, param_or_property, :absent, :present)
198
+ # rubocop:enable Lint/BooleanSymbol
199
+ when Puppet::Pops::Types::PIntegerType
200
+ Puppet::ResourceApi.def_newvalues(self, param_or_property, %r{^-?\d+$})
201
+ munge do |v|
202
+ Puppet::Pops::Utils.to_n(v)
203
+ end
204
+ when Puppet::Pops::Types::PFloatType, Puppet::Pops::Types::PNumericType
205
+ Puppet::ResourceApi.def_newvalues(self, param_or_property, Puppet::Pops::Patterns::NUMERIC)
206
+ munge do |v|
207
+ Puppet::Pops::Utils.to_n(v)
209
208
  end
210
209
  end
210
+
211
+ case options[:type]
212
+ when 'Enum[present, absent]'
213
+ Puppet::ResourceApi.def_newvalues(self, param_or_property, 'absent', 'present')
214
+ # puppet symbolizes these values through puppet/paramter/value.rb (see .convert()), but Enums are strings
215
+ # specifying a munge block here skips the value_collection fallback in puppet/parameter.rb's
216
+ # default .unsafe_munge() implementation
217
+ munge { |v| v }
218
+ end
211
219
  end
212
220
  end
213
221
 
@@ -248,7 +256,7 @@ module Puppet::ResourceApi
248
256
  end
249
257
  else
250
258
  result[namevar_name] = title
251
- result[:ensure] = :absent
259
+ result[:ensure] = 'absent'
252
260
  end
253
261
 
254
262
  @rapi_current_state = current_state
@@ -270,6 +278,20 @@ module Puppet::ResourceApi
270
278
 
271
279
  Puppet.debug("Target State: #{target_state.inspect}")
272
280
 
281
+ # enforce init_only attributes
282
+ if Puppet.settings[:strict] != :off && @rapi_current_state && (@rapi_current_state[:ensure] == 'present' && target_state[:ensure] == 'present')
283
+ target_state.each do |name, value|
284
+ next unless definition[:attributes][name][:behaviour] == :init_only && value != @rapi_current_state[name]
285
+ message = "Attempting to change `#{name}` init_only attribute value from `#{@rapi_current_state[name]}` to `#{value}`"
286
+ case Puppet.settings[:strict]
287
+ when :warning
288
+ Puppet.warning(message)
289
+ when :error
290
+ raise Puppet::ResourceError, message
291
+ end
292
+ end
293
+ end
294
+
273
295
  if feature_support?('supports_noop')
274
296
  my_provider.set(context, { title => { is: @rapi_current_state, should: target_state } }, noop: noop?)
275
297
  else
@@ -302,7 +324,7 @@ MESSAGE
302
324
  when :warning
303
325
  Puppet.warning(message)
304
326
  when :error
305
- raise Puppet::Error, message
327
+ raise Puppet::DevError, message
306
328
  end
307
329
 
308
330
  return nil
@@ -1,5 +1,5 @@
1
1
  module Puppet
2
2
  module ResourceApi
3
- VERSION = '1.0.2'.freeze
3
+ VERSION = '1.0.3'.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.0.2
4
+ version: 1.0.3
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-03-26 00:00:00.000000000 Z
11
+ date: 2018-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hocon