steplib 0.0.0.0 → 0.9.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/steplib/hash_utils.rb +81 -11
- data/lib/steplib/steplib_validator.rb +114 -0
- data/lib/steplib/workflow_updater.rb +96 -0
- data/lib/steplib/workflow_utils.rb +45 -0
- data/lib/steplib/workflow_validator.rb +111 -0
- data/lib/steplib.rb +4 -1
- metadata +7 -5
- data/lib/steplib/format_corrector.rb +0 -16
- data/lib/steplib/validator.rb +0 -114
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0532328cd85829decb7abc6f975c613bf779c5b
|
4
|
+
data.tar.gz: 068bb9377741bb74f22a463edc3d1a35675bbba0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75730c68760bc91caf0da54870b73789621929425161036c26ed73aeca204471da68b2579c4a7b98f24258732420c101c98a3db3dc08440514474c7845c2d14b
|
7
|
+
data.tar.gz: a4b16e7993fcede8fe53bfe5875346cfbd0bf10fce36b3c573f35b8aea6e627fe53036d410ffb5f5a572aa599414bf2eb28e237a94b928a596dd90c6426b2f53
|
data/lib/steplib/hash_utils.rb
CHANGED
@@ -7,20 +7,90 @@ class FalseClass; include ABooleanValue; end
|
|
7
7
|
|
8
8
|
module Steplib
|
9
9
|
class HashUtils
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
class << self
|
11
|
+
|
12
|
+
def deep_copy(hsh)
|
13
|
+
return Marshal.load(Marshal.dump(hsh))
|
14
|
+
end
|
15
|
+
|
16
|
+
def check_required_attributes_and_types!(hash_to_check, attribute_type_array)
|
17
|
+
attribute_type_array.each do |a_attribute_type_itm|
|
18
|
+
attribute_key = a_attribute_type_itm[0]
|
19
|
+
attribute_type = a_attribute_type_itm[1]
|
20
|
+
#
|
21
|
+
attr_value = hash_to_check[attribute_key]
|
22
|
+
if attr_value.nil?
|
23
|
+
raise "Attribute (#{attribute_key}) not found in hash"
|
24
|
+
end
|
25
|
+
unless attr_value.is_a? attribute_type
|
26
|
+
raise "Attribute (#{attribute_key}) found, but it's type (#{attr_value.class}) doesn't match the required (#{attribute_type})"
|
27
|
+
end
|
18
28
|
end
|
19
|
-
|
20
|
-
|
29
|
+
return true
|
30
|
+
end
|
31
|
+
|
32
|
+
#
|
33
|
+
# Sets the provided default value for the specified
|
34
|
+
# key if the key is missing.
|
35
|
+
# Defaults_arr is an array of {:key=>,:value=>} hashes
|
36
|
+
# Doesn't do a copy of input hash, will inline-set
|
37
|
+
# the attributes / modify the input hash!
|
38
|
+
def set_missing_defaults(hsh, defaults_arr)
|
39
|
+
defaults_arr.each do |a_def|
|
40
|
+
a_def_key = a_def[:key]
|
41
|
+
a_def_value = a_def[:value]
|
42
|
+
if hsh[a_def_key].nil?
|
43
|
+
hsh[a_def_key] = a_def_value
|
44
|
+
end
|
21
45
|
end
|
46
|
+
return hsh
|
47
|
+
end
|
48
|
+
# Deep-copy version
|
49
|
+
# Returns a new hash, the original input hash will be kept unchanged!
|
50
|
+
def set_missing_defaults_dcopy(in_hsh, defaults_arr)
|
51
|
+
hsh = deep_copy(in_hsh)
|
52
|
+
return set_missing_defaults(hsh, defaults_arr)
|
22
53
|
end
|
23
|
-
|
54
|
+
|
55
|
+
#
|
56
|
+
# Copies the listed attributes from the copy_from hash
|
57
|
+
# to the copy_to hash in case the attribute is missing
|
58
|
+
# from copy_to hash.
|
59
|
+
# Doesn't do a copy of input hash, will inline-set
|
60
|
+
# the attributes / modify the input hash!
|
61
|
+
def copy_missing_defaults(hsh_copy_to, hsh_copy_from, attr_to_copy_list)
|
62
|
+
attr_to_copy_list.each do |a_attr_to_copy|
|
63
|
+
if hsh_copy_to[a_attr_to_copy].nil?
|
64
|
+
hsh_copy_to[a_attr_to_copy] = hsh_copy_from[a_attr_to_copy]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
return hsh_copy_to
|
68
|
+
end
|
69
|
+
# Deep-copy version
|
70
|
+
# Returns a new hash, the original input hash will be kept unchanged!
|
71
|
+
def copy_missing_defaults_dcopy(in_hsh_copy_to, hsh_copy_from, attr_to_copy_list)
|
72
|
+
hsh_copy_to = deep_copy(in_hsh_copy_to)
|
73
|
+
return copy_missing_defaults(hsh_copy_to, hsh_copy_from, attr_to_copy_list)
|
74
|
+
end
|
75
|
+
|
76
|
+
#
|
77
|
+
# Copies the listed attributes from the copy_from hash
|
78
|
+
# to the copy_to hash.
|
79
|
+
# Doesn't do a copy of input hash, will inline-set
|
80
|
+
# the attributes / modify the input hash!
|
81
|
+
def copy_attributes(hsh_copy_to, hsh_copy_from, attr_to_copy_list)
|
82
|
+
attr_to_copy_list.each do |a_attr_to_copy|
|
83
|
+
hsh_copy_to[a_attr_to_copy] = hsh_copy_from[a_attr_to_copy]
|
84
|
+
end
|
85
|
+
return hsh_copy_to
|
86
|
+
end
|
87
|
+
# Deep-copy version
|
88
|
+
# Returns a new hash, the original input hash will be kept unchanged!
|
89
|
+
def copy_attributes_dcopy(in_hsh_copy_to, hsh_copy_from, attr_to_copy_list)
|
90
|
+
hsh_copy_to = deep_copy(in_hsh_copy_to)
|
91
|
+
return copy_attributes(hsh_copy_to, hsh_copy_from, attr_to_copy_list)
|
92
|
+
end
|
93
|
+
|
24
94
|
end
|
25
95
|
end
|
26
96
|
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require_relative 'hash_utils'
|
2
|
+
|
3
|
+
module Steplib
|
4
|
+
class SteplibValidator
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def validate_steplib!(steplib_data)
|
8
|
+
expected_format_version = '0.9.0'
|
9
|
+
|
10
|
+
if steplib_data['format_version'] != expected_format_version
|
11
|
+
raise "Invalid format_version, expected (#{expected_format_version}) got (#{steplib_data['format_version']})"
|
12
|
+
end
|
13
|
+
|
14
|
+
HashUtils.check_required_attributes_and_types!(steplib_data, [
|
15
|
+
['format_version', String],
|
16
|
+
['generated_at_timestamp', Fixnum],
|
17
|
+
['steplib_source', String],
|
18
|
+
['steps', Hash]
|
19
|
+
])
|
20
|
+
|
21
|
+
steps_arr = steplib_data['steps']
|
22
|
+
steps_arr.each do |a_step_id, a_step_data|
|
23
|
+
validate_step!(a_step_data)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def validate_step!(step_data)
|
28
|
+
HashUtils.check_required_attributes_and_types!(step_data, [
|
29
|
+
['id', String],
|
30
|
+
['versions', Array],
|
31
|
+
['latest', Hash]
|
32
|
+
])
|
33
|
+
|
34
|
+
# validate the versions
|
35
|
+
step_version_datas = step_data['versions']
|
36
|
+
step_version_datas.each do |a_step_version_data|
|
37
|
+
validate_step_version!(a_step_version_data)
|
38
|
+
end
|
39
|
+
|
40
|
+
# also validate the 'latest' item
|
41
|
+
validate_step_version!(step_data['latest'])
|
42
|
+
end
|
43
|
+
|
44
|
+
def validate_step_version!(step_version_data)
|
45
|
+
HashUtils.check_required_attributes_and_types!(step_version_data, [
|
46
|
+
# auto generated
|
47
|
+
['id', String],
|
48
|
+
['steplib_source', String],
|
49
|
+
['version_tag', String],
|
50
|
+
# data from step.yml
|
51
|
+
['name', String],
|
52
|
+
['description', String],
|
53
|
+
['website', String],
|
54
|
+
['fork_url', String],
|
55
|
+
['source', Hash],
|
56
|
+
['host_os_tags', Array],
|
57
|
+
['project_type_tags', Array],
|
58
|
+
['type_tags', Array],
|
59
|
+
['is_requires_admin_user', ABooleanValue],
|
60
|
+
['inputs', Array],
|
61
|
+
['outputs', Array],
|
62
|
+
])
|
63
|
+
|
64
|
+
HashUtils.check_required_attributes_and_types!(step_version_data['source'], [
|
65
|
+
['git', String]
|
66
|
+
])
|
67
|
+
|
68
|
+
a_host_os_tags = step_version_data['host_os_tags']
|
69
|
+
a_host_os_tags.each { |a_tag|
|
70
|
+
raise "Invalid host-os-tag (#{a_tag}), not a String (class: #{a_tag.class})!" unless a_tag.is_a? String
|
71
|
+
}
|
72
|
+
|
73
|
+
a_project_type_tags = step_version_data['project_type_tags']
|
74
|
+
a_project_type_tags.each { |a_tag|
|
75
|
+
raise "Invalid project-type-tag (#{a_tag}), not a String (class: #{a_tag.class})!" unless a_tag.is_a? String
|
76
|
+
}
|
77
|
+
|
78
|
+
a_type_tags = step_version_data['type_tags']
|
79
|
+
a_type_tags.each { |a_tag|
|
80
|
+
raise "Invalid type-tag (#{a_tag}), not a String (class: #{a_tag.class})!" unless a_tag.is_a? String
|
81
|
+
}
|
82
|
+
|
83
|
+
a_inputs = step_version_data['inputs']
|
84
|
+
a_inputs.each do |a_input_itm|
|
85
|
+
HashUtils.check_required_attributes_and_types!(a_input_itm, [
|
86
|
+
['title', String],
|
87
|
+
['description', String],
|
88
|
+
['mapped_to', String],
|
89
|
+
['is_expand', ABooleanValue],
|
90
|
+
['is_required', ABooleanValue],
|
91
|
+
['value_options', Array],
|
92
|
+
['value', String],
|
93
|
+
['is_dont_change_value', ABooleanValue]
|
94
|
+
])
|
95
|
+
|
96
|
+
a_value_options = a_input_itm['value_options']
|
97
|
+
a_value_options.each { |a_value_option|
|
98
|
+
raise "Invalid value-option (#{a_value_option}), not a String (class: #{a_value_option.class})!" unless a_value_option.is_a? String
|
99
|
+
}
|
100
|
+
end
|
101
|
+
|
102
|
+
a_outputs = step_version_data['outputs']
|
103
|
+
a_outputs.each do |a_output_itm|
|
104
|
+
HashUtils.check_required_attributes_and_types!(a_output_itm, [
|
105
|
+
['title', String],
|
106
|
+
['description', String],
|
107
|
+
['mapped_to', String]
|
108
|
+
])
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require_relative 'steplib_validator'
|
2
|
+
require_relative 'hash_utils'
|
3
|
+
|
4
|
+
module Steplib
|
5
|
+
class WorkflowUpdater
|
6
|
+
class << self
|
7
|
+
|
8
|
+
#
|
9
|
+
# The input steplib_step_version have to be a valid step-version!
|
10
|
+
# The input workflow_step is not copied, modified in-inline!
|
11
|
+
# Also: inputs which can't be found in the steplib-step-version
|
12
|
+
# WILL BE REMOVED and inputs which can be found in the steplib-step-version
|
13
|
+
# but not in the workflow-step inputs WILL BE ADDED
|
14
|
+
# Because of the potential destructive nature of this method you
|
15
|
+
# should use it carefully and you can expect an exception/error raised for:
|
16
|
+
# * steplib-step-version is not valid
|
17
|
+
# * steplib-step-version's version_tag doesn't match the workflow_step's version_tag
|
18
|
+
# * missing 'version_tag' in workflow_step
|
19
|
+
def update_workflow_step_with_steplib_step_version!(workflow_step, steplib_step_version)
|
20
|
+
#
|
21
|
+
SteplibValidator.validate_step_version!(steplib_step_version)
|
22
|
+
raise "Missing 'version_tag'" if workflow_step['version_tag'].nil?
|
23
|
+
if workflow_step['version_tag'] != steplib_step_version['version_tag']
|
24
|
+
raise "Workflow-step 'version_tag' doesn't match the steplib-step-version's"
|
25
|
+
end
|
26
|
+
#
|
27
|
+
# copy all except:
|
28
|
+
# * name
|
29
|
+
# * version_tag
|
30
|
+
workflow_step = HashUtils.copy_attributes(
|
31
|
+
workflow_step,
|
32
|
+
steplib_step_version,
|
33
|
+
[
|
34
|
+
'id', 'steplib_source', 'description',
|
35
|
+
'website', 'fork_url', 'source', 'host_os_tags',
|
36
|
+
'project_type_tags', 'type_tags', 'is_requires_admin_user'
|
37
|
+
]
|
38
|
+
)
|
39
|
+
|
40
|
+
# update inputs and remove the ones which can't be
|
41
|
+
# found in the steplib step version's inputs
|
42
|
+
# and add the missing ones
|
43
|
+
# update except:
|
44
|
+
# * mapped_to
|
45
|
+
# * value
|
46
|
+
steplib_step_version_inputs = steplib_step_version['inputs']
|
47
|
+
workflow_step['inputs'] = workflow_step['inputs'].map { |a_wf_step_inp|
|
48
|
+
# search for the same input in the steplib-step-version
|
49
|
+
related_steplib_input = steplib_step_version_inputs.find do |possible_inp|
|
50
|
+
if possible_inp['mapped_to'] == a_wf_step_inp['mapped_to']
|
51
|
+
true
|
52
|
+
else
|
53
|
+
false
|
54
|
+
end
|
55
|
+
end
|
56
|
+
if related_steplib_input.nil?
|
57
|
+
# not found - remove (w/ .compact)
|
58
|
+
# return:
|
59
|
+
nil
|
60
|
+
else
|
61
|
+
a_wf_step_inp = HashUtils.copy_attributes(
|
62
|
+
a_wf_step_inp,
|
63
|
+
related_steplib_input,
|
64
|
+
['title', 'description', 'is_expand',
|
65
|
+
'is_required', 'value_options', 'is_dont_change_value']
|
66
|
+
)
|
67
|
+
# return:
|
68
|
+
a_wf_step_inp
|
69
|
+
end
|
70
|
+
}.compact # .compact removes nil elements
|
71
|
+
# add missing ones
|
72
|
+
wf_step_inputs = workflow_step['inputs']
|
73
|
+
missing_inputs = steplib_step_version_inputs.select { |a_steplib_input|
|
74
|
+
wf_step_input = wf_step_inputs.find do |a_wf_inp|
|
75
|
+
if a_wf_inp['mapped_to'] == a_steplib_input['mapped_to']
|
76
|
+
true
|
77
|
+
else
|
78
|
+
false
|
79
|
+
end
|
80
|
+
end
|
81
|
+
# add, if not found
|
82
|
+
# return:
|
83
|
+
wf_step_input.nil?
|
84
|
+
}
|
85
|
+
workflow_step['inputs'] = wf_step_inputs.concat(missing_inputs)
|
86
|
+
|
87
|
+
# update outputs to match the steplib-step-version's
|
88
|
+
# output list
|
89
|
+
workflow_step['outputs'] = Steplib::HashUtils.deep_copy(steplib_step_version['outputs'])
|
90
|
+
|
91
|
+
return workflow_step
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require_relative 'hash_utils'
|
2
|
+
|
3
|
+
module Steplib
|
4
|
+
class WorkflowUtils
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def create_workflow_environment_item(title, mapped_to, value, is_expand)
|
8
|
+
return {
|
9
|
+
'title' => title.to_s, # string
|
10
|
+
'mapped_to' => mapped_to.to_s, # string
|
11
|
+
'value' => value.to_s, # string
|
12
|
+
'is_expand' => !!is_expand # bool
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_workflow_base_template
|
17
|
+
workflow_base_template = {
|
18
|
+
'format_version' => '0.9.0',
|
19
|
+
'environments' => [],
|
20
|
+
'steps' => []
|
21
|
+
}
|
22
|
+
return workflow_base_template
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_workflow_step_from_steplib_step(steplib_step, position_in_workflow, is_always_run=false)
|
26
|
+
wf_step = HashUtils.deep_copy(steplib_step).merge({
|
27
|
+
'position_in_workflow' => position_in_workflow.to_i,
|
28
|
+
'is_always_run' => !!is_always_run,
|
29
|
+
})
|
30
|
+
return wf_step
|
31
|
+
end
|
32
|
+
|
33
|
+
def create_workflow_from_step_versions(steplib_step_versions, workflow_environments=[])
|
34
|
+
workflow_data = create_workflow_base_template()
|
35
|
+
workflow_data['steps'] = steplib_step_versions.map.with_index { |steplib_step_ver, idx|
|
36
|
+
# return:
|
37
|
+
create_workflow_step_from_steplib_step(steplib_step_ver, idx, false)
|
38
|
+
}
|
39
|
+
workflow_data['environments'] = workflow_environments
|
40
|
+
return workflow_data
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require_relative 'hash_utils'
|
2
|
+
|
3
|
+
module Steplib
|
4
|
+
class WorkflowValidator
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def validate_workflow!(workflow_data)
|
8
|
+
expected_format_version = '0.9.0'
|
9
|
+
if workflow_data['format_version'] != expected_format_version
|
10
|
+
raise "Invalid format_version, expected (#{expected_format_version}) got (#{workflow_data['format_version']})"
|
11
|
+
end
|
12
|
+
|
13
|
+
HashUtils.check_required_attributes_and_types!(workflow_data, [
|
14
|
+
['format_version', String],
|
15
|
+
['environments', Array],
|
16
|
+
['steps', Array]
|
17
|
+
])
|
18
|
+
|
19
|
+
envs_arr = workflow_data['environments']
|
20
|
+
envs_arr.each do |a_env_data|
|
21
|
+
validate_workflow_environment!(a_env_data)
|
22
|
+
end
|
23
|
+
|
24
|
+
steps_arr = workflow_data['steps']
|
25
|
+
steps_arr.each do |a_step_data|
|
26
|
+
validate_workflow_step!(a_step_data)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def validate_workflow_environment!(env_item_data)
|
31
|
+
HashUtils.check_required_attributes_and_types!(env_item_data, [
|
32
|
+
['title', String],
|
33
|
+
['mapped_to', String],
|
34
|
+
['is_expand', ABooleanValue],
|
35
|
+
['value', String],
|
36
|
+
])
|
37
|
+
end
|
38
|
+
|
39
|
+
def validate_workflow_step!(workflow_step_data)
|
40
|
+
HashUtils.check_required_attributes_and_types!(workflow_step_data, [
|
41
|
+
['position_in_workflow', Fixnum],
|
42
|
+
['is_always_run', ABooleanValue],
|
43
|
+
# auto generated
|
44
|
+
['id', String],
|
45
|
+
['steplib_source', String],
|
46
|
+
['version_tag', String],
|
47
|
+
# data from step.yml
|
48
|
+
['name', String],
|
49
|
+
['description', String],
|
50
|
+
['website', String],
|
51
|
+
['fork_url', String],
|
52
|
+
['source', Hash],
|
53
|
+
['host_os_tags', Array],
|
54
|
+
['project_type_tags', Array],
|
55
|
+
['type_tags', Array],
|
56
|
+
['is_requires_admin_user', ABooleanValue],
|
57
|
+
['inputs', Array],
|
58
|
+
['outputs', Array],
|
59
|
+
])
|
60
|
+
|
61
|
+
HashUtils.check_required_attributes_and_types!(workflow_step_data['source'], [
|
62
|
+
['git', String]
|
63
|
+
])
|
64
|
+
|
65
|
+
a_host_os_tags = workflow_step_data['host_os_tags']
|
66
|
+
a_host_os_tags.each { |a_tag|
|
67
|
+
raise "Invalid host-os-tag (#{a_tag}), not a String (class: #{a_tag.class})!" unless a_tag.is_a? String
|
68
|
+
}
|
69
|
+
|
70
|
+
a_project_type_tags = workflow_step_data['project_type_tags']
|
71
|
+
a_project_type_tags.each { |a_tag|
|
72
|
+
raise "Invalid project-type-tag (#{a_tag}), not a String (class: #{a_tag.class})!" unless a_tag.is_a? String
|
73
|
+
}
|
74
|
+
|
75
|
+
a_type_tags = workflow_step_data['type_tags']
|
76
|
+
a_type_tags.each { |a_tag|
|
77
|
+
raise "Invalid type-tag (#{a_tag}), not a String (class: #{a_tag.class})!" unless a_tag.is_a? String
|
78
|
+
}
|
79
|
+
|
80
|
+
a_inputs = workflow_step_data['inputs']
|
81
|
+
a_inputs.each do |a_input_itm|
|
82
|
+
HashUtils.check_required_attributes_and_types!(a_input_itm, [
|
83
|
+
['title', String],
|
84
|
+
['description', String],
|
85
|
+
['mapped_to', String],
|
86
|
+
['is_expand', ABooleanValue],
|
87
|
+
['is_required', ABooleanValue],
|
88
|
+
['value_options', Array],
|
89
|
+
['value', String],
|
90
|
+
['is_dont_change_value', ABooleanValue]
|
91
|
+
])
|
92
|
+
|
93
|
+
a_value_options = a_input_itm['value_options']
|
94
|
+
a_value_options.each { |a_value_option|
|
95
|
+
raise "Invalid value-option (#{a_value_option}), not a String (class: #{a_value_option.class})!" unless a_value_option.is_a? String
|
96
|
+
}
|
97
|
+
end
|
98
|
+
|
99
|
+
a_outputs = workflow_step_data['outputs']
|
100
|
+
a_outputs.each do |a_output_itm|
|
101
|
+
HashUtils.check_required_attributes_and_types!(a_output_itm, [
|
102
|
+
['title', String],
|
103
|
+
['description', String],
|
104
|
+
['mapped_to', String]
|
105
|
+
])
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
data/lib/steplib.rb
CHANGED
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.
|
4
|
+
version: 0.9.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bitrise
|
@@ -20,10 +20,12 @@ extensions: []
|
|
20
20
|
extra_rdoc_files: []
|
21
21
|
files:
|
22
22
|
- lib/steplib.rb
|
23
|
-
- lib/steplib/format_corrector.rb
|
24
23
|
- lib/steplib/hash_utils.rb
|
25
|
-
- lib/steplib/
|
26
|
-
|
24
|
+
- lib/steplib/steplib_validator.rb
|
25
|
+
- lib/steplib/workflow_updater.rb
|
26
|
+
- lib/steplib/workflow_utils.rb
|
27
|
+
- lib/steplib/workflow_validator.rb
|
28
|
+
homepage: https://github.com/steplib/steplib_gem
|
27
29
|
licenses:
|
28
30
|
- MIT
|
29
31
|
metadata: {}
|
@@ -46,5 +48,5 @@ rubyforge_project:
|
|
46
48
|
rubygems_version: 2.2.2
|
47
49
|
signing_key:
|
48
50
|
specification_version: 4
|
49
|
-
summary: StepLib.com's validator and other utilities
|
51
|
+
summary: StepLib.com's validator and other utilities GEM
|
50
52
|
test_files: []
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require_relative 'validator'
|
2
|
-
|
3
|
-
module Steplib
|
4
|
-
class FormatCorrector
|
5
|
-
|
6
|
-
def initialize(workflow_data)
|
7
|
-
@workflow_data = workflow_data
|
8
|
-
end
|
9
|
-
|
10
|
-
def inject_missing_default_values_from_step_version(step_version_data)
|
11
|
-
|
12
|
-
return step_version_data
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|
data/lib/steplib/validator.rb
DELETED
@@ -1,114 +0,0 @@
|
|
1
|
-
require_relative 'hash_utils'
|
2
|
-
|
3
|
-
module Steplib
|
4
|
-
class Validator
|
5
|
-
|
6
|
-
def initialize(workflow_data)
|
7
|
-
@workflow_data = workflow_data
|
8
|
-
#
|
9
|
-
@expected_format_version = '0.9.0'
|
10
|
-
end
|
11
|
-
|
12
|
-
def validate!
|
13
|
-
if @workflow_data['format_version'] != @expected_format_version
|
14
|
-
raise "Invalid format_version, expected (#{@expected_format_version}) got (#{@workflow_data['format_version']})"
|
15
|
-
end
|
16
|
-
|
17
|
-
HashUtils.check_required_attributes_and_types!(@workflow_data, [
|
18
|
-
['format_version', String],
|
19
|
-
['environments', Array],
|
20
|
-
['steps', Array]
|
21
|
-
])
|
22
|
-
|
23
|
-
envs_arr = @workflow_data['environments']
|
24
|
-
envs_arr.each do |a_env_data|
|
25
|
-
validate_workflow_environment!(a_env_data)
|
26
|
-
end
|
27
|
-
|
28
|
-
steps_arr = @workflow_data['steps']
|
29
|
-
steps_arr.each do |a_step_data|
|
30
|
-
validate_workflow_step!(a_step_data)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def validate_workflow_environment!(env_item_data)
|
35
|
-
HashUtils.check_required_attributes_and_types!(env_item_data, [
|
36
|
-
['title', String],
|
37
|
-
['mapped_to', String],
|
38
|
-
['is_expand', ABooleanValue],
|
39
|
-
['value', String],
|
40
|
-
])
|
41
|
-
end
|
42
|
-
|
43
|
-
def validate_workflow_step!(workflow_step_data)
|
44
|
-
HashUtils.check_required_attributes_and_types!(workflow_step_data, [
|
45
|
-
['position_in_workflow', Fixnum],
|
46
|
-
['is_always_run', ABooleanValue],
|
47
|
-
# auto generated
|
48
|
-
['id', String],
|
49
|
-
['steplib_source', String],
|
50
|
-
['version_tag', String],
|
51
|
-
# data from step.yml
|
52
|
-
['name', String],
|
53
|
-
['description', String],
|
54
|
-
['website', String],
|
55
|
-
['fork_url', String],
|
56
|
-
['source', Hash],
|
57
|
-
['host_os_tags', Array],
|
58
|
-
['project_type_tags', Array],
|
59
|
-
['type_tags', Array],
|
60
|
-
['is_requires_admin_user', ABooleanValue],
|
61
|
-
['inputs', Array],
|
62
|
-
['outputs', Array],
|
63
|
-
])
|
64
|
-
|
65
|
-
HashUtils.check_required_attributes_and_types!(workflow_step_data['source'], [
|
66
|
-
['git', String]
|
67
|
-
])
|
68
|
-
|
69
|
-
a_host_os_tags = workflow_step_data['host_os_tags']
|
70
|
-
a_host_os_tags.each { |a_tag|
|
71
|
-
raise "Invalid host-os-tag (#{a_tag}), not a String (class: #{a_tag.class})!" unless a_tag.is_a? String
|
72
|
-
}
|
73
|
-
|
74
|
-
a_project_type_tags = workflow_step_data['project_type_tags']
|
75
|
-
a_project_type_tags.each { |a_tag|
|
76
|
-
raise "Invalid project-type-tag (#{a_tag}), not a String (class: #{a_tag.class})!" unless a_tag.is_a? String
|
77
|
-
}
|
78
|
-
|
79
|
-
a_type_tags = workflow_step_data['type_tags']
|
80
|
-
a_type_tags.each { |a_tag|
|
81
|
-
raise "Invalid type-tag (#{a_tag}), not a String (class: #{a_tag.class})!" unless a_tag.is_a? String
|
82
|
-
}
|
83
|
-
|
84
|
-
a_inputs = workflow_step_data['inputs']
|
85
|
-
a_inputs.each do |a_input_itm|
|
86
|
-
HashUtils.check_required_attributes_and_types!(a_input_itm, [
|
87
|
-
['title', String],
|
88
|
-
['description', String],
|
89
|
-
['mapped_to', String],
|
90
|
-
['is_expand', ABooleanValue],
|
91
|
-
['is_required', ABooleanValue],
|
92
|
-
['value_options', Array],
|
93
|
-
['value', String],
|
94
|
-
['is_dont_change_value', ABooleanValue]
|
95
|
-
])
|
96
|
-
|
97
|
-
a_value_options = a_input_itm['value_options']
|
98
|
-
a_value_options.each { |a_value_option|
|
99
|
-
raise "Invalid value-option (#{a_value_option}), not a String (class: #{a_value_option.class})!" unless a_value_option.is_a? String
|
100
|
-
}
|
101
|
-
end
|
102
|
-
|
103
|
-
a_outputs = workflow_step_data['outputs']
|
104
|
-
a_outputs.each do |a_output_itm|
|
105
|
-
HashUtils.check_required_attributes_and_types!(a_output_itm, [
|
106
|
-
['title', String],
|
107
|
-
['description', String],
|
108
|
-
['mapped_to', String]
|
109
|
-
])
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
end
|
114
|
-
end
|