sport_ngin_aws_auditor 3.11.3 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -28,75 +28,94 @@ module SportNginAwsAuditor
28
28
 
29
29
  context '#initialization' do
30
30
  it 'should gather instance data' do
31
- audit_results = AuditData.new(true, false, "EC2Instance", "no-reserved-instance", @ignore_instances_regexes)
31
+ info = {:instances => true, :reserved => false, :class => "EC2Instance", :tag_name => "no-reserved-instance", :regexes => @ignore_instances_regexes, :region => 'us-east-1'}
32
+ audit_results = AuditData.new(info)
32
33
  expect(audit_results.selected_audit_type).to eq("instances")
33
34
  end
34
35
 
35
36
  it 'should gather reserved instance data' do
36
- audit_results = AuditData.new(false, true, "EC2Instance", "no-reserved-instance", @ignore_instances_regexes)
37
+ info = {:instances => false, :reserved => true, :class => "EC2Instance", :tag_name => "no-reserved-instance", :regexes => @ignore_instances_regexes, :region => 'us-east-1'}
38
+ audit_results = AuditData.new(info)
37
39
  expect(audit_results.selected_audit_type).to eq("reserved")
38
40
  end
39
41
 
40
42
  it 'should by default gather instance data' do
41
- audit_results = AuditData.new(true, true, "EC2Instance", "no-reserved-instance", @ignore_instances_regexes)
43
+ info = {:instances => true, :reserved => true, :class => "EC2Instance", :tag_name => "no-reserved-instance", :regexes => @ignore_instances_regexes, :region => 'us-east-1'}
44
+ audit_results = AuditData.new(info)
42
45
  expect(audit_results.selected_audit_type).to eq("instances")
43
46
  end
44
47
 
45
48
  it 'should gather all data to compare' do
46
- audit_results = AuditData.new(false, false, "EC2Instance", "no-reserved-instance", @ignore_instances_regexes)
49
+ info = {:instances => false, :reserved => false, :class => "EC2Instance", :tag_name => "no-reserved-instance", :regexes => @ignore_instances_regexes, :region => 'us-east-1'}
50
+ audit_results = AuditData.new(info)
47
51
  expect(audit_results.selected_audit_type).to eq("all")
48
52
  end
49
53
 
50
54
  it 'should use EC2Instance class' do
51
- audit_results = AuditData.new(false, false, "EC2Instance", "no-reserved-instance", @ignore_instances_regexes)
55
+ info = {:instances => false, :reserved => false, :class => "EC2Instance", :tag_name => "no-reserved-instance", :regexes => @ignore_instances_regexes, :region => 'us-east-1'}
56
+ audit_results = AuditData.new(info)
52
57
  expect(audit_results.klass).to eq(SportNginAwsAuditor::EC2Instance)
53
58
  end
54
59
 
55
60
  it 'should use EC2Instance class' do
56
- audit_results = AuditData.new(false, false, "EC2Instance", "no-reserved-instance", @ignore_instances_regexes)
61
+ info = {:instances => false, :reserved => false, :class => "EC2Instance", :tag_name => "no-reserved-instance", :regexes => @ignore_instances_regexes, :region => 'us-east-1'}
62
+ audit_results = AuditData.new(info)
57
63
  expect(audit_results.tag_name).to eq("no-reserved-instance")
58
64
  end
65
+
66
+ it 'should use EC2Instance class' do
67
+ info = {:instances => false, :reserved => false, :class => "EC2Instance", :tag_name => "no-reserved-instance", :regexes => @ignore_instances_regexes, :region => 'us-east-1'}
68
+ audit_results = AuditData.new(info)
69
+ expect(audit_results.region).to eq("us-east")
70
+ end
59
71
  end
60
72
 
61
73
  context '#instances?' do
62
74
  it 'should return true' do
63
- audit_results = AuditData.new(true, false, "EC2Instance", "no-reserved-instance", @ignore_instances_regexes)
75
+ info = {:instances => true, :reserved => false, :class => "EC2Instance", :tag_name => "no-reserved-instance", :regexes => @ignore_instances_regexes, :region => 'us-east-1'}
76
+ audit_results = AuditData.new(info)
64
77
  expect(audit_results.instances?).to eq(true)
65
78
  end
66
79
 
67
80
  it 'should return true' do
68
- audit_results = AuditData.new(false, true, "EC2Instance", "no-reserved-instance", @ignore_instances_regexes)
81
+ info = {:instances => false, :reserved => true, :class => "EC2Instance", :tag_name => "no-reserved-instance", :regexes => @ignore_instances_regexes, :region => 'us-east-1'}
82
+ audit_results = AuditData.new(info)
69
83
  expect(audit_results.instances?).to eq(false)
70
84
  end
71
85
  end
