summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorKen Barber <ken@bob.sh>2011-07-01 21:09:02 +0200
committerKen Barber <ken@bob.sh>2011-07-01 21:09:02 +0200
commit07ee33455439d960b9996e8110e011437181b42a (patch)
treea5123f487a551a2608971b3ede13417139719b32 /examples
parent1abf4b62fc8e97c7096c9da3d350e3e6268c5c72 (diff)
Added validate_resource function and examples on how to use it (and kwalify as well)
Diffstat (limited to 'examples')
-rw-r--r--examples/kwalify-1.pp9
-rw-r--r--examples/kwalify-2.pp24
-rw-r--r--examples/validate_resource-1.pp23
-rw-r--r--examples/validate_resource-1.schema39
-rw-r--r--examples/validate_resource-2.pp17
-rw-r--r--examples/validate_resource-2.schema26
6 files changed, 138 insertions, 0 deletions
diff --git a/examples/kwalify-1.pp b/examples/kwalify-1.pp
new file mode 100644
index 0000000..852e46c
--- /dev/null
+++ b/examples/kwalify-1.pp
@@ -0,0 +1,9 @@
+$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
new file mode 100644
index 0000000..3f4ec33
--- /dev/null
+++ b/examples/kwalify-2.pp
@@ -0,0 +1,24 @@
+$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
new file mode 100644
index 0000000..c701b8d
--- /dev/null
+++ b/examples/validate_resource-1.pp
@@ -0,0 +1,23 @@
+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
new file mode 100644
index 0000000..c540db5
--- /dev/null
+++ b/examples/validate_resource-1.schema
@@ -0,0 +1,39 @@
+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
new file mode 100644
index 0000000..b53b109
--- /dev/null
+++ b/examples/validate_resource-2.pp
@@ -0,0 +1,17 @@
+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
new file mode 100644
index 0000000..b516945
--- /dev/null
+++ b/examples/validate_resource-2.schema
@@ -0,0 +1,26 @@
+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