sport_ngin_aws_auditor 3.7.0 → 3.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.markdown +6 -0
- data/lib/sport_ngin_aws_auditor/cache_instance.rb +3 -1
- data/lib/sport_ngin_aws_auditor/ec2_instance.rb +4 -2
- data/lib/sport_ngin_aws_auditor/instance.rb +23 -19
- data/lib/sport_ngin_aws_auditor/instance_helper.rb +19 -6
- data/lib/sport_ngin_aws_auditor/rds_instance.rb +4 -1
- data/lib/sport_ngin_aws_auditor/recently_retired_tag.rb +4 -2
- data/lib/sport_ngin_aws_auditor/scripts/audit.rb +76 -23
- data/lib/sport_ngin_aws_auditor/version.rb +1 -1
- data/spec/sport_ngin_aws_auditor/ec2_instance_spec.rb +10 -5
- data/spec/sport_ngin_aws_auditor/instance_spec.rb +12 -6
- data/spec/sport_ngin_aws_auditor/rds_instance_spec.rb +6 -3
- data/spec/sport_ngin_aws_auditor/recently_retired_tag_spec.rb +19 -4
- data/sport_ngin_aws_auditor.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61d6d41031de3858552e36e195d2d139d6a9a144
|
4
|
+
data.tar.gz: e12cdde6945decdf7dd19d9a957fabe6a53591a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7a8c9a59da8348942d6fb012530a634a2c239e94d81e47683ae5879e39d94537b6c28954a2497981dd3116e5a6011d003a03368faa6e2320da5e4bfb658da73
|
7
|
+
data.tar.gz: 82a740a5a5dfb4d8698f201ae9ea258eb83dec6d73d2f5cf44c1901fe0eaccda7ed2d13f7ee28a0be18bfef4e4338ecc6a9a3d412b2ceef021c83296d580a2dd
|
data/CHANGELOG.markdown
CHANGED
@@ -35,7 +35,7 @@ module SportNginAwsAuditor
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
attr_accessor :id, :name, :instance_type, :engine, :count, :tag_value, :expiration_date
|
38
|
+
attr_accessor :id, :name, :instance_type, :engine, :count, :tag_value, :tag_reason, :expiration_date
|
39
39
|
def initialize(cache_instance, account_id=nil, tag_name=nil, cache=nil)
|
40
40
|
if cache_instance.class.to_s == "Aws::ElastiCache::Types::ReservedCacheNode"
|
41
41
|
self.id = cache_instance.reserved_cache_node_id
|
@@ -60,6 +60,8 @@ module SportNginAwsAuditor
|
|
60
60
|
cache.list_tags_for_resource(resource_name: arn).tag_list.each do |tag|
|
61
61
|
if tag.key == tag_name
|
62
62
|
self.tag_value = tag.value
|
63
|
+
elsif tag.key == 'no-reserved-instance-reason'
|
64
|
+
self.tag_reason = tag.value
|
63
65
|
end
|
64
66
|
end
|
65
67
|
end
|
@@ -60,7 +60,7 @@ module SportNginAwsAuditor
|
|
60
60
|
private :get_more_info
|
61
61
|
end
|
62
62
|
|
63
|
-
attr_accessor :id, :name, :platform, :availability_zone, :instance_type, :count, :stack_name, :tag_value, :expiration_date
|
63
|
+
attr_accessor :id, :name, :platform, :availability_zone, :instance_type, :count, :stack_name, :tag_value, :tag_reason, :expiration_date
|
64
64
|
def initialize(ec2_instance, tag_name, count=1)
|
65
65
|
if ec2_instance.class.to_s == "Aws::EC2::Types::ReservedInstances"
|
66
66
|
self.id = ec2_instance.reserved_instances_id
|
@@ -73,7 +73,7 @@ module SportNginAwsAuditor
|
|
73
73
|
self.expiration_date = ec2_instance.end if ec2_instance.state == 'retired'
|
74
74
|
elsif ec2_instance.class.to_s == "Aws::EC2::Types::Instance"
|
75
75
|
self.id = ec2_instance.instance_id
|
76
|
-
self.name =
|
76
|
+
self.name = ec2_instance.key_name
|
77
77
|
self.platform = platform_helper((ec2_instance.platform || ''), ec2_instance.vpc_id)
|
78
78
|
self.availability_zone = ec2_instance.placement.availability_zone
|
79
79
|
self.instance_type = ec2_instance.instance_type
|
@@ -85,6 +85,8 @@ module SportNginAwsAuditor
|
|
85
85
|
ec2_instance.tags.each do |tag|
|
86
86
|
if tag.key == tag_name
|
87
87
|
self.tag_value = tag.value
|
88
|
+
elsif tag.key == 'no-reserved-instance-reason'
|
89
|
+
self.tag_reason = tag.value
|
88
90
|
end
|
89
91
|
end
|
90
92
|
end
|
@@ -4,41 +4,45 @@ module SportNginAwsAuditor
|
|
4
4
|
class Instance
|
5
5
|
extend InstanceHelper
|
6
6
|
|
7
|
-
attr_accessor :
|
8
|
-
def initialize(
|
9
|
-
if
|
10
|
-
|
11
|
-
|
12
|
-
self.
|
13
|
-
self.
|
7
|
+
attr_accessor :type, :count, :category, :tag_value, :reason, :name
|
8
|
+
def initialize(type, data_array)
|
9
|
+
if type.include?(" with tag")
|
10
|
+
type = type.dup # because type is a frozen string right now
|
11
|
+
type.slice!(" with tag")
|
12
|
+
self.type = type
|
13
|
+
self.category = "tagged"
|
14
|
+
self.name = data_array[1] || nil
|
15
|
+
self.reason = data_array[2] || nil
|
16
|
+
self.tag_value = data_array[3] || nil
|
14
17
|
else
|
15
|
-
self.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
self.type = type
|
19
|
+
|
20
|
+
if data_array[0] < 0
|
21
|
+
self.category = "running"
|
22
|
+
elsif data_array[0] == 0
|
23
|
+
self.category = "matched"
|
24
|
+
elsif data_array[0] > 0
|
25
|
+
self.category = "reserved"
|
22
26
|
end
|
23
27
|
end
|
24
28
|
|
25
|
-
self.count =
|
29
|
+
self.count = data_array[0].abs
|
26
30
|
end
|
27
31
|
|
28
32
|
def tagged?
|
29
|
-
self.
|
33
|
+
self.category == "tagged"
|
30
34
|
end
|
31
35
|
|
32
36
|
def reserved?
|
33
|
-
self.
|
37
|
+
self.category == "reserved"
|
34
38
|
end
|
35
39
|
|
36
40
|
def running?
|
37
|
-
self.
|
41
|
+
self.category == "running"
|
38
42
|
end
|
39
43
|
|
40
44
|
def matched?
|
41
|
-
self.
|
45
|
+
self.category == "matched"
|
42
46
|
end
|
43
47
|
end
|
44
48
|
end
|
@@ -16,8 +16,12 @@ module SportNginAwsAuditor
|
|
16
16
|
instance_hash = Hash.new()
|
17
17
|
instances.each do |instance|
|
18
18
|
next if instance.nil?
|
19
|
-
instance_hash[instance.to_s] = instance_hash.has_key?(instance.to_s) ? instance_hash[instance.to_s] + instance.count : instance.count
|
19
|
+
instance_hash[instance.to_s] = instance_hash.has_key?(instance.to_s) ? instance_hash[instance.to_s][0] + instance.count : instance.count
|
20
20
|
end if instances
|
21
|
+
|
22
|
+
instance_hash.each do |key, value|
|
23
|
+
instance_hash[key] = [instance_hash[key]]
|
24
|
+
end
|
21
25
|
instance_hash
|
22
26
|
end
|
23
27
|
|
@@ -25,7 +29,16 @@ module SportNginAwsAuditor
|
|
25
29
|
instances_to_add.each do |instance|
|
26
30
|
next if instance.nil?
|
27
31
|
key = instance.to_s << " with tag"
|
28
|
-
|
32
|
+
instance_result = []
|
33
|
+
if instance_hash.has_key?(key)
|
34
|
+
instance_result << instance_hash[key][0] + 1
|
35
|
+
else
|
36
|
+
instance_result << 1
|
37
|
+
end
|
38
|
+
instance_result << instance.name
|
39
|
+
instance_result << instance.tag_reason
|
40
|
+
instance_result << instance.tag_value
|
41
|
+
instance_hash[key] = instance_result
|
29
42
|
end if instances_to_add
|
30
43
|
instance_hash
|
31
44
|
end
|
@@ -38,9 +51,9 @@ module SportNginAwsAuditor
|
|
38
51
|
ris = instance_count_hash(get_reserved_instances)
|
39
52
|
|
40
53
|
instance_hash.keys.concat(ris.keys).uniq.each do |key|
|
41
|
-
instance_count = instance_hash.has_key?(key) ? instance_hash[key] : 0
|
42
|
-
ris_count = ris.has_key?(key) ? ris[key] : 0
|
43
|
-
differences[key] = ris_count - instance_count
|
54
|
+
instance_count = instance_hash.has_key?(key) ? instance_hash[key][0] : 0
|
55
|
+
ris_count = ris.has_key?(key) ? ris[key][0] : 0
|
56
|
+
differences[key] = [ris_count - instance_count]
|
44
57
|
end
|
45
58
|
|
46
59
|
add_instances_with_tag_to_hash(instances_with_tag, differences)
|
@@ -79,7 +92,7 @@ module SportNginAwsAuditor
|
|
79
92
|
value = gather_instance_tag_date(instance)
|
80
93
|
one_week_ago = (Date.today - 7).to_s
|
81
94
|
if (value && (one_week_ago < value.to_s) && (value.to_s < Date.today.to_s))
|
82
|
-
return_array << RecentlyRetiredTag.new(value.to_s, instance.to_s)
|
95
|
+
return_array << RecentlyRetiredTag.new(value.to_s, instance.to_s, instance.name, instance.tag_reason)
|
83
96
|
end
|
84
97
|
end
|
85
98
|
|
@@ -35,7 +35,7 @@ module SportNginAwsAuditor
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
attr_accessor :id, :name, :multi_az, :instance_type, :engine, :count, :tag_value, :expiration_date
|
38
|
+
attr_accessor :id, :name, :multi_az, :instance_type, :engine, :count, :tag_value, :tag_reason, :expiration_date
|
39
39
|
def initialize(rds_instance, account_id=nil, tag_name=nil, rds=nil)
|
40
40
|
if rds_instance.class.to_s == "Aws::RDS::Types::ReservedDBInstance"
|
41
41
|
self.id = rds_instance.reserved_db_instances_offering_id
|
@@ -46,6 +46,7 @@ module SportNginAwsAuditor
|
|
46
46
|
self.expiration_date = rds_instance.start_time + rds_instance.duration if rds_instance.state == 'retired'
|
47
47
|
elsif rds_instance.class.to_s == "Aws::RDS::Types::DBInstance"
|
48
48
|
self.id = rds_instance.db_instance_identifier
|
49
|
+
self.name = rds_instance.db_name
|
49
50
|
self.multi_az = rds_instance.multi_az ? "Multi-AZ" : "Single-AZ"
|
50
51
|
self.instance_type = rds_instance.db_instance_class
|
51
52
|
self.engine = engine_helper(rds_instance.engine)
|
@@ -60,6 +61,8 @@ module SportNginAwsAuditor
|
|
60
61
|
rds.list_tags_for_resource(resource_name: arn).tag_list.each do |tag|
|
61
62
|
if tag.key == tag_name
|
62
63
|
self.tag_value = tag.value
|
64
|
+
elsif tag.key == 'no-reserved-instance-reason'
|
65
|
+
self.tag_reason = tag.value
|
63
66
|
end
|
64
67
|
end
|
65
68
|
end
|
@@ -3,10 +3,12 @@ require_relative './instance_helper'
|
|
3
3
|
module SportNginAwsAuditor
|
4
4
|
class RecentlyRetiredTag
|
5
5
|
|
6
|
-
attr_accessor :value, :instance_name
|
7
|
-
def initialize(tag_value, instance_name)
|
6
|
+
attr_accessor :value, :instance_type, :instance_name, :reason
|
7
|
+
def initialize(tag_value, instance_type, instance_name, reason=nil)
|
8
8
|
self.value = tag_value
|
9
|
+
self.instance_type = instance_type
|
9
10
|
self.instance_name = instance_name
|
11
|
+
self.reason = reason
|
10
12
|
end
|
11
13
|
end
|
12
14
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'highline/import'
|
2
|
+
require 'colorize'
|
2
3
|
require_relative "../notify_slack"
|
3
4
|
require_relative "../instance"
|
4
5
|
require_relative "../audit_data"
|
@@ -42,13 +43,13 @@ module SportNginAwsAuditor
|
|
42
43
|
end
|
43
44
|
|
44
45
|
def self.print_data(slack, audit_results, class_type, environment)
|
45
|
-
audit_results.data.sort_by! { |instance| [instance.
|
46
|
+
audit_results.data.sort_by! { |instance| [instance.category, instance.type] }
|
46
47
|
|
47
48
|
if slack
|
48
49
|
print_to_slack(audit_results, class_type, environment)
|
49
50
|
elsif options[:reserved] || options[:instances]
|
50
51
|
puts header(class_type)
|
51
|
-
audit_results.data.each{ |instance| say "<%= color('#{instance.
|
52
|
+
audit_results.data.each{ |instance| say "<%= color('#{instance.type}: #{instance.count}', :white) %>" }
|
52
53
|
else
|
53
54
|
retired_ris = audit_results.retired_ris
|
54
55
|
retired_tags = audit_results.retired_tags
|
@@ -68,30 +69,59 @@ module SportNginAwsAuditor
|
|
68
69
|
|
69
70
|
def self.say_retired_tags(retired_tags, class_type, environment)
|
70
71
|
say "The following #{class_type}Instance tags have recently expired in #{environment}:"
|
71
|
-
retired_tags.each
|
72
|
+
retired_tags.each do |tag|
|
73
|
+
if tag.reason
|
74
|
+
say "#{tag.instance_name} (#{tag.instance_type}) retired on #{tag.value} because of #{tag.reason}"
|
75
|
+
else
|
76
|
+
say "#{tag.instance_name} (#{tag.instance_type}) retired on #{tag.value}"
|
77
|
+
end
|
78
|
+
end
|
72
79
|
end
|
73
80
|
|
74
81
|
def self.colorize(instance)
|
75
|
-
name = instance.
|
82
|
+
name = instance.type
|
76
83
|
count = instance.count
|
77
|
-
color, rgb = color_chooser(instance)
|
78
|
-
|
84
|
+
color, rgb, prefix = color_chooser(instance)
|
85
|
+
if instance.tagged?
|
86
|
+
if instance.reason
|
87
|
+
puts "#{prefix} #{name}: #{count} (expiring on #{instance.tag_value} because of #{instance.reason})".blue
|
88
|
+
else
|
89
|
+
say "<%= color('#{prefix} #{name}: #{count} (expiring on #{instance.tag_value})', :#{color}) %>"
|
90
|
+
end
|
91
|
+
else
|
92
|
+
say "<%= color('#{prefix} #{name}: #{count}', :#{color}) %>"
|
93
|
+
end
|
79
94
|
end
|
80
95
|
|
81
96
|
def self.print_to_slack(audit_results, class_type, environment)
|
82
97
|
discrepancy_array = []
|
98
|
+
tagged_array = []
|
83
99
|
|
84
100
|
audit_results.data.each do |instance|
|
85
|
-
unless instance.matched?
|
101
|
+
unless instance.matched? || instance.tagged?
|
86
102
|
discrepancy_array.push(instance)
|
87
103
|
end
|
88
104
|
end
|
89
105
|
|
90
|
-
|
91
|
-
|
92
|
-
unless true_discrepancies.empty?
|
106
|
+
unless discrepancy_array.empty?
|
93
107
|
print_discrepancies(discrepancy_array, audit_results, class_type, environment)
|
94
108
|
end
|
109
|
+
|
110
|
+
audit_results.data.each do |instance|
|
111
|
+
if instance.tagged?
|
112
|
+
tagged_array.push(instance)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
unless tagged_array.empty?
|
117
|
+
print_tagged(tagged_array, audit_results, class_type, environment)
|
118
|
+
end
|
119
|
+
|
120
|
+
retired_ris = audit_results.retired_ris
|
121
|
+
retired_tags = audit_results.retired_tags
|
122
|
+
|
123
|
+
print_retired_ris(retired_ris, class_type, environment) unless retired_ris.empty?
|
124
|
+
print_retired_tags(retired_tags, class_type, environment) unless retired_tags.empty?
|
95
125
|
end
|
96
126
|
|
97
127
|
def self.print_discrepancies(discrepancy_array, audit_results, class_type, environment)
|
@@ -99,19 +129,38 @@ module SportNginAwsAuditor
|
|
99
129
|
slack_instances = NotifySlack.new(title)
|
100
130
|
|
101
131
|
discrepancy_array.each do |discrepancy|
|
102
|
-
|
132
|
+
type = discrepancy.type
|
103
133
|
count = discrepancy.count
|
104
|
-
color, rgb = color_chooser(discrepancy)
|
105
|
-
|
134
|
+
color, rgb, prefix = color_chooser(discrepancy)
|
135
|
+
|
136
|
+
unless discrepancy.tagged?
|
137
|
+
text = "#{prefix} #{type}: #{count}"
|
138
|
+
slack_instances.attachments.push({"color" => rgb, "text" => text, "mrkdwn_in" => ["text"]})
|
139
|
+
end
|
106
140
|
end
|
107
141
|
|
108
|
-
slack_instances.perform
|
142
|
+
slack_instances.perform
|
143
|
+
end
|
109
144
|
|
110
|
-
|
111
|
-
|
145
|
+
def self.print_tagged(tagged_array, audit_results, class_type, environment)
|
146
|
+
title = "There are currently some tagged #{class_type}s in #{environment}:\n"
|
147
|
+
slack_instances = NotifySlack.new(title)
|
112
148
|
|
113
|
-
|
114
|
-
|
149
|
+
tagged_array.each do |tagged|
|
150
|
+
type = tagged.type
|
151
|
+
count = tagged.count
|
152
|
+
color, rgb, prefix = color_chooser(tagged)
|
153
|
+
|
154
|
+
if tagged.reason
|
155
|
+
text = "#{prefix} #{type}: #{count} (expiring on #{tagged.tag_value} because of #{tagged.reason})"
|
156
|
+
else
|
157
|
+
text = "#{prefix} #{type}: #{count} (expiring on #{tagged.tag_value})"
|
158
|
+
end
|
159
|
+
|
160
|
+
slack_instances.attachments.push({"color" => rgb, "text" => text, "mrkdwn_in" => ["text"]})
|
161
|
+
end
|
162
|
+
|
163
|
+
slack_instances.perform
|
115
164
|
end
|
116
165
|
|
117
166
|
def self.print_retired_ris(retired_ris, class_type, environment)
|
@@ -132,7 +181,11 @@ module SportNginAwsAuditor
|
|
132
181
|
message = "The following #{class_type} tags have recently expired in #{environment}:\n"
|
133
182
|
|
134
183
|
retired_tags.each do |tag|
|
135
|
-
|
184
|
+
if tag.reason
|
185
|
+
message << "*#{tag.instance_name}* (#{tag.instance_type}) retired on *#{tag.value}* because of #{tag.reason}\n"
|
186
|
+
else
|
187
|
+
message << "*#{tag.instance_name}* (#{tag.instance_type}) retired on *#{tag.value}*\n"
|
188
|
+
end
|
136
189
|
end
|
137
190
|
|
138
191
|
slack_retired_tags = NotifySlack.new(message)
|
@@ -141,13 +194,13 @@ module SportNginAwsAuditor
|
|
141
194
|
|
142
195
|
def self.color_chooser(instance)
|
143
196
|
if instance.tagged?
|
144
|
-
return "blue", "#0000CC"
|
197
|
+
return "blue", "#0000CC", "TAGGED -"
|
145
198
|
elsif instance.running?
|
146
|
-
return "yellow", "#FFD700"
|
199
|
+
return "yellow", "#FFD700", "MISSING RI -"
|
147
200
|
elsif instance.matched?
|
148
|
-
return "green", "#32CD32"
|
201
|
+
return "green", "#32CD32", "MATCHED RI -"
|
149
202
|
elsif instance.reserved?
|
150
|
-
return "red", "#BF1616"
|
203
|
+
return "red", "#BF1616", "UNUSED RI -"
|
151
204
|
end
|
152
205
|
end
|
153
206
|
|
@@ -22,7 +22,8 @@ module SportNginAwsAuditor
|
|
22
22
|
state: state,
|
23
23
|
placement: placement,
|
24
24
|
tags: instance_tags,
|
25
|
-
class: "Aws::EC2::Types::Instance"
|
25
|
+
class: "Aws::EC2::Types::Instance",
|
26
|
+
key_name: 'Example-instance-01')
|
26
27
|
ec2_instance2 = double('ec2_instance', instance_id: "i-thisisfake",
|
27
28
|
instance_type: "t2.large",
|
28
29
|
vpc_id: "vpc-alsofake",
|
@@ -30,7 +31,8 @@ module SportNginAwsAuditor
|
|
30
31
|
state: state,
|
31
32
|
placement: placement,
|
32
33
|
tags: instance_tags,
|
33
|
-
class: "Aws::EC2::Types::Instance"
|
34
|
+
class: "Aws::EC2::Types::Instance",
|
35
|
+
key_name: 'Example-instance-02')
|
34
36
|
ec2_reservations = double('ec2_reservations', instances: [ec2_instance1, ec2_instance2])
|
35
37
|
ec2_instances = double('ec2_instances', reservations: [ec2_reservations])
|
36
38
|
name_tag = { key: "Name", value: "our-app-instance-100" }
|
@@ -203,7 +205,8 @@ module SportNginAwsAuditor
|
|
203
205
|
state: state,
|
204
206
|
placement: placement,
|
205
207
|
tags: instance_tags,
|
206
|
-
class: "Aws::EC2::Types::Instance"
|
208
|
+
class: "Aws::EC2::Types::Instance",
|
209
|
+
key_name: 'Example-instance-01')
|
207
210
|
ec2_reservations = double('ec2_reservations', instances: [ec2_instance])
|
208
211
|
ec2_instances = double('ec2_instances', reservations: [ec2_reservations])
|
209
212
|
name_tag = { key: "Name", value: "our-app-instance-100" }
|
@@ -227,14 +230,16 @@ module SportNginAwsAuditor
|
|
227
230
|
platform: nil,
|
228
231
|
state: state,
|
229
232
|
placement: placement,
|
230
|
-
class: "Aws::EC2::Types::Instance"
|
233
|
+
class: "Aws::EC2::Types::Instance",
|
234
|
+
key_name: 'Example-instance-01')
|
231
235
|
ec2_instance2 = double('ec2_instance', instance_id: "i-alsofake",
|
232
236
|
instance_type: "t2.small",
|
233
237
|
vpc_id: "vpc-alsofake",
|
234
238
|
platform: "Windows",
|
235
239
|
state: state,
|
236
240
|
placement: placement,
|
237
|
-
class: "Aws::EC2::Types::Instance"
|
241
|
+
class: "Aws::EC2::Types::Instance",
|
242
|
+
key_name: 'Example-instance-01')
|
238
243
|
ec2_reservations = double('ec2_reservations', instances: [ec2_instance1, ec2_instance2])
|
239
244
|
ec2_instances = double('ec2_instances', reservations: [ec2_reservations])
|
240
245
|
name_tag = { key: "Name", value: "our-app-instance-100" }
|
@@ -3,26 +3,32 @@ require "sport_ngin_aws_auditor"
|
|
3
3
|
module SportNginAwsAuditor
|
4
4
|
describe Instance do
|
5
5
|
it "should make a reserved instance with proper attributes" do
|
6
|
-
instance = Instance.new("Windows VPC us-east-1e m1.large", 4)
|
6
|
+
instance = Instance.new("Windows VPC us-east-1e m1.large", [4])
|
7
7
|
expect(instance).to be_an_instance_of(Instance)
|
8
|
-
expect(instance.
|
8
|
+
expect(instance.category).to eq("reserved")
|
9
|
+
expect(instance.type).to eq("Windows VPC us-east-1e m1.large")
|
9
10
|
expect(instance.count).to eq(4)
|
10
11
|
expect(instance.tagged?).to eq(false)
|
11
12
|
expect(instance.reserved?).to eq(true)
|
12
13
|
end
|
13
14
|
|
14
15
|
it "should make a running instance with proper attributes" do
|
15
|
-
instance = Instance.new("Windows VPC us-east-1e m1.large", -1)
|
16
|
+
instance = Instance.new("Windows VPC us-east-1e m1.large", [-1])
|
16
17
|
expect(instance).to be_an_instance_of(Instance)
|
17
|
-
expect(instance.
|
18
|
+
expect(instance.category).to eq("running")
|
19
|
+
expect(instance.type).to eq("Windows VPC us-east-1e m1.large")
|
18
20
|
expect(instance.count).to eq(-1.abs)
|
19
21
|
end
|
20
22
|
|
21
23
|
it "should make an instance with a tag with proper attributes" do
|
22
|
-
instance = Instance.new("Windows VPC us-east-1e m1.large with tag", 4)
|
24
|
+
instance = Instance.new("Windows VPC us-east-1e m1.large with tag", [4, 'example-instance-name', 'This is an example', '09/12/2015'])
|
23
25
|
expect(instance).to be_an_instance_of(Instance)
|
24
|
-
expect(instance.
|
26
|
+
expect(instance.category).to eq("tagged")
|
27
|
+
expect(instance.type).to eq("Windows VPC us-east-1e m1.large")
|
25
28
|
expect(instance.count).to eq(4)
|
29
|
+
expect(instance.name).to eq('example-instance-name')
|
30
|
+
expect(instance.reason).to eq('This is an example')
|
31
|
+
expect(instance.tag_value).to eq('09/12/2015')
|
26
32
|
expect(instance.tagged?).to eq(true)
|
27
33
|
expect(instance.running?).to eq(false)
|
28
34
|
end
|
@@ -22,14 +22,16 @@ module SportNginAwsAuditor
|
|
22
22
|
db_instance_status: "available",
|
23
23
|
engine: "mysql",
|
24
24
|
availability_zone: "us-east-1a",
|
25
|
-
class: "Aws::RDS::Types::DBInstance"
|
25
|
+
class: "Aws::RDS::Types::DBInstance",
|
26
|
+
db_name: 'Example-instance-01')
|
26
27
|
rds_instance2 = double('rds_instance', db_instance_identifier: "our-service",
|
27
28
|
multi_az: false,
|
28
29
|
db_instance_class: "db.m3.large",
|
29
30
|
db_instance_status: "available",
|
30
31
|
engine: "mysql",
|
31
32
|
availability_zone: "us-east-1a",
|
32
|
-
class: "Aws::RDS::Types::DBInstance"
|
33
|
+
class: "Aws::RDS::Types::DBInstance",
|
34
|
+
db_name: 'Example-instance-01')
|
33
35
|
db_instances = double('db_instances', db_instances: [rds_instance1, rds_instance2])
|
34
36
|
tag1 = double('tag', key: "cookie", value: "chocolate chip")
|
35
37
|
tag2 = double('tag', key: "ice cream", value: "oreo")
|
@@ -177,7 +179,8 @@ module SportNginAwsAuditor
|
|
177
179
|
db_instance_status: "available",
|
178
180
|
engine: "postgres",
|
179
181
|
availability_zone: "us-east-1a",
|
180
|
-
class: "Aws::RDS::Types::DBInstance"
|
182
|
+
class: "Aws::RDS::Types::DBInstance",
|
183
|
+
db_name: 'Example-instance-01')
|
181
184
|
db_instances = double('db_instances', db_instances: [rds_instance])
|
182
185
|
tag1 = double('tag', key: "cookie", value: "chocolate chip")
|
183
186
|
tag2 = double('tag', key: "ice cream", value: "oreo")
|
@@ -2,13 +2,28 @@ require "sport_ngin_aws_auditor"
|
|
2
2
|
|
3
3
|
module SportNginAwsAuditor
|
4
4
|
describe RecentlyRetiredTag do
|
5
|
-
it 'should have an instance name as an
|
6
|
-
tag = RecentlyRetiredTag.new('09/01/2000', 'Linux VPC us-east-1b t2.small')
|
7
|
-
expect(tag.
|
5
|
+
it 'should have an instance name as an instance_type' do
|
6
|
+
tag = RecentlyRetiredTag.new('09/01/2000', 'Linux VPC us-east-1b t2.small', 'Tag name', 'This is an example')
|
7
|
+
expect(tag.instance_type).to eq('Linux VPC us-east-1b t2.small')
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should have a name as the instance_name' do
|
11
|
+
tag = RecentlyRetiredTag.new('09/01/2000', 'Linux VPC us-east-1b t2.small', 'Tag name', 'This is an example')
|
12
|
+
expect(tag.instance_name).to eq('Tag name')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should have a string description as the reason' do
|
16
|
+
tag = RecentlyRetiredTag.new('09/01/2000', 'Linux VPC us-east-1b t2.small', 'Tag name', 'This is an example')
|
17
|
+
expect(tag.reason).to eq('This is an example')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should have nil as the reason' do
|
21
|
+
tag = RecentlyRetiredTag.new('09/01/2000', 'Linux VPC us-east-1b t2.small', 'Tag name')
|
22
|
+
expect(tag.reason).to eq(nil)
|
8
23
|
end
|
9
24
|
|
10
25
|
it 'should have a string date as a value' do
|
11
|
-
tag = RecentlyRetiredTag.new('09/01/2000', 'Linux VPC us-east-1b t2.small')
|
26
|
+
tag = RecentlyRetiredTag.new('09/01/2000', 'Linux VPC us-east-1b t2.small', 'Tag name')
|
12
27
|
expect(tag.value).to eq('09/01/2000')
|
13
28
|
end
|
14
29
|
end
|
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_dependency 'rack', '~> 1.3.0'
|
28
28
|
spec.add_dependency 'activesupport', '~> 3.2'
|
29
29
|
spec.add_dependency 'httparty'
|
30
|
+
spec.add_dependency 'colorize'
|
30
31
|
|
31
32
|
spec.add_development_dependency "bundler", "~> 1.7"
|
32
33
|
spec.add_development_dependency "rake", "~> 10.0"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sport_ngin_aws_auditor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elliot Hursh
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-09-
|
13
|
+
date: 2016-09-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: aws-sdk
|
@@ -138,6 +138,20 @@ dependencies:
|
|
138
138
|
- - ">="
|
139
139
|
- !ruby/object:Gem::Version
|
140
140
|
version: '0'
|
141
|
+
- !ruby/object:Gem::Dependency
|
142
|
+
name: colorize
|
143
|
+
requirement: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
type: :runtime
|
149
|
+
prerelease: false
|
150
|
+
version_requirements: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
141
155
|
- !ruby/object:Gem::Dependency
|
142
156
|
name: bundler
|
143
157
|
requirement: !ruby/object:Gem::Requirement
|