72
86
 
73
87
  context '#reserved?' do
74
88
  it 'should return true' do
75
- audit_results = AuditData.new(true, false, "EC2Instance", "no-reserved-instance", @ignore_instances_regexes)
89
+ info = {:instances => true, :reserved => false, :class => "EC2Instance", :tag_name => "no-reserved-instance", :regexes => @ignore_instances_regexes, :region => 'us-east-1'}
90
+ audit_results = AuditData.new(info)
76
91
  expect(audit_results.reserved?).to eq(false)
77
92
  end
78
93
 
79
94
  it 'should return true' do
80
- audit_results = AuditData.new(false, true, "EC2Instance", "no-reserved-instance", @ignore_instances_regexes)
95
+ info = {:instances => false, :reserved => true, :class => "EC2Instance", :tag_name => "no-reserved-instance", :regexes => @ignore_instances_regexes, :region => 'us-east-1'}
96
+ audit_results = AuditData.new(info)
81
97
  expect(audit_results.reserved?).to eq(true)
82
98
  end
83
99
  end
84
100
 
85
101
  context '#all?' do
86
102
  it 'should return true' do
87
- audit_results = AuditData.new(true, false, "EC2Instance", "no-reserved-instance", @ignore_instances_regexes)
103
+ info = {:instances => true, :reserved => false, :class => "EC2Instance", :tag_name => "no-reserved-instance", :regexes => @ignore_instances_regexes, :region => 'us-east-1'}
104
+ audit_results = AuditData.new(info)
88
105
  expect(audit_results.all?).to eq(false)
89
106
  end
90
107
 
91
108
  it 'should return true' do
92
- audit_results = AuditData.new(false, false, "EC2Instance", "no-reserved-instance", @ignore_instances_regexes)
109
+ info = {:instances => false, :reserved => false, :class => "EC2Instance", :tag_name => "no-reserved-instance", :regexes => @ignore_instances_regexes, :region => 'us-east-1'}
110
+ audit_results = AuditData.new(info)
93
111
  expect(audit_results.all?).to eq(true)
94
112
  end
95
113
  end
96
114
 
97
115
  context '#gather_data' do
98
116
  it 'should gather some empty results by comparison' do
99
- audit_results = AuditData.new(false, false, "EC2Instance", "no-reserved-instance", @ignore_instances_regexes)
117
+ info = {:instances => false, :reserved => false, :class => "EC2Instance", :tag_name => "no-reserved-instance", :regexes => @ignore_instances_regexes, :region => 'us-east-1'}
118
+ audit_results = AuditData.new(info)
100
119
  audit_results.gather_data
101
120
  expect(audit_results.data).to eq([@instance, @instance])
102
121
  expect(audit_results.retired_tags).to eq([])
@@ -104,7 +123,8 @@ module SportNginAwsAuditor
104
123
  end
105
124
 
106
125
  it 'should gather some empty results from just instances' do
107
- audit_results = AuditData.new(true, false, "EC2Instance", "no-reserved-instance", @ignore_instances_regexes)
126
+ info = {:instances => true, :reserved => false, :class => "EC2Instance", :tag_name => "no-reserved-instance", :regexes => @ignore_instances_regexes, :region => 'us-east-1'}
127
+ audit_results = AuditData.new(info)
108
128
  audit_results.gather_data
109
129
  expect(audit_results.data).to eq([@instance, @instance])
110
130
  expect(audit_results.retired_tags).to eq([])
@@ -112,7 +132,8 @@ module SportNginAwsAuditor
112
132
  end
113
133
 
114
134
  it 'should gather some empty results from just reserved' do
115
- audit_results = AuditData.new(false, true, "EC2Instance", "no-reserved-instance", @ignore_instances_regexes)
135
+ info = {:instances => false, :reserved => true, :class => "EC2Instance", :tag_name => "no-reserved-instance", :regexes => @ignore_instances_regexes, :region => 'us-east-1'}
136
+ audit_results = AuditData.new(info)
116
137
  audit_results.gather_data
117
138
  expect(audit_results.data).to eq([@instance, @instance])
118
139
  expect(audit_results.retired_tags).to eq(nil)
@@ -122,7 +143,8 @@ module SportNginAwsAuditor
122
143
 
123
144
  context '#gather_instances_data' do
124
145
  it 'should gather some instances data but not convert' do
125
- audit_results = AuditData.new(true, false, "EC2Instance", "no-reserved-instance", @ignore_instances_regexes)
146
+ info = {:instances => true, :reserved => false, :class => "EC2Instance", :tag_name => "no-reserved-instance", :regexes => @ignore_instances_regexes, :region => 'us-east-1'}
147
+ audit_results = AuditData.new(info)
126
148
  result1, result2 = audit_results.gather_instances_data
