aptible-cli 0.5.13 → 0.5.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: afe6307751ef50d084ce1b378adc2f94b203c289
4
- data.tar.gz: 99a3c232ebef3b35e327f958fc4c61628ef6639b
3
+ metadata.gz: 8713f34b37e6276e5d322d7254ab78b3356d35a4
4
+ data.tar.gz: 8951124f8a1ca2d50decc963ba0a8f045c01d2f2
5
5
  SHA512:
6
- metadata.gz: 7f6b5177638c5c3a69215e8bee64e7d560fd22cae00db83112b51b0f53098c2737a92dbf666817b6d0689d513c0d27533e642d9af2a8fb06ed3a981afe30d0b7
7
- data.tar.gz: 5f7ed6c2a95c266fe018a7fcb026f5b6ad21d28d005a86b4e013c8eefc4a9d47b3ad4e3d401bdcce72410279cc8624c7934a2cfee19c4471649e68d2ec02b39c
6
+ metadata.gz: 6211969254e1b930bf5f9387760758f7540d482c8e18f9267cb77ac413e527ed966d037cf4f9b8ef911739457778cb205477e7bed8d8d97b306d0cbec6551f11
7
+ data.tar.gz: 79526232944a06f47d020c12097de08be45a8b4331f9735fb6808640e2e535f07640c0fbc9a1d44f113320332c042ec08ee336df35268f160111cd02528a8137
data/README.md CHANGED
@@ -35,6 +35,7 @@ Commands:
35
35
  aptible db:create HANDLE # Create a new database
36
36
  aptible db:dump HANDLE # Dump a remote database to file
37
37
  aptible db:execute HANDLE SQL_FILE # Executes sql against a database
38
+ aptible db:list # List all databases
38
39
  aptible db:tunnel HANDLE # Create a local tunnel to a database
39
40
  aptible help [COMMAND] # Describe available commands or one specific command
40
41
  aptible login # Log in to Aptible
@@ -59,7 +60,8 @@ Commands:
59
60
  * Graham Melcher ([@melcher](https://github.com/melcher))
60
61
  * Pete Browne ([@petebrowne](https://github.com/petebrowne))
61
62
  * Rich Humphrey ([@rdh](https://github.com/rdh))
62
-
63
+ * Daniel Levenson ([@dleve123](https://github.com/dleve123))
64
+ * Ryan Aipperspach ([@ryanaip](https://github.com/ryanaip))
63
65
 
64
66
  ## Copyright and License
65
67
 
@@ -11,6 +11,7 @@ require_relative 'helpers/env'
11
11
  require_relative 'subcommands/apps'
12
12
  require_relative 'subcommands/config'
13
13
  require_relative 'subcommands/db'
14
+ require_relative 'subcommands/domains'
14
15
  require_relative 'subcommands/logs'
15
16
  require_relative 'subcommands/ps'
16
17
  require_relative 'subcommands/rebuild'
@@ -26,6 +27,7 @@ module Aptible
26
27
  include Subcommands::Apps
27
28
  include Subcommands::Config
28
29
  include Subcommands::DB
30
+ include Subcommands::Domains
29
31
  include Subcommands::Logs
30
32
  include Subcommands::Ps
31
33
  include Subcommands::Rebuild
@@ -7,6 +7,18 @@ module Aptible
7
7
  module Account
8
8
  include Helpers::Token
9
9
 
10
+ def scoped_accounts(options)
11
+ if options[:account]
12
+ if (account = account_from_handle(options[:account]))
13
+ [account]
14
+ else
15
+ fail Thor::Error, 'Specified account does not exist'
16
+ end
17
+ else
18
+ Aptible::Api::Account.all(token: fetch_token)
19
+ end
20
+ end
21
+
10
22
  def ensure_account(options = {})
11
23
  if (handle = options[:account])
12
24
  account = account_from_handle(handle)
@@ -10,13 +10,7 @@ module Aptible
10
10
  desc 'apps', 'List all applications'
11
11
  option :account
12
12
  def apps
13
- if options[:account]
14
- accounts = [account_from_handle(options[:account])]
15
- else
16
- accounts = Aptible::Api::Account.all(token: fetch_token)
17
- end
18
-
19
- accounts.each do |account|
13
+ scoped_accounts(options).each do |account|
20
14
  say "=== #{account.handle}"
21
15
  account.apps.each do |app|
22
16
  say app.handle
@@ -10,6 +10,14 @@ module Aptible
10
10
  include Helpers::Token
11
11
  include Term::ANSIColor
12
12
 
13
+ desc 'db:list', 'List all databases'
14
+ option :account
15
+ define_method 'db:list' do
16
+ scoped_accounts(options).each do |account|
17
+ present_account_databases(account)
18
+ end
19
+ end
20
+
13
21
  desc 'db:create HANDLE', 'Create a new database'
14
22
  option :type, default: 'postgresql'
15
23
  option :size, default: 10
@@ -78,6 +86,12 @@ module Aptible
78
86
 
79
87
  private
80
88
 
89
+ def present_account_databases(account)
90
+ say "=== #{account.handle}"
91
+ account.databases.each { |db| say db.handle }
92
+ say ''
93
+ end
94
+
81
95
  def establish_connection(database, local_port)
82
96
  ENV['ACCESS_TOKEN'] = fetch_token
83
97
  ENV['APTIBLE_DATABASE'] = database.handle
@@ -0,0 +1,39 @@
1
+ require 'shellwords'
2
+
3
+ module Aptible
4
+ module CLI
5
+ module Subcommands
6
+ module Domains
7
+ def self.included(thor)
8
+ thor.class_eval do
9
+ include Helpers::Operation
10
+ include Helpers::App
11
+
12
+ desc 'domains', "Print an app's current virtual domains"
13
+ option :app
14
+ option :verbose, aliases: '-v'
15
+ option :remote, aliases: '-r'
16
+ def domains
17
+ app = ensure_app(options)
18
+ print_vhosts(app) do |vhost|
19
+ if options[:verbose]
20
+ "#{vhost.virtual_domain} -> #{vhost.external_host}"
21
+ else
22
+ vhost.virtual_domain
23
+ end
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def print_vhosts(app)
30
+ (app.vhosts || []).each do |vhost|
31
+ say yield(vhost)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,5 +1,5 @@
1
1
  module Aptible
2
2
  module CLI
3
- VERSION = '0.5.13'
3
+ VERSION = '0.5.14'
4
4
  end
5
5
  end
@@ -4,6 +4,9 @@ require 'spec_helper'
4
4
  class Database < OpenStruct
5
5
  end
6
6
 
7
+ class Account < OpenStruct
8
+ end
9
+
7
10
  describe Aptible::CLI::Agent do
8
11
  before { subject.stub(:ask) }
9
12
  before { subject.stub(:save_token) }
@@ -39,4 +42,87 @@ describe Aptible::CLI::Agent do
39
42
  subject.send('db:tunnel', 'foobar')
40
43
  end
41
44
  end
45
+
46
+ describe '#db:list' do
47
+ context 'when no account is specified' do
48
+ it 'prints out the grouped database handles for all accounts' do
49
+ setup_prod_and_staging_accounts
50
+ allow(subject).to receive(:say)
51
+
52
+ subject.send('db:list')
53
+
54
+ expect(subject).to have_received(:say).with('=== staging')
55
+ expect(subject).to have_received(:say).with('staging-redis-db')
56
+ expect(subject).to have_received(:say).with('staging-postgres-db')
57
+
58
+ expect(subject).to have_received(:say).with('=== production')
59
+ expect(subject).to have_received(:say).with('prod-elsearch-db')
60
+ expect(subject).to have_received(:say).with('prod-postgres-db')
61
+ end
62
+ end
63
+
64
+ context 'when a valid account is specified' do
65
+ it 'prints out the database handles for the account' do
66
+ setup_prod_and_staging_accounts
67
+ allow(subject).to receive(:say)
68
+
69
+ subject.options = { account: 'staging' }
70
+ subject.send('db:list')
71
+
72
+ expect(subject).to have_received(:say).with('=== staging')
73
+ expect(subject).to have_received(:say).with('staging-redis-db')
74
+ expect(subject).to have_received(:say).with('staging-postgres-db')
75
+
76
+ expect(subject).to_not have_received(:say).with('=== production')
77
+ expect(subject).to_not have_received(:say).with('prod-elsearch-db')
78
+ expect(subject).to_not have_received(:say).with('prod-postgres-db')
79
+ end
80
+ end
81
+
82
+ context 'when an invalid account is specified' do
83
+ it 'prints out an error' do
84
+ setup_prod_and_staging_accounts
85
+ allow(subject).to receive(:say)
86
+
87
+ subject.options = { account: 'foo' }
88
+ expect { subject.send('db:list') }.to raise_error(
89
+ 'Specified account does not exist'
90
+ )
91
+ end
92
+ end
93
+ end
94
+
95
+ def setup_prod_and_staging_accounts
96
+ staging_redis = Database.new(handle: 'staging-redis-db')
97
+ staging_postgres = Database.new(handle: 'staging-postgres-db')
98
+ prod_elsearch = Database.new(handle: 'prod-elsearch-db')
99
+ prod_postgres = Database.new(handle: 'prod-postgres-db')
100
+
101
+ stub_local_token_with('the-token')
102
+ setup_new_accounts_with_dbs(
103
+ token: 'the-token',
104
+ account_db_mapping: {
105
+ 'staging' => [staging_redis, staging_postgres],
106
+ 'production' => [prod_elsearch, prod_postgres]
107
+ }
108
+ )
109
+ end
110
+
111
+ def setup_new_accounts_with_dbs(options)
112
+ token = options.fetch(:token)
113
+ account_db_mapping = options.fetch(:account_db_mapping)
114
+
115
+ accounts_with_dbs = []
116
+ account_db_mapping.each do |account_handle, dbs|
117
+ account = Account.new(handle: account_handle, databases: dbs)
118
+ accounts_with_dbs << account
119
+ end
120
+
121
+ allow(Aptible::Api::Account).to receive(:all).with(token: token)
122
+ .and_return(accounts_with_dbs)
123
+ end
124
+
125
+ def stub_local_token_with(token)
126
+ allow(subject).to receive(:fetch_token).and_return(token)
127
+ end
42
128
  end
@@ -0,0 +1,63 @@
1
+ require 'ostruct'
2
+ require 'spec_helper'
3
+
4
+ class App < OpenStruct
5
+ end
6
+
7
+ class Service < OpenStruct
8
+ end
9
+
10
+ class Operation < OpenStruct
11
+ end
12
+
13
+ class Vhost < OpenStruct
14
+ end
15
+
16
+ describe Aptible::CLI::Agent do
17
+ before { subject.stub(:ask) }
18
+ before { subject.stub(:save_token) }
19
+ before { subject.stub(:fetch_token) { double 'token' } }
20
+
21
+ let(:service) { Service.new(process_type: 'web') }
22
+ let(:op) { Operation.new(status: 'succeeded') }
23
+ let(:app) { App.new(handle: 'hello', services: [service]) }
24
+ let(:apps) { [app] }
25
+
26
+ let(:vhost1) { Vhost.new(virtual_domain: 'domain1', external_host: 'host1') }
27
+ let(:vhost2) { Vhost.new(virtual_domain: 'domain2', external_host: 'host2') }
28
+
29
+ describe '#domains' do
30
+ it 'should print out the hostnames' do
31
+ allow(service).to receive(:create_operation) { op }
32
+ allow(subject).to receive(:options) { { app: 'hello' } }
33
+ allow(Aptible::Api::App).to receive(:all) { apps }
34
+
35
+ expect(app).to receive(:vhosts) { [vhost1, vhost2] }
36
+ expect(subject).to receive(:say).with('domain1')
37
+ expect(subject).to receive(:say).with('domain2')
38
+
39
+ subject.send('domains')
40
+ end
41
+
42
+ it 'should fail if app is non-existent' do
43
+ allow(service).to receive(:create_operation) { op }
44
+ allow(Aptible::Api::App).to receive(:all) { apps }
45
+
46
+ expect do
47
+ subject.send('domains')
48
+ end.to raise_error(Thor::Error)
49
+ end
50
+
51
+ it 'should print hostnames if -v is passed' do
52
+ allow(service).to receive(:create_operation) { op }
53
+ allow(subject).to receive(:options) { { verbose: true, app: 'hello' } }
54
+ allow(Aptible::Api::App).to receive(:all) { apps }
55
+
56
+ expect(app).to receive(:vhosts) { [vhost1, vhost2] }
57
+ expect(subject).to receive(:say).with('domain1 -> host1')
58
+ expect(subject).to receive(:say).with('domain2 -> host2')
59
+
60
+ subject.send('domains')
61
+ end
62
+ end
63
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aptible-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.13
4
+ version: 0.5.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Macreery
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-07 00:00:00.000000000 Z
11
+ date: 2016-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aptible-api
@@ -178,6 +178,7 @@ files:
178
178
  - lib/aptible/cli/subcommands/apps.rb
179
179
  - lib/aptible/cli/subcommands/config.rb
180
180
  - lib/aptible/cli/subcommands/db.rb
181
+ - lib/aptible/cli/subcommands/domains.rb
181
182
  - lib/aptible/cli/subcommands/logs.rb
182
183
  - lib/aptible/cli/subcommands/ps.rb
183
184
  - lib/aptible/cli/subcommands/rebuild.rb
@@ -187,6 +188,7 @@ files:
187
188
  - spec/aptible/cli/agent_spec.rb
188
189
  - spec/aptible/cli/subcommands/apps_spec.rb
189
190
  - spec/aptible/cli/subcommands/db_spec.rb
191
+ - spec/aptible/cli/subcommands/domains_spec.rb
190
192
  - spec/aptible/cli/subcommands/logs_spec.rb
191
193
  - spec/aptible/cli/subcommands/ps_spec.rb
192
194
  - spec/spec_helper.rb
@@ -210,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
212
  version: '0'
211
213
  requirements: []
212
214
  rubyforge_project:
213
- rubygems_version: 2.2.2
215
+ rubygems_version: 2.4.5
214
216
  signing_key:
215
217
  specification_version: 4
216
218
  summary: Command-line interface for Aptible services
@@ -218,6 +220,7 @@ test_files:
218
220
  - spec/aptible/cli/agent_spec.rb
219
221
  - spec/aptible/cli/subcommands/apps_spec.rb
220
222
  - spec/aptible/cli/subcommands/db_spec.rb
223
+ - spec/aptible/cli/subcommands/domains_spec.rb
221
224
  - spec/aptible/cli/subcommands/logs_spec.rb
222
225
  - spec/aptible/cli/subcommands/ps_spec.rb
223
226
  - spec/spec_helper.rb