arql 0.1.22 → 0.1.23

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
  SHA256:
3
- metadata.gz: 8f5c7a264d240ee1cac06ad0f79ebf578f877e5e151f7ab294c43f742ba110d2
4
- data.tar.gz: 738eb831752775b5c55fa919e9a064eca8439e239a4b345aea36c3cbab9e0500
3
+ metadata.gz: ebb803df936a94d7bb9599aff2dd0db0b625a576e6736799fb50c89d3402808e
4
+ data.tar.gz: 72e84b31307d1bb6d0dad35eeb96702debb55a54a7db0f5a007cd0edd1bf0d28
5
5
  SHA512:
6
- metadata.gz: 3e6f61c3cf125f1cfa81be9737ed7aa54857651344916d10ba587580842d4985b4873fb6ae042cac917dbdfe73a0306e4ead523d4f99613e0786f377da10b228
7
- data.tar.gz: 5c6ba812cde58dfb5ece38cbb89d369c078d4c06d42a48df55eba59a064eaeeae4de9a1273b3b0f882acc88130d0379d1800fa4f9cadd316cc8dc67683d0a75f
6
+ metadata.gz: a7e4905293900ad7e515c35fd8b96a16357dedd940d2f65473a5a087e84444585d335e9922225a87156a453c7eff439cf015b9fbaed318ae8a9c80018dd99350
7
+ data.tar.gz: 69871e396b27eb0b9ceca1f5d3f66aef292d8eb82154018da720878373d95b5554971f5c492327d445bd5762fa1c118d299d9cacda3a163c8d75e94072cf4ddd
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- arql (0.1.21)
4
+ arql (0.1.22)
5
5
  activerecord (~> 6.0.3)
6
6
  activerecord-oracle_enhanced-adapter
7
7
  activerecord-sqlserver-adapter
@@ -4,6 +4,7 @@ require 'arql/id'
4
4
  require 'arql/multi_io'
5
5
  require 'arql/ext'
6
6
  require "arql/repl"
7
+ require "arql/ssh_proxy"
7
8
  require "arql/app"
8
9
  require "arql/cli"
9
10
 
@@ -9,10 +9,6 @@ module Arql
9
9
  def config
10
10
  @@effective_config
11
11
  end
12
-
13
- def local_ssh_proxy_port
14
- @@local_ssh_proxy_port
15
- end
16
12
  end
17
13
 
18
14
  def initialize(options)
@@ -48,11 +44,13 @@ module Arql
48
44
 
49
45
  def start_ssh_proxy!
50
46
  ssh_config = effective_config[:ssh]
51
- @ssh_gateway = Net::SSH::Gateway.new(ssh_config[:host], ssh_config[:user], ssh_config.slice(:port, :password).symbolize_keys)
52
- @@local_ssh_proxy_port = @ssh_gateway.open(effective_config[:host], effective_config[:port], ssh_config[:local_port])
47
+ local_ssh_proxy_port = Arql::SSHProxy.connect(ssh_config.slice(:host, :user, :port, :password).merge(
48
+ forward_host: effective_config[:host],
49
+ forward_port: effective_config[:port],
50
+ local_port: ssh_config[:local_port]))
53
51
  {
54
52
  host: '127.0.0.1',
55
- port: @@local_ssh_proxy_port
53
+ port: local_ssh_proxy_port
56
54
  }
57
55
  end
58
56
 
@@ -1,3 +1,5 @@
1
+ require 'rainbow'
2
+
1
3
  module Arql::Commands
2
4
  module Info
3
5
  class << self
@@ -5,6 +7,8 @@ module Arql::Commands
5
7
  <<~EOF
6
8
 
7
9
  Database Connection Information:
10
+
11
+ Active: #{color_boolean(ActiveRecord::Base.connection.active?)}
8
12
  Host: #{Arql::App.config[:host]}
9
13
  Port: #{Arql::App.config[:port]}
10
14
  Username: #{Arql::App.config[:username]}
@@ -20,13 +24,24 @@ module Arql::Commands
20
24
  <<~EOF
21
25
 
22
26
  SSH Connection Information:
27
+
28
+ Active: #{color_boolean(Arql::SSHProxy.active?)}
23
29
  Host: #{Arql::App.config[:ssh][:host]}
24
30
  Port: #{Arql::App.config[:ssh][:port]}
25
31
  Username: #{Arql::App.config[:ssh][:user]}
26
32
  Password: #{(Arql::App.config[:ssh][:password] || '').gsub(/./, '*')}
27
- Local Port: #{Arql::App.local_ssh_proxy_port}
33
+ Local Port: #{Arql::SSHProxy.local_ssh_proxy_port}
28
34
  EOF
29
35
  end
36
+
37
+ private
38
+ def color_boolean(bool)
39
+ if bool
40
+ Rainbow('TRUE').green
41
+ else
42
+ Rainbow('FALSE').red
43
+ end
44
+ end
30
45
  end
31
46
 
32
47
  Pry.commands.block_command 'info' do
@@ -2,6 +2,12 @@ module Arql::Commands
2
2
  module Reconnect
3
3
  class << self
4
4
  def reconnect
5
+ Arql::SSHProxy.reconnect
6
+ ActiveRecord::Base.connection.reconnect! unless ActiveRecord::Base.connection.active?
7
+ end
8
+
9
+ def reconnect!
10
+ Arql::SSHProxy.reconnect!
5
11
  ActiveRecord::Base.connection.reconnect!
6
12
  end
7
13
  end
@@ -9,5 +15,9 @@ module Arql::Commands
9
15
  Pry.commands.block_command 'reconnect' do
10
16
  Reconnect.reconnect
11
17
  end
18
+
19
+ Pry.commands.block_command 'reconnect!' do
20
+ Reconnect.reconnect!
21
+ end
12
22
  end
13
23
  end
@@ -0,0 +1,30 @@
1
+ require 'net/ssh/gateway'
2
+
3
+ module Arql
4
+ class SSHProxy
5
+ class << self
6
+
7
+ attr_accessor :config, :ssh_gateway, :local_ssh_proxy_port
8
+
9
+ def connect(config)
10
+ @config = config
11
+ @ssh_gateway = Net::SSH::Gateway.new(config[:host], config[:user], config.slice(:port, :password).symbolize_keys)
12
+ @local_ssh_proxy_port = @ssh_gateway.open(config[:forward_host], config[:forward_port], config[:local_port])
13
+ end
14
+
15
+ def reconnect
16
+ reconnect! unless @ssh_gateway.active?
17
+ end
18
+
19
+ def reconnect!
20
+ @ssh_gateway.shutdown!
21
+ @ssh_gateway = Net::SSH::Gateway.new(@config[:host], @config[:user], @config.slice(:port, :password).symbolize_keys)
22
+ @ssh_gateway.open(config[:forward_host], config[:forward_port], @local_ssh_proxy_port)
23
+ end
24
+
25
+ def active?
26
+ @ssh_gateway.active?
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,3 +1,3 @@
1
1
  module Arql
2
- VERSION = "0.1.22"
2
+ VERSION = "0.1.23"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.22
4
+ version: 0.1.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Liu Xiang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-09 00:00:00.000000000 Z
11
+ date: 2020-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mysql2
@@ -252,6 +252,7 @@ files:
252
252
  - lib/arql/id.rb
253
253
  - lib/arql/multi_io.rb
254
254
  - lib/arql/repl.rb
255
+ - lib/arql/ssh_proxy.rb
255
256
  - lib/arql/version.rb
256
257
  homepage: https://github.com/lululau/arql
257
258
  licenses: