arql 0.1.25 → 0.1.30
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/exe/arql +2 -0
- data/exe/arql_setsid_wrapper +5 -0
- data/lib/arql/app.rb +20 -6
- data/lib/arql/cli.rb +1 -4
- data/lib/arql/repl.rb +1 -1
- data/lib/arql/ssh_proxy.rb +2 -1
- data/lib/arql/ssh_proxy_patch.rb +88 -0
- data/lib/arql/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8fb2d02931fdd0af7a9eec6b20db222f6f2fff93e0c506186316157987a443f
|
4
|
+
data.tar.gz: ae61f43b49612c316a82aac8e0c63dfc70c34527026c62201397f267ace5c188
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8deb0c597de52fe5d1dd24f7eaa60c07133d7c0d583eb93f746b416d660a5911f556820b1937cb5f0d2d9667de3a53a1b8057e7bc6ad36321eb96b0e93f454e2
|
7
|
+
data.tar.gz: 77ba16537c3fa67c65518db3e5fbca9fa012452c2135a0d26ffabbb47ec9c65f6a3de1c052a98553b65640d9c534467a77ef5993013cb9f3d265c830db70e613
|
data/Gemfile.lock
CHANGED
data/exe/arql
CHANGED
data/lib/arql/app.rb
CHANGED
@@ -4,7 +4,7 @@ module Arql
|
|
4
4
|
class App
|
5
5
|
|
6
6
|
class << self
|
7
|
-
attr_accessor :log_io
|
7
|
+
attr_accessor :log_io, :env
|
8
8
|
|
9
9
|
def config
|
10
10
|
@@effective_config
|
@@ -17,6 +17,7 @@ module Arql
|
|
17
17
|
require "arql/connection"
|
18
18
|
require "arql/definition"
|
19
19
|
@options = options
|
20
|
+
App.env = @options.env
|
20
21
|
Connection.open(connect_options)
|
21
22
|
@definition = Definition.new(effective_config)
|
22
23
|
load_initializer!
|
@@ -35,11 +36,12 @@ module Arql
|
|
35
36
|
|
36
37
|
def load_initializer!
|
37
38
|
return unless effective_config[:initializer]
|
38
|
-
|
39
|
+
initializer_file = File.expand_path(effective_config[:initializer])
|
40
|
+
unless File.exists?(initializer_file)
|
39
41
|
STDERR.puts "Specified initializer file not found, #{effective_config[:initializer]}"
|
40
42
|
exit(1)
|
41
43
|
end
|
42
|
-
load(
|
44
|
+
load(initializer_file)
|
43
45
|
end
|
44
46
|
|
45
47
|
def start_ssh_proxy!
|
@@ -55,18 +57,30 @@ module Arql
|
|
55
57
|
end
|
56
58
|
|
57
59
|
def config
|
58
|
-
@config ||= YAML.load(IO.read(@options.config_file)).with_indifferent_access
|
60
|
+
@config ||= YAML.load(IO.read(File.expand_path(@options.config_file))).with_indifferent_access
|
59
61
|
end
|
60
62
|
|
61
63
|
def selected_config
|
62
64
|
if @options.env.present? && !config[@options.env].present?
|
63
65
|
STDERR.puts "Specified ENV `#{@options.env}' not exists"
|
64
66
|
end
|
65
|
-
|
67
|
+
if env = @options.env
|
68
|
+
config[env]
|
69
|
+
else
|
70
|
+
{}
|
71
|
+
end
|
66
72
|
end
|
67
73
|
|
68
74
|
def effective_config
|
69
|
-
@@effective_config ||=
|
75
|
+
@@effective_config ||= nil
|
76
|
+
unless @@effective_config
|
77
|
+
@@effective_config = selected_config.deep_merge(@options.to_h)
|
78
|
+
if @@effective_config[:adapter].blank?
|
79
|
+
@@effective_config[:adapter] = 'sqlite3'
|
80
|
+
end
|
81
|
+
@@effective_config[:database] = File.expand_path(@@effective_config[:database]) if @@effective_config[:adapter] == 'sqlite3'
|
82
|
+
end
|
83
|
+
@@effective_config
|
70
84
|
end
|
71
85
|
|
72
86
|
def run!
|
data/lib/arql/cli.rb
CHANGED
@@ -10,10 +10,7 @@ module Arql
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def parse_options!
|
13
|
-
@options = OpenStruct.new(
|
14
|
-
encoding: 'utf8',
|
15
|
-
pool: 5,
|
16
|
-
config_file: default_config_file,
|
13
|
+
@options = OpenStruct.new(config_file: default_config_file,
|
17
14
|
initializer: default_initializer,
|
18
15
|
ssh: {})
|
19
16
|
|
data/lib/arql/repl.rb
CHANGED
@@ -31,7 +31,7 @@ module Arql
|
|
31
31
|
else
|
32
32
|
nest_level_prompt = "(#{obj}:#{nest_level})"
|
33
33
|
end
|
34
|
-
"%s#{nest_level_prompt} %s " % [Rainbow('ARQL').red, Rainbow('❯').green]
|
34
|
+
"%s#{Rainbow('@').green}%s#{nest_level_prompt} %s " % [Rainbow('ARQL').red, Rainbow(App.env).yellow, Rainbow('❯').green]
|
35
35
|
end]
|
36
36
|
end
|
37
37
|
end
|
data/lib/arql/ssh_proxy.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'net/ssh/gateway'
|
2
|
+
require 'arql/ssh_proxy_patch'
|
2
3
|
|
3
4
|
module Arql
|
4
5
|
class SSHProxy
|
@@ -8,7 +9,7 @@ module Arql
|
|
8
9
|
|
9
10
|
def connect(config)
|
10
11
|
@config = config
|
11
|
-
@ssh_gateway = Net::SSH::Gateway.new(config[:host], config[:user], config.slice(:port, :password).symbolize_keys.merge(keepalive: true, keepalive_interval: 30))
|
12
|
+
@ssh_gateway = Net::SSH::Gateway.new(config[:host], config[:user], config.slice(:port, :password).symbolize_keys.merge(keepalive: true, keepalive_interval: 30, loop_wait: 1))
|
12
13
|
@local_ssh_proxy_port = @ssh_gateway.open(config[:forward_host], config[:forward_port], config[:local_port])
|
13
14
|
end
|
14
15
|
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'net/ssh/proxy/command'
|
2
|
+
|
3
|
+
module Net
|
4
|
+
module SSH
|
5
|
+
module Proxy
|
6
|
+
class Command
|
7
|
+
|
8
|
+
# Return a new socket connected to the given host and port via the
|
9
|
+
# proxy that was requested when the socket factory was instantiated.
|
10
|
+
def open(host, port, connection_options = nil)
|
11
|
+
command_line = @command_line_template.gsub(/%(.)/) {
|
12
|
+
case $1
|
13
|
+
when 'h'
|
14
|
+
host
|
15
|
+
when 'p'
|
16
|
+
port.to_s
|
17
|
+
when 'r'
|
18
|
+
remote_user = connection_options && connection_options[:remote_user]
|
19
|
+
if remote_user
|
20
|
+
remote_user
|
21
|
+
else
|
22
|
+
raise ArgumentError, "remote user name not available"
|
23
|
+
end
|
24
|
+
when '%'
|
25
|
+
'%'
|
26
|
+
else
|
27
|
+
raise ArgumentError, "unknown key: #{$1}"
|
28
|
+
end
|
29
|
+
}
|
30
|
+
command_line = '%s %s' % [ArqlSetsidWrrapper, command_line]
|
31
|
+
begin
|
32
|
+
io = IO.popen(command_line, "r+")
|
33
|
+
begin
|
34
|
+
if result = IO.select([io], nil, [io], @timeout)
|
35
|
+
if result.last.any? || io.eof?
|
36
|
+
raise "command failed"
|
37
|
+
end
|
38
|
+
else
|
39
|
+
raise "command timed out"
|
40
|
+
end
|
41
|
+
rescue StandardError
|
42
|
+
close_on_error(io)
|
43
|
+
raise
|
44
|
+
end
|
45
|
+
rescue StandardError => e
|
46
|
+
raise ConnectError, "#{e}: #{command_line}"
|
47
|
+
end
|
48
|
+
@command_line = command_line
|
49
|
+
if Gem.win_platform?
|
50
|
+
# read_nonblock and write_nonblock are not available on Windows
|
51
|
+
# pipe. Use sysread and syswrite as a replacement works.
|
52
|
+
def io.send(data, flag)
|
53
|
+
syswrite(data)
|
54
|
+
end
|
55
|
+
|
56
|
+
def io.recv(size)
|
57
|
+
sysread(size)
|
58
|
+
end
|
59
|
+
else
|
60
|
+
def io.send(data, flag)
|
61
|
+
begin
|
62
|
+
result = write_nonblock(data)
|
63
|
+
rescue IO::WaitWritable, Errno::EINTR
|
64
|
+
IO.select(nil, [self])
|
65
|
+
retry
|
66
|
+
end
|
67
|
+
result
|
68
|
+
end
|
69
|
+
|
70
|
+
def io.recv(size)
|
71
|
+
begin
|
72
|
+
result = read_nonblock(size)
|
73
|
+
rescue IO::WaitReadable, Errno::EINTR
|
74
|
+
timeout_in_seconds = 20
|
75
|
+
if IO.select([self], nil, [self], timeout_in_seconds) == nil
|
76
|
+
raise "Unexpected spurious read wakeup"
|
77
|
+
end
|
78
|
+
retry
|
79
|
+
end
|
80
|
+
result
|
81
|
+
end
|
82
|
+
end
|
83
|
+
io
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/lib/arql/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.30
|
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-07-
|
11
|
+
date: 2020-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mysql2
|
@@ -169,6 +169,7 @@ email:
|
|
169
169
|
- liuxiang921@gmail.com
|
170
170
|
executables:
|
171
171
|
- arql
|
172
|
+
- arql_setsid_wrapper
|
172
173
|
extensions: []
|
173
174
|
extra_rdoc_files: []
|
174
175
|
files:
|
@@ -183,6 +184,7 @@ files:
|
|
183
184
|
- bin/console
|
184
185
|
- bin/setup
|
185
186
|
- exe/arql
|
187
|
+
- exe/arql_setsid_wrapper
|
186
188
|
- lib/arql.rb
|
187
189
|
- lib/arql/app.rb
|
188
190
|
- lib/arql/cli.rb
|
@@ -205,6 +207,7 @@ files:
|
|
205
207
|
- lib/arql/multi_io.rb
|
206
208
|
- lib/arql/repl.rb
|
207
209
|
- lib/arql/ssh_proxy.rb
|
210
|
+
- lib/arql/ssh_proxy_patch.rb
|
208
211
|
- lib/arql/version.rb
|
209
212
|
homepage: https://github.com/lululau/arql
|
210
213
|
licenses:
|