awspec 0.30.0 → 0.31.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +15 -0
  3. data/awspec.gemspec +1 -1
  4. data/doc/_resource_types/ec2.md +8 -0
  5. data/doc/_resource_types/network_acl.md +8 -0
  6. data/doc/_resource_types/route_table.md +8 -0
  7. data/doc/_resource_types/subnet.md +8 -0
  8. data/doc/_resource_types/vpc.md +10 -2
  9. data/doc/resource_types.md +48 -3
  10. data/lib/awspec.rb +1 -0
  11. data/lib/awspec/command/generate.rb +4 -5
  12. data/lib/awspec/generator/spec/cloudwatch_alarm.rb +1 -1
  13. data/lib/awspec/generator/spec/directconnect.rb +1 -1
  14. data/lib/awspec/generator/spec/ebs.rb +1 -1
  15. data/lib/awspec/generator/spec/ec2.rb +1 -1
  16. data/lib/awspec/generator/spec/elb.rb +1 -2
  17. data/lib/awspec/generator/spec/iam_policy.rb +1 -1
  18. data/lib/awspec/generator/spec/nat_gateway.rb +1 -1
  19. data/lib/awspec/generator/spec/network_acl.rb +11 -11
  20. data/lib/awspec/generator/spec/rds.rb +1 -1
  21. data/lib/awspec/generator/spec/route53_hosted_zone.rb +2 -3
  22. data/lib/awspec/generator/spec/route_table.rb +1 -3
  23. data/lib/awspec/generator/spec/s3_bucket.rb +1 -1
  24. data/lib/awspec/generator/spec/security_group.rb +6 -6
  25. data/lib/awspec/generator/spec/subnet.rb +1 -1
  26. data/lib/awspec/generator/spec/vpc.rb +1 -1
  27. data/lib/awspec/helper.rb +0 -1
  28. data/lib/awspec/helper/finder/ec2.rb +1 -0
  29. data/lib/awspec/matcher.rb +1 -0
  30. data/lib/awspec/matcher/have_tag.rb +9 -0
  31. data/lib/awspec/resource_reader.rb +7 -10
  32. data/lib/awspec/setup.rb +1 -1
  33. data/lib/awspec/type/base.rb +8 -0
  34. data/lib/awspec/type/ec2.rb +1 -0
  35. data/lib/awspec/type/network_acl.rb +1 -0
  36. data/lib/awspec/type/route53_hosted_zone.rb +2 -1
  37. data/lib/awspec/type/route_table.rb +1 -0
  38. data/lib/awspec/type/security_group.rb +2 -5
  39. data/lib/awspec/type/subnet.rb +1 -0
  40. data/lib/awspec/type/vpc.rb +1 -0
  41. data/lib/awspec/version.rb +1 -1
  42. metadata +8 -8
  43. data/lib/awspec/helper/credentials_loader.rb +0 -30
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a905721558237afba127319af4db1276f903347
4
- data.tar.gz: 13acb88e7253a96c4bd8eb23afea29c5fb934c37
3
+ metadata.gz: 8160e6d118ed605184bcc364565d0a5c0653ee65
4
+ data.tar.gz: eee4aee22a2cb01f93b81a194a251f79b4ab4560
5
5
  SHA512:
6
- metadata.gz: d5af22547903d27edce8b88bba5b627578ba1b5e1d0783d549bb48e024e3a30e8aaedd61ea922685155009f9c9143791e84784f6dc6731990102b1578baa1542
7
- data.tar.gz: 74fbb35e7cb25517623416b245e48fea042c381356960562f63ec387a6f2eb6e2a3f72e8496e0884796635fe93ddffe0a72a721cbd5d06a132ede3571509811e
6
+ metadata.gz: 1c150a676daa377f6b74514572b6af6a123dc9d269f3bb1cea0822945e57bd367947f66ace85627eec04eb2d79f32c3254fa0f1c8185c3d1cc654c4be4adeaea
7
+ data.tar.gz: c9b2d48ec1c1db7e08f59a13df0e6feeecc5cbc3652a9379f103395a15e7c784be6cd1cfcc51627fc230305f76237200a3a9f3ed5ffd9310eb7fefe8a21d2d7f
@@ -1,3 +1,6 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.1
3
+
1
4
  Lint/Eval:
2
5
  Enabled: false
3
6
 
@@ -25,6 +28,12 @@ Metrics/MethodLength:
25
28
  Metrics/PerceivedComplexity:
26
29
  Max: 15
27
30
 
31
+ Performance/StringReplacement:
32
+ Enabled: false
33
+
34
+ Style/Alias:
35
+ Enabled: false
36
+
28
37
  Style/BarePercentLiterals:
29
38
  Enabled: false
30
39
 
@@ -34,6 +43,12 @@ Style/ClassAndModuleChildren:
34
43
  Style/Documentation:
35
44
  Enabled: false
36
45
 
46
+ Style/MutableConstant:
47
+ Enabled: false
48
+
49
+ Style/MultilineOperationIndentation:
50
+ Enabled: false
51
+
37
52
  Style/StabbyLambdaParentheses:
38
53
  Enabled: false
39
54
 
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_runtime_dependency 'rspec', '~> 3.0'
24
24
  spec.add_runtime_dependency 'rspec-its'
25
25
  spec.add_runtime_dependency 'aws-sdk', '~> 2.1'
26
- spec.add_runtime_dependency 'aws_config'
26
+ spec.add_runtime_dependency 'awsecrets', '~> 0.2'
27
27
  spec.add_runtime_dependency 'thor'
28
28
  spec.add_runtime_dependency 'activesupport'
29
29
  spec.add_runtime_dependency 'term-ansicolor'
@@ -48,6 +48,14 @@ describe ec2('my-ec2') do
48
48
  end
49
49
  ```
50
50
 
51
+ ### have_tag
52
+
53
+ ```ruby
54
+ describe ec2('my-ec2') do
55
+ it { should have_tag('Name').value('my-ec2') }
56
+ end
57
+ ```
58
+
51
59
  ### belong_to_subnet
52
60
 
53
61
  ```ruby
@@ -14,6 +14,14 @@ describe network_acl('my-network-acl') do
14
14
  end
15
15
  ```
16
16
 
17
+ ### have_tag
18
+
19
+ ```ruby
20
+ describe network_acl('my-network-acl') do
21
+ it { should have_tag('Name').value('my-network-acl') }
22
+ end
23
+ ```
24
+
17
25
  ### belong_to_vpc
18
26
 
19
27
  ```ruby
@@ -26,6 +26,14 @@ describe route_table('my-route-table') do
26
26
  end
27
27
  ```
28
28
 
29
+ ### have_tag
30
+
31
+ ```ruby
32
+ describe route_table('my-route-table') do
33
+ it { should have_tag('Name').value('my-route-table') }
34
+ end
35
+ ```
36
+
29
37
  ### advanced
30
38
 
31
39
  `route_table` can use `Aws::EC2::RouteTable` resource (see http://docs.aws.amazon.com/sdkforruby/api/Aws/EC2/RouteTable.html).
@@ -14,6 +14,14 @@ describe subnet('my-subnet') do
14
14
  end
15
15
  ```
16
16
 
17
+ ### have_tag
18
+
19
+ ```ruby
20
+ describe subnet('my-subnet') do
21
+ it { should have_tag('Environment').value('QA') }
22
+ end
23
+ ```
24
+
17
25
  ### advanced
18
26
 
