awspec 0.70.0 → 0.71.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/doc/_resource_types/ec2.md +9 -0
- data/doc/resource_types.md +10 -0
- data/lib/awspec/helper/finder/security_group.rb +22 -16
- data/lib/awspec/stub/ec2_has_multi_security_groups.rb +21 -0
- data/lib/awspec/type/ec2.rb +23 -0
- data/lib/awspec/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc669dded96eca85392499ed934f5e74a3792255
|
4
|
+
data.tar.gz: 200f595fd7e078ee438168ad458abef078b9e5bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d4485290d46b5255eccbde9b3155a072f9242466b2ccd574d6760b5d942ee7200dcb6b49ae363be92f5f4a76b9f2da2a3233f63896f16189f3bb4f09dd75f47
|
7
|
+
data.tar.gz: 6452260c37fe0de431d89d1bfa788fab472d30b87ee5ae25815affd4ba41c57e9f37672bc75262dd48491df15db2aec706a738f1835086401fd654fbf6b9ee6d
|
data/doc/_resource_types/ec2.md
CHANGED
@@ -91,6 +91,15 @@ describe ec2('my-ec2') do
|
|
91
91
|
end
|
92
92
|
```
|
93
93
|
|
94
|
+
### have_security_groups
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
describe ec2('my-ec2') do
|
98
|
+
it { should have_security_groups(['my-security-group-name-1', 'my-security-group-name-2']) }
|
99
|
+
it { should have_security_groups(['sg-1a2b3cd4', 'sg-5e6f7gh8']) }
|
100
|
+
end
|
101
|
+
```
|
102
|
+
|
94
103
|
### have_tag
|
95
104
|
|
96
105
|
```ruby
|
data/doc/resource_types.md
CHANGED
@@ -445,6 +445,16 @@ end
|
|
445
445
|
```
|
446
446
|
|
447
447
|
|
448
|
+
### have_security_groups
|
449
|
+
|
450
|
+
```ruby
|
451
|
+
describe ec2('my-ec2') do
|
452
|
+
it { should have_security_groups(['my-security-group-name-1', 'my-security-group-name-2']) }
|
453
|
+
it { should have_security_groups(['sg-1a2b3cd4', 'sg-5e6f7gh8']) }
|
454
|
+
end
|
455
|
+
```
|
456
|
+
|
457
|
+
|
448
458
|
### have_tag
|
449
459
|
|
450
460
|
```ruby
|
@@ -2,27 +2,33 @@ module Awspec::Helper
|
|
2
2
|
module Finder
|
3
3
|
module SecurityGroup
|
4
4
|
def find_security_group(sg_id)
|
5
|
-
|
6
|
-
filters: [{ name: 'group-id', values: [sg_id] }]
|
7
|
-
})
|
8
|
-
resource = res.security_groups.single_resource(sg_id)
|
5
|
+
resource = select_security_group_by_group_id([sg_id]).single_resource(sg_id)
|
9
6
|
return resource if resource
|
10
|
-
|
11
|
-
|
12
|
-
})
|
13
|
-
resource = res.security_groups.single_resource(sg_id)
|
7
|
+
|
8
|
+
resource = select_security_group_by_group_name([sg_id]).single_resource(sg_id)
|
14
9
|
return resource if resource
|
15
|
-
|
16
|
-
|
17
|
-
})
|
18
|
-
res.security_groups.single_resource(sg_id)
|
10
|
+
|
11
|
+
select_security_group_by_tag_name([sg_id]).single_resource(sg_id)
|
19
12
|
end
|
20
13
|
|
21
14
|
def select_security_group_by_vpc_id(vpc_id)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
15
|
+
describe_security_groups({ filters: [{ name: 'vpc-id', values: [vpc_id] }] })
|
16
|
+
end
|
17
|
+
|
18
|
+
def select_security_group_by_group_id(ids)
|
19
|
+
describe_security_groups({ filters: [{ name: 'group-id', values: ids }] })
|
20
|
+
end
|
21
|
+
|
22
|
+
def select_security_group_by_group_name(names)
|
23
|
+
describe_security_groups({ filters: [{ name: 'group-name', values: names }] })
|
24
|
+
end
|
25
|
+
|
26
|
+
def select_security_group_by_tag_name(names)
|
27
|
+
describe_security_groups({ filters: [{ name: 'tag:Name', values: names }] })
|
28
|
+
end
|
29
|
+
|
30
|
+
def describe_security_groups(param)
|
31
|
+
ec2_client.describe_security_groups(param).security_groups
|
26
32
|
end
|
27
33
|
end
|
28
34
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative '../stub/ec2'
|
2
|
+
|
3
|
+
stub_responses = Aws.config[:ec2][:stub_responses]
|
4
|
+
|
5
|
+
stub_responses[:describe_instances][:reservations][0][:instances][0][:security_groups] <<
|
6
|
+
{
|
7
|
+
group_id: 'sg-5e6f7gh8',
|
8
|
+
group_name: 'my-security-group-name-2'
|
9
|
+
}
|
10
|
+
|
11
|
+
stub_responses[:describe_security_groups][:security_groups] <<
|
12
|
+
{
|
13
|
+
group_id: 'sg-5e6f7gh8',
|
14
|
+
group_name: 'my-security-group-name-2',
|
15
|
+
tags: [
|
16
|
+
{
|
17
|
+
key: 'Name',
|
18
|
+
value: 'my-security-group-tag-name-2'
|
19
|
+
}
|
20
|
+
]
|
21
|
+
}
|
data/lib/awspec/type/ec2.rb
CHANGED
@@ -42,6 +42,15 @@ module Awspec::Type
|
|
42
42
|
return ret.addresses.count > 0 unless ip_address
|
43
43
|
end
|
44
44
|
|
45
|
+
def has_security_groups?(sg_ids)
|
46
|
+
return true if match_group_ids?(sg_ids) || match_group_names?(sg_ids)
|
47
|
+
|
48
|
+
group_ids = resource_security_groups.map { |sg| sg.group_id }
|
49
|
+
tags = select_security_group_by_group_id(group_ids).map { |sg| sg.tags }.flatten
|
50
|
+
group_names = tags.select { |tag| tag.key == 'Name' }.map { |tag| tag.value }
|
51
|
+
group_names == sg_ids
|
52
|
+
end
|
53
|
+
|
45
54
|
def has_security_group?(sg_id)
|
46
55
|
sgs = resource_via_client.security_groups
|
47
56
|
ret = sgs.find do |sg|
|
@@ -118,5 +127,19 @@ module Awspec::Type
|
|
118
127
|
end
|
119
128
|
return true if ret
|
120
129
|
end
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
def match_group_ids?(sg_ids)
|
134
|
+
sg_ids.sort == resource_security_groups.map { |sg| sg.group_id }.sort
|
135
|
+
end
|
136
|
+
|
137
|
+
def match_group_names?(sg_names)
|
138
|
+
sg_names.sort == resource_security_groups.map { |sg| sg.group_name }.sort
|
139
|
+
end
|
140
|
+
|
141
|
+
def resource_security_groups
|
142
|
+
resource_via_client.security_groups
|
143
|
+
end
|
121
144
|
end
|
122
145
|
end
|
data/lib/awspec/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: awspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.71.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- k1LoW
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -428,6 +428,7 @@ files:
|
|
428
428
|
- lib/awspec/stub/duplicated_resource_type.rb
|
429
429
|
- lib/awspec/stub/ebs.rb
|
430
430
|
- lib/awspec/stub/ec2.rb
|
431
|
+
- lib/awspec/stub/ec2_has_multi_security_groups.rb
|
431
432
|
- lib/awspec/stub/ecr_repository.rb
|
432
433
|
- lib/awspec/stub/ecs.rb
|
433
434
|
- lib/awspec/stub/ecs_cluster.rb
|