aptible-cli 0.3.3 → 0.3.4

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: 02cb684565a0efb38b9a81bfe8e528288db946d8
4
- data.tar.gz: 5cbc7f790a2a8049c74a44a95761e5d5eb42b68b
3
+ metadata.gz: 893705266c3c0a61f332a5272d8be9edc6f9d85d
4
+ data.tar.gz: 2caa6f0a15c7cf284164dbc1a15811b3b4c1deca
5
5
  SHA512:
6
- metadata.gz: 77f9d47520ffcdc4c2bec46a6691eda79cd8236f503b5488923217e66b147e8591f6edab81bc174c8ed7681b864a6acee3595344746494ca91acafb55aa5689e
7
- data.tar.gz: a3fc0f4e2808a7d7bd96eebb7dcef1805df1a2f4d194116d9dadb14447dd07daba76797cf855301cedeade3fab33c4d1177ee080b949e56596eba8fe59ee8e20
6
+ metadata.gz: 2e47cca08a9234fdb7471b351c4bf1599885e1ddb2cc1c035ef95a0959f9113a90c9676e2c913b99edabbc483e4716a3a1ba2f441da12806c8af34e50281357a
7
+ data.tar.gz: 331156dc9fbe99a8dfc9b4cd4707afcfbcb294c6400c4cbc6759125446e4a8f9d043c5dc488e1edd14a034170716ab7595ee6400dad9bcd3009e9bfa2aafac7b
@@ -8,6 +8,7 @@ require_relative 'helpers/app'
8
8
 
9
9
  require_relative 'subcommands/config'
10
10
  require_relative 'subcommands/ssh'
11
+ require_relative 'subcommands/tunnel'
11
12
 
12
13
  module Aptible
13
14
  module CLI
@@ -17,6 +18,7 @@ module Aptible
17
18
  include Helpers::Token
18
19
  include Subcommands::Config
19
20
  include Subcommands::SSH
21
+ include Subcommands::Tunnel
20
22
 
21
23
  desc 'version', 'Print Aptible CLI version'
22
24
  def version
@@ -0,0 +1,55 @@
1
+ module Aptible
2
+ module CLI
3
+ module Subcommands
4
+ module Tunnel
5
+ # rubocop:disable MethodLength
6
+ def self.included(thor)
7
+ thor.class_eval do
8
+ include Helpers::Operation
9
+ include Helpers::Token
10
+
11
+ desc 'tunnel DATABASE', 'Create a local tunnel to a database'
12
+ def tunnel(handle)
13
+ database = database_from_handle(handle)
14
+ unless database
15
+ fail Thor::Error, "Could not find database #{handle}"
16
+ end
17
+ host = database.account.bastion_host
18
+ port = database.account.bastion_port
19
+
20
+ ENV['ACCESS_TOKEN'] = fetch_token
21
+ ENV['APTIBLE_DATABASE'] = handle
22
+ tunnel_args = "-L #{local_port}:localhost:#{remote_port}"
23
+ connection_args = "-o 'SendEnv=*' -p #{port} root@#{host}"
24
+ puts "Creating tunnel at localhost:#{local_port}..."
25
+ Kernel.exec "ssh #{tunnel_args} #{connection_args}"
26
+ end
27
+
28
+ private
29
+
30
+ def database_from_handle(handle)
31
+ Aptible::Api::Database.all(token: fetch_token).find do |a|
32
+ a.handle == handle
33
+ end
34
+ end
35
+
36
+ def local_port
37
+ return @local_port if @local_port
38
+
39
+ # Allocate a dummy server to discover an available port
40
+ dummy = TCPServer.new('127.0.0.1', 0)
41
+ port = dummy.addr[1]
42
+ dummy.close
43
+ @local_port = port
44
+ end
45
+
46
+ def remote_port
47
+ 8080
48
+ end
49
+ end
50
+ end
51
+ # rubocop:enable MethodLength
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,5 +1,5 @@
1
1
  module Aptible
2
2
  module CLI
3
- VERSION = '0.3.3'
3
+ VERSION = '0.3.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.3.3
4
+ version: 0.3.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: 2014-05-22 00:00:00.000000000 Z
11
+ date: 2014-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aptible-api
@@ -146,6 +146,7 @@ files:
146
146
  - lib/aptible/cli/helpers/token.rb
147
147
  - lib/aptible/cli/subcommands/config.rb
148
148
  - lib/aptible/cli/subcommands/ssh.rb
149
+ - lib/aptible/cli/subcommands/tunnel.rb
149
150
  - lib/aptible/cli/version.rb
150
151
  - spec/aptible/cli/agent_spec.rb
151
152
  - spec/spec_helper.rb