summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/parser/ast/resource.rb3
-rw-r--r--lib/puppet/parser/resource.rb10
-rw-r--r--lib/puppet/resource.rb18
3 files changed, 21 insertions, 10 deletions
diff --git a/lib/puppet/parser/ast/resource.rb b/lib/puppet/parser/ast/resource.rb
index 5da40b32f..c82e0b525 100644
--- a/lib/puppet/parser/ast/resource.rb
+++ b/lib/puppet/parser/ast/resource.rb
@@ -44,7 +44,8 @@ class Resource < AST::ResourceReference
:exported => self.exported,
:virtual => virt,
:source => scope.source,
- :scope => scope
+ :scope => scope,
+ :strict => true
)
# And then store the resource in the compiler.
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index 3f6d73df3..2d71079cc 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -110,9 +110,6 @@ class Puppet::Parser::Resource < Puppet::Resource
def initialize(type, title, options)
@scope = options[:scope]
- self.relative_type = type
- self.title = title
-
@params = {}
# Define all of the parameters
if params = options[:params]
@@ -136,6 +133,13 @@ class Puppet::Parser::Resource < Puppet::Resource
@source ||= scope.source
+ self.relative_type = type
+ self.title = title
+
+ if strict? and ! resource_type
+ raise ArgumentError, "Invalid resource type #{type}"
+ end
+
tag(self.type)
tag(self.title) if valid_tag?(self.title.to_s)
end
diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb
index 630e8a823..e29fecf45 100644
--- a/lib/puppet/resource.rb
+++ b/lib/puppet/resource.rb
@@ -12,7 +12,7 @@ class Puppet::Resource
extend Puppet::Util::Pson
include Enumerable
- attr_accessor :file, :line, :catalog, :exported, :virtual, :validate_parameters
+ attr_accessor :file, :line, :catalog, :exported, :virtual, :validate_parameters, :strict
attr_reader :title, :namespaces
attr_writer :relative_type
@@ -138,7 +138,7 @@ class Puppet::Resource
end
end
- %w{exported virtual}.each do |m|
+ %w{exported virtual strict}.each do |m|
define_method(m+"?") do
self.send(m)
end
@@ -149,10 +149,7 @@ class Puppet::Resource
@parameters = {}
@namespaces = [""]
- (attributes[:parameters] || {}).each do |param, value|
- self[param] = value
- end
-
+ # Set things like namespaces and strictness first.
attributes.each do |attr, value|
next if attr == :parameters
send(attr.to_s + "=", value)
@@ -165,8 +162,17 @@ class Puppet::Resource
self.type = tmp_type
self.title = tmp_title
+ (attributes[:parameters] || {}).each do |param, value|
+ validate_parameter(param) if strict?
+ self[param] = value
+ end
+
tag(self.type)
tag(self.title) if valid_tag?(self.title)
+
+ if strict? and ! resource_type
+ raise ArgumentError, "Invalid resource type #{type}"
+ end
end
def ref