chef-validation 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/chef/validation.rb +9 -0
- data/lib/chef/validation/validator.rb +8 -5
- data/lib/chef/validation/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d0e9b458060b1ff05e0351dd1d96917b6f3d5a8
|
4
|
+
data.tar.gz: 4806e2f4670ad28454893828cc904c5610074c10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 261ea5766065f68152e7b11a7975b2b0a6f4b2c644ddf449198bed3a93607c6961d6865046d315256ddc7e81a1392ea779bba38817a30efeae30c49a2f95fb15
|
7
|
+
data.tar.gz: 453e514792b2f9b588779881a1e9441307664027abe811ebf8672a48647296bbce91b0dba9ac500b55a5c7288e58a695fe59b1cd9ecd94d9133a67038e1b36bd
|
data/CHANGELOG.md
CHANGED
data/lib/chef/validation.rb
CHANGED
@@ -39,9 +39,17 @@ module Chef::Validation
|
|
39
39
|
|
40
40
|
private
|
41
41
|
|
42
|
+
# It's quite sad, but metadata is not guaranteed to be 100% loaded depending on the
|
43
|
+
# version of Chef you are using and at which point of the Chef Client run you are at.
|
44
|
+
def reload_metadata(cookbook)
|
45
|
+
file = cookbook.root_filenames.find { |x| File.basename(x) == "metadata.json" }
|
46
|
+
cookbook.metadata.from_json(IO.read(file))
|
47
|
+
end
|
48
|
+
|
42
49
|
def validate_all(node)
|
43
50
|
total_errors = {}
|
44
51
|
ContextExt.cookbooks(node.run_context).each do |cookbook|
|
52
|
+
reload_metadata(cookbook)
|
45
53
|
unless (errors = Validator.run(node, cookbook.metadata)).empty?
|
46
54
|
total_errors[cookbook.name] = errors
|
47
55
|
end
|
@@ -54,6 +62,7 @@ module Chef::Validation
|
|
54
62
|
unless cookbook = ContextExt.cookbook(node.run_context, name)
|
55
63
|
raise "Cookbook not found: #{cookbook}"
|
56
64
|
end
|
65
|
+
reload_metadata(cookbook)
|
57
66
|
unless (errors = Validator.run(node, cookbook.metadata)).empty?
|
58
67
|
total_errors[cookbook.name] = errors
|
59
68
|
end
|
@@ -60,22 +60,25 @@ module Chef::Validation
|
|
60
60
|
BOOLEAN = "boolean".freeze
|
61
61
|
NUMERIC = "numeric".freeze
|
62
62
|
|
63
|
-
def validate_choice(value, choices, name
|
63
|
+
def validate_choice(value, choices, name)
|
64
|
+
errors = []
|
64
65
|
unless choices.include?(value)
|
65
66
|
errors << "Must be one of the following choices: #{choices.join(", ")}."
|
66
67
|
end
|
67
68
|
errors
|
68
69
|
end
|
69
70
|
|
70
|
-
def validate_required(value, name
|
71
|
-
|
71
|
+
def validate_required(value, name)
|
72
|
+
errors = []
|
73
|
+
if value.nil? || value.empty?
|
72
74
|
errors << "Required attribute but was not present."
|
73
75
|
end
|
74
76
|
errors
|
75
77
|
end
|
76
78
|
|
77
|
-
def validate_type(value, type, name
|
78
|
-
|
79
|
+
def validate_type(value, type, name)
|
80
|
+
errors = []
|
81
|
+
state = nil
|
79
82
|
case type.downcase
|
80
83
|
when STRING
|
81
84
|
state = :error unless value.is_a?(String)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-validation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jamie Winsor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chef
|