awspec 0.23.0 → 0.24.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: 29714cb2509f97ff68e7b273854fc1829a43161f
4
- data.tar.gz: c6f75d467f1fbf92d96309a4e563aa356a6aee49
3
+ metadata.gz: 9d18888b14d8e1858e59126b09d82f75705cc744
4
+ data.tar.gz: 51e0923dc3afb735b6566a1beb4e8de83f79475f
5
5
  SHA512:
6
- metadata.gz: 345ee0b436e56b86b65d784738a745a9addb2913fb0b63b981c04cb13e48ea3e483a190ce524c5aa2d96cd8ea630422b916c5fb4ae94b56852b60b11abf9683a
7
- data.tar.gz: b0c9ad16b2b6aa41c83189f42ea8b6df451f6965eac01c665f77847d12787e8694d3291953e5524c02162ccea13c1dd6e807271c8e4a8cfcc79de7c5379c54f6
6
+ metadata.gz: a29ad76af244e9feac511c78779200d3c2a400e58dddcb7f6e967441c9d3758e7a29e9f6d472f6df7ddd512637f411c55910d5547509190ba4a641fffebe96b7
7
+ data.tar.gz: 75b430184399d5e2d46da464525b75b03b0a6c31ad3b34c6d54cc856f8d8459c7fed9c7bec453d2d2e5722f0ad893872a579278b5829f5619ef662e4096c5367
@@ -5,7 +5,7 @@
5
5
  | [rds_db_parameter_group](#rds_db_parameter_group)
6
6
  | [security_group](#security_group)
7
7
  | [vpc](#vpc)
8
- | [s3](#s3)
8
+ | [s3_bucket](#s3_bucket)
9
9
  | [route53_hosted_zone](#route53_hosted_zone)
10
10
  | [autoscaling_group](#autoscaling_group)
11
11
  | [subnet](#subnet)
@@ -270,41 +270,21 @@ end
270
270
  ```
271
271
 
272
272
  #### its(:vpc_id), its(:state), its(:cidr_block), its(:dhcp_options_id), its(:instance_tenancy), its(:is_default)
273
- ## <a name="s3">s3</a>
273
+ ## <a name="s3_bucket">s3_bucket</a>
274
274
 
275
- S3 resource type.
275
+ S3Bucket resource type.
276
276
 
277
277
  ### exist
278
278
 
279
- ```ruby
280
- describe s3('my-bucket') do
281
- it { should exist }
282
- end
283
- ```
284
-
285
-
286
279
  ### have_acl_grant
287
280
 
288
- ```ruby
289
- describe s3('my-bucket') do
290
- its(:acl_grants_count) { should eq 3 }
291
- it { should have_acl_grant(grantee: 'my-bucket-owner', permission: 'FULL_CONTROL') }
292
- it { should have_acl_grant(grantee: 'my-bucket-write-only', permission: 'WRITE') }
293
- it { should have_acl_grant(grantee: 'my-bucket-read-only', permission: 'READ') }
294
- its(:acl_owner) { should eq 'my-bucket-owner' }
295
- end
296
- ```
297
-
281
+ ### have_cors_rule
298
282
 
299
283
  ### have_object
300
284
 
301
- ```ruby
302
- describe s3('my-bucket') do
303
- it { should have_object('path/to/object') }
304
- end
305
- ```
285
+ ### have_policy
306
286
 
307
- #### its(:acl_grants_count), its(:acl_owner), its(:name), its(:creation_date)
287
+ #### its(:acl_grants_count), its(:acl_owner), its(:cors_rules_count), its(:name), its(:creation_date)
308
288
  ## <a name="route53_hosted_zone">route53_hosted_zone</a>
309
289
 
310
290
  Route53HostedZone resource type.
@@ -26,12 +26,12 @@ module Awspec
26
26
  end
27
27
 
28
28
  types_for_generate_all = %w(
29
- iam_policy cloudwatch_alarm directconnect
29
+ iam_policy cloudwatch_alarm directconnect ebs s3_bucket
30
30
  )
31
31
 
32
32
  types_for_generate_all.each do |type|
33
- if type == 'iam_policy'
34
- desc 'iam_policy', 'Generate attached iam_policy spec'
33
+ if %w(iam_policy ebs).include?(type)
34
+ desc type, "Generate attached #{type} spec"
35
35
  else
36
36
  desc type, "Generate #{type} spec"
37
37
  end
@@ -13,6 +13,8 @@ require 'awspec/generator/spec/network_acl'
13
13
  require 'awspec/generator/spec/route_table'
14
14
  require 'awspec/generator/spec/subnet'
15
15
  require 'awspec/generator/spec/directconnect'
16
+ require 'awspec/generator/spec/ebs'
17
+ require 'awspec/generator/spec/s3_bucket'
16
18
 
17
19
  # Doc
18
20
  require 'awspec/generator/doc/type'
@@ -1,14 +1,14 @@
1
1
  module Awspec::Generator
2
2
  module Doc
3
3
  module Type
4
- class S3 < Base
4
+ class S3Bucket < Base
5
5
  def initialize
6
6
  super
7
- @type = Awspec::Type::S3.new('my-bucket')
7
+ @type = Awspec::Type::S3Bucket.new('my-bucket')
8
8
  @ret = @type.resource
9
9
  @matchers = []
10
10
  @ignore_matchers = []
11
- @describes = %w(acl_grants_count acl_owner)
11
+ @describes = %w(acl_grants_count acl_owner cors_rules_count)
12
12
  end
13
13
  end
14
14
  end
@@ -0,0 +1,55 @@
1
+ module Awspec::Generator
2
+ module Spec
3
+ class Ebs
4
+ include Awspec::Helper::Finder
5
+ def generate_all
6
+ volumes = select_all_attached_ebs
7
+ volumes.empty? && fail('Not Found EBS')
8
+ specs = volumes.map do |volume|
9
+ attachment_specs = generate_attachment_specs(volume)
10
+ content = ERB.new(ebs_spec_template, nil, '-').result(binding).gsub(/^\n/, '')
11
+ end
12
+ specs.join("\n")
13
+ end
14
+
15
+ def generate_attachment_specs(volume)
16
+ linespecs = []
17
+ volume.attachments.each do |attachment|
18
+ instance = find_ec2(attachment.instance_id)
19
+ linespecs.push(ERB.new(attachment_linetemplate, nil, '-').result(binding)) if attachment.instance_id
20
+ end
21
+ linespecs
22
+ end
23
+
24
+ def attachment_linetemplate
25
+ template = <<-'EOF'
26
+ <%- if instance.tag_name -%>
27
+ it { should be_attached_to('<%= instance.tag_name %>') }
28
+ <%- else -%>
29
+ it { should be_attached_to('<%= instance.instance_id %>') }
30
+ <%- end -%>
31
+ EOF
32
+ template
33
+ end
34
+
35
+ def ebs_spec_template
36
+ template = <<-'EOF'
37
+ <%- if volume.tag_name -%>
38
+ describe ebs('<%= volume.tag_name %>') do
39
+ <%- else -%>
40
+ describe ebs('<%= volume.volume_id %>') do
41
+ <%- end -%>
42
+ it { should exist }
43
+ it { should be_<%= volume.state.tr('-', '_') %> }
44
+ its(:size) { should eq <%= volume.size %> }
45
+ its(:volume_type) { should eq '<%= volume.volume_type %>' }
46
+ <% attachment_specs.each do |line| %>
47
+ <%= line %>
48
+ <% end %>
49
+ end
50
+ EOF
51
+ template
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,46 @@
1
+ module Awspec::Generator
2
+ module Spec
3
+ class S3Bucket
4
+ include Awspec::Helper::Finder
5
+ def generate_all
6
+ buckets = select_all_buckets
7
+ buckets.empty? && fail('Not Found Bucket')
8
+ specs = buckets.map do |bucket|
9
+ acl = find_bucket_acl(bucket.name)
10
+ grant_specs = generate_grant_specs(acl)
11
+ content = ERB.new(bucket_spec_template, nil, '-').result(binding).gsub(/^\n/, '')
12
+ end
13
+ specs.join("\n")
14
+ end
15
+
16
+ def generate_grant_specs(acl)
17
+ linespecs = []
18
+ acl.grants.each do |grant|
19
+ linespecs.push(ERB.new(grant_linetemplate, nil, '-').result(binding))
20
+ end
21
+ linespecs
22
+ end
23
+
24
+ def grant_linetemplate
25
+ template = <<-'EOF'
26
+ it { should have_acl_grant(grantee: '<%= grant.grantee.display_name %>', permission: '<%= grant.permission %>') }
27
+ EOF
28
+ template
29
+ end
30
+
31
+ def bucket_spec_template
32
+ template = <<-'EOF'
33
+ describe s3_bucket('<%= bucket.name %>') do
34
+ it { should exist }
35
+ its(:acl_grants_count) { should eq <%= acl.grants.count %> }
36
+ <% grant_specs.each do |line| %>
37
+ <%= line %>
38
+ <% end %>
39
+ its(:acl_owner) { should eq '<%= acl.owner.display_name %>' }
40
+ end
41
+ EOF
42
+ template
43
+ end
44
+ end
45
+ end
46
+ end
@@ -22,6 +22,18 @@ module Awspec::Helper
22
22
  end
23
23
  volumes
24
24
  end
25
+
26
+ def select_all_attached_ebs
27
+ selected = []
28
+ res = @ec2_client.describe_volumes
29
+
30
+ loop do
31
+ selected += res.volumes.select { |v| v.attachments.count > 0 }
32
+ (res.next_page? && res = res.next_page) || break
33
+ end
34
+
35
+ selected
36
+ end
25
37
  end
26
38
  end
27
39
  end
@@ -13,6 +13,22 @@ module Awspec::Helper
13
13
  rescue Aws::S3::Errors::NoSuchBucket
14
14
  nil
15
15
  end
16
+
17
+ def find_bucket_cors(id)
18
+ @s3_client.get_bucket_cors(bucket: id)
19
+ rescue Aws::S3::Errors::NoSuchBucket
20
+ nil
21
+ end
22
+
23
+ def find_bucket_policy(id)
24
+ @s3_client.get_bucket_policy(bucket: id)
25
+ rescue Aws::S3::Errors::NoSuchBucket
26
+ nil
27
+ end
28
+
29
+ def select_all_buckets
30
+ @s3_client.list_buckets.buckets
31
+ end
16
32
  end
17
33
  end
18
34
  end
@@ -3,7 +3,7 @@ module Awspec
3
3
  module Type
4
4
  TYPES = %w(
5
5
  base ec2 rds rds_db_parameter_group security_group
6
- vpc s3 route53_hosted_zone autoscaling_group subnet
6
+ vpc s3_bucket route53_hosted_zone autoscaling_group subnet
7
7
  route_table ebs elb lambda iam_user iam_group iam_role
8
8
  iam_policy elasticache elasticache_cache_parameter_group
9
9
  cloudwatch_alarm ses_identity network_acl directconnect_virtual_interface
@@ -23,6 +23,12 @@ module Awspec
23
23
  puts Color.on_red(Color.white('!!! `auto_scaling_group` type is deprecated. use `autoscaling_group` !!!'))
24
24
  Awspec::Type::AutoscalingGroup.new(name)
25
25
  end
26
+
27
+ def s3(name)
28
+ puts ''
29
+ puts Color.on_red(Color.white('!!! `s3` type is deprecated. use `s3_bucket` !!!'))
30
+ Awspec::Type::S3Bucket.new(name)
31
+ end
26
32
  end
27
33
  end
28
34
  end
@@ -46,6 +46,7 @@ Aws.config[:ec2] = {
46
46
  volume_id: 'vpc-ab123cde',
47
47
  state: 'in-use',
48
48
  size: 100,
49
+ volume_type: 'gp2',
49
50
  attachments: [
50
51
  {
51
52
  instance_id: 'i-ec12345a',
@@ -37,6 +37,37 @@ Aws.config[:s3] = {
37
37
  permission: 'READ'
38
38
  }
39
39
  ]
40
+ },
41
+ get_bucket_cors: {
42
+ cors_rules: [
43
+ {
44
+ allowed_methods: ['GET'],
45
+ allowed_origins: ['*']
46
+ },
47
+ {
48
+ allowed_headers: ['*'],
49
+ allowed_methods: ['GET'],
50
+ allowed_origins: ['https://example.com', 'https://example.org'],
51
+ expose_headers: ['X-Custom-Header'],
52
+ max_age_seconds: 3600
53
+ }
54
+ ]
55
+ },
56
+ get_bucket_policy: {
57
+ policy: <<-POLICY
58
+ {
59
+ "Version": "2012-10-17",
60
+ "Statement": [
61
+ {
62
+ "Sid": "AllowPublicRead",
63
+ "Effect": "Allow",
64
+ "Principal": "*",
65
+ "Action": "s3:GetObject",
66
+ "Resource": "arn:aws:s3:::my-bucket/*"
67
+ }
68
+ ]
69
+ }
70
+ POLICY
40
71
  }
41
72
  }
42
73
  }
@@ -1,5 +1,5 @@
1
1
  module Awspec::Type
2
- class S3 < Base
2
+ class S3Bucket < Base
3
3
  def initialize(id)
4
4
  super
5
5
  @resource = find_bucket(id)
@@ -34,5 +34,35 @@ module Awspec::Type
34
34
  @acl = find_bucket_acl(@id)
35
35
  @acl.grants.count
36
36
  end
37
+
38
+ def has_cors_rule?(allowed_headers: [],
39
+ allowed_methods:,
40
+ allowed_origins:,
41
+ expose_headers: [],
42
+ max_age_seconds: nil)
43
+ cors_rules.any? do |rule|
44
+ (rule.allowed_headers - allowed_headers).empty? &&
45
+ (rule.allowed_methods - allowed_methods).empty? &&
46
+ (rule.allowed_origins - allowed_origins).empty? &&
47
+ (rule.expose_headers - expose_headers).empty? &&
48
+ rule.max_age_seconds == max_age_seconds
49
+ end
50
+ end
51
+
52
+ def cors_rules_count
53
+ cors_rules.count
54
+ end
55
+
56
+ def has_policy?(policy)
57
+ bp = find_bucket_policy(@id)
58
+ bp ? (bp.policy.read == policy) : false
59
+ end
60
+
61
+ private
62
+
63
+ def cors_rules
64
+ cors = find_bucket_cors(@id)
65
+ cors ? cors.cors_rules : []
66
+ end
37
67
  end
38
68
  end
@@ -1,3 +1,3 @@
1
1
  module Awspec
2
- VERSION = '0.23.0'
2
+ VERSION = '0.24.0'
3
3
  end
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.23.0
4
+ version: 0.24.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - k1LoW
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-02 00:00:00.000000000 Z
11
+ date: 2015-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -235,13 +235,14 @@ files:
235
235
  - lib/awspec/generator/doc/type/rds_db_parameter_group.rb
236
236
  - lib/awspec/generator/doc/type/route53_hosted_zone.rb
237
237
  - lib/awspec/generator/doc/type/route_table.rb
238
- - lib/awspec/generator/doc/type/s3.rb
238
+ - lib/awspec/generator/doc/type/s3_bucket.rb
239
239
  - lib/awspec/generator/doc/type/security_group.rb
240
240
  - lib/awspec/generator/doc/type/ses_identity.rb
241
241
  - lib/awspec/generator/doc/type/subnet.rb
242
242
  - lib/awspec/generator/doc/type/vpc.rb
243
243
  - lib/awspec/generator/spec/cloudwatch_alarm.rb
244
244
  - lib/awspec/generator/spec/directconnect.rb
245
+ - lib/awspec/generator/spec/ebs.rb
245
246
  - lib/awspec/generator/spec/ec2.rb
246
247
  - lib/awspec/generator/spec/elb.rb
247
248
  - lib/awspec/generator/spec/iam_policy.rb
@@ -249,6 +250,7 @@ files:
249
250
  - lib/awspec/generator/spec/rds.rb
250
251
  - lib/awspec/generator/spec/route53_hosted_zone.rb
251
252
  - lib/awspec/generator/spec/route_table.rb
253
+ - lib/awspec/generator/spec/s3_bucket.rb
252
254
  - lib/awspec/generator/spec/security_group.rb
253
255
  - lib/awspec/generator/spec/subnet.rb
254
256
  - lib/awspec/generator/spec/vpc.rb
@@ -307,7 +309,7 @@ files:
307
309
  - lib/awspec/stub/rds_db_parameter_group.rb
308
310
  - lib/awspec/stub/route53_hosted_zone.rb
309
311
  - lib/awspec/stub/route_table.rb
310
- - lib/awspec/stub/s3.rb
312
+ - lib/awspec/stub/s3_bucket.rb
311
313
  - lib/awspec/stub/security_group.rb
312
314
  - lib/awspec/stub/ses_identity.rb
313
315
  - lib/awspec/stub/subnet.rb
@@ -332,7 +334,7 @@ files:
332
334
  - lib/awspec/type/rds_db_parameter_group.rb
333
335
  - lib/awspec/type/route53_hosted_zone.rb
334
336
  - lib/awspec/type/route_table.rb
335
- - lib/awspec/type/s3.rb
337
+ - lib/awspec/type/s3_bucket.rb
336
338
  - lib/awspec/type/security_group.rb
337
339
  - lib/awspec/type/ses_identity.rb
338
340
  - lib/awspec/type/subnet.rb