Skip to content

Commit fcae5bc

Browse files
authored
add db.container_profile and account.stack (#374)
* add db.container_profile and account.stack * modify specs * resolve rspec deprecation warnings * add stack info to environment:list only
1 parent 377e8f4 commit fcae5bc

File tree

6 files changed

+80
-16
lines changed

6 files changed

+80
-16
lines changed

lib/aptible/cli/resource_formatter.rb

+17-3
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,22 @@ def inject_deleted_database(node, database, account)
6767
attach_account(node, account)
6868
end
6969

70-
def inject_account(node, account)
70+
def inject_account(node, account, include_stack = false)
7171
node.value('id', account.id)
7272
node.value('handle', account.handle)
7373
node.value('created_at', account.created_at)
74+
75+
if include_stack && account.stack
76+
node.keyed_object('stack', 'name') do |n|
77+
n.value('name', account.stack.name)
78+
n.value('id', account.stack.id)
79+
n.value('region', account.stack.region)
80+
n.value(
81+
'outbound_ip_addresses',
82+
account.stack.outbound_ip_addresses
83+
)
84+
end
85+
end
7486
end
7587

7688
def inject_operation(node, operation)
@@ -145,6 +157,8 @@ def inject_database(node, database, account)
145157
if database.service
146158
node.value('container_size', \
147159
database.service.container_memory_limit_mb)
160+
node.value('container_profile', \
161+
database.service.instance_class.to_s[/[a-z]/])
148162
end
149163
end
150164

@@ -309,10 +323,10 @@ def inject_service_sizing_policy(node, policy, service)
309323

310324
private
311325

312-
def attach_account(node, account)
326+
def attach_account(node, account, include_stack = false)
313327
return if NO_NESTING.eql?(account)
314328
node.keyed_object('environment', 'handle') do |n|
315-
inject_account(n, account)
329+
inject_account(n, account, include_stack)
316330
end
317331
end
318332

lib/aptible/cli/subcommands/environment.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def self.included(thor)
1919
) do |node|
2020
scoped_environments(options).each do |account|
2121
node.object do |n|
22-
ResourceFormatter.inject_account(n, account)
22+
ResourceFormatter.inject_account(n, account, true)
2323
end
2424
end
2525
end

spec/aptible/cli/helpers/s3_log_helpers_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
]
185185
)
186186
before do
187-
subject.stub(:s3_client) do
187+
allow(subject).to receive(:s3_client) do
188188
Aws::S3::Resource.new(region: 'us-east-1', client: client_stub)
189189
end
190190
end
@@ -227,7 +227,7 @@
227227
{ key: v3app }
228228
]
229229
)
230-
subject.stub(:s3_client) do
230+
allow(subject).to receive(:s3_client) do
231231
Aws::S3::Resource.new(region: 'us-east-1', client: client_stub)
232232
end
233233
end

spec/aptible/cli/subcommands/db_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class SocatHelperMock < OpenStruct
2323
allow(Aptible::Api::Account).to receive(:all).and_return([account])
2424
end
2525
before do
26-
subject.stub(:validate_image_type) { true }
26+
allow(subject).to receive(:validate_image_type).and_return(true)
2727
end
2828

2929
def expect_provision_database(create_opts, provision_opts = {})

spec/aptible/cli/subcommands/environment_spec.rb

+50-3
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,58 @@
1919
end
2020

2121
describe('#environment:list') do
22-
it 'lists avaliable environments' do
22+
it 'lists available environments' do
2323
subject.send('environment:list')
2424

2525
expect(captured_output_text.split("\n")).to include('foo')
2626
expect(captured_output_text.split("\n")).to include('bar')
2727
end
28+
29+
it 'includes stack information in JSON output' do
30+
stack1 = Fabricate(
31+
:stack,
32+
name: 'stack1',
33+
region: 'us-east-1',
34+
outbound_ip_addresses: ['1.1.1.1']
35+
)
36+
stack2 = Fabricate(
37+
:stack,
38+
name: 'stack2',
39+
region: 'us-west-1',
40+
outbound_ip_addresses: ['2.2.2.2']
41+
)
42+
a1.stack = stack1
43+
a2.stack = stack2
44+
45+
subject.send('environment:list')
46+
47+
expected_json = [
48+
{
49+
'id' => a1.id,
50+
'handle' => 'foo',
51+
'created_at' => fmt_time(a1.created_at),
52+
'stack' => {
53+
'id' => stack1.id,
54+
'name' => 'stack1',
55+
'region' => 'us-east-1',
56+
'outbound_ip_addresses' => ['1.1.1.1']
57+
}
58+
},
59+
{
60+
'id' => a2.id,
61+
'handle' => 'bar',
62+
'created_at' => fmt_time(a2.created_at),
63+
'stack' => {
64+
'id' => stack2.id,
65+
'name' => 'stack2',
66+
'region' => 'us-west-1',
67+
'outbound_ip_addresses' => ['2.2.2.2']
68+
}
69+
}
70+
]
71+
72+
expect(captured_output_json).to eq(expected_json)
73+
end
2874
end
2975

3076
describe('#environment:ca_cert') do
@@ -46,8 +92,9 @@
4692
'created_at' => fmt_time(a2.created_at)
4793
}
4894
]
49-
expect(captured_output_json.map! { |account| account.except('id') })
50-
.to eq(expected_accounts)
95+
expect(
96+
captured_output_json.map! { |account| account.except('id', 'stack') }
97+
).to eq(expected_accounts)
5198
end
5299

53100
it 'fetches certs for specified environment' do

spec/aptible/cli/subcommands/logs_spec.rb

+9-6
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@
7373
string_matches: 'foo',
7474
download_location: './'
7575
}
76-
subject.stub(:info_from_path) { { shasum: 'foo' } }
77-
subject.stub(:encryption_key) { subject.options[:decryption_keys] }
76+
allow(subject).to receive(:info_from_path).and_return(shasum: 'foo')
77+
allow(subject).to receive(:encryption_key)
78+
.and_return(subject.options[:decryption_keys])
7879
end
7980

8081
it 'download all files' do
@@ -116,8 +117,9 @@
116117
app_id: 123,
117118
download_location: './'
118119
}
119-
subject.stub(:info_from_path) { { shasum: 'foo' } }
120-
subject.stub(:encryption_key) { subject.options[:decryption_keys] }
120+
allow(subject).to receive(:info_from_path).and_return(shasum: 'foo')
121+
allow(subject).to receive(:encryption_key)
122+
.and_return(subject.options[:decryption_keys])
121123
end
122124

123125
it 'download all files' do
@@ -161,8 +163,9 @@
161163
'9080b96447f98b31ef9831d5fd98b09e3c5c545269734e2e825644571152457c',
162164
download_location: './'
163165
}
164-
subject.stub(:info_from_path) { { shasum: 'foo' } }
165-
subject.stub(:encryption_key) { subject.options[:decryption_keys] }
166+
allow(subject).to receive(:info_from_path).and_return(shasum: 'foo')
167+
allow(subject).to receive(:encryption_key)
168+
.and_return(subject.options[:decryption_keys])
166169
end
167170

168171
it 'download all files' do

0 commit comments

Comments
 (0)