19
27
  `subnet` can use `Aws::EC2::Subnet` resource (see http://docs.aws.amazon.com/sdkforruby/api/Aws/EC2/Subnet.html).
@@ -27,8 +27,16 @@ end
27
27
 
28
28
  ```ruby
29
29
  describe vpc('vpc-ab123cde') do
30
- it { should have_network_acl('acl-1abc2d3e') }
31
- it { should have_network_acl('my-network-acl') }
30
+ it { should have_route_table('rtb-ab123cde') }
31
+ it { should have_route_table('my-route-table') }
32
+ end
33
+ ```
34
+
35
+ ### have_tag
36
+
37
+ ```ruby
38
+ describe vpc('vpc-ab123cde') do
39
+ it { should have_tag('Stack').value('Networking') }
32
40
  end
33
41
  ```
34
42
 
@@ -280,6 +280,15 @@ end
280
280
  ```
281
281
 
282
282
 
283
+ ### have_tag
284
+
285
+ ```ruby
286
+ describe ec2('my-ec2') do
287
+ it { should have_tag('Name').value('my-ec2') }
288
+ end
289
+ ```
290
+
291
+
283
292
  ### belong_to_subnet
284
293
 
285
294
  ```ruby
@@ -639,7 +648,7 @@ end
639
648
 
640
649
  This matcher does not support Amazon S3 event sources. ( [See SDK doc](http://docs.aws.amazon.com/sdkforruby/api/Aws/Lambda/Client.html#list_event_source_mappings-instance_method) )
641
650
 
642
- ### its(:function_name), its(:function_arn), its(:runtime), its(:role), its(:handler), its(:code_size), its(:description), its(:timeout), its(:memory_size), its(:last_modified), its(:code_sha_256), its(:version)
651
+ ### its(:function_name), its(:function_arn), its(:runtime), its(:role), its(:handler), its(:code_size), its(:description), its(:timeout), its(:memory_size), its(:last_modified), its(:code_sha_256), its(:version), its(:vpc_config)
643
652
  ## <a name="launch_configuration">launch_configuration</a>
644
653
 
645
654
  LaunchConfiguration resource type.
@@ -724,6 +733,15 @@ end
724
733
  ```
725
734
 
726
735
 
736
+ ### have_tag
737
+
738
+ ```ruby
739
+ describe network_acl('my-network-acl') do
740
+ it { should have_tag('Name').value('my-network-acl') }
741
+ end
742
+ ```
743
+
744
+
727
745
  ### belong_to_vpc
728
746
 
729
747
  ```ruby
@@ -950,6 +968,15 @@ end
950
968
  ```
951
969
 
952
970
 
971
+ ### have_tag
972
+
973
+ ```ruby
974
+ describe route_table('my-route-table') do
975
+ it { should have_tag('Name').value('my-route-table') }
976
+ end
977
+ ```
978
+
979
+
953
980
  ### its(:route_table_id), its(:vpc_id)
954
981
  ### :unlock: Advanced use
955
982
 
@@ -1160,6 +1187,15 @@ end
1160
1187
  ```
1161
1188
 
1162
1189
 
1190
+ ### have_tag
1191
+
1192
+ ```ruby
1193
+ describe subnet('my-subnet') do
1194
+ it { should have_tag('Environment').value('QA') }
1195
+ end
1196
+ ```
1197
+
1198
+
1163
1199
  ### its(:subnet_id), its(:state), its(:vpc_id), its(:cidr_block), its(:available_ip_address_count), its(:availability_zone), its(:default_for_az), its(:map_public_ip_on_launch)
1164
1200
  ### :unlock: Advanced use
1165
1201
 
@@ -1215,8 +1251,17 @@ end
1215
1251
 
1216
1252
  ```ruby
1217
1253
  describe vpc('vpc-ab123cde') do
1218
- it { should have_network_acl('acl-1abc2d3e') }
1219
- it { should have_network_acl('my-network-acl') }
1254
+ it { should have_route_table('rtb-ab123cde') }
1255
+ it { should have_route_table('my-route-table') }
1256
+ end
1257
+ ```
1258
+
1259
+
1260
+ ### have_tag
1261
+
1262
+ ```ruby
1263
+ describe vpc('vpc-ab123cde') do
1264
+ it { should have_tag('Stack').value('Networking') }
1220
1265
  end
1221
1266
  ```
1222
1267
 
@@ -3,6 +3,7 @@ require 'rspec'
3
3
  require 'rspec/its'
4
4
  require 'time'
5
5
  require 'active_support/inflector'
6
+ require 'awsecrets'
6
7
  require 'awspec/version'
7
8
  require 'awspec/cli'
8
9
  require 'awspec/stub'
@@ -1,6 +1,5 @@
1
1
  require 'thor'
2
2
  require 'awspec/setup'
3
- require 'awspec/helper/credentials_loader'
4
3
 
5
4
  module Awspec
6
5
  class Generate < Thor
@@ -13,7 +12,7 @@ module Awspec
13
12
  types.each do |type|
14
13
  desc type + ' [vpc_id]', "Generate #{type} spec from VPC ID (or VPC \"Name\" tag)"
15
14
  define_method type do |*args|
16
- Awspec::Helper::CredentialsLoader.load(options[:profile])
15
+ Awsecrets.load(profile: options[:profile])
17
16
  vpc_id = args.first
18
17
  eval "puts Awspec::Generator::Spec::#{type.camelize}.new.generate_by_vpc_id(vpc_id)"
19
18
  end
@@ -21,13 +20,13 @@ module Awspec
21
20
 
22
21
  desc 'route53_hosted_zone [example.com.]', 'Generate route53_hosted_zone spec from Domain name'
23
22
  def route53_hosted_zone(hosted_zone)
24
- Awspec::Helper::CredentialsLoader.load(options[:profile])
23
+ Awsecrets.load(profile: options[:profile])
25
24
  puts Awspec::Generator::Spec::Route53HostedZone.new.generate_by_domain_name(hosted_zone)
26
25
  end
27
26
 
28
27
  desc 's3_bucket [backet_name]', 'Generate s3_bucket spec from S3 bucket name. if NO args, Generate all.'
29
28
  def s3_bucket(bucket_name = nil)
30
- Awspec::Helper::CredentialsLoader.load(options[:profile])
29
+ Awsecrets.load(profile: options[:profile])
31
30
  if bucket_name
32
31
  puts Awspec::Generator::Spec::S3Bucket.new.generate(bucket_name)
33
32
  else
@@ -46,7 +45,7 @@ module Awspec
46
45
  desc type, "Generate #{type} spec"
47
46
  end
48
47
  define_method type do
49
- Awspec::Helper::CredentialsLoader.load(options[:profile])
48
+ Awsecrets.load(profile: options[:profile])
50
49
  eval "puts Awspec::Generator::Spec::#{type.camelize}.new.generate_all"
51
50
  end
52
51
  end
@@ -4,7 +4,7 @@ module Awspec::Generator
4
4
  include Awspec::Helper::Finder
5
5
  def generate_all
6
6
  alarms = select_all_cloudwatch_alarms
7
- alarms.empty? && fail('Not Found alarm')
7
+ raise 'Not Found alarm' if alarms.empty?
8
8
  ERB.new(alarm_spec_template, nil, '-').result(binding).chomp
9
9
  end
10
10
 
@@ -8,7 +8,7 @@ module Awspec::Generator
8
8
 
9
9
  def generate_virtual_interface_all
10
10
  virtual_interfaces = select_virtual_interfaces
11
- virtual_interfaces.empty? && fail('Not Found virtual_interfaces')
11
+ raise 'Not Found virtual_interfaces' if virtual_interfaces.empty?
12
12
  ERB.new(virtual_interface_spec_template, nil, '-').result(binding).chomp
13
13
  end
14
14
 
@@ -4,7 +4,7 @@ module Awspec::Generator
4
4
  include Awspec::Helper::Finder
5
5
  def generate_all
6
6
  volumes = select_all_attached_ebs
7
- volumes.empty? && fail('Not Found EBS')
7
+ raise 'Not Found EBS' if volumes.empty?
8
8
  specs = volumes.map do |volume|
9
9
  attachment_specs = generate_attachment_specs(volume)
10
10
  content = ERB.new(ebs_spec_template, nil, '-').result(binding).gsub(/^\n/, '')
@@ -8,7 +8,7 @@ module Awspec::Generator
8
8
  instance_type private_ip_address public_ip_address
9
9
  )
10
10
  vpc = find_vpc(vpc_id)
11
- fail 'Not Found VPC' unless vpc
11
+ raise 'Not Found VPC' unless vpc
12
12
  @vpc_id = vpc[:vpc_id]
13
13
  @vpc_tag_name = vpc.tag_name
14
14
  instances = select_ec2_by_vpc_id(@vpc_id)
@@ -11,7 +11,7 @@ module Awspec::Generator
11
11
  unhealthy_threshold healthy_threshold
12
12
  )
13
13
  vpc = find_vpc(vpc_id)
14
- fail 'Not Found VPC' unless vpc
14
+ raise 'Not Found VPC' unless vpc
15
15
  @vpc_id = vpc[:vpc_id]
16
16
  @vpc_tag_name = vpc.tag_name
17
17
  lbs = select_elb_by_vpc_id(@vpc_id)
@@ -22,7 +22,6 @@ module Awspec::Generator
22
22
  specs.join("\n")
23
23
  end
24
24
 
25
- # rubocop:disable all
26
25
  def elb_spec_template
27
26
  template = <<-'EOF'
28
27
  describe elb('<%= lb.load_balancer_name %>') do
@@ -4,7 +4,7 @@ module Awspec::Generator
4
4
  include Awspec::Helper::Finder
5
5
  def generate_all
6
6
  policies = select_all_attached_policies
7
- policies.empty? && fail('Not Found policy')
7
+ raise 'Not Found policy' if policies.empty?
8
8
  ERB.new(policy_spec_template, nil, '-').result(binding).chomp
9
9
  end
10
10
 
@@ -6,7 +6,7 @@ module Awspec::Generator
6
6
  describes = %w(
7
7
  )
8
8
  vpc = find_vpc(vpc_id)
9
- fail 'Not Found VPC' unless vpc
9
+ raise 'Not Found VPC' unless vpc
10
10
  @vpc_id = vpc[:vpc_id]
11
11
  @vpc_tag_name = vpc.tag_name
12
12
  nat_gateways = select_nat_gateway_by_vpc_id(@vpc_id)
@@ -6,7 +6,7 @@ module Awspec::Generator
6
6
  describes = %w(
7
7
  )
8
8
  vpc = find_vpc(vpc_id)
9
- fail 'Not Found VPC' unless vpc
9
+ raise 'Not Found VPC' unless vpc
10
10
  @vpc_id = vpc[:vpc_id]
11
11
  @vpc_tag_name = vpc.tag_name
12
12
  network_acls = select_network_acl_by_vpc_id(@vpc_id)
@@ -30,11 +30,11 @@ module Awspec::Generator
30
30
  specs = []
31
31
  acl.associations.each do |a|
32
32
  subnet = find_subnet(a.subnet_id)
33
- if subnet.tag_name
34
- spec = "it { should have_subnet('" + subnet.tag_name + "') }"
35
- else
36
- spec = "it { should have_subnet('" + subnet.subnet_id + "') }"
37
- end
33
+ spec = if subnet.tag_name
34
+ "it { should have_subnet('" + subnet.tag_name + "') }"
35
+ else
36
+ "it { should have_subnet('" + subnet.subnet_id + "') }"
37
+ end
38
38
  specs.push(spec)
39
39
  end
40
40
  specs
@@ -52,11 +52,11 @@ module Awspec::Generator
52
52
  line += ' ' + actions[entry.rule_action.to_sym]
53
53
  port_range = entry.port_range
54
54
  unless port_range.nil?
55
- if port_range.from == port_range.to
56
- port = port_range.from.to_s
57
- else
58
- port = "'" + port_range.from.to_s + '-' + port_range.to.to_s + "'"
59
- end
55
+ port = if port_range.from == port_range.to
56
+ port_range.from.to_s
57
+ else
58
+ "'" + port_range.from.to_s + '-' + port_range.to.to_s + "'"
59
+ end
60
60
  line += '(' + port + ')'
61
61
  end
62
62
  line += ".protocol('" + protocols[entry.protocol.to_i] + "')"
@@ -7,7 +7,7 @@ module Awspec::Generator
7
7
  db_instance_identifier db_instance_class multi_az availability_zone
8
8
  )