127
149
  expect(result1).to eq({'instance1' => 1, 'instance2' => 1})
128
150
  expect(result2).to eq([])
@@ -131,20 +153,13 @@ module SportNginAwsAuditor
131
153
 
132
154
  context '#gather_all_data' do
133
155
  it 'should gather some comparison data but not convert' do
134
- audit_results = AuditData.new(false, false, "EC2Instance", "no-reserved-instance", @ignore_instances_regexes)
156
+ info = {:instances => false, :reserved => false, :class => "EC2Instance", :tag_name => "no-reserved-instance", :regexes => @ignore_instances_regexes, :region => 'us-east-1'}
157
+ audit_results = AuditData.new(info)
135
158
  result1, result2, result3 = audit_results.gather_all_data
136
159
  expect(result1).to eq({'instance1' => 1, 'instance2' => 1})
137
160
  expect(result2).to eq([])
138
161
  expect(result3).to eq(@retired_ris)
139
162
  end
140
163
  end
141
-
142
- context '#gather_region' do
143
- it 'should gather the region from an instance' do
144
- audit_results = AuditData.new(false, false, "EC2Instance", "no-reserved-instance", @ignore_instances_regexes)
145
- audit_results.gather_region(@ec2_instances)
146
- expect(audit_results.region).to eq('us-east')
147
- end
148
- end
149
164
  end
150
165
  end
@@ -11,14 +11,14 @@ module SportNginAwsAuditor
11
11
 
12
12
  it "should receive new Aws::SharedCredentials" do
13
13
  expect(Aws::SharedCredentials).to receive(:new).with(profile_name: 'staging')
14
- AWSSDK::authenticate('staging')
14
+ AWSSDK::authenticate_with_iam('staging')
15
15
  end
16
16
 
17
17
  it "should update configs" do
18
18
  coffee_types = {:coffee => "cappuccino", :beans => "arabica"}
19
19
  allow(Aws::SharedCredentials).to receive(:new).and_return(coffee_types)
20
20
  expect(Aws.config).to receive(:update).with({region: 'us-east-1', credentials: coffee_types})
21
- AWSSDK::authenticate('staging')
21
+ AWSSDK::authenticate_with_iam('staging')
22
22
  end
23
23
  end
24
24
 
@@ -41,14 +41,36 @@ module SportNginAwsAuditor
41
41
 
42
42
  expect(Aws::Credentials).to receive(:new).and_return(cred_double).at_least(:once)
43
43
  expect(Aws::SharedCredentials).to receive(:new).and_return(shared_creds)
44
- AWSSDK::authenticate('staging')
44
+ AWSSDK::authenticate_with_iam('staging')
45
45
  end
46
46
  end
47
47
 
48
48
  context 'without mfa with roles' do
49
49
  it "should update configs" do
50
50
  expect(Aws.config).to receive(:update).with({region: 'us-east-1'})
51
- AWSSDK::authenticate_with_roles('staging')
51
+ AWSSDK::update_aws_config({region: 'us-east-1'})
52
+ end
53
+ end
54
+
55
+ context 'without mfa with multiple accounts' do
56
+ before :each do
57
+ cred_double = double('cred_hash', access_key_id: 'access_key_id',
58
+ secret_access_key: 'secret_access_key',
59
+ session_token: 'session_token')
60
+ new_creds = double('new_creds', credentials: cred_double)
61
+ @sts = double('sts', get_session_token: new_creds)
62
+ allow(Aws::STS::Client).to receive(:new).and_return(@sts)
63
+ allow(Aws::AssumeRoleCredentials).to receive(:new).and_return(cred_double)
64
+ end
65
+
66
+ it "should update config" do
67
+ expect(Aws.config).to receive(:update)
68
+ AWSSDK::authenticate_with_assumed_roles('staging', '999999999999', 'CrossAccountAuditorAccess', @sts)
69
+ end
70
+
71
+ it "should call for some credentials" do
72
+ expect(Aws::AssumeRoleCredentials).to receive(:new)
73
+ AWSSDK::authenticate_with_assumed_roles('staging', '999999999999', 'CrossAccountAuditorAccess', @sts)
52
74
  end
53
75
  end
54
76
  end
@@ -7,6 +7,7 @@ module SportNginAwsAuditor
7
7
  identity = double('identity', account: 123456789)
8
8
  client = double('client', get_caller_identity: identity)
9
9
  allow(Aws::STS::Client).to receive(:new).and_return(client)
10
+ # @client = Aws::ElastiCache::Client.new(region: 'us-east-1')
10
11
  end
11
12
 
12
13
  after :each do
@@ -34,24 +35,23 @@ module SportNginAwsAuditor
34
35
  tag1 = double('tag', key: "cookie", value: "chocolate chip")
