awspec 0.73.1 → 0.73.2

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: e570a6a990e351cb5185bfaea27857ba2179f155
4
- data.tar.gz: 80339d75578c5fb87b0e2eb5b29eae3dd1ef38e1
3
+ metadata.gz: f6bd0b2085bd7ae739cea83dd5f2713235eb3bde
4
+ data.tar.gz: 3acda26007092f63eda0f5d5d0b23c7aba07f622
5
5
  SHA512:
6
- metadata.gz: 992599280ba5f2de8d3457f990557564c23360c0200fb9c8e3b78ca99952d6d54e7b2a28d7b9c2a8dea5bb07d6ef6a09889e4f06303850b11c1b4eb966b3bf04
7
- data.tar.gz: ea5fc0d07b3eedc77dbe34f9857391dd4a86bd3385f1f878a612e6bd1c51c3a5471babdece320710d115e0b932a350ec37b00e3ff4f3e84aa9eb2f5c0a64a842
6
+ metadata.gz: a8fb6fab06cf538c72b19c57d7e0555eb555d6d1e5df311855003050b2ed5edceab6a6f8bc9826c00d0a042597ea9cba421beda05730f2e88e6e31ed3eed8d5e
7
+ data.tar.gz: 9dfeb8d62661b6064eeee9a7f39908079ac1d5861326f59e461c8e7a67630ab9e6ff8f09674530352ae35670a988bd4bd54633e4704a57b2c26b9b438f94674d
@@ -38,7 +38,7 @@ module Awspec
38
38
  types_for_generate_all = %w(
39
39
  cloudwatch_alarm cloudwatch_event directconnect ebs efs
40
40
  elasticsearch iam_group iam_policy iam_role iam_user kms lambda
41
- acm
41
+ acm cloudwatch_logs
42
42
  )
43
43
 
44
44
  types_for_generate_all.each do |type|
@@ -23,6 +23,7 @@ require 'awspec/generator/spec/iam_user'
23
23
  require 'awspec/generator/spec/iam_group'
24
24
  require 'awspec/generator/spec/iam_role'
25
25
  require 'awspec/generator/spec/acm'
26
+ require 'awspec/generator/spec/cloudwatch_logs'
26
27
 
27
28
  # Doc
28
29
  require 'awspec/generator/doc/type'
@@ -4,7 +4,7 @@ module Awspec::Generator
4
4
  include Awspec::Helper::Finder
5
5
  def generate_all
6
6
  events = select_all_cloudwatch_events
7
- raise 'Not Found alarm' if events.empty?
7
+ raise 'Not Found event' if events.empty?
8
8
  ERB.new(event_spec_template, nil, '-').result(binding).chomp
9
9
  end
10
10
 
