Skip to content

Commit

Permalink
Merge pull request #84 from DavidS/improve-type-validation
Browse files Browse the repository at this point in the history
Check for more attributes that puppet can't use
da-ar authored May 24, 2018
2 parents e76c854 + ff2c165 commit ada3f0f
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -209,8 +209,9 @@ There are still a few notable gaps between the implementation and the specificat
* Complex data types, like Hash, Tuple or Struct are not yet implemented.
* Only a single runtime environment (the Puppet commands) is currently implemented.

Restrictions of running under puppet:
* `supports_noop` is not effective, as puppet doesn't call into the type under noop.
Restrictions of puppet:
* `supports_noop` is not effective, as puppet doesn't call into the type under noop at all.
* 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.

Future possibilities:
* [Composite Namevars](https://tickets.puppetlabs.com/browse/PDK-531)
5 changes: 3 additions & 2 deletions lib/puppet/resource_api.rb
Original file line number Diff line number Diff line change
@@ -11,8 +11,9 @@ def register_type(definition)
raise Puppet::DevError, 'requires a `:name`' unless definition.key? :name
raise Puppet::DevError, 'requires `:attributes`' unless definition.key? :attributes
raise Puppet::DevError, '`:attributes` must be a hash, not `%{other_type}`' % { other_type: definition[:attributes].class } unless definition[:attributes].is_a?(Hash)
raise Puppet::DevError, 'must not define an attribute called `:title`' if definition[:attributes].key? :title
raise Puppet::DevError, 'must not define an attribute called `:provider`' if definition[:attributes].key? :provider
[:title, :provider, :alias, :audit, :before, :consume, :export, :loglevel, :noop, :notify, :require, :schedule, :stage, :subscribe, :tag].each do |name|
raise Puppet::DevError, 'must not define an attribute called `%{name}`' % { name: name.inspect } if definition[:attributes].key? name
end
if definition.key?(:title_patterns) && !definition[:title_patterns].is_a?(Array)
raise Puppet::DevError, '`:title_patterns` must be an array, not `%{other_type}`' % { other_type: definition[:title_patterns].class }
end

0 comments on commit ada3f0f

Please sign in to comment.