35
36
  tag2 = double('tag', key: "ice cream", value: "oreo")
36
37
  tags = double('tags', tag_list: [tag1, tag2])
37
- cache_client = double('cache_client', describe_cache_clusters: cache_clusters, list_tags_for_resource: tags)
38
- allow(CacheInstance).to receive(:cache).and_return(cache_client)
38
+ @cache_client = double('cache_client', describe_cache_clusters: cache_clusters, list_tags_for_resource: tags)
39
39
  end
40
40
 
41
41
  it "should make a cache_instance for each instance" do
42
- instances = CacheInstance.get_instances("tag_name")
42
+ instances = CacheInstance.get_instances(@cache_client, "tag_name")
43
43
  expect(instances.first).to be_an_instance_of(CacheInstance)
44
44
  expect(instances.last).to be_an_instance_of(CacheInstance)
45
45
  end
46
46
 
47
47
  it "should return an array of cache_instances" do
48
- instances = CacheInstance.get_instances("tag_name")
48
+ instances = CacheInstance.get_instances(@cache_client, "tag_name")
49
49
  expect(instances).not_to be_empty
50
50
  expect(instances.length).to eq(2)
51
51
  end
52
52
 
53
53
  it "should have proper variables set" do
54
- instances = CacheInstance.get_instances("tag_name")
54
+ instances = CacheInstance.get_instances(@cache_client, "tag_name")
55
55
  instance = instances.first
56
56
  expect(instance.id).to eq("job-queue-cluster")
57
57
  expect(instance.name).to eq("job-queue-cluster")
@@ -75,24 +75,23 @@ module SportNginAwsAuditor
75
75
  cache_node_count: 1,
76
76
  class: "Aws::ElastiCache::Types::ReservedCacheNode")
77
77
  reserved_cache_nodes = double('cache_cluster', reserved_cache_nodes: [reserved_cache_instance1, reserved_cache_instance2])
78
- cache_client = double('cache_client', describe_reserved_cache_nodes: reserved_cache_nodes)
79
- allow(CacheInstance).to receive(:cache).and_return(cache_client)
78
+ @cache_client = double('cache_client', describe_reserved_cache_nodes: reserved_cache_nodes)
80
79
  end
81
80
 
82
81
  it "should make a reserved_cache_instance for each instance" do
83
- reserved_instances = CacheInstance.get_reserved_instances
82
+ reserved_instances = CacheInstance.get_reserved_instances(@cache_client)
84
83
  expect(reserved_instances.first).to be_an_instance_of(CacheInstance)
85
84
  expect(reserved_instances.last).to be_an_instance_of(CacheInstance)
86
85
  end
87
86
 
88
87
  it "should return an array of reserved_cache_instances" do
89
- reserved_instances = CacheInstance.get_reserved_instances
88
+ reserved_instances = CacheInstance.get_reserved_instances(@cache_client)
90
89
  expect(reserved_instances).not_to be_empty
91
90
  expect(reserved_instances.length).to eq(2)
92
91
  end
93
92
 
94
93
  it "should have proper variables set" do
95
- reserved_instances = CacheInstance.get_reserved_instances
94
+ reserved_instances = CacheInstance.get_reserved_instances(@cache_client)
96
95
  reserved_instance = reserved_instances.first
97
96
  expect(reserved_instance.id).to eq("job-queue-cluster")
98
97
  expect(reserved_instance.name).to eq("job-queue-cluster")
@@ -121,24 +120,23 @@ module SportNginAwsAuditor
121
120
  duration: 31536000)
122
121
  reserved_cache_nodes = double('cache_cluster', reserved_cache_nodes: [retired_reserved_cache_instance1,
123
122
  retired_reserved_cache_instance2])
124
- cache_client = double('cache_client', describe_reserved_cache_nodes: reserved_cache_nodes)
125
- allow(CacheInstance).to receive(:cache).and_return(cache_client)
123
+ @cache_client = double('cache_client', describe_reserved_cache_nodes: reserved_cache_nodes)
126
124
  end
127
125
 
128
126
  it "should make a retired_reserved_cache_instance for each instance" do
129
- retired_reserved_instances = CacheInstance.get_retired_reserved_instances
127
+ retired_reserved_instances = CacheInstance.get_retired_reserved_instances(@cache_client)
130
128
  expect(retired_reserved_instances.first).to be_an_instance_of(CacheInstance)
131
129
  expect(retired_reserved_instances.last).to be_an_instance_of(CacheInstance)
132
130
  end
133
131
 
134
132
  it "should return an array of retired_reserved_cache_instances" do
135
- retired_reserved_instances = CacheInstance.get_retired_reserved_instances
133
+ retired_reserved_instances = CacheInstance.get_retired_reserved_instances(@cache_client)
136
134
  expect(retired_reserved_instances).not_to be_empty
