aptible-cli 0.5.2 → 0.5.4

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: 2873265292d7a6e0b2fdca4c295ec26b4a376178
4
- data.tar.gz: d63b904efdb8c50141197671fff9fe91f4d5e51e
3
+ metadata.gz: eb9dfc6735786325e67752acf288b43d9ebf21a3
4
+ data.tar.gz: fa7dcfac1d1eefecd10a7ae268d47a7ed379c44b
5
5
  SHA512:
6
- metadata.gz: 11dffb5566df015f9afdc1b0107645819a6e453c7ae54be92cec857bdd5c44828215f76b50fa7b66ae4a217bb4a6e9b3e26ef7361db9b96200b5f15ff62cbf13
7
- data.tar.gz: c69135c258a8c3fd7a3bf012544136fd0e7382d278593aca3db67c275180b2edb1e66fecb37123d0ad9cef631c844e50730d25c88c108092ec8cca080ca5b39e
6
+ metadata.gz: b8e773b844383936d986e66d708001e745b02bc125037c484d66dc6c7ad0286cc36922c7c53eacc1e0ea2568e92dc4fc48b62b3e784af2a1e779448665b0d91e
7
+ data.tar.gz: 9a1f29d08c93c330aeb442cd6352b6b9c0e2d938b8d1241198eee7d2e2be4863390131014a84239c97eb939c9bc0fc44cc985237818ee4314b47d63daff3c649
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  *.gem
2
2
  *.rbc
3
+ *.dump
3
4
  .bundle
4
5
  .config
5
6
  .yardoc
@@ -15,3 +16,5 @@ spec/reports
15
16
  test/tmp
16
17
  test/version_tmp
17
18
  tmp
19
+ /.idea
20
+
data/README.md CHANGED
@@ -22,22 +22,25 @@ From `aptible help`:
22
22
 
23
23
  ```
24
24
  Commands:
25
- aptible apps # List all applications
26
- aptible apps:create HANDLE # Create a new application
27
- aptible config # Print an app's current configuration
28
- aptible config:add # Add an ENV variable to an app
29
- aptible config:rm # Remove an ENV variable from an app
30
- aptible config:set # Alias for config:add
31
- aptible config:unset # Alias for config:rm
32
- aptible db:clone SOURCE DEST # Clone a database to create a new one
33
- aptible db:create HANDLE # Create a new database
34
- aptible db:dump HANDLE # Dump a remote database to file
35
- aptible db:tunnel HANDLE # Create a local tunnel to a database
36
- aptible login # Log in to Aptible
37
- aptible rebuild # Rebuild an app, and restart its services
38
- aptible restart # Restart all services associated with an app
39
- aptible ssh [COMMAND] # Run a command against an app
40
- aptible version # Print Aptible CLI version
25
+ aptible apps # List all applications
26
+ aptible apps:create HANDLE # Create a new application
27
+ aptible config # Print an app's current configuration
28
+ aptible config:add # Add an ENV variable to an app
29
+ aptible config:rm # Remove an ENV variable from an app
30
+ aptible config:set # Alias for config:add
31
+ aptible config:unset # Alias for config:rm
32
+ aptible db:clone SOURCE DEST # Clone a database to create a new one
33
+ aptible db:create HANDLE # Create a new database
34
+ aptible db:dump HANDLE # Dump a remote database to file
35
+ aptible db:execute HANDLE SQL_FILE # Executes sql against a database
36
+ aptible db:tunnel HANDLE # Create a local tunnel to a database
37
+ aptible help [COMMAND] # Describe available commands or one specific command
38
+ aptible login # Log in to Aptible
39
+ aptible logs # Follows logs from a running app
40
+ aptible rebuild # Rebuild an app, and restart its services
41
+ aptible restart # Restart all services associated with an app
42
+ aptible ssh [COMMAND] # Run a command against an app
43
+ aptible version # Print Aptible CLI version
41
44
  ```
42
45
 
43
46
  ## Contributing
@@ -48,10 +51,18 @@ Commands:
48
51
  1. If you add a command, update this README with the output of `aptible help | grep -v help`.
49
52
  1. Create a new pull request on GitHub.
50
53
 