@@ -0,0 +1,68 @@
1
+ module Awspec::Generator
2
+ module Spec
3
+ class CloudwatchLogs
4
+ include Awspec::Helper::Finder
5
+ def generate_all
6
+ log_groups = select_all_cloudwatch_logs_log_groups
7
+ raise 'Not Found Log Group' if log_groups.empty?
8
+ specs = log_groups.map do |log_group|
9
+ log_stream_line = generate_log_stream_spec(log_group.log_group_name)
10
+ metric_filter_lines = generate_log_metric_filters_specs(log_group.log_group_name)
11
+ subscription_filter_lines = generate_log_subscription_filters_specs(log_group.log_group_name)
12
+ content = ERB.new(cloudwatch_logs_spec_template, nil, '-').result(binding).gsub(/^\n/, '')
13
+ end
14
+ specs.join("\n")
15
+ end
16
+
17
+ def generate_log_stream_spec(log_group)
18
+ log_stream = find_cloudwatch_logs_stream_by_log_group_name(log_group)
19
+ "it { should have_log_stream('#{log_stream.log_stream_name}') }" unless log_stream.nil?
20
+ end
21
+
22
+ def generate_log_metric_filters_specs(log_group)
23
+ metric_filters = select_all_cloudwatch_logs_metric_filter(log_group)
24
+ metric_filter_lines = []
25
+ metric_filters.each do |metric_filter|
26
+ line = "it { should have_metric_filter('#{metric_filter.filter_name}') }"
27
+ metric_filter_lines.push(line)
28
+ end
29
+ metric_filter_lines
30
+ end
31
+
32
+ def generate_log_subscription_filters_specs(log_group)
33
+ subscription_filters = select_all_cloudwatch_logs_subscription_filter(log_group)
34
+ subscription_filter_lines = []
35
+ subscription_filters.each do |subscription_filter|
36
+ line = "it { should have_subscription_filter('#{subscription_filter.filter_name}')"
37
+ unless subscription_filter.filter_pattern.empty?
38
+ line += ".filter_pattern('#{subscription_filter.filter_pattern}')"
39
+ end
40
+ line += ' }'
41
+ subscription_filter_lines.push(line)
42
+ end
43
+ subscription_filter_lines
44
+ end
45
+
46
+ def cloudwatch_logs_spec_template
47
+ template = <<-'EOF'
48
+ describe cloudwatch_logs('<%= log_group.log_group_name %>') do
49
+ it { should exist }
50
+ <%- unless log_group.retention_in_days.nil? -%>
51
+ its(:retention_in_days) { should eq <%= log_group.retention_in_days %> }
52
+ <% end -%>
53
+ <%- unless log_stream_line.nil? -%>
54
+ <%= log_stream_line %>
55
+ <% end -%>
56
+ <% metric_filter_lines.each do |metric_filter_line| %>
57
+ <%= metric_filter_line %>
58
+ <% end %>
59
+ <% subscription_filter_lines.each do |subscription_filter_line| %>
60
+ <%= subscription_filter_line %>
61
+ <% end %>
62
+ end
63
+ EOF
64
+ template
65
+ end
66
+ end
67
+ end
68
+ end
@@ -30,6 +30,39 @@ module Awspec::Helper
30
30
  filter.filter_name == filter_name
31
31
  end
32
32
  end
33
+
34
+ def select_all_cloudwatch_logs_log_groups
35
+ req = {}
36
+ log_groups = []
37
+ loop do
38
+ res = cloudwatch_logs_client.describe_log_groups(req)
39
+ log_groups.push(*res.log_groups)
40
+ break if res.next_token.nil?
41
+ req[:next_token] = res.next_token
42
+ end
43
+ log_groups
44
+ end
45
+
46
+ filter_types = %w(metric subscription)
47
+ filter_types.each do |type|
48
+ define_method 'select_all_cloudwatch_logs_' + type + '_filter' do |*args|
49
+ req = { log_group_name: args.first }
50
+ method_name = 'describe_' + type + '_filters'
51
+ resources = []
52
+ loop do
53
+ res = cloudwatch_logs_client.method(method_name).call(req)
54
+ case type
55
+ when 'metric' then
56
+ resources.push(*res.metric_filters)
57
+ when 'subscription' then
58
+ resources.push(*res.subscription_filters)
59
+ end
60
+ break if res.next_token.nil?
61
+ req[:next_token] = res.next_token
62
+ end
63
+ resources
64
+ end
65
+ end
33
66
  end
34
67
  end
35
68
  end
@@ -20,7 +20,11 @@ module Awspec::Type
20
20
 
21
21
  def has_subscription_filter?(filter_name, pattern = nil)
22
22
  ret = find_cloudwatch_logs_subscription_fileter_by_log_group_name(@id, filter_name)
23
- return false unless ret.filter_pattern == pattern
23
+ if pattern.nil?
24
+ return true if ret.filter_name == filter_name
25
+ else
26
+ return false unless ret.filter_pattern == pattern
27
+ end
24
28
  return true if ret.filter_name == filter_name
25
29
  end
26
30
  end
@@ -1,3 +1,3 @@
1
1
  module Awspec
2
- VERSION = '0.73.1'
2
+ VERSION = '0.73.2'
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.73.1
4
+ version: 0.73.2
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-30 00:00:00.000000000 Z
11
+ date: 2017-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -330,6 +330,7 @@ files:
330
330
  - lib/awspec/generator/spec/acm.rb
331
331
  - lib/awspec/generator/spec/cloudwatch_alarm.rb
332
332
  - lib/awspec/generator/spec/cloudwatch_event.rb
333
+ - lib/awspec/generator/spec/cloudwatch_logs.rb
333
334
  - lib/awspec/generator/spec/directconnect.rb
334
335
  - lib/awspec/generator/spec/ebs.rb
335
336
  - lib/awspec/generator/spec/ec2.rb