137
135
  expect(retired_reserved_instances.length).to eq(2)
138
136
  end
139
137
 
140
138
  it "should have proper variables set" do
141
- retired_reserved_instances = CacheInstance.get_retired_reserved_instances
139
+ retired_reserved_instances = CacheInstance.get_retired_reserved_instances(@cache_client)
142
140
  retired_reserved_instance = retired_reserved_instances.first
143
141
  expect(retired_reserved_instance.id).to eq("job-queue-cluster")
144
142
  expect(retired_reserved_instance.name).to eq("job-queue-cluster")
@@ -162,9 +160,8 @@ module SportNginAwsAuditor
162
160
  tag1 = double('tag', key: "cookie", value: "chocolate chip")
163
161
  tag2 = double('tag', key: "ice cream", value: "oreo")
164
162
  tags = double('tags', tag_list: [tag1, tag2])
165
- cache_client = double('cache_client', describe_cache_clusters: cache_clusters, list_tags_for_resource: tags)
166
- allow(CacheInstance).to receive(:cache).and_return(cache_client)
167
- instances = CacheInstance.get_instances("tag_name")
163
+ @cache_client = double('cache_client', describe_cache_clusters: cache_clusters, list_tags_for_resource: tags)
164
+ instances = CacheInstance.get_instances(@cache_client, "tag_name")
168
165
  instance = instances.first
169
166
  expect(instance.to_s).to eq("Redis cache.t2.small")
170
167
  end
@@ -38,24 +38,23 @@ module SportNginAwsAuditor
38
38
  name_tag = { key: "Name", value: "our-app-instance-100" }
39
39
  stack_tag = { key: "opsworks:stack", value: "our_app_service_2" }
40
40
  client_tags = double('tags', tags: [name_tag, stack_tag])
41
- ec2_client = double('ec2_client', describe_instances: ec2_instances, describe_tags: client_tags)
42
- allow(EC2Instance).to receive(:ec2).and_return(ec2_client)
41
+ @ec2_client = double('@ec2_client', describe_instances: ec2_instances, describe_tags: client_tags)
43
42
  end
44
43
 
45
44
  it "should make an ec2_instance for each instance" do
46
- instances = EC2Instance.get_instances("tag_name")
45
+ instances = EC2Instance.get_instances(@ec2_client, "tag_name")
47
46
  expect(instances.first).to be_an_instance_of(EC2Instance)
48
47
  expect(instances.last).to be_an_instance_of(EC2Instance)
49
48
  end
50
49
 
51
50
  it "should return an array of ec2_instances" do
52
- instances = EC2Instance.get_instances("tag_name")
51
+ instances = EC2Instance.get_instances(@ec2_client, "tag_name")
53
52
  expect(instances).not_to be_empty
54
53
  expect(instances.length).to eq(2)
55
54
  end
56
55
 
57
56
  it "should have proper variables set" do
58
- instances = EC2Instance.get_instances("tag_name")
57
+ instances = EC2Instance.get_instances(@ec2_client, "tag_name")
59
58
  instance = instances.first
60
59
  expect(instance.stack_name).to eq("our_app_service_2")
61
60
  expect(instance.name).to eq("our-app-instance-100")
@@ -66,7 +65,7 @@ module SportNginAwsAuditor
66
65
  end
67
66
 
68
67
  it "should recognize Windows vs. Linux" do
69
- instances = EC2Instance.get_instances("tag_name")
68
+ instances = EC2Instance.get_instances(@ec2_client, "tag_name")
70
69
  instance1 = instances.first
71
70
  instance2 = instances.last
72
71
  expect(instance1.platform).to eq("Linux VPC")
@@ -93,24 +92,23 @@ module SportNginAwsAuditor
93
92
  scope: 'Availability Zone',
94
93
  class: "Aws::EC2::Types::ReservedInstances")
95
94
  reserved_ec2_instances = double('reserved_ec2_instances', reserved_instances: [reserved_ec2_instance1, reserved_ec2_instance2])
96
- ec2_client = double('ec2_client', describe_reserved_instances: reserved_ec2_instances)
97
- allow(EC2Instance).to receive(:ec2).and_return(ec2_client)
95
+ @ec2_client = double('@ec2_client', describe_reserved_instances: reserved_ec2_instances)
98
96
  end
99
97
 
100
98
  it "should make a reserved_ec2_instance for each instance" do
101
- reserved_instances = EC2Instance.get_reserved_instances
99
+ reserved_instances = EC2Instance.get_reserved_instances(@ec2_client)
102
100
  expect(reserved_instances.first).to be_an_instance_of(EC2Instance)
103
101
  expect(reserved_instances.last).to be_an_instance_of(EC2Instance)
104
102
  end
105
103
 
106
104
  it "should return an array of reserved_ec2_instances" do
107
- reserved_instances = EC2Instance.get_reserved_instances
105
+ reserved_instances = EC2Instance.get_reserved_instances(@ec2_client)
108
106
  expect(reserved_instances).not_to be_empty
109
107
  expect(reserved_instances.length).to eq(2)
110
108
  end
111
109
 
112
110
  it "should have proper variables set" do
113
- reserved_instances = EC2Instance.get_reserved_instances
111
+ reserved_instances = EC2Instance.get_reserved_instances(@ec2_client)
114
112
  reserved_instance = reserved_instances.first
115
113
  expect(reserved_instance.id).to eq("12345-dfas-1234-asdf-thisisfake!!")
116
114
  expect(reserved_instance.platform).to eq("Windows VPC")
@@ -120,7 +118,7 @@ module SportNginAwsAuditor
120
118
  end
121
119
 
122
120
  it "should recognize Windows vs. Linux" do
123
- reserved_instances = EC2Instance.get_reserved_instances
121
+ reserved_instances = EC2Instance.get_reserved_instances(@ec2_client)
124
122
  reserved_instance1 = reserved_instances.first
125
123
  reserved_instance2 = reserved_instances.last
126
124
  expect(reserved_instance1.platform).to eq("Windows VPC")
@@ -159,24 +157,23 @@ module SportNginAwsAuditor
159
157
  reserved_ec2_instances = double('reserved_ec2_instances', reserved_instances: [retired_reserved_ec2_instance1,
160
158
  retired_reserved_ec2_instance2,
161
159
  reserved_ec2_instance1])
162
- ec2_client = double('ec2_client', describe_reserved_instances: reserved_ec2_instances)
163
- allow(EC2Instance).to receive(:ec2).and_return(ec2_client)
160
+ @ec2_client = double('@ec2_client', describe_reserved_instances: reserved_ec2_instances)
164
161
  end
165
162
 
166
163
  it "should make a retired_reserved_ec2_instance for each instance" do
167
- retired_reserved_instances = EC2Instance.get_retired_reserved_instances
164
+ retired_reserved_instances = EC2Instance.get_retired_reserved_instances(@ec2_client)
168
165
  expect(retired_reserved_instances.first).to be_an_instance_of(EC2Instance)
169
166
  expect(retired_reserved_instances.last).to be_an_instance_of(EC2Instance)
170
167
  end
171
168
 
172
169
  it "should return an array of retired_reserved_ec2_instances" do
173
- retired_reserved_instances = EC2Instance.get_retired_reserved_instances
170
+ retired_reserved_instances = EC2Instance.get_retired_reserved_instances(@ec2_client)
174
171
  expect(retired_reserved_instances).not_to be_empty
175
172
  expect(retired_reserved_instances.length).to eq(2)
176
173
  end
177
174
 
178
175
  it "should have proper variables set" do
179
- retired_reserved_instances = EC2Instance.get_retired_reserved_instances
176
+ retired_reserved_instances = EC2Instance.get_retired_reserved_instances(@ec2_client)
180
177
  retired_reserved_instance = retired_reserved_instances.first
181
178
  expect(retired_reserved_instance.id).to eq("12345-dfas-1234-asdf-thisisfake!!")
182
179
  expect(retired_reserved_instance.platform).to eq("Windows VPC")
@@ -187,7 +184,7 @@ module SportNginAwsAuditor
187
184
  end
188
185
 
189
186
  it "should recognize Windows vs. Linux" do
190
- retired_reserved_instances = EC2Instance.get_retired_reserved_instances
187
+ retired_reserved_instances = EC2Instance.get_retired_reserved_instances(@ec2_client)
191
188
  retired_reserved_instance1 = retired_reserved_instances.first
192
189
  retired_reserved_instance2 = retired_reserved_instances.last
193
190
  expect(retired_reserved_instance1.platform).to eq("Windows VPC")
@@ -217,9 +214,8 @@ module SportNginAwsAuditor
217
214
  name_tag = { key: "Name", value: "our-app-instance-100" }
218
215
  stack_tag = { key: "opsworks:stack", value: "our_app_service_2" }
219
216
  tags = double('tags', tags: [name_tag, stack_tag])
220
- ec2_client = double('ec2_client', describe_instances: ec2_instances, describe_tags: tags)
221
- allow(EC2Instance).to receive(:ec2).and_return(ec2_client)
222
- instances = EC2Instance.get_instances("tag_name")
217
+ @ec2_client = double('@ec2_client', describe_instances: ec2_instances, describe_tags: tags)
218
+ instances = EC2Instance.get_instances(@ec2_client, "tag_name")
223
219
  instance = instances.first
