ec2-host 0.5.9 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/ec2/host/host_data.rb +8 -4
- data/lib/ec2/host/role_data.rb +9 -1
- data/lib/ec2/host/version.rb +1 -1
- data/spec/host_data_spec.rb +40 -0
- data/spec/role_data_spec.rb +34 -6
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a1249847be80c2f1fcf6c5a857b510a5c1a3687
|
4
|
+
data.tar.gz: a1e32094a8f8ba1b0b36798533227c80154e9137
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d87051be62134563c27c0f94e41a8791b7a0b42a58541cefbd9f3226518ea4edbdb256591e1f2ed3e7c557a319fc3ba16de06eebb609cc96bca798995368c59
|
7
|
+
data.tar.gz: 4943af6805767f3f7019ffc8d074661f67e692ad403fbaea58f57f54f62760f80f054f020e898a2570495f0bb5b76d504bede6fd35b2670b2e2169a6d0dbe1d5
|
data/CHANGELOG.md
CHANGED
data/lib/ec2/host/host_data.rb
CHANGED
@@ -208,14 +208,18 @@ class EC2
|
|
208
208
|
def role_match?(condition)
|
209
209
|
# usage is an alias of role
|
210
210
|
if role = (condition[:role] || condition[:usage])
|
211
|
-
|
211
|
+
role.any? do |r|
|
212
|
+
parts = r.split(Config.role_tag_delimiter, Config.role_max_depth)
|
213
|
+
next true if parts.compact.empty? # no role conditions
|
214
|
+
roles.find {|role| role.match?(*parts) }
|
215
|
+
end
|
212
216
|
else
|
213
217
|
parts = 1.upto(Config.role_max_depth).map do |i|
|
214
|
-
|
218
|
+
condition["role#{i}".to_sym] || condition["usage#{i}".to_sym]
|
215
219
|
end
|
220
|
+
return true if parts.compact.empty? # no role conditions
|
221
|
+
roles.find {|role| role.match?(*parts) }
|
216
222
|
end
|
217
|
-
return true if parts.compact.empty? # no role conditions
|
218
|
-
roles.find {|role| role.match?(*parts) }
|
219
223
|
end
|
220
224
|
|
221
225
|
def instance_match?(condition)
|
data/lib/ec2/host/role_data.rb
CHANGED
@@ -54,10 +54,18 @@ class EC2
|
|
54
54
|
# RoleData.new('admin', 'jenkins', 'slave').match?(nil, 'jenkins') #=> true
|
55
55
|
# RoleData.new('admin', 'jenkins', 'slave').match?(nil, nil, 'slave') #=> true
|
56
56
|
#
|
57
|
+
# RoleData.new('foo', 'a').match?(['foo', 'bar']) #=> true
|
58
|
+
# RoleData.new('bar', 'a').match?(['foo', 'bar']) #=> true
|
59
|
+
#
|
60
|
+
# RoleData.new('foo', 'a').match?(['foo', 'bar'], ['a', 'b']) #=> true
|
61
|
+
# RoleData.new('foo', 'a').match?(['foo', 'bar'], ['a', 'b']) #=> true
|
62
|
+
# RoleData.new('bar', 'b').match?(['foo', 'bar'], ['a', 'b']) #=> true
|
63
|
+
# RoleData.new('bar', 'b').match?(['foo', 'bar'], ['a', 'b']) #=> true
|
64
|
+
#
|
57
65
|
# @param [Array] role_parts such as ["admin", "jenkins", "slave"]
|
58
66
|
def match?(*role_parts)
|
59
67
|
indexes = role_parts.map.with_index {|part, i| part ? i : nil }.compact
|
60
|
-
|
68
|
+
indexes.all? {|i| Array(role_parts[i]).include?(@role_parts[i]) }
|
61
69
|
end
|
62
70
|
|
63
71
|
# Equality
|
data/lib/ec2/host/version.rb
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EC2::Host::HostData do
|
4
|
+
describe '#role_match?' do
|
5
|
+
def host_with_role(role)
|
6
|
+
EC2::Host::HostData.new(Object.new).tap do |data|
|
7
|
+
roles = [EC2::Host::RoleData.build(role)]
|
8
|
+
data.instance_variable_set(:@roles, roles)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'with role' do
|
13
|
+
it do
|
14
|
+
expect(host_with_role('admin:jenkins:slave').send(:role_match?, role: ['admin'])).to be_truthy
|
15
|
+
expect(host_with_role('admin:jenkins:slave').send(:role_match?, role: ['admin:jenkins'])).to be_truthy
|
16
|
+
expect(host_with_role('admin:jenkins:slave').send(:role_match?, role: ['admin:jenkins:slave'])).to be_truthy
|
17
|
+
|
18
|
+
expect(host_with_role('foo:a').send(:role_match?, role: ['foo:a', 'bar:b'])).to be_truthy
|
19
|
+
expect(host_with_role('bar:a').send(:role_match?, role: ['foo:a', 'bar:b'])).to be_falsey
|
20
|
+
expect(host_with_role('foo:b').send(:role_match?, role: ['foo:a', 'bar:b'])).to be_falsey
|
21
|
+
expect(host_with_role('bar:b').send(:role_match?, role: ['foo:a', 'bar:b'])).to be_truthy
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'with roleN' do
|
26
|
+
it do
|
27
|
+
expect(host_with_role('foo:a').send(:role_match?, role1: ['foo', 'bar'], role2: ['a', 'b'])).to be_truthy
|
28
|
+
expect(host_with_role('bar:a').send(:role_match?, role1: ['foo', 'bar'], role2: ['a', 'b'])).to be_truthy
|
29
|
+
expect(host_with_role('baz:a').send(:role_match?, role1: ['foo', 'bar'], role2: ['a', 'b'])).to be_falsey
|
30
|
+
expect(host_with_role('foo:b').send(:role_match?, role1: ['foo', 'bar'], role2: ['a', 'b'])).to be_truthy
|
31
|
+
expect(host_with_role('bar:b').send(:role_match?, role1: ['foo', 'bar'], role2: ['a', 'b'])).to be_truthy
|
32
|
+
expect(host_with_role('baz:b').send(:role_match?, role1: ['foo', 'bar'], role2: ['a', 'b'])).to be_falsey
|
33
|
+
|
34
|
+
expect(host_with_role('foo:a').send(:role_match?, role2: ['a', 'b'])).to be_truthy
|
35
|
+
expect(host_with_role('foo:b').send(:role_match?, role2: ['a', 'b'])).to be_truthy
|
36
|
+
expect(host_with_role('foo:c').send(:role_match?, role2: ['a', 'b'])).to be_falsey
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/spec/role_data_spec.rb
CHANGED
@@ -29,12 +29,40 @@ describe EC2::Host::RoleData do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
describe '#match?' do
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
context 'with single match' do
|
33
|
+
let(:subject) { EC2::Host::RoleData.build('admin:jenkins:slave') }
|
34
|
+
|
35
|
+
it do
|
36
|
+
expect(subject.match?('admin')).to be_truthy
|
37
|
+
expect(subject.match?('admin', 'jenkins')).to be_truthy
|
38
|
+
expect(subject.match?('admin', 'jenkins', 'slave')).to be_truthy
|
39
|
+
expect(subject.match?(nil, 'jenkins')).to be_truthy
|
40
|
+
expect(subject.match?(nil, nil, 'slave')).to be_truthy
|
41
|
+
|
42
|
+
expect(subject.match?('wrong')).to be_falsey
|
43
|
+
expect(subject.match?('admin', 'wrong')).to be_falsey
|
44
|
+
expect(subject.match?('admin', 'jenkins', 'wrong')).to be_falsey
|
45
|
+
expect(subject.match?(nil, 'wrong')).to be_falsey
|
46
|
+
expect(subject.match?(nil, nil, 'wrong')).to be_falsey
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
context 'with array match' do
|
52
|
+
it do
|
53
|
+
expect(EC2::Host::RoleData.build('foo:a').match?(['foo', 'bar'])).to be_truthy
|
54
|
+
expect(EC2::Host::RoleData.build('bar:a').match?(['foo', 'bar'])).to be_truthy
|
55
|
+
expect(EC2::Host::RoleData.build('baz:a').match?(['foo', 'bar'])).to be_falsey
|
56
|
+
|
57
|
+
expect(EC2::Host::RoleData.build('foo:a').match?(['foo', 'bar'], ['a', 'b'])).to be_truthy
|
58
|
+
expect(EC2::Host::RoleData.build('bar:a').match?(['foo', 'bar'], ['a', 'b'])).to be_truthy
|
59
|
+
expect(EC2::Host::RoleData.build('baz:a').match?(['foo', 'bar'], ['a', 'b'])).to be_falsey
|
60
|
+
expect(EC2::Host::RoleData.build('foo:b').match?(['foo', 'bar'], ['a', 'b'])).to be_truthy
|
61
|
+
expect(EC2::Host::RoleData.build('bar:b').match?(['foo', 'bar'], ['a', 'b'])).to be_truthy
|
62
|
+
expect(EC2::Host::RoleData.build('baz:b').match?(['foo', 'bar'], ['a', 'b'])).to be_falsey
|
63
|
+
|
64
|
+
expect(EC2::Host::RoleData.build('foo:a').match?(nil, ['a', 'b'])).to be_truthy
|
65
|
+
end
|
38
66
|
end
|
39
67
|
end
|
40
68
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ec2-host
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naotoshi Seo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -218,6 +218,7 @@ files:
|
|
218
218
|
- lib/ec2/host/role_data.rb
|
219
219
|
- lib/ec2/host/string_util.rb
|
220
220
|
- lib/ec2/host/version.rb
|
221
|
+
- spec/host_data_spec.rb
|
221
222
|
- spec/host_spec.rb
|
222
223
|
- spec/role_data_spec.rb
|
223
224
|
- spec/spec_helper.rb
|
@@ -247,6 +248,7 @@ signing_key:
|
|
247
248
|
specification_version: 4
|
248
249
|
summary: Search hosts on AWS EC2
|
249
250
|
test_files:
|
251
|
+
- spec/host_data_spec.rb
|
250
252
|
- spec/host_spec.rb
|
251
253
|
- spec/role_data_spec.rb
|
252
254
|
- spec/spec_helper.rb
|