54
+ ## Contributors
55
+
56
+ * Frank Macreery ([@fancyremarker](https://github.com/fancyremarker))
57
+ * Graham Melcher ([@melcher](https://github.com/melcher))
58
+ * Pete Browne ([@petebrowne](https://github.com/petebrowne))
59
+ * Rich Humphrey ([@rdh](https://github.com/rdh))
60
+
61
+
51
62
  ## Copyright and License
52
63
 
53
64
  MIT License, see [LICENSE](LICENSE.md) for details.
54
65
 
55
- Copyright (c) 2014 [Aptible](https://www.aptible.com) and contributors.
66
+ Copyright (c) 2015 [Aptible](https://www.aptible.com) and contributors.
56
67
 
57
68
  [<img src="https://s.gravatar.com/avatar/f7790b867ae619ae0496460aa28c5861?s=60" style="border-radius: 50%;" alt="@fancyremarker" />](https://github.com/fancyremarker)
@@ -28,41 +28,20 @@ module Aptible
28
28
 
29
29
  desc 'db:clone SOURCE DEST', 'Clone a database to create a new one'
30
30
  define_method 'db:clone' do |source_handle, dest_handle|
31
- source = database_from_handle(source_handle)
32
-
33
- unless source
34
- fail Thor::Error, "Could not find database #{source_handle}"
35
- end
36
-
37
- op = source.create_operation(type: 'clone', handle: dest_handle)
38
- poll_for_success(op)
39
- dest = database_from_handle(dest_handle)
31
+ dest = clone_database(source_handle, dest_handle)
40
32
  say dest.connection_url
41
33
  end
42
34
 
43
35
  desc 'db:dump HANDLE', 'Dump a remote database to file'
44
36
  define_method 'db:dump' do |handle|
45
- begin
46
- database = database_from_handle(handle)
47
- unless database
48
- fail Thor::Error, "Could not find database #{handle}"
49
- end
50
- unless database.type == 'postgresql'
51
- fail Thor::Error, 'db:dump only works for PostgreSQL'
52
- end
53
-
54
- local_port = random_local_port
55
- pid = fork { establish_connection(database, local_port) }
56
-
57
- # TODO: Better test for connection readiness
58
- sleep 10
37
+ dump_database(handle)
38
+ end
59
39
 
60
- filename = "#{handle}.dump"
61
- puts "Dumping to #{filename}"
62
- url = "aptible:#{database.passphrase}@localhost:#{local_port}"
63
- `pg_dump postgresql://#{url}/db > #{filename}`
64
- ensure
65
- Process.kill('HUP', pid) if pid
40
+ desc 'db:execute HANDLE SQL_FILE', 'Executes sql against a database'
41
+ define_method 'db:execute' do |handle, sql_path|
42
+ execute_local_tunnel(handle) do |url|
43
+ puts "Executing #{sql_path} against #{handle}"
44
+ `psql #{url} < #{sql_path}`
66
45
  end
67
46
  end
68
47
 
@@ -70,10 +49,6 @@ module Aptible
70
49
  option :port, type: :numeric
71
50
  define_method 'db:tunnel' do |handle|
72
51
  database = database_from_handle(handle)
73
- unless database
74
- fail Thor::Error, "Could not find database #{handle}"
75
- end
76
-
77
52
  local_port = options[:port] || random_local_port
78
53
  puts "Creating tunnel at localhost:#{local_port}..."
79
54
  establish_connection(database, local_port)
@@ -93,10 +68,55 @@ module Aptible
93
68
  Kernel.exec(command)
94
69
  end
95
70
 
96
- def database_from_handle(handle)
97
- Aptible::Api::Database.all(token: fetch_token).find do |a|
98
- a.handle == handle
71
+ def database_from_handle(handle, options = { postgres_only: false })
72
+ all = Aptible::Api::Database.all(token: fetch_token)
73
+ database = all.find { |a| a.handle == handle }
74
+
75
+ unless database
76
+ fail Thor::Error, "Could not find database #{handle}"
77
+ end
78
+
79
+ if options[:postgres_only] && database.type != 'postgresql'
80
+ fail Thor::Error, 'This command only works for PostgreSQL'
99
81
  end
82
+
83
+ database
84
+ end
85
+
86
+ def clone_database(source_handle, dest_handle)
87
+ puts "Cloning #{source_handle} to #{dest_handle}"
88
+
89
+ source = database_from_handle(source_handle)
90
+ op = source.create_operation(type: 'clone', handle: dest_handle)
91
+ poll_for_success(op)
92
+
93
+ database_from_handle(dest_handle)
94
+ end
95
+
96
+ def dump_database(handle)
97
+ execute_local_tunnel(handle) do |url|
98
+ filename = "#{handle}.dump"
99
+ puts "Dumping to #{filename}"
100
+ `pg_dump #{url} > #{filename}`
101
+ end
102
+ end
103
+
104
+ # Creates a local tunnel and yields the url to it
105
+
106
+ def execute_local_tunnel(handle)
107
+ database = database_from_handle(handle, postgres_only: true)
108
+
109
+ local_port = random_local_port
110
+ pid = fork { establish_connection(database, local_port) }
111
+
112
+ # TODO: Better test for connection readiness
113
+ sleep 10
114
+
115
+ auth = "aptible:#{database.passphrase}"
116
+ host = "localhost:#{local_port}"
117
+ yield "postgresql://#{auth}@#{host}/db"
118
+ ensure
119
+ Process.kill('HUP', pid) if pid
100
120
  end
101
121
 
102
122
  def random_local_port
@@ -1,5 +1,5 @@
1
1
  module Aptible
2
2
  module CLI
3
- VERSION = '0.5.2'
3
+ VERSION = '0.5.4'
4
4
  end
5
5
  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.2
4
+ version: 0.5.4
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-01-19 00:00:00.000000000 Z
11
+ date: 2015-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aptible-api