arql 0.1.24 → 0.1.29

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: 564734f7acc9af2155ed815a64d8409e7ba3cf1478186271802ae5885bab0aca
4
- data.tar.gz: 94171bccabc7a2e8a48d8a8dcbb29922dd30a50e22d696e2552fcae670a8efb8
3
+ metadata.gz: 823a5527aa1dfc5e12de5284dc43d7afcba4978608a00f31bcf53e8058e4ad67
4
+ data.tar.gz: ed6026bf27d00fc953400a4776081d7f17de730dc70e96143cd448b42e21d779
5
5
  SHA512:
6
- metadata.gz: 3be7226f6ba22d715fd56b2c8b51fa86195be8167d080c41c6f1308e69366d8bc95d773260440fe48dcee0b1df3bee1260e1e836e70f0d470446057dff49f746
7
- data.tar.gz: '0846f6882b40846f8f42293a9e08d474e4306719fd5fd817bd19590a893efde21d67d2af41d91b7a552283fd33510ab698ba7efe016bc95418ab4bf9550566cc'
6
+ metadata.gz: a47d663c5b8a2297e16f895b1d74add187da511b3abeec29e142d03a2ec6ae9fe577e942c8a471590f6312c8f937945912ea12db1e620fcf29973dbac5f4297f
7
+ data.tar.gz: f700d21883edbddef9c82f748dbc01c99ba984cd52048a5e9e93fc29d701036ada9fe07441746020b400a8ed632343dae3a6cdd3d04848fc0a2781b2875c9006
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- arql (0.1.24)
4
+ arql (0.1.29)
5
5
  activerecord (~> 6.0.3)
6
6
  activesupport (~> 6.0.3)
7
7
  mysql2 (~> 0.5.3)
data/exe/arql CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ ArqlSetsidWrrapper = File.dirname(File.absolute_path(__FILE__)) + '/arql_setsid_wrapper'
4
+
3
5
  require "arql"
4
6
 
5
7
  Arql::Cli.start
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ Process.setsid
4
+
5
+ exec(*ARGV)
@@ -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
- unless File.exists?(effective_config[:initializer])
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(effective_config[:initializer])
44
+ load(initializer_file)
43
45
  end
44
46
 
45
47
  def start_ssh_proxy!
@@ -55,14 +57,16 @@ 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
- config[@options.env]
67
+ sc = config[@options.env]
68
+ sc[:database] = File.expand_path(sc[:database]) if sc[:adapter] == 'sqlite3'
69
+ sc
66
70
  end
67
71
 
68
72
  def effective_config
@@ -10,10 +10,7 @@ module Arql
10
10
  end
11
11
 
12
12
  def parse_options!
13
- @options = OpenStruct.new(adapter: 'mysql2',
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
 
@@ -9,7 +9,7 @@ class Time
9
9
  to_s
10
10
  end
11
11
 
12
- def as_json
12
+ def as_json(*args)
13
13
  to_s
14
14
  end
15
15
  end
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Arql
2
- VERSION = "0.1.24"
2
+ VERSION = "0.1.29"
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.24
4
+ version: 0.1.29
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-01 00:00:00.000000000 Z
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: