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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a15fd593235c24ad34c3f26a1a201de288121c09
4
- data.tar.gz: 035d0489d27be80ceb7593d0f0d8a55e39d9681f
3
+ metadata.gz: 1a1249847be80c2f1fcf6c5a857b510a5c1a3687
4
+ data.tar.gz: a1e32094a8f8ba1b0b36798533227c80154e9137
5
5
  SHA512:
6
- metadata.gz: fd11b4bc9543b4b3145ae46197f83c836cd1126b0a312592d3a457d3b7d30282d951b70a80fbb63ea601d171ed72750f38a3a560cd42e80cfcd52cf5ecee3762
7
- data.tar.gz: cb3682963b997aea698c19702a861a93e6a79146820ef014234b5d3eef9f00c2bb375154c34d39ae5132c580ba71585b0581055a0fb20eab9a4cdb5f31ee8e4f
6
+ metadata.gz: 2d87051be62134563c27c0f94e41a8791b7a0b42a58541cefbd9f3226518ea4edbdb256591e1f2ed3e7c557a319fc3ba16de06eebb609cc96bca798995368c59
7
+ data.tar.gz: 4943af6805767f3f7019ffc8d074661f67e692ad403fbaea58f57f54f62760f80f054f020e898a2570495f0bb5b76d504bede6fd35b2670b2e2169a6d0dbe1d5
@@ -1,3 +1,11 @@
1
+ # 0.6.0 (2017/05/20)
2
+
3
+ Fixes:
4
+
5
+ * Fix to support multile roles and roleNs with command line arguments as
6
+ * ec2-host --role foo:a,bar:b
7
+ * ec2-host --role1 foo,bar --role2 a,b
8
+
1
9
  # 0.5.9 (2017/04/24)
2
10
 
3
11
  Fixes:
@@ -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
- parts = role.first.split(Config.role_tag_delimiter, Config.role_max_depth)
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
- (condition["role#{i}".to_sym] || condition["usage#{i}".to_sym] || []).first
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)
@@ -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
- @role_parts.values_at(*indexes) == role_parts.values_at(*indexes)
68
+ indexes.all? {|i| Array(role_parts[i]).include?(@role_parts[i]) }
61
69
  end
62
70
 
63
71
  # Equality
@@ -1,5 +1,5 @@
1
1
  class EC2
2
2
  class Host
3
- VERSION = '0.5.9'
3
+ VERSION = '0.6.0'
4
4
  end
5
5
  end
@@ -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
@@ -29,12 +29,40 @@ describe EC2::Host::RoleData do
29
29
  end
30
30
 
31
31
  describe '#match?' do
32
- let(:subject) { EC2::Host::RoleData.build('web:test') }
33
- it do
34
- expect(subject.match?('web')).to be_truthy
35
- expect(subject.match?('web', 'test')).to be_truthy
36
- expect(subject.match?('web', 'test', 'wrong')).to be_falsey
37
- expect(subject.match?('web', 'wrong')).to be_falsey
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.5.9
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-04-24 00:00:00.000000000 Z
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