aptible-cli 0.5.8 → 0.5.9

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: a4b91444b0b662e1ab07c80526ba3f5054fd7ea6
4
- data.tar.gz: f587f3803827f79e03f917134427cbad12aeff42
3
+ metadata.gz: f4d9a2c5e7a80842934a122c1a11527ef05c1395
4
+ data.tar.gz: 58467bec285d73b6931fef00cb3b1f024b04ec08
5
5
  SHA512:
6
- metadata.gz: 78a8eab1b55ba1e03c80eb102bece4876ac0f9dc873e551d552ee3a79e6a11610548cfc22fcc14e906f7149eb27bf41c0cb2aed94ce146f9dc0abdd0d9772bac
7
- data.tar.gz: c44a10640e89b53dee298aa13044d2211ceeeaea3de1cc59173fd694b70f99be98c91e3af29bfdc2bc27e045a39ebd392772343976174453be6ce03d70d0e374
6
+ metadata.gz: ab3bfc0457f47e32db4082fc86b039426664849528b7146886c7365b7983c09bece8afd360b7bcca230f4a5dd767d499c717a98d9624b83a7ea50f846745a8ee
7
+ data.tar.gz: c03299b36d7951e4c4d8e42bda9ab949df13c5a3d64237532905c1508fc4ae37343ce9b74002c813922c57955d028a33e8c9a9d6e007264f3fe69732e5b3fbb7
data/aptible-cli.gemspec CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency 'aptible-resource', '>= 0.3.0'
25
25
  spec.add_dependency 'thor', '>= 0.19.0'
26
26
  spec.add_dependency 'git'
27
+ spec.add_dependency 'term-ansicolor'
27
28
 
28
29
  spec.add_development_dependency 'bundler', '~> 1.3'
29
30
  spec.add_development_dependency 'aptible-tasks', '>= 0.2.0'
@@ -1,3 +1,5 @@
1
+ require 'term/ansicolor'
2
+
1
3
  module Aptible
2
4
  module CLI
3
5
  module Subcommands
@@ -6,6 +8,7 @@ module Aptible
6
8
  thor.class_eval do
7
9
  include Helpers::Operation
8
10
  include Helpers::Token
11
+ include Term::ANSIColor
9
12
 
10
13
  desc 'db:create HANDLE', 'Create a new database'
11
14
  option :type, default: 'postgresql'
@@ -40,7 +43,7 @@ module Aptible
40
43
  desc 'db:execute HANDLE SQL_FILE', 'Executes sql against a database'
41
44
  define_method 'db:execute' do |handle, sql_path|
42
45
  execute_local_tunnel(handle) do |url|
43
- puts "Executing #{sql_path} against #{handle}"
46
+ say "Executing #{sql_path} against #{handle}"
44
47
  `psql #{url} < #{sql_path}`
45
48
  end
46
49
  end
@@ -50,14 +53,16 @@ module Aptible
50
53
  define_method 'db:tunnel' do |handle|
51
54
  database = database_from_handle(handle)
52
55
  local_port = options[:port] || random_local_port
53
- puts "Creating tunnel at localhost:#{local_port}..."
56
+
57
+ say 'Creating tunnel...', :green
58
+ say "Connect at #{local_url(database, local_port)}", :green
54
59
  establish_connection(database, local_port)
55
60
  end
56
61
 
57
62
  desc 'db:deprovision HANDLE', 'Deprovision a database'
58
63
  define_method 'db:deprovision' do |handle|
59
64
  database = database_from_handle(handle)
60
- puts "Deprovisioning #{handle}..."
65
+ say "Deprovisioning #{handle}..."
61
66
  database.update!(status: 'deprovisioned')
62
67
  database.create_operation(type: 'deprovision')
63
68
  end
@@ -92,7 +97,7 @@ module Aptible
92
97
  end
93
98
 
94
99
  def clone_database(source_handle, dest_handle)
95
- puts "Cloning #{source_handle} to #{dest_handle}"
100
+ say "Cloning #{source_handle} to #{dest_handle}"
96
101
 
97
102
  source = database_from_handle(source_handle)
98
103
  op = source.create_operation(type: 'clone', handle: dest_handle)
@@ -104,7 +109,7 @@ module Aptible
104
109
  def dump_database(handle)
105
110
  execute_local_tunnel(handle) do |url|
106
111
  filename = "#{handle}.dump"
107
- puts "Dumping to #{filename}"
112
+ say "Dumping to #{filename}"
108
113
  `pg_dump #{url} > #{filename}`
109
114
  end
110
115
  end
@@ -135,6 +140,14 @@ module Aptible
135
140
  port
136
141
  end
137
142
 
143
+ def local_url(database, local_port)
144
+ remote_url = database.connection_url
145
+ uri = URI.parse(remote_url)
146
+
147
+ "#{uri.scheme}://#{uri.user}:#{uri.password}@" \
148
+ "127.0.0.1:#{local_port}#{uri.path}"
149
+ end
150
+
138
151
  def claim_remote_port(database)
139
152
  ENV['ACCESS_TOKEN'] = fetch_token
140
153
 
@@ -15,6 +15,11 @@ module Aptible
15
15
  def logs
16
16
  app = ensure_app(options)
17
17
 
18
+ unless app.status == 'provisioned' && app.services.any?
19
+ fail Thor::Error, 'Unable to retrieve logs. ' \
20
+ "Have you deployed #{app.handle} yet?"
21
+ end
22
+
18
23
  host = app.account.bastion_host
19
24
  port = app.account.dumptruck_port
20
25
 
@@ -1,5 +1,5 @@
1
1
  module Aptible
2
2
  module CLI
3
- VERSION = '0.5.8'
3
+ VERSION = '0.5.9'
4
4
  end
5
5
  end
@@ -15,9 +15,9 @@ describe Aptible::CLI::Agent do
15
15
  before { subject.stub(:save_token) }
16
16
  before { subject.stub(:fetch_token) { double 'token' } }
17
17
 
18
- service = Service.new(process_type: 'web')
19
- op = Operation.new(status: 'succeeded')
20
- apps = [App.new(handle: 'hello', services: [service])]
18
+ let(:service) { Service.new(process_type: 'web') }
19
+ let(:op) { Operation.new(status: 'succeeded') }
20
+ let(:apps) { [App.new(handle: 'hello', services: [service])] }
21
21
 
22
22
  describe '#apps:scale' do
23
23
  it 'should pass given correct parameters' do
@@ -0,0 +1,39 @@
1
+ require 'ostruct'
2
+ require 'spec_helper'
3
+
4
+ class Database < OpenStruct
5
+ end
6
+
7
+ describe Aptible::CLI::Agent do
8
+ before { subject.stub(:ask) }
9
+ before { subject.stub(:save_token) }
10
+ before { subject.stub(:fetch_token) { double 'token' } }
11
+ before { subject.stub(:random_local_port) { 4242 } }
12
+ before { subject.stub(:establish_connection) }
13
+
14
+ let(:database) do
15
+ Database.new(
16
+ type: 'postgresql',
17
+ handle: 'foobar',
18
+ passphrase: 'password',
19
+ connection_url: 'postgresql://aptible:password@10.252.1.125:49158/db'
20
+ )
21
+ end
22
+
23
+ describe '#db:tunnel' do
24
+ it 'should fail if database is non-existent' do
25
+ allow(Aptible::Api::Database).to receive(:all) { [] }
26
+ expect do
27
+ subject.send('db:tunnel', 'foobar')
28
+ end.to raise_error('Could not find database foobar')
29
+ end
30
+
31
+ it 'should print a message about how to connect' do
32
+ allow(Aptible::Api::Database).to receive(:all) { [database] }
33
+ local_url = 'postgresql://aptible:password@127.0.0.1:4242/db'
34
+ expect(subject).to receive(:say).with('Creating tunnel...', :green)
35
+ expect(subject).to receive(:say).with("Connect at #{local_url}", :green)
36
+ subject.send('db:tunnel', 'foobar')
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,33 @@
1
+ require 'ostruct'
2
+ require 'spec_helper'
3
+
4
+ class App < OpenStruct
5
+ end
6
+
7
+ class Service < OpenStruct
8
+ end
9
+
10
+ describe Aptible::CLI::Agent do
11
+ before { subject.stub(:ask) }
12
+ before { subject.stub(:save_token) }
13
+ before { subject.stub(:fetch_token) { double 'token' } }
14
+
15
+ let(:service) { Service.new(process_type: 'web') }
16
+ let(:app) do
17
+ App.new(handle: 'foobar', status: 'provisioned', services: [service])
18
+ end
19
+
20
+ describe '#logs' do
21
+ it 'should fail if the app is unprovisioned' do
22
+ allow(app).to receive(:status) { 'pending' }
23
+ allow(subject).to receive(:ensure_app) { app }
24
+ expect { subject.send('logs') }.to raise_error(Thor::Error)
25
+ end
26
+
27
+ it 'should fail if the app has no services' do
28
+ allow(app).to receive(:services) { [] }
29
+ allow(subject).to receive(:ensure_app) { app }
30
+ expect { subject.send('logs') }.to raise_error(Thor::Error)
31
+ end
32
+ end
33
+ 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.8
4
+ version: 0.5.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Macreery
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-10 00:00:00.000000000 Z
11
+ date: 2015-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aptible-api
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: term-ansicolor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: bundler
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -172,6 +186,8 @@ files:
172
186
  - lib/aptible/cli/version.rb
173
187
  - spec/aptible/cli/agent_spec.rb
174
188
  - spec/aptible/cli/subcommands/apps_spec.rb
189
+ - spec/aptible/cli/subcommands/db_spec.rb
190
+ - spec/aptible/cli/subcommands/logs_spec.rb
175
191
  - spec/aptible/cli/subcommands/ps_spec.rb
176
192
  - spec/spec_helper.rb
177
193
  homepage: https://github.com/aptible/aptible-cli
@@ -194,12 +210,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
210
  version: '0'
195
211
  requirements: []
196
212
  rubyforge_project:
197
- rubygems_version: 2.4.6
213
+ rubygems_version: 2.4.8
198
214
  signing_key:
199
215
  specification_version: 4
200
216
  summary: Command-line interface for Aptible services
201
217
  test_files:
202
218
  - spec/aptible/cli/agent_spec.rb
203
219
  - spec/aptible/cli/subcommands/apps_spec.rb
220
+ - spec/aptible/cli/subcommands/db_spec.rb
221
+ - spec/aptible/cli/subcommands/logs_spec.rb
204
222
  - spec/aptible/cli/subcommands/ps_spec.rb
205
223
  - spec/spec_helper.rb