steplib 0.9.0.6 → 0.9.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac2ab879cd2d14f65be39f5e31dfb1a9f50c83eb
4
- data.tar.gz: 550f989699a6e3575479ed61ce32a8e0fb692340
3
+ metadata.gz: c487d428b66291bc8c2661014d48a7a0ee3f2222
4
+ data.tar.gz: 695069371c9936d4b657076e1c88045201558ef3
5
5
  SHA512:
6
- metadata.gz: ecb3c5e44bde0e8124d1e55d3e6e0a5199310e6c92afd6492d3903947aa26c208127c773be7aded7aec2d428286e7e8aa85b2c7f8873af026baf100d38fe5651
7
- data.tar.gz: b0bfb6e6419be8939f9e77761705b865443ab1125ceb1278e33c55c82510c7e59a7f61348361a456e33123d648c8ec051eb10e2a9fe172f5f3b23d260d5c9c5c
6
+ metadata.gz: 32c5e41dc32538d47033947b4c88ee0b9a50b54e19ddbe67343635baa8f73667230f8dd9054287ebecec6ef507e41fed32239da2ba4235fc8a92e2a94a18d000
7
+ data.tar.gz: e33072831220441ab59f487b35383558fd7ef86c8139051a57ed5d99299becc788fc54608dc68c16dc0a3bf0e7dd3afa49ce4c093b7e5e74d2a87cbc8af01ca6
@@ -13,6 +13,15 @@ module Steplib
13
13
  return Marshal.load(Marshal.dump(hsh))
14
14
  end
15
15
 
16
+ def whitelist(hsh, whitelist)
17
+ return nil if hsh.nil?
18
+ res_hash = {}
19
+ whitelist.each do |whiteitm|
20
+ res_hash[whiteitm] = hsh[whiteitm]
21
+ end
22
+ return res_hash
23
+ end
24
+
16
25
  def check_required_attributes_and_types!(hash_to_check, attribute_type_array)
17
26
  attribute_type_array.each do |a_attribute_type_itm|
18
27
  attribute_key = a_attribute_type_itm[0]
@@ -41,8 +41,33 @@ module Steplib
41
41
  validate_step_version!(step_data['latest'])
42
42
  end
43
43
 
44
- def validate_step_version!(step_version_data)
45
- HashUtils.check_required_attributes_and_types!(step_version_data, [
44
+ def whitelist_step_version(step_version_data)
45
+ raise "Input step_version_data hash is nil" if step_version_data.nil?
46
+
47
+ base_prop_whitelist = required_step_version_properties_with_types().map { |e| e.first }
48
+ base_prop_whitelist = base_prop_whitelist.concat( optional_step_version_properties() )
49
+ step_version_data = HashUtils.whitelist(step_version_data, base_prop_whitelist)
50
+ # source
51
+ step_version_data['source'] = HashUtils.whitelist(
52
+ step_version_data['source'],
53
+ required_step_version_source_properties_with_types().map { |e| e.first })
54
+ # inputs
55
+ step_version_data['inputs'] = step_version_data['inputs'].map do |a_step_input|
56
+ HashUtils.whitelist(
57
+ a_step_input,
58
+ required_step_version_inputs_properties_with_types().map { |e| e.first })
59
+ end
60
+ # outputs
61
+ step_version_data['outputs'] = step_version_data['outputs'].map do |a_step_output|
62
+ HashUtils.whitelist(
63
+ a_step_output,
64
+ required_step_version_outputs_properties_with_types().map { |e| e.first })
65
+ end
66
+ return step_version_data
67
+ end
68
+
69
+ def required_step_version_properties_with_types
70
+ return [
46
71
  # auto generated
47
72
  ['id', String],
48
73
  ['steplib_source', String],
@@ -59,16 +84,56 @@ module Steplib
59
84
  ['is_requires_admin_user', ABooleanValue],
60
85
  ['inputs', Array],
61
86
  ['outputs', Array],
62
- ])
87
+ ]
88
+ end
89
+
90
+ def optional_step_version_properties
91
+ return ['icon_url_256']
92
+ end
93
+
94
+ def required_step_version_source_properties_with_types
95
+ return [ ['git', String] ]
96
+ end
97
+
98
+ def required_step_version_inputs_properties_with_types
99
+ return [
100
+ ['title', String],
101
+ ['description', String],
102
+ ['mapped_to', String],
103
+ ['is_expand', ABooleanValue],
104
+ ['is_required', ABooleanValue],
105
+ ['value_options', Array],
106
+ ['value', String],
107
+ ['is_dont_change_value', ABooleanValue]
108
+ ]
109
+ end
110
+
111
+ def required_step_version_outputs_properties_with_types
112
+ return [
113
+ ['title', String],
114
+ ['description', String],
115
+ ['mapped_to', String]
116
+ ]
117
+ end
118
+
119
+ def validate_step_version!(step_version_data)
120
+ # whitelist
121
+ step_version_data = whitelist_step_version(step_version_data)
122
+ # check/validate
123
+ HashUtils.check_required_attributes_and_types!(
124
+ step_version_data,
125
+ required_step_version_properties_with_types()
126
+ )
63
127
 
64
128
  # optional - can be nil
65
129
  step_version_data = HashUtils.set_missing_defaults(
66
130
  step_version_data,
67
131
  [{key: 'icon_url_256', value: nil}])
68
132
 
69
- HashUtils.check_required_attributes_and_types!(step_version_data['source'], [
70
- ['git', String]
71
- ])
133
+ HashUtils.check_required_attributes_and_types!(
134
+ step_version_data['source'],
135
+ required_step_version_source_properties_with_types()
136
+ )
72
137
 
73
138
  a_host_os_tags = step_version_data['host_os_tags']
74
139
  a_host_os_tags.each { |a_tag|
@@ -87,16 +152,10 @@ module Steplib
87
152
 
88
153
  a_inputs = step_version_data['inputs']
89
154
  a_inputs.each do |a_input_itm|
90
- HashUtils.check_required_attributes_and_types!(a_input_itm, [
91
- ['title', String],
92
- ['description', String],
93
- ['mapped_to', String],
94
- ['is_expand', ABooleanValue],
95
- ['is_required', ABooleanValue],
96
- ['value_options', Array],
97
- ['value', String],
98
- ['is_dont_change_value', ABooleanValue]
99
- ])
155
+ HashUtils.check_required_attributes_and_types!(
156
+ a_input_itm,
157
+ required_step_version_inputs_properties_with_types()
158
+ )
100
159
 
101
160
  a_value_options = a_input_itm['value_options']
102
161
  a_value_options.each { |a_value_option|
@@ -106,11 +165,10 @@ module Steplib
106
165
 
107
166
  a_outputs = step_version_data['outputs']
108
167
  a_outputs.each do |a_output_itm|
109
- HashUtils.check_required_attributes_and_types!(a_output_itm, [
110
- ['title', String],
111
- ['description', String],
112
- ['mapped_to', String]
113
- ])
168
+ HashUtils.check_required_attributes_and_types!(
169
+ a_output_itm,
170
+ required_step_version_outputs_properties_with_types()
171
+ )
114
172
  end
115
173
  end
116
174
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: steplib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0.6
4
+ version: 0.9.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bitrise