steplib 0.0.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4e3c30d11a10f40220b04db01b9a8123c746eb46
4
+ data.tar.gz: 7f519032f630ab11195cf9e6ebad91b76b1409c4
5
+ SHA512:
6
+ metadata.gz: 6079617bd9a1ab65ec3bb4e48b9b2ea1a940a24aeca7041e251c9dff2e96c397319e6ac1534c0a26925756194fe39ac1c68f4adcb15c76df17049f58ece7e909
7
+ data.tar.gz: 0dc7cd1493257d6731e4e537e62a7231170f6a0ec61b7ba44a850cd168959d3ce22e7f17e8143633dcbe0f4897812cbd024ed1ce985c1984565fbae745ad8a49
@@ -0,0 +1,16 @@
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
@@ -0,0 +1,26 @@
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
+
8
+ module Steplib
9
+ class HashUtils
10
+ def self.check_required_attributes_and_types!(hash_to_check, attribute_type_array)
11
+ attribute_type_array.each do |a_attribute_type_itm|
12
+ attribute_key = a_attribute_type_itm[0]
13
+ attribute_type = a_attribute_type_itm[1]
14
+ #
15
+ attr_value = hash_to_check[attribute_key]
16
+ if attr_value.nil?
17
+ raise "Attribute (#{attribute_key}) not found in hash"
18
+ end
19
+ unless attr_value.is_a? attribute_type
20
+ raise "Attribute (#{attribute_key}) found, but it's type (#{attr_value.class}) doesn't match the required (#{attribute_type})"
21
+ end
22
+ end
23
+ return true
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,114 @@
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
data/lib/steplib.rb ADDED
@@ -0,0 +1,2 @@
1
+ require_relative 'steplib/hash_utils'
2
+ require_relative 'steplib/validator'
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: steplib
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Bitrise
8
+ - Viktor Benei
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-01-06 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Validates, converts, etc. a StepLib, Workflow and other steplib datastore
15
+ formats. This GEM's major and minor version number matches the related StepLib format
16
+ specification's major and minor version number.
17
+ email: letsconnect@bitrise.io
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - lib/steplib.rb
23
+ - lib/steplib/format_corrector.rb
24
+ - lib/steplib/hash_utils.rb
25
+ - lib/steplib/validator.rb
26
+ homepage: https://github.com/steplib/steplib
27
+ licenses:
28
+ - MIT
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 2.2.2
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: StepLib.com's validator and other utilities
50
+ test_files: []