Class: Steplib::SteplibValidator
- Inherits:
-
Object
- Object
- Steplib::SteplibValidator
- Defined in:
- lib/steplib/steplib_validator.rb
Class Method Summary collapse
- .optional_step_version_properties ⇒ Object
- .optional_step_version_properties_with_types ⇒ Object
- .required_step_version_inputs_properties_with_types ⇒ Object
- .required_step_version_log_highlights_properties_with_types ⇒ Object
- .required_step_version_outputs_properties_with_types ⇒ Object
- .required_step_version_properties_with_types ⇒ Object
- .required_step_version_source_properties_with_types ⇒ Object
- .validate_step!(step_data) ⇒ Object
- .validate_step_version!(step_version_data) ⇒ Object
- .validate_steplib!(steplib_data) ⇒ Object
- .whitelist_step_version(step_version_data) ⇒ Object
Class Method Details
.optional_step_version_properties ⇒ Object
104 105 106 |
# File 'lib/steplib/steplib_validator.rb', line 104 def optional_step_version_properties return optional_step_version_properties_with_types().map { |e| e.first } end |
.optional_step_version_properties_with_types ⇒ Object
98 99 100 101 102 |
# File 'lib/steplib/steplib_validator.rb', line 98 def optional_step_version_properties_with_types return [ ['icon_url_256', String], ] end |
.required_step_version_inputs_properties_with_types ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/steplib/steplib_validator.rb', line 112 def required_step_version_inputs_properties_with_types return [ ['title', String], ['description', String], ['mapped_to', String], ['is_expand', ABooleanValue], ['is_required', ABooleanValue], ['value_options', Array], ['value', String], ['is_dont_change_value', ABooleanValue] ] end |
.required_step_version_log_highlights_properties_with_types ⇒ Object
133 134 135 136 137 138 |
# File 'lib/steplib/steplib_validator.rb', line 133 def required_step_version_log_highlights_properties_with_types return [ ['search_pattern', String], ['highlight_type', String] ] end |
.required_step_version_outputs_properties_with_types ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/steplib/steplib_validator.rb', line 125 def required_step_version_outputs_properties_with_types return [ ['title', String], ['description', String], ['mapped_to', String] ] end |
.required_step_version_properties_with_types ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/steplib/steplib_validator.rb', line 75 def required_step_version_properties_with_types return [ # auto-generated IDs ['id', String], ['steplib_source', String], ['version_tag', String], # data from step.yml ['name', String], ['description', String], ['website', String], ['fork_url', String], ['source', Hash], ['host_os_tags', Array], ['project_type_tags', Array], ['type_tags', Array], ['is_requires_admin_user', ABooleanValue], ['is_always_run', ABooleanValue], ['inputs', Array], ['outputs', Array], ['log_highlights', Array], ] end |
.required_step_version_source_properties_with_types ⇒ Object
108 109 110 |
# File 'lib/steplib/steplib_validator.rb', line 108 def required_step_version_source_properties_with_types return [ ['git', String] ] end |
.validate_step!(step_data) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/steplib/steplib_validator.rb', line 27 def validate_step!(step_data) HashUtils.check_required_attributes_and_types!(step_data, [ ['id', String], ['versions', Array], ['latest', Hash] ]) # validate the versions step_version_datas = step_data['versions'] step_version_datas.each do |a_step_version_data| validate_step_version!(a_step_version_data) end # also validate the 'latest' item validate_step_version!(step_data['latest']) end |
.validate_step_version!(step_version_data) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/steplib/steplib_validator.rb', line 140 def validate_step_version!(step_version_data) # whitelist step_version_data = whitelist_step_version(step_version_data) # check/validate HashUtils.check_required_attributes_and_types!( step_version_data, required_step_version_properties_with_types() ) # optional step_version_data = HashUtils.set_missing_defaults( step_version_data, [ {key: 'icon_url_256', value: nil}, {key: 'log_highlights', value: []} ] ) HashUtils.check_required_attributes_and_types!( step_version_data['source'], required_step_version_source_properties_with_types() ) = step_version_data['host_os_tags'] .each { |a_tag| raise "Invalid host-os-tag (#{a_tag}), not a String (class: #{a_tag.class})!" unless a_tag.is_a? String } = step_version_data['project_type_tags'] .each { |a_tag| raise "Invalid project-type-tag (#{a_tag}), not a String (class: #{a_tag.class})!" unless a_tag.is_a? String } = step_version_data['type_tags'] .each { |a_tag| raise "Invalid type-tag (#{a_tag}), not a String (class: #{a_tag.class})!" unless a_tag.is_a? String } a_inputs = step_version_data['inputs'] a_inputs.each do |a_input_itm| HashUtils.check_required_attributes_and_types!( a_input_itm, required_step_version_inputs_properties_with_types() ) = a_input_itm['value_options'] .each { |a_value_option| raise "Invalid value-option (#{a_value_option}), not a String (class: #{a_value_option.class})!" unless a_value_option.is_a? String } end a_outputs = step_version_data['outputs'] a_outputs.each do |a_output_itm| HashUtils.check_required_attributes_and_types!( a_output_itm, required_step_version_outputs_properties_with_types() ) end a_log_highlights = step_version_data['log_highlights'] a_log_highlights.each do |a_log_highlight_itm| HashUtils.check_required_attributes_and_types!( a_log_highlight_itm, required_step_version_log_highlights_properties_with_types() ) end end |
.validate_steplib!(steplib_data) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/steplib/steplib_validator.rb', line 7 def validate_steplib!(steplib_data) expected_format_version = '0.9.0' if steplib_data['format_version'] != expected_format_version raise "Invalid format_version, expected (#{expected_format_version}) got (#{steplib_data['format_version']})" end HashUtils.check_required_attributes_and_types!(steplib_data, [ ['format_version', String], ['generated_at_timestamp', Fixnum], ['steplib_source', String], ['steps', Hash] ]) steps_arr = steplib_data['steps'] steps_arr.each do |a_step_id, a_step_data| validate_step!(a_step_data) end end |
.whitelist_step_version(step_version_data) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/steplib/steplib_validator.rb', line 44 def whitelist_step_version(step_version_data) raise "Input step_version_data hash is nil" if step_version_data.nil? base_prop_whitelist = required_step_version_properties_with_types().map { |e| e.first } base_prop_whitelist = base_prop_whitelist.concat( optional_step_version_properties() ) step_version_data = HashUtils.whitelist(step_version_data, base_prop_whitelist) # source step_version_data['source'] = HashUtils.whitelist( step_version_data['source'], required_step_version_source_properties_with_types().map { |e| e.first }) # inputs step_version_data['inputs'] = step_version_data['inputs'].map do |a_step_input| HashUtils.whitelist( a_step_input, required_step_version_inputs_properties_with_types().map { |e| e.first }) end # outputs step_version_data['outputs'] = step_version_data['outputs'].map do |a_step_output| HashUtils.whitelist( a_step_output, required_step_version_outputs_properties_with_types().map { |e| e.first }) end # log_highlights step_version_data['log_highlights'] = step_version_data['log_highlights'].map do |a_step_log_highlight| HashUtils.whitelist( a_step_log_highlight, required_step_version_log_highlights_properties_with_types().map { |e| e.first }) end return step_version_data end |