vcloud-edge_gateway 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +11 -0
- data/README.md +219 -11
- data/examples/firewall-rules.yaml +50 -0
- data/examples/loadbalancer-rules.yaml +55 -0
- data/examples/nat-rules.yaml +58 -0
- data/lib/vcloud/edge_gateway.rb +2 -3
- data/lib/vcloud/edge_gateway/configuration_differ.rb +13 -1
- data/lib/vcloud/edge_gateway/configuration_generator/nat_service.rb +10 -10
- data/lib/vcloud/edge_gateway/edge_gateway_configuration.rb +2 -2
- data/lib/vcloud/edge_gateway/firewall_configuration_differ.rb +18 -0
- data/lib/vcloud/edge_gateway/load_balancer_configuration_differ.rb +3 -13
- data/lib/vcloud/edge_gateway/nat_configuration_differ.rb +18 -0
- data/lib/vcloud/edge_gateway/version.rb +1 -1
- data/lib/vcloud/edge_gateway_services.rb +1 -1
- data/spec/integration/edge_gateway/edge_gateway_services_spec.rb +7 -13
- data/spec/integration/edge_gateway/firewall_service_spec.rb +2 -12
- data/spec/integration/edge_gateway/load_balancer_service_spec.rb +4 -4
- data/spec/integration/edge_gateway/nat_service_spec.rb +4 -4
- data/spec/spec_helper.rb +2 -2
- data/spec/vcloud/edge_gateway/configuration_differ_shared_examples.rb +132 -0
- data/spec/vcloud/edge_gateway/configuration_differ_spec.rb +5 -122
- data/spec/vcloud/edge_gateway/configuration_generator/firewall_service_spec.rb +46 -52
- data/spec/vcloud/edge_gateway/firewall_configuration_differ_spec.rb +65 -0
- data/spec/vcloud/edge_gateway/firewall_schema_validation_spec.rb +2 -2
- data/spec/vcloud/edge_gateway/load_balancer_configuration_differ_spec.rb +32 -147
- data/spec/vcloud/edge_gateway/load_balancer_schema_validation_spec.rb +7 -7
- data/spec/vcloud/edge_gateway/nat_configuration_differ_spec.rb +65 -0
- data/spec/vcloud/edge_gateway/nat_schema_validation_spec.rb +4 -4
- data/vcloud-edge_gateway.gemspec +2 -2
- metadata +18 -13
- data/lib/vcloud/config_loader.rb +0 -27
- data/lib/vcloud/config_validator.rb +0 -207
- data/spec/vcloud/config_loader_spec.rb +0 -112
- data/spec/vcloud/config_validator_spec.rb +0 -570
@@ -53,7 +53,7 @@ module Vcloud
|
|
53
53
|
|
54
54
|
valid_tests.each do |test|
|
55
55
|
it "#{test[:name]}" do
|
56
|
-
validator = ConfigValidator.validate(:base, test[:input],
|
56
|
+
validator = Vcloud::Core::ConfigValidator.validate(:base, test[:input],
|
57
57
|
Vcloud::Schema::LOAD_BALANCER_POOL_ENTRY)
|
58
58
|
expect(validator.errors).to eq([])
|
59
59
|
expect(validator.valid?).to be_true
|
@@ -93,7 +93,7 @@ module Vcloud
|
|
93
93
|
|
94
94
|
valid_tests.each do |test|
|
95
95
|
it "#{test[:name]}" do
|
96
|
-
validator = ConfigValidator.validate(:base, test[:input],
|
96
|
+
validator = Vcloud::Core::ConfigValidator.validate(:base, test[:input],
|
97
97
|
Vcloud::Schema::LOAD_BALANCER_VIRTUAL_SERVER_ENTRY)
|
98
98
|
expect(validator.errors).to eq([])
|
99
99
|
expect(validator.valid?).to be_true
|
@@ -124,7 +124,7 @@ module Vcloud
|
|
124
124
|
},
|
125
125
|
],
|
126
126
|
}
|
127
|
-
validator = ConfigValidator.validate(:base, input, Vcloud::Schema::LOAD_BALANCER_SERVICE)
|
127
|
+
validator = Vcloud::Core::ConfigValidator.validate(:base, input, Vcloud::Schema::LOAD_BALANCER_SERVICE)
|
128
128
|
expect(validator.errors).to eq([])
|
129
129
|
expect(validator.valid?).to be_true
|
130
130
|
end
|
@@ -144,7 +144,7 @@ module Vcloud
|
|
144
144
|
},
|
145
145
|
],
|
146
146
|
}
|
147
|
-
validator = ConfigValidator.validate(:base, input, Vcloud::Schema::LOAD_BALANCER_SERVICE)
|
147
|
+
validator = Vcloud::Core::ConfigValidator.validate(:base, input, Vcloud::Schema::LOAD_BALANCER_SERVICE)
|
148
148
|
expect(validator.errors).to eq([])
|
149
149
|
expect(validator.valid?).to be_true
|
150
150
|
end
|
@@ -166,7 +166,7 @@ module Vcloud
|
|
166
166
|
},
|
167
167
|
],
|
168
168
|
}
|
169
|
-
validator = ConfigValidator.validate(:base, input, Vcloud::Schema::LOAD_BALANCER_SERVICE)
|
169
|
+
validator = Vcloud::Core::ConfigValidator.validate(:base, input, Vcloud::Schema::LOAD_BALANCER_SERVICE)
|
170
170
|
expect(validator.errors).to eq([])
|
171
171
|
expect(validator.valid?).to be_true
|
172
172
|
end
|
@@ -175,7 +175,7 @@ module Vcloud
|
|
175
175
|
input = {
|
176
176
|
virtual_servers: []
|
177
177
|
}
|
178
|
-
validator = ConfigValidator.validate(:base, input, Vcloud::Schema::LOAD_BALANCER_SERVICE)
|
178
|
+
validator = Vcloud::Core::ConfigValidator.validate(:base, input, Vcloud::Schema::LOAD_BALANCER_SERVICE)
|
179
179
|
expect(validator.valid?).to be_true
|
180
180
|
end
|
181
181
|
|
@@ -183,7 +183,7 @@ module Vcloud
|
|
183
183
|
input = {
|
184
184
|
pools: []
|
185
185
|
}
|
186
|
-
validator = ConfigValidator.validate(:base, input, Vcloud::Schema::LOAD_BALANCER_SERVICE)
|
186
|
+
validator = Vcloud::Core::ConfigValidator.validate(:base, input, Vcloud::Schema::LOAD_BALANCER_SERVICE)
|
187
187
|
expect(validator.valid?).to be_true
|
188
188
|
end
|
189
189
|
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative 'configuration_differ_shared_examples.rb'
|
3
|
+
|
4
|
+
module Vcloud
|
5
|
+
module EdgeGateway
|
6
|
+
describe NatConfigurationDiffer do
|
7
|
+
|
8
|
+
it_behaves_like "a configuration differ" do
|
9
|
+
let(:config_differ) { NatConfigurationDiffer }
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should ignore Id parameters in NatRule sections, when showing additions' do
|
13
|
+
local = { NatRule: [
|
14
|
+
{ Id: '65539', deeper: [ 1, 2, 3, 4, 5 ] },
|
15
|
+
{ Id: '65540', deeper: [ 5, 6, 4, 3, 2 ] },
|
16
|
+
]}
|
17
|
+
remote = { NatRule: [
|
18
|
+
{ Id: '65539', deeper: [ 1, 1, 1, 1, 1 ] },
|
19
|
+
{ Id: '65540', deeper: [ 1, 2, 3, 4, 5 ] },
|
20
|
+
{ Id: '65541', deeper: [ 5, 6, 4, 3, 2 ] },
|
21
|
+
]}
|
22
|
+
output = [
|
23
|
+
["+", "NatRule[0]", {:deeper=>[1, 1, 1, 1, 1]}]
|
24
|
+
]
|
25
|
+
differ = NatConfigurationDiffer.new(local, remote)
|
26
|
+
expect(differ.diff).to eq(output)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should still highlight a reordering despite ignoring Id' do
|
30
|
+
local = { NatRule: [
|
31
|
+
{ Id: '65538', deeper: [ 1, 1, 1, 1, 1 ] },
|
32
|
+
{ Id: '65539', deeper: [ 1, 2, 3, 4, 5 ] },
|
33
|
+
{ Id: '65540', deeper: [ 5, 6, 4, 3, 2 ] },
|
34
|
+
]}
|
35
|
+
remote = { NatRule: [
|
36
|
+
{ Id: '65538', deeper: [ 1, 2, 3, 4, 5 ] },
|
37
|
+
{ Id: '65539', deeper: [ 5, 6, 4, 3, 2 ] },
|
38
|
+
{ Id: '65540', deeper: [ 1, 1, 1, 1, 1 ] },
|
39
|
+
]}
|
40
|
+
output = [
|
41
|
+
["-", "NatRule[0]", {:deeper=>[1, 1, 1, 1, 1]}],
|
42
|
+
["+", "NatRule[2]", {:deeper=>[1, 1, 1, 1, 1]}],
|
43
|
+
]
|
44
|
+
differ = NatConfigurationDiffer.new(local, remote)
|
45
|
+
expect(differ.diff).to eq(output)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should not ignore Id parameter outside of a NatRule (just in case)' do
|
49
|
+
local = {
|
50
|
+
NatRule: [ { Id: '65538', deeper: [ 1, 1, 1, 1, 1 ] } ],
|
51
|
+
Id: 'outside of NAT rule'
|
52
|
+
}
|
53
|
+
remote = {
|
54
|
+
NatRule: [ { Id: '65538', deeper: [ 1, 1, 1, 1, 1 ] } ],
|
55
|
+
}
|
56
|
+
output = [
|
57
|
+
["-", "Id", 'outside of NAT rule']
|
58
|
+
]
|
59
|
+
differ = NatConfigurationDiffer.new(local, remote)
|
60
|
+
expect(differ.diff).to eq(output)
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -13,7 +13,7 @@ module Vcloud
|
|
13
13
|
translated_ip: "10.10.20.20",
|
14
14
|
|
15
15
|
}
|
16
|
-
validator = ConfigValidator.validate(:base, snat_rule, Vcloud::Schema::NAT_RULE)
|
16
|
+
validator = Vcloud::Core::ConfigValidator.validate(:base, snat_rule, Vcloud::Schema::NAT_RULE)
|
17
17
|
expect(validator.valid?).to be_true
|
18
18
|
expect(validator.errors).to be_empty
|
19
19
|
|
@@ -33,7 +33,7 @@ module Vcloud
|
|
33
33
|
mandatory_fields.each do |mandatory_field|
|
34
34
|
it "should error since mandatory field #{mandatory_field} is missing" do
|
35
35
|
@snat_rule.delete(mandatory_field)
|
36
|
-
validator = ConfigValidator.validate(:base, @snat_rule, Vcloud::Schema::NAT_RULE)
|
36
|
+
validator = Vcloud::Core::ConfigValidator.validate(:base, @snat_rule, Vcloud::Schema::NAT_RULE)
|
37
37
|
expect(validator.valid?).to be_false
|
38
38
|
expect(validator.errors).to eq(["base: missing '#{mandatory_field}' parameter"])
|
39
39
|
end
|
@@ -52,7 +52,7 @@ module Vcloud
|
|
52
52
|
protocol: 'tcp'
|
53
53
|
|
54
54
|
}
|
55
|
-
validator = ConfigValidator.validate(:base, snat_rule, Vcloud::Schema::NAT_RULE)
|
55
|
+
validator = Vcloud::Core::ConfigValidator.validate(:base, snat_rule, Vcloud::Schema::NAT_RULE)
|
56
56
|
expect(validator.valid?).to be_true
|
57
57
|
expect(validator.errors).to be_empty
|
58
58
|
end
|
@@ -84,7 +84,7 @@ module Vcloud
|
|
84
84
|
}
|
85
85
|
]
|
86
86
|
}
|
87
|
-
validator = ConfigValidator.validate(:base, nat_service, Vcloud::Schema::NAT_SERVICE)
|
87
|
+
validator = Vcloud::Core::ConfigValidator.validate(:base, nat_service, Vcloud::Schema::NAT_SERVICE)
|
88
88
|
expect(validator.valid?).to be_true
|
89
89
|
expect(validator.errors).to be_empty
|
90
90
|
end
|
data/vcloud-edge_gateway.gemspec
CHANGED
@@ -21,8 +21,8 @@ Gem::Specification.new do |s|
|
|
21
21
|
|
22
22
|
s.required_ruby_version = '>= 1.9.2'
|
23
23
|
|
24
|
-
s.add_runtime_dependency 'fog', '>= 1.
|
25
|
-
s.add_runtime_dependency 'vcloud-core', '>= 0.0.
|
24
|
+
s.add_runtime_dependency 'fog', '>= 1.21.0'
|
25
|
+
s.add_runtime_dependency 'vcloud-core', '>= 0.0.12'
|
26
26
|
s.add_runtime_dependency 'hashdiff'
|
27
27
|
s.add_development_dependency 'rake'
|
28
28
|
s.add_development_dependency 'rspec', '~> 2.14.1'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vcloud-edge_gateway
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-04-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fog
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 1.
|
21
|
+
version: 1.21.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 1.
|
29
|
+
version: 1.21.0
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: vcloud-core
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 0.0.
|
37
|
+
version: 0.0.12
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.0.
|
45
|
+
version: 0.0.12
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: hashdiff
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -138,10 +138,11 @@ files:
|
|
138
138
|
- README.md
|
139
139
|
- Rakefile
|
140
140
|
- bin/vcloud-configure-edge
|
141
|
+
- examples/firewall-rules.yaml
|
142
|
+
- examples/loadbalancer-rules.yaml
|
143
|
+
- examples/nat-rules.yaml
|
141
144
|
- jenkins.sh
|
142
145
|
- jenkins_integration_tests.sh
|
143
|
-
- lib/vcloud/config_loader.rb
|
144
|
-
- lib/vcloud/config_validator.rb
|
145
146
|
- lib/vcloud/edge_gateway.rb
|
146
147
|
- lib/vcloud/edge_gateway/configuration_differ.rb
|
147
148
|
- lib/vcloud/edge_gateway/configuration_generator/firewall_service.rb
|
@@ -149,7 +150,9 @@ files:
|
|
149
150
|
- lib/vcloud/edge_gateway/configuration_generator/load_balancer_service.rb
|
150
151
|
- lib/vcloud/edge_gateway/configuration_generator/nat_service.rb
|
151
152
|
- lib/vcloud/edge_gateway/edge_gateway_configuration.rb
|
153
|
+
- lib/vcloud/edge_gateway/firewall_configuration_differ.rb
|
152
154
|
- lib/vcloud/edge_gateway/load_balancer_configuration_differ.rb
|
155
|
+
- lib/vcloud/edge_gateway/nat_configuration_differ.rb
|
153
156
|
- lib/vcloud/edge_gateway/version.rb
|
154
157
|
- lib/vcloud/edge_gateway_services.rb
|
155
158
|
- lib/vcloud/schema/edge_gateway.rb
|
@@ -176,13 +179,12 @@ files:
|
|
176
179
|
- spec/integration/edge_gateway/load_balancer_service_spec.rb
|
177
180
|
- spec/integration/edge_gateway/nat_service_spec.rb
|
178
181
|
- spec/spec_helper.rb
|
179
|
-
- spec/vcloud/config_loader_spec.rb
|
180
|
-
- spec/vcloud/config_validator_spec.rb
|
181
182
|
- spec/vcloud/data/basic_preamble_test.erb
|
182
183
|
- spec/vcloud/data/basic_preamble_test.erb.OUT
|
183
184
|
- spec/vcloud/data/working.json
|
184
185
|
- spec/vcloud/data/working.yaml
|
185
186
|
- spec/vcloud/data/working_with_defaults.yaml
|
187
|
+
- spec/vcloud/edge_gateway/configuration_differ_shared_examples.rb
|
186
188
|
- spec/vcloud/edge_gateway/configuration_differ_spec.rb
|
187
189
|
- spec/vcloud/edge_gateway/configuration_generator/data/load_balancer_http-input.yaml
|
188
190
|
- spec/vcloud/edge_gateway/configuration_generator/data/load_balancer_http-output.yaml
|
@@ -194,9 +196,11 @@ files:
|
|
194
196
|
- spec/vcloud/edge_gateway/configuration_generator/load_balancer_service_spec.rb
|
195
197
|
- spec/vcloud/edge_gateway/configuration_generator/nat_service_spec.rb
|
196
198
|
- spec/vcloud/edge_gateway/edge_gateway_configuration_spec.rb
|
199
|
+
- spec/vcloud/edge_gateway/firewall_configuration_differ_spec.rb
|
197
200
|
- spec/vcloud/edge_gateway/firewall_schema_validation_spec.rb
|
198
201
|
- spec/vcloud/edge_gateway/load_balancer_configuration_differ_spec.rb
|
199
202
|
- spec/vcloud/edge_gateway/load_balancer_schema_validation_spec.rb
|
203
|
+
- spec/vcloud/edge_gateway/nat_configuration_differ_spec.rb
|
200
204
|
- spec/vcloud/edge_gateway/nat_schema_validation_spec.rb
|
201
205
|
- vcloud-edge_gateway.gemspec
|
202
206
|
homepage: http://github.com/alphagov/vcloud-edge_gateway
|
@@ -220,7 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
220
224
|
version: '0'
|
221
225
|
segments:
|
222
226
|
- 0
|
223
|
-
hash:
|
227
|
+
hash: -981764383968782471
|
224
228
|
requirements: []
|
225
229
|
rubyforge_project:
|
226
230
|
rubygems_version: 1.8.23
|
@@ -247,13 +251,12 @@ test_files:
|
|
247
251
|
- spec/integration/edge_gateway/load_balancer_service_spec.rb
|
248
252
|
- spec/integration/edge_gateway/nat_service_spec.rb
|
249
253
|
- spec/spec_helper.rb
|
250
|
-
- spec/vcloud/config_loader_spec.rb
|
251
|
-
- spec/vcloud/config_validator_spec.rb
|
252
254
|
- spec/vcloud/data/basic_preamble_test.erb
|
253
255
|
- spec/vcloud/data/basic_preamble_test.erb.OUT
|
254
256
|
- spec/vcloud/data/working.json
|
255
257
|
- spec/vcloud/data/working.yaml
|
256
258
|
- spec/vcloud/data/working_with_defaults.yaml
|
259
|
+
- spec/vcloud/edge_gateway/configuration_differ_shared_examples.rb
|
257
260
|
- spec/vcloud/edge_gateway/configuration_differ_spec.rb
|
258
261
|
- spec/vcloud/edge_gateway/configuration_generator/data/load_balancer_http-input.yaml
|
259
262
|
- spec/vcloud/edge_gateway/configuration_generator/data/load_balancer_http-output.yaml
|
@@ -265,7 +268,9 @@ test_files:
|
|
265
268
|
- spec/vcloud/edge_gateway/configuration_generator/load_balancer_service_spec.rb
|
266
269
|
- spec/vcloud/edge_gateway/configuration_generator/nat_service_spec.rb
|
267
270
|
- spec/vcloud/edge_gateway/edge_gateway_configuration_spec.rb
|
271
|
+
- spec/vcloud/edge_gateway/firewall_configuration_differ_spec.rb
|
268
272
|
- spec/vcloud/edge_gateway/firewall_schema_validation_spec.rb
|
269
273
|
- spec/vcloud/edge_gateway/load_balancer_configuration_differ_spec.rb
|
270
274
|
- spec/vcloud/edge_gateway/load_balancer_schema_validation_spec.rb
|
275
|
+
- spec/vcloud/edge_gateway/nat_configuration_differ_spec.rb
|
271
276
|
- spec/vcloud/edge_gateway/nat_schema_validation_spec.rb
|
data/lib/vcloud/config_loader.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
require 'json'
|
3
|
-
|
4
|
-
module Vcloud
|
5
|
-
class ConfigLoader
|
6
|
-
|
7
|
-
def load_config(config_file, schema = nil)
|
8
|
-
input_config = YAML::load(File.open(config_file))
|
9
|
-
|
10
|
-
# There is no way in YAML or Ruby to symbolize keys in a hash
|
11
|
-
json_string = JSON.generate(input_config)
|
12
|
-
config = JSON.parse(json_string, :symbolize_names => true)
|
13
|
-
|
14
|
-
if schema
|
15
|
-
validation = ConfigValidator.validate(:base, config, schema)
|
16
|
-
unless validation.valid?
|
17
|
-
validation.errors.each do |error|
|
18
|
-
Vcloud::EdgeGateway.logger.fatal(error)
|
19
|
-
end
|
20
|
-
raise("Supplied configuration does not match supplied schema")
|
21
|
-
end
|
22
|
-
end
|
23
|
-
config
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
@@ -1,207 +0,0 @@
|
|
1
|
-
require 'ipaddr'
|
2
|
-
|
3
|
-
module Vcloud
|
4
|
-
class ConfigValidator
|
5
|
-
|
6
|
-
attr_reader :key, :data, :schema, :type, :errors
|
7
|
-
|
8
|
-
VALID_ALPHABETICAL_VALUES_FOR_IP_RANGE = %w(Any external internal)
|
9
|
-
|
10
|
-
def initialize(key, data, schema)
|
11
|
-
raise "Nil schema" unless schema
|
12
|
-
raise "Invalid schema" unless schema.key?(:type)
|
13
|
-
@type = schema[:type].to_s.downcase
|
14
|
-
@errors = []
|
15
|
-
@data = data
|
16
|
-
@schema = schema
|
17
|
-
@key = key
|
18
|
-
validate
|
19
|
-
end
|
20
|
-
|
21
|
-
def valid?
|
22
|
-
@errors.empty?
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.validate(key, data, schema)
|
26
|
-
new(key, data, schema)
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def validate
|
32
|
-
self.send("validate_#{type}".to_sym)
|
33
|
-
end
|
34
|
-
|
35
|
-
def validate_string
|
36
|
-
unless @data.is_a? String
|
37
|
-
errors << "#{key}: #{@data} is not a string"
|
38
|
-
return
|
39
|
-
end
|
40
|
-
return unless check_emptyness_ok
|
41
|
-
return unless check_matcher_matches
|
42
|
-
end
|
43
|
-
|
44
|
-
def validate_string_or_number
|
45
|
-
unless data.is_a?(String) || data.is_a?(Numeric)
|
46
|
-
@errors << "#{key}: #{@data} is not a string_or_number"
|
47
|
-
return
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def validate_ip_address
|
52
|
-
unless data.is_a?(String)
|
53
|
-
@errors << "#{key}: #{@data} is not a valid ip_address"
|
54
|
-
return
|
55
|
-
end
|
56
|
-
@errors << "#{key}: #{@data} is not a valid ip_address" unless valid_ip_address?(data)
|
57
|
-
end
|
58
|
-
|
59
|
-
def validate_ip_address_range
|
60
|
-
unless data.is_a?(String)
|
61
|
-
@errors << "#{key}: #{@data} is not a valid IP address range. Valid values can be IP address, CIDR, IP range, 'Any','internal' and 'external'."
|
62
|
-
return
|
63
|
-
end
|
64
|
-
valid = valid_cidr_or_ip_address? || valid_alphabetical_ip_range? || valid_ip_range?
|
65
|
-
@errors << "#{key}: #{@data} is not a valid IP address range. Valid values can be IP address, CIDR, IP range, 'Any','internal' and 'external'." unless valid
|
66
|
-
end
|
67
|
-
|
68
|
-
def valid_cidr_or_ip_address?
|
69
|
-
begin
|
70
|
-
ip = IPAddr.new(data)
|
71
|
-
ip.ipv4?
|
72
|
-
rescue ArgumentError
|
73
|
-
false
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def valid_alphabetical_ip_range?
|
78
|
-
VALID_ALPHABETICAL_VALUES_FOR_IP_RANGE.include?(data)
|
79
|
-
end
|
80
|
-
|
81
|
-
def valid_ip_address? ip_address
|
82
|
-
begin
|
83
|
-
#valid formats recognized by IPAddr are : “address”, “address/prefixlen” and “address/mask”.
|
84
|
-
# Attribute like member_ip in case of load-balancer is an "address"
|
85
|
-
# and we should not accept “address/prefixlen” and “address/mask” for such fields.
|
86
|
-
ip = IPAddr.new(ip_address)
|
87
|
-
ip.ipv4? && !ip_address.include?('/')
|
88
|
-
rescue ArgumentError
|
89
|
-
false
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def valid_ip_range?
|
94
|
-
range_parts = data.split('-')
|
95
|
-
return false if range_parts.size != 2
|
96
|
-
start_address = range_parts.first
|
97
|
-
end_address = range_parts.last
|
98
|
-
valid_ip_address?(start_address) && valid_ip_address?(end_address) &&
|
99
|
-
valid_start_and_end_address_combination?(end_address, start_address)
|
100
|
-
end
|
101
|
-
|
102
|
-
def valid_start_and_end_address_combination?(end_address, start_address)
|
103
|
-
IPAddr.new(start_address) < IPAddr.new(end_address)
|
104
|
-
end
|
105
|
-
|
106
|
-
def validate_hash
|
107
|
-
unless data.is_a? Hash
|
108
|
-
@errors << "#{key}: is not a hash"
|
109
|
-
return
|
110
|
-
end
|
111
|
-
return unless check_emptyness_ok
|
112
|
-
check_for_unknown_parameters
|
113
|
-
if schema.key?(:internals)
|
114
|
-
internals = schema[:internals]
|
115
|
-
internals.each do |param_key,param_schema|
|
116
|
-
check_hash_parameter(param_key, param_schema)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def validate_array
|
122
|
-
unless data.is_a? Array
|
123
|
-
@errors << "#{key} is not an array"
|
124
|
-
return
|
125
|
-
end
|
126
|
-
return unless check_emptyness_ok
|
127
|
-
if schema.key?(:each_element_is)
|
128
|
-
element_schema = schema[:each_element_is]
|
129
|
-
data.each do |element|
|
130
|
-
sub_validator = ConfigValidator.validate(key, element, element_schema)
|
131
|
-
unless sub_validator.valid?
|
132
|
-
@errors = errors + sub_validator.errors
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
def validate_enum
|
139
|
-
unless (acceptable_values = schema[:acceptable_values]) && acceptable_values.is_a?(Array)
|
140
|
-
raise "Must set :acceptable_values for type 'enum'"
|
141
|
-
end
|
142
|
-
unless acceptable_values.include?(data)
|
143
|
-
acceptable_values_string = acceptable_values.collect {|v| "'#{v}'" }.join(', ')
|
144
|
-
@errors << "#{key}: #{@data} is not a valid value. Acceptable values are #{acceptable_values_string}."
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
def validate_boolean
|
149
|
-
unless [true, false].include?(data)
|
150
|
-
@errors << "#{key}: #{data} is not a valid boolean value."
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
def check_emptyness_ok
|
155
|
-
unless schema.key?(:allowed_empty) && schema[:allowed_empty]
|
156
|
-
if data.empty?
|
157
|
-
@errors << "#{key}: cannot be empty #{type}"
|
158
|
-
return false
|
159
|
-
end
|
160
|
-
end
|
161
|
-
true
|
162
|
-
end
|
163
|
-
|
164
|
-
def check_matcher_matches
|
165
|
-
return unless regex = schema[:matcher]
|
166
|
-
raise "#{key}: #{regex} is not a Regexp" unless regex.is_a? Regexp
|
167
|
-
unless data =~ regex
|
168
|
-
@errors << "#{key}: #{data} does not match"
|
169
|
-
return false
|
170
|
-
end
|
171
|
-
true
|
172
|
-
end
|
173
|
-
|
174
|
-
def check_hash_parameter(sub_key, sub_schema)
|
175
|
-
if sub_schema.key?(:required) && sub_schema[:required] == false
|
176
|
-
# short circuit out if we do not have the key, but it's not required.
|
177
|
-
return true unless data.key?(sub_key)
|
178
|
-
end
|
179
|
-
unless data.key?(sub_key)
|
180
|
-
@errors << "#{key}: missing '#{sub_key}' parameter"
|
181
|
-
return false
|
182
|
-
end
|
183
|
-
sub_validator = ConfigValidator.validate(
|
184
|
-
sub_key,
|
185
|
-
data[sub_key],
|
186
|
-
sub_schema
|
187
|
-
)
|
188
|
-
unless sub_validator.valid?
|
189
|
-
@errors = errors + sub_validator.errors
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
def check_for_unknown_parameters
|
194
|
-
unless internals = schema[:internals]
|
195
|
-
# if there are no parameters specified, then assume all are ok.
|
196
|
-
return true
|
197
|
-
end
|
198
|
-
if schema[:permit_unknown_parameters]
|
199
|
-
return true
|
200
|
-
end
|
201
|
-
data.keys.each do |k|
|
202
|
-
@errors << "#{key}: parameter '#{k}' is invalid" unless internals[k]
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
end
|
207
|
-
end
|