steplib_validator 0.0.0 → 0.0.0.1
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/lib/steplib_validator.rb +131 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2e440dc45f65bec97455845bae43bbb7d155cdb
|
4
|
+
data.tar.gz: 3be2df1e12d2061be34b2dea7d95e944afa1ac42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8e174d29a91a054f4fb8b76e9b3925ef316acd931cf58dddc6a157999b730cea721b2f59c6c5690fd4aca457dadb6ec0f60be81dbae4e203ce7c1da863bd9ea
|
7
|
+
data.tar.gz: dc5a9e784a6f0937d07c753cc4b7191aa721950e47983a6c38bc186eae5375b36fa67e8341a8af98a721bdb284d1745d821a6c85a8090ba11f3aae96887c294d
|
data/lib/steplib_validator.rb
CHANGED
@@ -1,5 +1,133 @@
|
|
1
|
+
# monkeypatching a ABooleanValue type
|
2
|
+
# so we can call .is_a? on true and false values
|
3
|
+
# and get a positive answer for both for ABooleanValue type
|
4
|
+
module ABooleanValue; end
|
5
|
+
class TrueClass; include ABooleanValue; end
|
6
|
+
class FalseClass; include ABooleanValue; end
|
7
|
+
|
1
8
|
class SteplibValidator
|
2
|
-
|
3
|
-
|
4
|
-
|
9
|
+
def initialize(steplib_data)
|
10
|
+
@steplib_data = steplib_data
|
11
|
+
end
|
12
|
+
|
13
|
+
def validate!
|
14
|
+
if @steplib_data['format_version'] != '0.9.0'
|
15
|
+
raise 'Invalid format_version'
|
16
|
+
end
|
17
|
+
|
18
|
+
check_required_attributes_and_types!(@steplib_data, [
|
19
|
+
['format_version', String],
|
20
|
+
['generated_at_timestamp', Fixnum],
|
21
|
+
['steplib_source', String],
|
22
|
+
['steps', Hash]
|
23
|
+
])
|
24
|
+
|
25
|
+
steps_arr = @steplib_data['steps']
|
26
|
+
steps_arr.each do |a_step_id, a_step_data|
|
27
|
+
validate_step!(a_step_data)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def validate_step!(step_data)
|
32
|
+
check_required_attributes_and_types!(step_data, [
|
33
|
+
['id', String],
|
34
|
+
['versions', Array],
|
35
|
+
['latest', Hash]
|
36
|
+
])
|
37
|
+
|
38
|
+
# validate the versions
|
39
|
+
step_version_datas = step_data['versions']
|
40
|
+
step_version_datas.each do |a_step_version_data|
|
41
|
+
validate_step_version!(a_step_version_data)
|
42
|
+
end
|
43
|
+
|
44
|
+
# also validate the 'latest' item
|
45
|
+
validate_step_version!(step_data['latest'])
|
46
|
+
end
|
47
|
+
|
48
|
+
def validate_step_version!(step_version_data)
|
49
|
+
check_required_attributes_and_types!(step_version_data, [
|
50
|
+
# auto generated
|
51
|
+
['id', String],
|
52
|
+
['steplib_source', String],
|
53
|
+
['version_tag', String],
|
54
|
+
# data from step.yml
|
55
|
+
['name', String],
|
56
|
+
['description', String],
|
57
|
+
['website', String],
|
58
|
+
['fork_url', String],
|
59
|
+
['source', Hash],
|
60
|
+
['host_os_tags', Array],
|
61
|
+
['project_type_tags', Array],
|
62
|
+
['type_tags', Array],
|
63
|
+
['is_requires_admin_user', ABooleanValue],
|
64
|
+
['inputs', Array],
|
65
|
+
['outputs', Array],
|
66
|
+
])
|
67
|
+
|
68
|
+
check_required_attributes_and_types!(step_version_data['source'], [
|
69
|
+
['git', String]
|
70
|
+
])
|
71
|
+
|
72
|
+
a_host_os_tags = step_version_data['host_os_tags']
|
73
|
+
a_host_os_tags.each { |a_tag|
|
74
|
+
raise "Invalid host-os-tag (#{a_tag}), not a String (class: #{a_tag.class})!" unless a_tag.is_a? String
|
75
|
+
}
|
76
|
+
|
77
|
+
a_project_type_tags = step_version_data['project_type_tags']
|
78
|
+
a_project_type_tags.each { |a_tag|
|
79
|
+
raise "Invalid project-type-tag (#{a_tag}), not a String (class: #{a_tag.class})!" unless a_tag.is_a? String
|
80
|
+
}
|
81
|
+
|
82
|
+
a_type_tags = step_version_data['type_tags']
|
83
|
+
a_type_tags.each { |a_tag|
|
84
|
+
raise "Invalid type-tag (#{a_tag}), not a String (class: #{a_tag.class})!" unless a_tag.is_a? String
|
85
|
+
}
|
86
|
+
|
87
|
+
a_inputs = step_version_data['inputs']
|
88
|
+
a_inputs.each do |a_input_itm|
|
89
|
+
check_required_attributes_and_types!(a_input_itm, [
|
90
|
+
['title', String],
|
91
|
+
['description', String],
|
92
|
+
['mapped_to', String],
|
93
|
+
['is_expand', ABooleanValue],
|
94
|
+
['is_required', ABooleanValue],
|
95
|
+
['value_options', Array],
|
96
|
+
['value', String],
|
97
|
+
['is_dont_change_value', ABooleanValue]
|
98
|
+
])
|
99
|
+
|
100
|
+
a_value_options = a_input_itm['value_options']
|
101
|
+
a_value_options.each { |a_value_option|
|
102
|
+
raise "Invalid value-option (#{a_value_option}), not a String (class: #{a_value_option.class})!" unless a_value_option.is_a? String
|
103
|
+
}
|
104
|
+
end
|
105
|
+
|
106
|
+
a_outputs = step_version_data['outputs']
|
107
|
+
a_outputs.each do |a_output_itm|
|
108
|
+
check_required_attributes_and_types!(a_output_itm, [
|
109
|
+
['title', String],
|
110
|
+
['description', String],
|
111
|
+
['mapped_to', String]
|
112
|
+
])
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
private
|
117
|
+
|
118
|
+
def check_required_attributes_and_types!(hash_to_check, attribute_type_array)
|
119
|
+
attribute_type_array.each do |a_attribute_type_itm|
|
120
|
+
attribute_key = a_attribute_type_itm[0]
|
121
|
+
attribute_type = a_attribute_type_itm[1]
|
122
|
+
#
|
123
|
+
attr_value = hash_to_check[attribute_key]
|
124
|
+
if attr_value.nil?
|
125
|
+
raise "Attribute (#{attribute_key}) not found in hash"
|
126
|
+
end
|
127
|
+
unless attr_value.is_a? attribute_type
|
128
|
+
raise "Attribute (#{attribute_key}) found, but it's type (#{attr_value.class}) doesn't match the required (#{attribute_type})"
|
129
|
+
end
|
130
|
+
end
|
131
|
+
return true
|
132
|
+
end
|
5
133
|
end
|