9
9
  vpc = find_vpc(vpc_id)
10
- fail 'Not Found VPC' unless vpc
10
+ raise 'Not Found VPC' unless vpc
11
11
  @vpc_id = vpc[:vpc_id]
12
12
  @vpc_tag_name = vpc.tag_name
13
13
  db_instances = select_rds_by_vpc_id(@vpc_id)
@@ -4,7 +4,7 @@ module Awspec::Generator
4
4
  include Awspec::Helper::Finder
5
5
  def generate_by_domain_name(id)
6
6
  hosted_zone = find_hosted_zone(id)
7
- fail 'Not Found Route53 Hosted Zone' unless hosted_zone
7
+ raise 'Not Found Route53 Hosted Zone' unless hosted_zone
8
8
  id = hosted_zone[:id]
9
9
  res = @route53_client.list_resource_record_sets({
10
10
  hosted_zone_id: id
@@ -24,7 +24,6 @@ it { should have_record_set('<%= name %>').<%= type %>('<%= v %>').ttl(<%= recor
24
24
  EOF
25
25
  v = record_set.resource_records.map { |r| r.value }.join("\n")
26
26
  type = record_set.type.downcase
27
- return ERB.new(template, nil, '-').result(binding)
28
27
  else
29
28
  # ALIAS
30
29
  dns_name = record_set.alias_target.dns_name
@@ -32,8 +31,8 @@ EOF
32
31
  template = <<-'EOF'
33
32
  it { should have_record_set('<%= name %>').alias('<%= dns_name %>', '<%= hosted_zone_id %>') }
34
33
  EOF
35
- return ERB.new(template, nil, '-').result(binding)
36
34
  end
35
+ ERB.new(template, nil, '-').result(binding)
37
36
  end
38
37
 
39
38
  def route53_hosted_zone_spec_template
@@ -6,7 +6,7 @@ module Awspec::Generator
6
6
  describes = %w(
7
7
  )
8
8
  vpc = find_vpc(vpc_id)
9
- fail 'Not Found VPC' unless vpc
9
+ raise 'Not Found VPC' unless vpc
10
10
  @vpc_id = vpc[:vpc_id]
11
11
  @vpc_tag_name = vpc.tag_name
12
12
  route_tables = select_route_table_by_vpc_id(@vpc_id)
@@ -67,7 +67,6 @@ EOF
67
67
  template
68
68
  end
69
69
 
70
- # rubocop:disable Metrics/LineLength
71
70
  def route_table_spec_connection_linetemplate
72
71
  template = <<-'EOF'
73
72
  <%- if connection.tag_name -%>
@@ -78,7 +77,6 @@ it { should have_route('<%= route.destination_cidr_block %>').target(vpc_peering
78
77
  EOF
79
78
  template
80
79
  end
81
- # rubocop:enable Metrics/LineLength
82
80
 
83
81
  def route_table_spec_nat_linetemplate
84
82
  template = <<-'EOF'
@@ -4,7 +4,7 @@ module Awspec::Generator
4
4
  include Awspec::Helper::Finder
5
5
  def generate_all
6
6
  buckets = select_all_buckets
7
- buckets.empty? && fail('Not Found Bucket')
7
+ raise 'Not Found Bucket' if buckets.empty?
8
8
  specs = buckets.map do |bucket|
9
9
  content(bucket)
10
10
  end
@@ -7,7 +7,7 @@ module Awspec::Generator
7
7
  group_id group_name
8
8
  )
9
9
  vpc = find_vpc(vpc_id)
10
- fail 'Not Found VPC' unless vpc
10
+ raise 'Not Found VPC' unless vpc
11
11
  @vpc_id = vpc[:vpc_id]
12
12
  @vpc_tag_name = vpc.tag_name
13
13
  sgs = select_security_group_by_vpc_id(@vpc_id)
@@ -35,11 +35,11 @@ module Awspec::Generator
35
35
  next
36
36
  end
37
37
 
38
- if permission.from_port == permission.to_port
39
- port = permission.from_port
40
- else
41
- port = "'" + permission.from_port.to_s + '-' + permission.to_port.to_s + "'"
42
- end
38
+ port = if permission.from_port == permission.to_port
39
+ permission.from_port
40
+ else
41
+ "'" + permission.from_port.to_s + '-' + permission.to_port.to_s + "'"
42
+ end
43
43
 
44
44
  protocol = permission.ip_protocol
45
45
  permission.ip_ranges.each do |ip_range|
@@ -7,7 +7,7 @@ module Awspec::Generator
7
7
  subnet_id cidr_block
8
8
  )
9
9
  vpc = find_vpc(vpc_id)
10
- fail 'Not Found VPC' unless vpc
10
+ raise 'Not Found VPC' unless vpc
11
11
  @vpc_id = vpc[:vpc_id]
12
12
  @vpc_tag_name = vpc.tag_name
13
13
  subnets = select_subnet_by_vpc_id(@vpc_id)
@@ -7,7 +7,7 @@ module Awspec::Generator
7
7
  vpc_id cidr_block
8
8
  )
9
9
  vpc = find_vpc(vpc_id)
10
- fail 'Not Found VPC' unless vpc
10
+ raise 'Not Found VPC' unless vpc
11
11
  @vpc_id = vpc[:vpc_id]
12
12
  @vpc_tag_name = vpc.tag_name
13
13
  route_tables = select_route_table_by_vpc_id(@vpc_id)
@@ -1,7 +1,6 @@
1
1
  require 'awspec/helper/color'
2
2
  require 'awspec/helper/type'
3
3
  require 'awspec/helper/finder'
4
- require 'awspec/helper/credentials_loader'
5
4
  extend Awspec::Helper::Type
6
5
  class RSpec::Core::ExampleGroup
7
6
  extend Awspec::Helper::Type
@@ -32,6 +32,7 @@ module Awspec::Helper
32
32
  else
33
33
  return nil
34
34
  end
35
+ # rubocop:enable Style/GuardClause
35
36
  return res[:reservations].first[:instances].first if res[:reservations].count == 1 && \
36
37
  res[:reservations].first[:instances].count == 1
37
38
  end
@@ -1,6 +1,7 @@
1
1
  # EC2
2
2
  require 'awspec/matcher/belong_to_vpc'
3
3
  require 'awspec/matcher/belong_to_subnet'
4
+ require 'awspec/matcher/have_tag'
4
5
 
5
6
  # RDS
6
7
  require 'awspec/matcher/belong_to_db_subnet_group'
@@ -0,0 +1,9 @@
1
+ RSpec::Matchers.define :have_tag do |key|
2
+ match do |type|
3
+ type.has_tag?(key, @value)
4
+ end
5
+
6
+ chain :value do |val|
7
+ @value = val
8
+ end
9
+ end
@@ -4,17 +4,14 @@ module Awspec
4
4
  end
5
5
 
6
6
  def method_missing_via_black_list(name, delegate_to: nil)
7
- fail(ArguementError, 'delegate_to: must be specified') unless delegate_to
8
- if match_black_list?(name)
9
- fail CalledMethodInBlackList, "Method call #{name.inspect} is black-listed"
7
+ raise ArguementError, 'delegate_to: must be specified' unless delegate_to
8
+ raise CalledMethodInBlackList, "Method call #{name.inspect} is black-listed" if match_black_list?(name)
9
+ attr = delegate_to.send(name)
10
+ case attr
11
+ when Aws::Resources::Resource
12
+ ResourceReader.new(attr)
10
13
  else
11
- attr = delegate_to.send(name)
12
- case attr
13
- when Aws::Resources::Resource
14
- ResourceReader.new(attr)
15
- else
16
- attr
17
- end
14
+ attr
18
15
  end
19
16
  end
20
17
 
@@ -13,7 +13,7 @@ module Awspec
13
13
  def self.generate_spec_helper
14
14
  content = <<-'EOF'
15
15
  require 'awspec'
16
- Awspec::Helper::CredentialsLoader.load
16
+ Awsecrets.load(secrets_path: File.expand_path('./secrets.yml', File.dirname(__FILE__)))
17
17
  EOF
18
18
  dir = 'spec'
19
19
  if File.exist? dir
@@ -33,6 +33,14 @@ module Awspec::Type
33
33
  end
34
34
  end
35
35
 
36
+ def self.tags_allowed
37
+ define_method :has_tag? do |key, value|
38
+ tags = @resource_via_client[:tags]
39
+ return false unless tags
40
+ tags.any? { |t| t['key'] == key && t['value'] == value }
41
+ end
42
+ end
43
+
36
44
  def method_missing(name)
37
45
  describe = name.to_sym
38
46
  if @resource_via_client.members.include?(describe)
@@ -1,6 +1,7 @@
1
1
  module Awspec::Type
2
2
  class Ec2 < Base
3
3
  aws_resource Aws::EC2::Instance
4
+ tags_allowed
4
5
 
5
6
  def initialize(id)
6
7
  super
@@ -1,6 +1,7 @@
1
1
  module Awspec::Type
2
2
  class NetworkAcl < Base
3
3
  aws_resource Aws::EC2::NetworkAcl
4
+ tags_allowed
4
5
 
5
6
  def initialize(id)
6
7
  super
@@ -11,7 +11,8 @@ module Awspec::Type
11
11
  def has_record_set?(name, type, value, options = {})
12
12
  name.gsub!(/\*/, '\\\052') # wildcard support
13
13
  ret = @resource_via_client_record_sets.find do |record_set|
14
- next if record_set.type != type.upcase
14
+ # next if record_set.type != type.upcase
15
+ next unless record_set.type.casecmp(type) == 0
15
16
  options[:ttl] = record_set.ttl unless options[:ttl]
16
17
  if !record_set.resource_records.empty?
17
18
  v = record_set.resource_records.map { |r| r.value }.join("\n")
@@ -1,6 +1,7 @@
1
1
  module Awspec::Type
2
2
  class RouteTable < Base
3
3
  aws_resource Aws::EC2::RouteTable
4
+ tags_allowed
4
5
 
5
6
  def initialize(id)
6
7
  super
@@ -10,11 +10,8 @@ module Awspec::Type
10
10
  end
11
11
 
12
12
  def opened?(port = nil, protocol = nil, cidr = nil)
13
- if @inbound
14
- return inbound_opened?(port, protocol, cidr)
15
- else
16
- return outbound_opened?(port, protocol, cidr)
17
- end
13
+ return inbound_opened?(port, protocol, cidr) if @inbound
14
+ outbound_opened?(port, protocol, cidr)
18
15
  end
19
16
 
20
17
  def inbound_opened?(port = nil, protocol = nil, cidr = nil)
@@ -1,6 +1,7 @@
1
1
  module Awspec::Type
2
2
  class Subnet < Base
3
3
  aws_resource Aws::EC2::Subnet
4
+ tags_allowed
4
5
 
5
6
  def initialize(id)
6
7
  super
@@ -1,6 +1,7 @@
1
1
  module Awspec::Type
2
2
  class Vpc < Base
3
3
  aws_resource Aws::EC2::Vpc
4
+ tags_allowed
4
5
 
5
6
  def initialize(id)
6
7
  super
@@ -1,3 +1,3 @@
1
1
  module Awspec
2
- VERSION = '0.30.0'
2
+ VERSION = '0.31.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.30.0
4
+ version: 0.31.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - k1LoW
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-06 00:00:00.000000000 Z
11
+ date: 2016-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -53,19 +53,19 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.1'
55
55
  - !ruby/object:Gem::Dependency
56
- name: aws_config
56
+ name: awsecrets
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '0.2'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '0.2'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: thor
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -281,7 +281,6 @@ files:
281
281
  - lib/awspec/generator/template.rb
282
282
  - lib/awspec/helper.rb
283
283
  - lib/awspec/helper/color.rb
284
- - lib/awspec/helper/credentials_loader.rb
285
284
  - lib/awspec/helper/finder.rb
286
285
  - lib/awspec/helper/finder/ami.rb
287
286
  - lib/awspec/helper/finder/autoscaling.rb
@@ -314,6 +313,7 @@ files:
314
313
  - lib/awspec/matcher/belong_to_vpc.rb
315
314
  - lib/awspec/matcher/have_record_set.rb
316
315
  - lib/awspec/matcher/have_route.rb
316
+ - lib/awspec/matcher/have_tag.rb
317
317
  - lib/awspec/resource_reader.rb
318
318
  - lib/awspec/setup.rb
319
319
  - lib/awspec/stub.rb
@@ -1,30 +0,0 @@
1
- require 'aws-sdk'
2
- require 'aws_config'
3
-
4
- module Awspec::Helper
5
- module CredentialsLoader
6
- def self.load(profile = nil)
7
- profile = ENV['AWS_PROFILE'] if profile.nil?
8
- if profile
9
- # SharedCredentials
10
- aws_config = AWSConfig.profiles[profile]
11
- aws_config = AWSConfig.profiles['default'] unless aws_config
12
- Aws.config[:region] = aws_config.config_hash[:region] if aws_config
13
- Aws.config[:credentials] = Aws::SharedCredentials.new(profile_name: profile)
14
- else
15
- # secrets.yml
16
- creds = YAML.load_file('spec/secrets.yml') if File.exist?('spec/secrets.yml')
17
- creds = YAML.load_file('secrets.yml') if File.exist?('secrets.yml')
18
- return if creds.nil?
19
- Aws.config.update({
20
- region: creds['region']
21
- }) if creds.include?('region')
22
- Aws.config.update({
23
- credentials: Aws::Credentials.new(
24
- creds['aws_access_key_id'],
25
- creds['aws_secret_access_key'])
26
- }) if creds.include?('aws_access_key_id') && creds.include?('aws_secret_access_key')
27
- end
28
- end
29
- end
30
- end