224
220
  expect(instance.to_s).to eq("Linux VPC us-east-1d t2.large")
225
221
  end
@@ -250,25 +246,24 @@ module SportNginAwsAuditor
250
246
  name_tag = { key: "Name", value: "our-app-instance-100" }
251
247
  stack_tag = { key: "opsworks:stack", value: "our_app_service_2" }
252
248
  tags = double('tags', tags: [name_tag, stack_tag])
253
- ec2_client = double('ec2_client', describe_instances: ec2_instances, describe_tags: tags)
254
- allow(EC2Instance).to receive(:ec2).and_return(ec2_client)
249
+ @ec2_client = double('@ec2_client', describe_instances: ec2_instances, describe_tags: tags)
255
250
  end
256
251
 
257
252
  it "should return a hash where the first element's key is the opsworks:stack name of the instances" do
258
- instances = EC2Instance.get_instances
259
- buckets = EC2Instance.bucketize
253
+ instances = EC2Instance.get_instances(@ec2_client)
254
+ buckets = EC2Instance.bucketize(@ec2_client)
260
255
  expect(buckets.first.first).to eq("our_app_service_2")
261
256
  end
262
257
 
263
258
  it "should return a hash where the last element's key is the opsworks:stack name of the instances" do
264
- instances = EC2Instance.get_instances
265
- buckets = EC2Instance.bucketize
259
+ instances = EC2Instance.get_instances(@ec2_client)
260
+ buckets = EC2Instance.bucketize(@ec2_client)
266
261
  expect(buckets.last.first).to eq("our_app_service_2")
267
262
  end
268
263
 
269
264
  it "should return a hash where each element is a list of ec2_instances" do
270
- instances = EC2Instance.get_instances
271
- buckets = EC2Instance.bucketize
265
+ instances = EC2Instance.get_instances(@ec2_client)
266
+ buckets = EC2Instance.bucketize(@ec2_client)
272
267
  expect(buckets).not_to be_empty
273
268
  expect(buckets.length).to eq(1)
274
269
  expect(buckets.first.length).to eq(2)
@@ -36,24 +36,23 @@ module SportNginAwsAuditor
36
36
  tag1 = double('tag', key: "cookie", value: "chocolate chip")
37
37
  tag2 = double('tag', key: "ice cream", value: "oreo")
38
38
  tags = double('tags', tag_list: [tag1, tag2])
39
- rds_client = double('rds_client', describe_db_instances: db_instances, list_tags_for_resource: tags)
40
- allow(RDSInstance).to receive(:rds).and_return(rds_client)
39
+ @rds_client = double('@rds_client', describe_db_instances: db_instances, list_tags_for_resource: tags)
41
40
  end
42
41
 
43
42
  it "should make a rds_instance for each instance" do
44
- instances = RDSInstance.get_instances("tag_name")
43
+ instances = RDSInstance.get_instances(@rds_client, "tag_name")
45
44
  expect(instances.first).to be_an_instance_of(RDSInstance)
46
45
  expect(instances.last).to be_an_instance_of(RDSInstance)
47
46
  end
48
47
 
49
48
  it "should return an array of rds_instances" do
50
- instances = RDSInstance.get_instances("tag_name")
49
+ instances = RDSInstance.get_instances(@rds_client, "tag_name")
51
50
  expect(instances).not_to be_empty
52
51
  expect(instances.length).to eq(2)
53
52
  end
54
53
 
55
54
  it "should have proper variables set" do
56
- instances = RDSInstance.get_instances("tag_name")
55
+ instances = RDSInstance.get_instances(@rds_client, "tag_name")
57
56
  instance = instances.first
58
57
  expect(instance.id).to eq("our-service")
59
58
  expect(instance.multi_az).to eq("Single-AZ")
@@ -79,24 +78,23 @@ module SportNginAwsAuditor
79
78
  db_instance_count: 2,
80
79
  class: "Aws::RDS::Types::ReservedDBInstance")
81
80
  reserved_db_instances = double('db_instances', reserved_db_instances: [reserved_rds_instance1, reserved_rds_instance2])
82
- rds_client = double('rds_client', describe_reserved_db_instances: reserved_db_instances)
83
- allow(RDSInstance).to receive(:rds).and_return(rds_client)
81
+ @rds_client = double('@rds_client', describe_reserved_db_instances: reserved_db_instances)
84
82
  end
85
83
 
86
84
  it "should make a reserved_rds_instance for each instance" do
87
- reserved_instances = RDSInstance.get_reserved_instances
85
+ reserved_instances = RDSInstance.get_reserved_instances(@rds_client)
88
86
  expect(reserved_instances.first).to be_an_instance_of(RDSInstance)
89
87
  expect(reserved_instances.last).to be_an_instance_of(RDSInstance)
