diff --git a/README.markdown b/README.markdown index 68e559e..a15338f 100644 --- a/README.markdown +++ b/README.markdown @@ -20,29 +20,4 @@ Depending on the version of Puppet, you may need to restart the puppetmasterd (o ## Functions -### kwalify - -This function allows you to validate Puppet data structures using Kwalify -schemas as documented here: - -http://www.kuwata-lab.com/kwalify/ruby/users-guide.01.html - -To validate, create a schema in Puppet: - - $schema = { - 'type' => 'seq', - 'sequence' => [ - { 'type' => 'str' } - ] - } - -And create some content that you want validated: - - $document = ['a', 'b', 'c'] - -And then use the function to validate: - - kwalify($schema, $document) - -The function will throw an error and list all validation errors if there is a -problem otherwise it succeeds silently. +TODO diff --git a/examples/kwalify-1.pp b/examples/kwalify-1.pp deleted file mode 100644 index 852e46c..0000000 --- a/examples/kwalify-1.pp +++ /dev/null @@ -1,9 +0,0 @@ -$schema = { - 'type' => 'seq', - 'sequence' => [ - { 'type' => 'str', 'enum' => ['asdf','fdsa'] } - ] -} -$document = ['a', 'b', 'c'] - -kwalify($schema, $document) diff --git a/examples/kwalify-2.pp b/examples/kwalify-2.pp deleted file mode 100644 index 3f4ec33..0000000 --- a/examples/kwalify-2.pp +++ /dev/null @@ -1,24 +0,0 @@ -$schema = { - 'type' => 'map', - 'mapping' => { - 'name' => { - 'type' => 'str', - 'required' => true, - }, - 'email' => { - 'type' => 'str', - 'pattern' => '/@/', - }, - 'age' => { - 'type' => 'str', - 'pattern' => '/^\d+$/', - }, - } -} -$document = { - 'name' => 'foo', - 'email' => 'foo@mail.com', - 'age' => 20, -} - -kwalify($schema, $document) diff --git a/examples/validate_resource-1.pp b/examples/validate_resource-1.pp deleted file mode 100644 index c701b8d..0000000 --- a/examples/validate_resource-1.pp +++ /dev/null @@ -1,23 +0,0 @@ -define fooresource( - $color, - $type, - $somenumber, - $map - ) { - - validate_resource() - - # ... do something ... - -} - -fooresource { "example1": - color => "blue", - type => "circle", - somenumber => 5, - map => { - a => 1, - b => 2, - c => 3, - } -} diff --git a/examples/validate_resource-1.schema b/examples/validate_resource-1.schema deleted file mode 100644 index c540db5..0000000 --- a/examples/validate_resource-1.schema +++ /dev/null @@ -1,39 +0,0 @@ -type: map -mapping: - "title": - type: str - required: yes - "name": - type: str - required: yes - "caller_module_name": - type: str - required: yes - "module_name": - type: str - required: yes - "color": - type: str - required: yes - "type": - type: str - required: yes - "somenumber": - type: str - required: yes - pattern: /^\d+$/ - "map": - type: map - mapping: - "a": - type: str - required: yes - pattern: /^\d+$/ - "b": - type: str - required: yes - pattern: /^\d+$/ - "c": - type: str - required: yes - pattern: /^\d+$/ diff --git a/examples/validate_resource-2.pp b/examples/validate_resource-2.pp deleted file mode 100644 index b53b109..0000000 --- a/examples/validate_resource-2.pp +++ /dev/null @@ -1,17 +0,0 @@ -class foo ( - $a, - $b, - $c - ) { - - validate_resource() - - # ... do something ... - -} - -class { "foo": - a => "1", - b => "foobaz", - c => ['a','b','c'] -} diff --git a/examples/validate_resource-2.schema b/examples/validate_resource-2.schema deleted file mode 100644 index b516945..0000000 --- a/examples/validate_resource-2.schema +++ /dev/null @@ -1,26 +0,0 @@ -type: map -mapping: - "title": - type: str - required: yes - "name": - type: str - required: yes - "caller_module_name": - type: str - required: yes - "module_name": - type: str - required: yes - "a": - type: str - required: yes - "b": - type: str - required: yes - pattern: /^foo/ - "c": - type: seq - required: yes - sequence: - - type: str diff --git a/lib/puppet/parser/functions/kwalify.rb b/lib/puppet/parser/functions/kwalify.rb deleted file mode 100644 index 49b9aeb..0000000 --- a/lib/puppet/parser/functions/kwalify.rb +++ /dev/null @@ -1,35 +0,0 @@ -# -# kwalify.rb -# - -module Puppet::Parser::Functions - newfunction(:kwalify, :type => :statement, :doc => <<-EOS -This function uses kwalify to validate Puppet data structures against Kwalify -schemas. - EOS - ) do |args| - - raise(Puppet::ParseError, "kwalify(): Wrong number of arguments " + - "given (#{args.size} for 2)") if args.size != 2 - - schema = args[0] - document = args[1] - - require 'kwalify' - - validator = Kwalify::Validator.new(schema) - - errors = validator.validate(document) - - if errors && !errors.empty? - error_out = [] - for e in errors - error_out << "[#{e.path}] #{e.message}" - end - raise(Puppet::ParseError, "Failed kwalify schema validation:\n" + error_out.join("\n")) - end - - end -end - -# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/validate_resource.rb b/lib/puppet/parser/functions/validate_resource.rb deleted file mode 100644 index d71ef3f..0000000 --- a/lib/puppet/parser/functions/validate_resource.rb +++ /dev/null @@ -1,41 +0,0 @@ -# -# validate_resource -# - -module Puppet::Parser::Functions - newfunction(:validate_resource, :type => :statement, :doc => <<-EOS -This function when placed at the beginning of a class, will go looking for a -valid kwalify schema by replacing the extension of the file with '.schema'. - -It will then validate the arguments passed to the function using that kwalify -schema. - EOS - ) do |arguments| - - require 'kwalify' - - if (arguments.size != 0) then - raise(Puppet::ParseError, "validate_resource(): Wrong number of arguments "+ - "given #{arguments.size} for 0") - end - - - classhash = to_hash(recursive=false) - sourcepath = source.file - schemapath = sourcepath.gsub(/\.(rb|pp)$/, ".schema") - schema = Kwalify::Yaml.load_file(schemapath) - validator = Kwalify::Validator.new(schema) - errors = validator.validate(classhash) - - if errors && !errors.empty? - error_output = "Resource validation failed:\n" - for e in errors - error_output += "[#{e.path}] #{e.message}\n" - end - raise(Puppet::ParseError, error_output) - end - - end -end - -# vim: set ts=2 sw=2 et : diff --git a/spec/unit/parser/functions/kwalify_spec.rb b/spec/unit/parser/functions/kwalify_spec.rb deleted file mode 100755 index abdd529..0000000 --- a/spec/unit/parser/functions/kwalify_spec.rb +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env rspec -require 'spec_helper' - -describe "the kwalify function" do - before :all do - Puppet::Parser::Functions.autoloader.loadall - end - - before :each do - @scope = Puppet::Parser::Scope.new - end - - it "should exist" do - Puppet::Parser::Functions.function("kwalify").should == "function_kwalify" - end - - it "should raise a ParseError if there is less than 2 arguments" do - lambda { @scope.function_kwalify([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should validate a simple array schema" do - schema = { - 'type' => 'seq', - 'sequence' => [ - { 'type' => 'str' } - ] - } - document = ['a','b','c'] - @scope.function_kwalify([schema, document]) - end - - it "should not validate a simple array schema when invalid" do - schema = { - 'type' => 'seq', - 'sequence' => [ - { 'type' => 'str' } - ] - } - document = ['a','b',{'a' => 'b'}] - lambda { @scope.function_kwalify([schema, document]) }.should(raise_error(Puppet::ParseError)) - end - - it "should validate a hash schema" do - schema = { - 'type' => 'map', - 'mapping' => { - 'key1' => { - 'type' => 'str', - }, - 'key2' => { - 'type' => 'str', - }, - } - } - document = { - 'key1' => 'b', - 'key2' => 'c', - } - @scope.function_kwalify([schema, document]) - end - -end diff --git a/spec/unit/parser/functions/abs_spec.rb b/spec/unit/puppet/parser/functions/abs_spec.rb similarity index 100% rename from spec/unit/parser/functions/abs_spec.rb rename to spec/unit/puppet/parser/functions/abs_spec.rb diff --git a/spec/unit/parser/functions/bool2num_spec.rb b/spec/unit/puppet/parser/functions/bool2num_spec.rb similarity index 100% rename from spec/unit/parser/functions/bool2num_spec.rb rename to spec/unit/puppet/parser/functions/bool2num_spec.rb diff --git a/spec/unit/parser/functions/capitalize_spec.rb b/spec/unit/puppet/parser/functions/capitalize_spec.rb similarity index 100% rename from spec/unit/parser/functions/capitalize_spec.rb rename to spec/unit/puppet/parser/functions/capitalize_spec.rb diff --git a/spec/unit/parser/functions/chomp_spec.rb b/spec/unit/puppet/parser/functions/chomp_spec.rb similarity index 100% rename from spec/unit/parser/functions/chomp_spec.rb rename to spec/unit/puppet/parser/functions/chomp_spec.rb diff --git a/spec/unit/parser/functions/chop_spec.rb b/spec/unit/puppet/parser/functions/chop_spec.rb similarity index 100% rename from spec/unit/parser/functions/chop_spec.rb rename to spec/unit/puppet/parser/functions/chop_spec.rb diff --git a/spec/unit/parser/functions/delete_at_spec.rb b/spec/unit/puppet/parser/functions/delete_at_spec.rb similarity index 100% rename from spec/unit/parser/functions/delete_at_spec.rb rename to spec/unit/puppet/parser/functions/delete_at_spec.rb diff --git a/spec/unit/parser/functions/delete_spec.rb b/spec/unit/puppet/parser/functions/delete_spec.rb similarity index 100% rename from spec/unit/parser/functions/delete_spec.rb rename to spec/unit/puppet/parser/functions/delete_spec.rb diff --git a/spec/unit/parser/functions/downcase_spec.rb b/spec/unit/puppet/parser/functions/downcase_spec.rb similarity index 100% rename from spec/unit/parser/functions/downcase_spec.rb rename to spec/unit/puppet/parser/functions/downcase_spec.rb diff --git a/spec/unit/parser/functions/empty_spec.rb b/spec/unit/puppet/parser/functions/empty_spec.rb similarity index 100% rename from spec/unit/parser/functions/empty_spec.rb rename to spec/unit/puppet/parser/functions/empty_spec.rb diff --git a/spec/unit/parser/functions/flatten_spec.rb b/spec/unit/puppet/parser/functions/flatten_spec.rb similarity index 100% rename from spec/unit/parser/functions/flatten_spec.rb rename to spec/unit/puppet/parser/functions/flatten_spec.rb diff --git a/spec/unit/parser/functions/grep_spec.rb b/spec/unit/puppet/parser/functions/grep_spec.rb similarity index 100% rename from spec/unit/parser/functions/grep_spec.rb rename to spec/unit/puppet/parser/functions/grep_spec.rb diff --git a/spec/unit/parser/functions/hash_spec.rb b/spec/unit/puppet/parser/functions/hash_spec.rb similarity index 100% rename from spec/unit/parser/functions/hash_spec.rb rename to spec/unit/puppet/parser/functions/hash_spec.rb diff --git a/spec/unit/parser/functions/is_array_spec.rb b/spec/unit/puppet/parser/functions/is_array_spec.rb similarity index 100% rename from spec/unit/parser/functions/is_array_spec.rb rename to spec/unit/puppet/parser/functions/is_array_spec.rb diff --git a/spec/unit/parser/functions/is_domain_name_spec.rb b/spec/unit/puppet/parser/functions/is_domain_name_spec.rb similarity index 100% rename from spec/unit/parser/functions/is_domain_name_spec.rb rename to spec/unit/puppet/parser/functions/is_domain_name_spec.rb diff --git a/spec/unit/parser/functions/is_float_spec.rb b/spec/unit/puppet/parser/functions/is_float_spec.rb similarity index 100% rename from spec/unit/parser/functions/is_float_spec.rb rename to spec/unit/puppet/parser/functions/is_float_spec.rb diff --git a/spec/unit/parser/functions/is_hash_spec.rb b/spec/unit/puppet/parser/functions/is_hash_spec.rb similarity index 100% rename from spec/unit/parser/functions/is_hash_spec.rb rename to spec/unit/puppet/parser/functions/is_hash_spec.rb diff --git a/spec/unit/parser/functions/is_integer_spec.rb b/spec/unit/puppet/parser/functions/is_integer_spec.rb similarity index 100% rename from spec/unit/parser/functions/is_integer_spec.rb rename to spec/unit/puppet/parser/functions/is_integer_spec.rb diff --git a/spec/unit/parser/functions/is_ip_address_spec.rb b/spec/unit/puppet/parser/functions/is_ip_address_spec.rb similarity index 100% rename from spec/unit/parser/functions/is_ip_address_spec.rb rename to spec/unit/puppet/parser/functions/is_ip_address_spec.rb diff --git a/spec/unit/parser/functions/is_mac_address_spec.rb b/spec/unit/puppet/parser/functions/is_mac_address_spec.rb similarity index 100% rename from spec/unit/parser/functions/is_mac_address_spec.rb rename to spec/unit/puppet/parser/functions/is_mac_address_spec.rb diff --git a/spec/unit/parser/functions/is_numeric_spec.rb b/spec/unit/puppet/parser/functions/is_numeric_spec.rb similarity index 100% rename from spec/unit/parser/functions/is_numeric_spec.rb rename to spec/unit/puppet/parser/functions/is_numeric_spec.rb diff --git a/spec/unit/parser/functions/is_string_spec.rb b/spec/unit/puppet/parser/functions/is_string_spec.rb similarity index 100% rename from spec/unit/parser/functions/is_string_spec.rb rename to spec/unit/puppet/parser/functions/is_string_spec.rb diff --git a/spec/unit/parser/functions/join_spec.rb b/spec/unit/puppet/parser/functions/join_spec.rb similarity index 100% rename from spec/unit/parser/functions/join_spec.rb rename to spec/unit/puppet/parser/functions/join_spec.rb diff --git a/spec/unit/parser/functions/keys_spec.rb b/spec/unit/puppet/parser/functions/keys_spec.rb similarity index 100% rename from spec/unit/parser/functions/keys_spec.rb rename to spec/unit/puppet/parser/functions/keys_spec.rb diff --git a/spec/unit/parser/functions/lstrip_spec.rb b/spec/unit/puppet/parser/functions/lstrip_spec.rb similarity index 100% rename from spec/unit/parser/functions/lstrip_spec.rb rename to spec/unit/puppet/parser/functions/lstrip_spec.rb diff --git a/spec/unit/parser/functions/member_spec.rb b/spec/unit/puppet/parser/functions/member_spec.rb similarity index 100% rename from spec/unit/parser/functions/member_spec.rb rename to spec/unit/puppet/parser/functions/member_spec.rb diff --git a/spec/unit/parser/functions/num2bool_spec.rb b/spec/unit/puppet/parser/functions/num2bool_spec.rb similarity index 100% rename from spec/unit/parser/functions/num2bool_spec.rb rename to spec/unit/puppet/parser/functions/num2bool_spec.rb diff --git a/spec/unit/parser/functions/parsejson_spec.rb b/spec/unit/puppet/parser/functions/parsejson_spec.rb similarity index 100% rename from spec/unit/parser/functions/parsejson_spec.rb rename to spec/unit/puppet/parser/functions/parsejson_spec.rb diff --git a/spec/unit/parser/functions/parseyaml_spec.rb b/spec/unit/puppet/parser/functions/parseyaml_spec.rb similarity index 100% rename from spec/unit/parser/functions/parseyaml_spec.rb rename to spec/unit/puppet/parser/functions/parseyaml_spec.rb diff --git a/spec/unit/parser/functions/prefix_spec.rb b/spec/unit/puppet/parser/functions/prefix_spec.rb similarity index 100% rename from spec/unit/parser/functions/prefix_spec.rb rename to spec/unit/puppet/parser/functions/prefix_spec.rb diff --git a/spec/unit/parser/functions/range_spec.rb b/spec/unit/puppet/parser/functions/range_spec.rb similarity index 100% rename from spec/unit/parser/functions/range_spec.rb rename to spec/unit/puppet/parser/functions/range_spec.rb diff --git a/spec/unit/parser/functions/reverse_spec.rb b/spec/unit/puppet/parser/functions/reverse_spec.rb similarity index 100% rename from spec/unit/parser/functions/reverse_spec.rb rename to spec/unit/puppet/parser/functions/reverse_spec.rb diff --git a/spec/unit/parser/functions/rstrip_spec.rb b/spec/unit/puppet/parser/functions/rstrip_spec.rb similarity index 100% rename from spec/unit/parser/functions/rstrip_spec.rb rename to spec/unit/puppet/parser/functions/rstrip_spec.rb diff --git a/spec/unit/parser/functions/shuffle_spec.rb b/spec/unit/puppet/parser/functions/shuffle_spec.rb similarity index 100% rename from spec/unit/parser/functions/shuffle_spec.rb rename to spec/unit/puppet/parser/functions/shuffle_spec.rb diff --git a/spec/unit/parser/functions/size_spec.rb b/spec/unit/puppet/parser/functions/size_spec.rb similarity index 100% rename from spec/unit/parser/functions/size_spec.rb rename to spec/unit/puppet/parser/functions/size_spec.rb diff --git a/spec/unit/parser/functions/sort_spec.rb b/spec/unit/puppet/parser/functions/sort_spec.rb similarity index 100% rename from spec/unit/parser/functions/sort_spec.rb rename to spec/unit/puppet/parser/functions/sort_spec.rb diff --git a/spec/unit/parser/functions/squeeze_spec.rb b/spec/unit/puppet/parser/functions/squeeze_spec.rb similarity index 100% rename from spec/unit/parser/functions/squeeze_spec.rb rename to spec/unit/puppet/parser/functions/squeeze_spec.rb diff --git a/spec/unit/parser/functions/str2bool_spec.rb b/spec/unit/puppet/parser/functions/str2bool_spec.rb similarity index 100% rename from spec/unit/parser/functions/str2bool_spec.rb rename to spec/unit/puppet/parser/functions/str2bool_spec.rb diff --git a/spec/unit/parser/functions/strftime_spec.rb b/spec/unit/puppet/parser/functions/strftime_spec.rb similarity index 100% rename from spec/unit/parser/functions/strftime_spec.rb rename to spec/unit/puppet/parser/functions/strftime_spec.rb diff --git a/spec/unit/parser/functions/strip_spec.rb b/spec/unit/puppet/parser/functions/strip_spec.rb similarity index 100% rename from spec/unit/parser/functions/strip_spec.rb rename to spec/unit/puppet/parser/functions/strip_spec.rb diff --git a/spec/unit/parser/functions/swapcase_spec.rb b/spec/unit/puppet/parser/functions/swapcase_spec.rb similarity index 100% rename from spec/unit/parser/functions/swapcase_spec.rb rename to spec/unit/puppet/parser/functions/swapcase_spec.rb diff --git a/spec/unit/parser/functions/time_spec.rb b/spec/unit/puppet/parser/functions/time_spec.rb similarity index 100% rename from spec/unit/parser/functions/time_spec.rb rename to spec/unit/puppet/parser/functions/time_spec.rb diff --git a/spec/unit/parser/functions/type_spec.rb b/spec/unit/puppet/parser/functions/type_spec.rb similarity index 100% rename from spec/unit/parser/functions/type_spec.rb rename to spec/unit/puppet/parser/functions/type_spec.rb diff --git a/spec/unit/parser/functions/unique_spec.rb b/spec/unit/puppet/parser/functions/unique_spec.rb similarity index 100% rename from spec/unit/parser/functions/unique_spec.rb rename to spec/unit/puppet/parser/functions/unique_spec.rb diff --git a/spec/unit/parser/functions/upcase_spec.rb b/spec/unit/puppet/parser/functions/upcase_spec.rb similarity index 100% rename from spec/unit/parser/functions/upcase_spec.rb rename to spec/unit/puppet/parser/functions/upcase_spec.rb diff --git a/spec/unit/parser/functions/values_at_spec.rb b/spec/unit/puppet/parser/functions/values_at_spec.rb similarity index 100% rename from spec/unit/parser/functions/values_at_spec.rb rename to spec/unit/puppet/parser/functions/values_at_spec.rb diff --git a/spec/unit/parser/functions/values_spec.rb b/spec/unit/puppet/parser/functions/values_spec.rb similarity index 100% rename from spec/unit/parser/functions/values_spec.rb rename to spec/unit/puppet/parser/functions/values_spec.rb diff --git a/spec/unit/parser/functions/zip_spec.rb b/spec/unit/puppet/parser/functions/zip_spec.rb similarity index 100% rename from spec/unit/parser/functions/zip_spec.rb rename to spec/unit/puppet/parser/functions/zip_spec.rb