90
88
  end
91
89
 
92
90
  it "should return an array of reserved_rds_instances" do
93
- reserved_instances = RDSInstance.get_reserved_instances
91
+ reserved_instances = RDSInstance.get_reserved_instances(@rds_client)
94
92
  expect(reserved_instances).not_to be_empty
95
93
  expect(reserved_instances.length).to eq(2)
96
94
  end
97
95
 
98
96
  it "should have proper variables set" do
99
- reserved_instances = RDSInstance.get_reserved_instances
97
+ reserved_instances = RDSInstance.get_reserved_instances(@rds_client)
100
98
  reserved_instance = reserved_instances.first
101
99
  expect(reserved_instance.id).to eq("555te4yy-1234-555c-5678-thisisafake!!")
102
100
  expect(reserved_instance.multi_az).to eq("Single-AZ")
@@ -127,24 +125,23 @@ module SportNginAwsAuditor
127
125
  duration: 31536000)
128
126
  reserved_db_instances = double('db_instances', reserved_db_instances: [retired_reserved_rds_instance1,
129
127
  retired_reserved_rds_instance2])
130
- rds_client = double('rds_client', describe_reserved_db_instances: reserved_db_instances)
131
- allow(RDSInstance).to receive(:rds).and_return(rds_client)
128
+ @rds_client = double('@rds_client', describe_reserved_db_instances: reserved_db_instances)
132
129
  end
133
130
 
134
131
  it "should make a retired_reserved_rds_instance for each instance" do
135
- retired_reserved_instances = RDSInstance.get_retired_reserved_instances
132
+ retired_reserved_instances = RDSInstance.get_retired_reserved_instances(@rds_client)
136
133
  expect(retired_reserved_instances.first).to be_an_instance_of(RDSInstance)
137
134
  expect(retired_reserved_instances.last).to be_an_instance_of(RDSInstance)
138
135
  end
139
136
 
140
137
  it "should return an array of retired_reserved_rds_instances" do
141
- retired_reserved_instances = RDSInstance.get_retired_reserved_instances
138
+ retired_reserved_instances = RDSInstance.get_retired_reserved_instances(@rds_client)
142
139
  expect(retired_reserved_instances).not_to be_empty
143
140
  expect(retired_reserved_instances.length).to eq(2)
144
141
  end
145
142
 
146
143
  it "should have proper variables set" do
147
- retired_reserved_instances = RDSInstance.get_retired_reserved_instances
144
+ retired_reserved_instances = RDSInstance.get_retired_reserved_instances(@rds_client)
148
145
  retired_reserved_instance = retired_reserved_instances.first
149
146
  expect(retired_reserved_instance.id).to eq("555te4yy-1234-555c-5678-thisisafake!!")
150
147
  expect(retired_reserved_instance.multi_az).to eq("Single-AZ")
@@ -165,9 +162,8 @@ module SportNginAwsAuditor
165
162
  db_instance_count: 3,
166
163
  class: "Aws::RDS::Types::ReservedDBInstance")
167
164
  reserved_db_instances = double('db_instances', reserved_db_instances: [reserved_rds_instance])
168
- rds_client = double('rds_client', describe_reserved_db_instances: reserved_db_instances)
169
- allow(RDSInstance).to receive(:rds).and_return(rds_client)
170
- reserved_instances = RDSInstance.get_reserved_instances
165
+ @rds_client = double('@rds_client', describe_reserved_db_instances: reserved_db_instances)
166
+ reserved_instances = RDSInstance.get_reserved_instances(@rds_client)
171
167
  reserved_instance = reserved_instances.first
172
168
  expect(reserved_instance.to_s).to eq("MySQL Single-AZ db.t2.small")
173
169
  end
@@ -185,9 +181,8 @@ module SportNginAwsAuditor
185
181
  tag1 = double('tag', key: "cookie", value: "chocolate chip")
186
182
  tag2 = double('tag', key: "ice cream", value: "oreo")
187
183
  tags = double('tags', tag_list: [tag1, tag2])
188
- rds_client = double('rds_client', describe_db_instances: db_instances, list_tags_for_resource: tags)
189
- allow(RDSInstance).to receive(:rds).and_return(rds_client)
190
- instances = RDSInstance.get_instances("tag_name")
184
+ @rds_client = double('@rds_client', describe_db_instances: db_instances, list_tags_for_resource: tags)
185
+ instances = RDSInstance.get_instances(@rds_client, "tag_name")
191
186
  instance = instances.first
192
187
  expect(instance.to_s).to eq("PostgreSQL Single-AZ db.t2.small")
193
188
  end
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.11.3
4
+ version: 4.0.0
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-12-19 00:00:00.000000000 Z
13
+ date: 2017-01-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: aws-sdk