canals 0.8.7 → 0.9.0
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 +4 -4
- data/Gemfile +2 -0
- data/assets/canals.sh +7 -2
- data/lib/canals/cli.rb +39 -1
- data/lib/canals/cli/helpers.rb +33 -13
- data/lib/canals/cli/list.rb +6 -0
- data/lib/canals/cli/session.rb +18 -14
- data/lib/canals/core.rb +13 -3
- data/lib/canals/environment.rb +9 -9
- data/lib/canals/options.rb +38 -22
- data/lib/canals/repository.rb +10 -1
- data/lib/canals/session.rb +32 -2
- data/lib/canals/version.rb +1 -1
- data/spec/canals/environment_spec.rb +10 -2
- data/spec/canals/options_spec.rb +58 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e283a22a7f6c82810b5d6882f43261d52049c43
|
4
|
+
data.tar.gz: 3241f8e7db64722f49d194fcd7913e9c03d3276a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70c882e0a9523ac94c4f4fc752952e00250234c6ab41fa437c942e7ec01fcef08f7ddfb441c2d04fa1a6a91aab4f62c73a56bd1bde751145be44d0f2aef597d6
|
7
|
+
data.tar.gz: fdaf278face0c256fac3f38db681f4fdaef3bd30161d59037acf1c6c59dceaf8c3b0e256c8eeb8b406bb6e7a2a401d5b853c19aa803cebc1739e5600e015dc92
|
data/Gemfile
CHANGED
data/assets/canals.sh
CHANGED
@@ -10,7 +10,7 @@ _canal_complete() {
|
|
10
10
|
# Setup the base level (everything after "canal")
|
11
11
|
if [ $COMP_CWORD -eq 1 ]; then
|
12
12
|
COMPREPLY=( $(compgen \
|
13
|
-
-W "create environment help repo restart session setup start stop update" \
|
13
|
+
-W "adhoc create environment help repo restart session setup start stop update" \
|
14
14
|
-- $cur) )
|
15
15
|
return 0
|
16
16
|
fi
|
@@ -18,11 +18,16 @@ _canal_complete() {
|
|
18
18
|
# Setup the second level
|
19
19
|
if [ $COMP_CWORD -eq 2 ]; then
|
20
20
|
case "$prev" in
|
21
|
-
start|
|
21
|
+
start|update)
|
22
22
|
COMPREPLY=( $(compgen \
|
23
23
|
-W "`canal list tunnels`" \
|
24
24
|
-- $cur) )
|
25
25
|
;;
|
26
|
+
stop|restart)
|
27
|
+
COMPREPLY=( $(compgen \
|
28
|
+
-W "`canal list session`" \
|
29
|
+
-- $cur) )
|
30
|
+
;;
|
26
31
|
environment)
|
27
32
|
COMPREPLY=( $(compgen \
|
28
33
|
-W "create help show" \
|
data/lib/canals/cli.rb
CHANGED
@@ -20,6 +20,12 @@ module Canals
|
|
20
20
|
startup_checks
|
21
21
|
end
|
22
22
|
|
23
|
+
desc "--version, -v", "prints the canal's version information", :hide => true
|
24
|
+
def __print_version
|
25
|
+
say "Canals version #{Canals::VERSION}"
|
26
|
+
end
|
27
|
+
map %w[--version -v] => :__print_version
|
28
|
+
|
23
29
|
desc 'create NAME REMOTE_HOST REMOTE_PORT [LOCAL_PORT]', "Create a new tunnel; if LOCAL_PORT isn't supplied, REMOTE_PORT will be used as LOCAL"
|
24
30
|
method_option :env, :type => :string, :desc => "The proxy environment to use"
|
25
31
|
method_option :hostname, :type => :string, :desc => "The proxy host we will use to connect through"
|
@@ -32,6 +38,18 @@ module Canals
|
|
32
38
|
say "Tunnel #{name.inspect} created.", :green
|
33
39
|
end
|
34
40
|
|
41
|
+
desc 'delete NAME', "Delete an existing tunnel; if tunnel is active, stop it first"
|
42
|
+
def delete(name)
|
43
|
+
tunnel = Canals.repository.get(name)
|
44
|
+
if tunnel.nil?
|
45
|
+
say "couldn't find tunnel #{name.inspect}. try using 'create' instead", :red
|
46
|
+
return
|
47
|
+
end
|
48
|
+
tstop(name, silent: true)
|
49
|
+
Canals.repository.delete(name)
|
50
|
+
say "Tunnel #{name.inspect} deleted.", :green
|
51
|
+
end
|
52
|
+
|
35
53
|
desc 'update NAME', "Update an existing tunnel"
|
36
54
|
method_option :remote_host, :type => :string, :desc => "The remote host of the tunnel"
|
37
55
|
method_option :remote_port, :type => :string, :desc => "The remote port of the tunnel"
|
@@ -57,8 +75,15 @@ module Canals
|
|
57
75
|
end
|
58
76
|
|
59
77
|
desc 'start NAME', 'Start tunnel'
|
78
|
+
method_option :local_port, :type => :numeric, :desc => "The local port to use"
|
60
79
|
def start(name)
|
61
|
-
|
80
|
+
tunnel = tunnel_options(name)
|
81
|
+
if options["local_port"]
|
82
|
+
tunnel.local_port = options["local_port"]
|
83
|
+
tunnel.name = "adhoc-#{name}-#{options["local_port"]}"
|
84
|
+
tunnel.adhoc = true
|
85
|
+
end
|
86
|
+
tstart(tunnel)
|
62
87
|
end
|
63
88
|
|
64
89
|
desc 'stop NAME', 'Stop tunnel'
|
@@ -98,6 +123,19 @@ module Canals
|
|
98
123
|
say "* use --full to show more data", [:white, :dim] if !options[:full]
|
99
124
|
end
|
100
125
|
|
126
|
+
desc "adhoc REMOTE_HOST REMOTE_PORT [LOCAL_PORT]", "Create and run a new tunnel, without keeping it in the repository; if LOCAL_PORT isn't supplied, REMOTE_PORT will be used as LOCAL"
|
127
|
+
method_option :name, :type => :string, :desc => "The name to use for the tunnel, if not supplied a template will be generated"
|
128
|
+
method_option :env, :type => :string, :desc => "The proxy environment to use"
|
129
|
+
method_option :hostname, :type => :string, :desc => "The proxy host we will use to connect through"
|
130
|
+
method_option :user, :type => :string, :desc => "The user for the ssh proxy host"
|
131
|
+
method_option :bind_address, :type => :string, :desc => "The bind address to connect to"
|
132
|
+
def adhoc(remote_host, remote_port, local_port=nil)
|
133
|
+
opts = {"adhoc" => true, "remote_host" => remote_host, "remote_port" => remote_port, "local_port" => local_port}.merge(options)
|
134
|
+
opts["name"] ||= "adhoc-#{remote_host}-#{remote_port}"
|
135
|
+
opts = Canals::CanalOptions.new(opts)
|
136
|
+
tstart(opts)
|
137
|
+
end
|
138
|
+
|
101
139
|
desc "environment SUBCOMMAND", "Environment related command (use 'canal environment help' to find out more)"
|
102
140
|
subcommand "environment", Canals::Cli::Environment
|
103
141
|
|
data/lib/canals/cli/helpers.rb
CHANGED
@@ -6,26 +6,46 @@ module Canals
|
|
6
6
|
module Cli
|
7
7
|
module Helpers
|
8
8
|
|
9
|
-
def tstop(
|
10
|
-
|
11
|
-
|
9
|
+
def tstop(tunnel_opts, silent: false)
|
10
|
+
if tunnel_opts.instance_of? String
|
11
|
+
tunnel_opts = tunnel_options(tunnel_opts)
|
12
|
+
end
|
13
|
+
Canals.stop(tunnel_opts)
|
14
|
+
say "Tunnel #{tunnel_opts.name.inspect} stopped." unless silent
|
12
15
|
end
|
13
16
|
|
14
|
-
def tstart(
|
15
|
-
|
16
|
-
|
17
|
-
|
17
|
+
def tstart(tunnel_opts, silent: false)
|
18
|
+
if tunnel_opts.instance_of? String
|
19
|
+
tunnel_opts = tunnel_options(tunnel_opts)
|
20
|
+
end
|
21
|
+
pid = Canals.start(tunnel_opts)
|
22
|
+
say "Created tunnel #{tunnel_opts.name.inspect} with pid #{pid}. You can access it using '#{tunnel_opts.bind_address}:#{tunnel_opts.local_port}'" unless silent
|
18
23
|
pid
|
19
24
|
rescue Canals::Exception => e
|
20
|
-
|
21
|
-
|
22
|
-
|
25
|
+
if tunnel_opts.instance_of? String
|
26
|
+
tunnel_opts = tunnel_options(tunnel_opts)
|
27
|
+
end
|
28
|
+
isalive = Canals.isalive? tunnel_opts
|
29
|
+
say "Unable to create tunnel #{tunnel_opts.name.inspect}#{isalive ? ', A tunnel for ' + tunnel_opts.name.inspect + ' Already exists.' : ''}", :red
|
23
30
|
0
|
24
31
|
end
|
25
32
|
|
26
|
-
def trestart(
|
27
|
-
|
28
|
-
|
33
|
+
def trestart(tunnel_opts)
|
34
|
+
if tunnel_opts.instance_of? String
|
35
|
+
tunnel_opts = tunnel_options(tunnel_opts)
|
36
|
+
end
|
37
|
+
tstop(tunnel_opts)
|
38
|
+
tstart(tunnel_opts)
|
39
|
+
end
|
40
|
+
|
41
|
+
def tunnel_options(name)
|
42
|
+
if (Canals.session.has?(name))
|
43
|
+
Canals.session.get_obj(name)
|
44
|
+
elsif (Canals.repository.has?(name))
|
45
|
+
Canals.repository.get(name)
|
46
|
+
else
|
47
|
+
raise Thor::Error.new "Unable to find tunnel #{name.inspect}."
|
48
|
+
end
|
29
49
|
end
|
30
50
|
|
31
51
|
def startup_checks
|
data/lib/canals/cli/list.rb
CHANGED
@@ -20,6 +20,12 @@ module Canals
|
|
20
20
|
say tunnels.sort.join " "
|
21
21
|
end
|
22
22
|
|
23
|
+
desc 'session', 'List the tunnels in the current session'
|
24
|
+
def session
|
25
|
+
tunnels = Canals.session.map{ |conf| conf[:name] }
|
26
|
+
say tunnels.sort.join " "
|
27
|
+
end
|
28
|
+
|
23
29
|
desc 'commands', 'List all the base level commands'
|
24
30
|
def commands(subcommand=nil)
|
25
31
|
thor_class = Canals::Cli::Application
|
data/lib/canals/cli/session.rb
CHANGED
@@ -25,36 +25,36 @@ module Canals
|
|
25
25
|
|
26
26
|
desc "restore", "Restore the connection to tunnels which aren't working"
|
27
27
|
def restore
|
28
|
-
on_all_canals_in_session(:restore) do |
|
29
|
-
if Canals.isalive?
|
30
|
-
say "Canal #{name.inspect} is running."
|
28
|
+
on_all_canals_in_session(:restore) do |canal|
|
29
|
+
if Canals.isalive? canal
|
30
|
+
say "Canal #{canal.name.inspect} is running."
|
31
31
|
else
|
32
|
-
Canals.session.del(name)
|
33
|
-
tstart(
|
32
|
+
Canals.session.del(canal.name)
|
33
|
+
tstart(canal)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
desc "restart", "Restart the current session (closing and starting all connections)"
|
39
39
|
def restart
|
40
|
-
on_all_canals_in_session(:restart) do |
|
41
|
-
trestart(
|
40
|
+
on_all_canals_in_session(:restart) do |canal|
|
41
|
+
trestart(canal)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
desc "stop", "Stop the current session"
|
46
46
|
def stop
|
47
|
-
on_all_canals_in_session(:stop) do |
|
48
|
-
tstop(
|
47
|
+
on_all_canals_in_session(:stop) do |canal|
|
48
|
+
tstop(canal)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
no_commands do
|
53
53
|
def on_all_canals_in_session(command, &block)
|
54
54
|
return if session_empty?
|
55
|
-
Canals.session.
|
56
|
-
say "#{command.to_s.capitalize} canal #{name.inspect}:", :green
|
57
|
-
block.call(
|
55
|
+
Canals.session.each_obj do |canal|
|
56
|
+
say "#{command.to_s.capitalize} canal #{canal.name.inspect}:", :green
|
57
|
+
block.call(canal)
|
58
58
|
end
|
59
59
|
say
|
60
60
|
say "#{command} done.", :green
|
@@ -87,8 +87,12 @@ module Canals
|
|
87
87
|
c = session_color(session)
|
88
88
|
val = case key
|
89
89
|
when "local_port"
|
90
|
-
|
91
|
-
|
90
|
+
if session[key.to_sym]
|
91
|
+
session[key.to_sym]
|
92
|
+
else
|
93
|
+
entry = Canals.repository.get(session[:name])
|
94
|
+
entry.local_port if entry
|
95
|
+
end
|
92
96
|
when "up"
|
93
97
|
checkmark(session_alive(session))
|
94
98
|
else
|
data/lib/canals/core.rb
CHANGED
@@ -17,13 +17,19 @@ module Canals
|
|
17
17
|
exit_code = tunnel_start(tunnel_opts)
|
18
18
|
raise Canals::Exception, "could not start tunnel" unless exit_code.success?
|
19
19
|
pid = tunnel_pid(tunnel_opts)
|
20
|
-
|
20
|
+
session_data = {name: tunnel_opts.name, pid: pid, socket: socket_file(tunnel_opts)}
|
21
|
+
session_data = tunnel_opts.to_hash(:full).merge(session_data) if tunnel_opts.adhoc
|
22
|
+
Canals.session.add(session_data)
|
21
23
|
pid.to_i
|
22
24
|
end
|
23
25
|
|
24
26
|
def stop(tunnel_opts)
|
25
27
|
if tunnel_opts.instance_of? String
|
26
|
-
|
28
|
+
if (Canals.repository.has?(tunnel_opts))
|
29
|
+
tunnel_opts = Canals.repository.get(tunnel_opts)
|
30
|
+
else
|
31
|
+
tunnel_opts = Canals.session.get_obj(tunnel_opts)
|
32
|
+
end
|
27
33
|
end
|
28
34
|
tunnel_close(tunnel_opts)
|
29
35
|
Canals.session.del(tunnel_opts.name)
|
@@ -36,7 +42,11 @@ module Canals
|
|
36
42
|
|
37
43
|
def isalive?(tunnel_opts)
|
38
44
|
if tunnel_opts.instance_of? String
|
39
|
-
|
45
|
+
if (Canals.repository.has?(tunnel_opts))
|
46
|
+
tunnel_opts = Canals.repository.get(tunnel_opts)
|
47
|
+
else
|
48
|
+
tunnel_opts = Canals.session.get_obj(tunnel_opts)
|
49
|
+
end
|
40
50
|
end
|
41
51
|
!!tunnel_pid(tunnel_opts)
|
42
52
|
end
|
data/lib/canals/environment.rb
CHANGED
@@ -7,24 +7,24 @@ module Canals
|
|
7
7
|
attr_reader :name, :user, :hostname, :pem
|
8
8
|
def initialize(args)
|
9
9
|
@args = validate?(args)
|
10
|
-
@name = @args[
|
11
|
-
@user = @args[
|
12
|
-
@hostname = @args[
|
13
|
-
@pem = @args[
|
10
|
+
@name = @args[:name]
|
11
|
+
@user = @args[:user]
|
12
|
+
@hostname = @args[:hostname]
|
13
|
+
@pem = @args[:pem]
|
14
14
|
end
|
15
15
|
|
16
16
|
def validate?(args)
|
17
|
-
vargs = args.
|
18
|
-
raise CanalEnvironmentError.new("Missing option: \"name\" in environment creation") if
|
17
|
+
vargs = args.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
18
|
+
raise CanalEnvironmentError.new("Missing option: \"name\" in environment creation") if vargs[:name].nil?
|
19
19
|
vargs
|
20
20
|
end
|
21
21
|
|
22
22
|
def default=(val)
|
23
|
-
@args[
|
23
|
+
@args[:default] = !!val
|
24
24
|
end
|
25
25
|
|
26
26
|
def is_default?
|
27
|
-
!!@args[
|
27
|
+
!!@args[:default]
|
28
28
|
end
|
29
29
|
|
30
30
|
def to_yaml
|
@@ -32,7 +32,7 @@ module Canals
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def to_hash
|
35
|
-
@args
|
35
|
+
Marshal.load(Marshal.dump(@args))
|
36
36
|
end
|
37
37
|
|
38
38
|
end
|
data/lib/canals/options.rb
CHANGED
@@ -1,19 +1,29 @@
|
|
1
1
|
require 'psych'
|
2
2
|
|
3
3
|
module Canals
|
4
|
-
|
4
|
+
CanalOptionError = Class.new StandardError
|
5
5
|
|
6
6
|
class CanalOptions
|
7
7
|
BIND_ADDRESS = "127.0.0.1"
|
8
|
-
attr_reader :name, :remote_host, :remote_port, :local_port, :env_name, :env
|
8
|
+
attr_reader :name, :remote_host, :remote_port, :local_port, :env_name, :env, :adhoc
|
9
|
+
|
10
|
+
# define setters
|
11
|
+
[:name, :local_port, :adhoc].each do |attribute|
|
12
|
+
define_method :"#{attribute}=" do |value|
|
13
|
+
@args[attribute] = value
|
14
|
+
self.instance_variable_set(:"@#{attribute}", value)
|
15
|
+
end
|
16
|
+
end
|
9
17
|
|
10
18
|
def initialize(args)
|
11
|
-
@
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
15
|
-
@
|
16
|
-
@
|
19
|
+
@original_args = validate?(args)
|
20
|
+
@args = Marshal.load(Marshal.dump(@original_args))
|
21
|
+
@name = @args[:name]
|
22
|
+
@remote_host = @args[:remote_host]
|
23
|
+
@remote_port = @args[:remote_port]
|
24
|
+
@local_port = @args[:local_port]
|
25
|
+
@adhoc = @args[:adhoc] || false
|
26
|
+
@env_name = @args[:env]
|
17
27
|
@env = Canals.repository.environment(@env_name)
|
18
28
|
end
|
19
29
|
|
@@ -22,21 +32,21 @@ module Canals
|
|
22
32
|
end
|
23
33
|
|
24
34
|
def bind_address
|
25
|
-
return @args[
|
35
|
+
return @args[:bind_address] if @args[:bind_address]
|
26
36
|
return Canals.config[:bind_address] if Canals.config[:bind_address]
|
27
37
|
return BIND_ADDRESS
|
28
38
|
end
|
29
39
|
|
30
40
|
def hostname
|
31
|
-
get_env_var(
|
41
|
+
get_env_var(:hostname)
|
32
42
|
end
|
33
43
|
|
34
44
|
def user
|
35
|
-
get_env_var(
|
45
|
+
get_env_var(:user)
|
36
46
|
end
|
37
47
|
|
38
48
|
def pem
|
39
|
-
get_env_var(
|
49
|
+
get_env_var(:pem)
|
40
50
|
end
|
41
51
|
|
42
52
|
def proxy
|
@@ -50,22 +60,28 @@ module Canals
|
|
50
60
|
Psych.dump(@args)
|
51
61
|
end
|
52
62
|
|
53
|
-
def to_hash
|
54
|
-
@args
|
63
|
+
def to_hash(mode=:basic)
|
64
|
+
args_copy = Marshal.load(Marshal.dump(@args))
|
65
|
+
args_copy.merge! exploded_options if mode == :full
|
66
|
+
args_copy
|
67
|
+
end
|
68
|
+
|
69
|
+
def exploded_options
|
70
|
+
{bind_address: bind_address, hostname: hostname, user: user, pem: pem, proxy: proxy, adhoc: adhoc}
|
55
71
|
end
|
56
72
|
|
57
73
|
private
|
58
74
|
|
59
75
|
def validate?(args)
|
60
|
-
vargs = args.
|
61
|
-
raise CanalOptionError.new("Missing option: \"name\" in canal creation") if
|
62
|
-
raise CanalOptionError.new("Missing option: \"remote_host\" in canal creation") if
|
63
|
-
raise CanalOptionError.new("Missing option: \"remote_port\" in canal creation") if
|
64
|
-
vargs[
|
65
|
-
if vargs[
|
66
|
-
vargs[
|
76
|
+
vargs = args.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
77
|
+
raise CanalOptionError.new("Missing option: \"name\" in canal creation") if vargs[:name].nil?
|
78
|
+
raise CanalOptionError.new("Missing option: \"remote_host\" in canal creation") if vargs[:remote_host].nil?
|
79
|
+
raise CanalOptionError.new("Missing option: \"remote_port\" in canal creation") if vargs[:remote_port].nil?
|
80
|
+
vargs[:remote_port] = vargs[:remote_port].to_i
|
81
|
+
if vargs[:local_port].nil?
|
82
|
+
vargs[:local_port] = vargs[:remote_port]
|
67
83
|
else
|
68
|
-
vargs[
|
84
|
+
vargs[:local_port] = vargs[:local_port].to_i
|
69
85
|
end
|
70
86
|
vargs
|
71
87
|
end
|
data/lib/canals/repository.rb
CHANGED
@@ -29,16 +29,25 @@ module Canals
|
|
29
29
|
def add(options, save=true)
|
30
30
|
@repo[TUNNELS][options.name] = options.to_hash
|
31
31
|
if options.env_name.nil? && !options.env.nil? && options.env.is_default?
|
32
|
-
@repo[TUNNELS][options.name][
|
32
|
+
@repo[TUNNELS][options.name][:env] = options.env.name
|
33
33
|
end
|
34
34
|
save! if save
|
35
35
|
end
|
36
36
|
|
37
|
+
def delete(name, save=true)
|
38
|
+
@repo[TUNNELS].delete(name)
|
39
|
+
save! if save
|
40
|
+
end
|
41
|
+
|
37
42
|
def get(name)
|
38
43
|
return nil if !@repo[:tunnels].has_key? name
|
39
44
|
CanalOptions.new(@repo[:tunnels][name])
|
40
45
|
end
|
41
46
|
|
47
|
+
def has?(name)
|
48
|
+
return @repo[:tunnels].has_key? name
|
49
|
+
end
|
50
|
+
|
42
51
|
def add_environment(environment, save=true)
|
43
52
|
if environment.is_default?
|
44
53
|
@repo[ENVIRONMENTS].each { |name, env| env.delete("default") }
|
data/lib/canals/session.rb
CHANGED
@@ -7,6 +7,8 @@ module Canals
|
|
7
7
|
include Enumerable
|
8
8
|
extend Forwardable
|
9
9
|
|
10
|
+
BASIC_FIELDS = [:name, :pid, :socket]
|
11
|
+
|
10
12
|
def initialize
|
11
13
|
@session = load_session(session_file)
|
12
14
|
end
|
@@ -17,6 +19,10 @@ module Canals
|
|
17
19
|
@session.each(&block)
|
18
20
|
end
|
19
21
|
|
22
|
+
def each_obj(&block)
|
23
|
+
@session.map{|sess| CanalOptions.new(fill_from_repository(sess))}.each(&block)
|
24
|
+
end
|
25
|
+
|
20
26
|
def empty?
|
21
27
|
@session.empty?
|
22
28
|
end
|
@@ -32,12 +38,24 @@ module Canals
|
|
32
38
|
end
|
33
39
|
|
34
40
|
def get(session_id)
|
41
|
+
sess = nil
|
35
42
|
case session_id
|
36
43
|
when Numeric
|
37
|
-
@session.find{ |s| s[:pid] == session_id }
|
44
|
+
sess = @session.find{ |s| s[:pid] == session_id }
|
38
45
|
when String
|
39
|
-
@session.find{ |s| s[:name] == session_id }
|
46
|
+
sess = @session.find{ |s| s[:name] == session_id }
|
40
47
|
end
|
48
|
+
fill_from_repository(sess) if sess
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_obj(session_id)
|
52
|
+
sess = get(session_id)
|
53
|
+
return nil if sess.nil?
|
54
|
+
CanalOptions.new(sess)
|
55
|
+
end
|
56
|
+
|
57
|
+
def has?(session_id)
|
58
|
+
get(session_id) != nil
|
41
59
|
end
|
42
60
|
|
43
61
|
def alive?(session_id)
|
@@ -65,5 +83,17 @@ module Canals
|
|
65
83
|
return Psych.load_file(_session_file)
|
66
84
|
end
|
67
85
|
|
86
|
+
def basic?(sess)
|
87
|
+
(sess.keys - BASIC_FIELDS).empty?
|
88
|
+
end
|
89
|
+
|
90
|
+
def fill_from_repository(sess)
|
91
|
+
if (basic?(sess) && Canals.repository.has?(sess[:name]))
|
92
|
+
Canals.repository.get(sess[:name]).to_hash.merge(sess)
|
93
|
+
else
|
94
|
+
sess
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
68
98
|
end
|
69
99
|
end
|
data/lib/canals/version.rb
CHANGED
@@ -67,10 +67,18 @@ describe Canals::Environment do
|
|
67
67
|
args = {"name" => name, "default" => true}
|
68
68
|
env = Canals::Environment.new(args)
|
69
69
|
expect(env.is_default?).to eq true
|
70
|
-
expect(env.to_hash[
|
70
|
+
expect(env.to_hash[:default]).to eq true
|
71
71
|
env.default = false
|
72
72
|
expect(env.is_default?).to eq false
|
73
|
-
expect(env.to_hash[
|
73
|
+
expect(env.to_hash[:default]).to eq false
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "to_hash" do
|
78
|
+
it "turns keys into symbols" do
|
79
|
+
args = {"name" => name, "default" => false}
|
80
|
+
reparsed = Canals::Environment.new(args).to_hash
|
81
|
+
expect(reparsed.keys).to all be_an(Symbol)
|
74
82
|
end
|
75
83
|
end
|
76
84
|
end
|
data/spec/canals/options_spec.rb
CHANGED
@@ -12,6 +12,7 @@ describe Canals::CanalOptions do
|
|
12
12
|
let(:hostname) { "nat.example.com" }
|
13
13
|
let(:user) { "user" }
|
14
14
|
let(:pem) { "/tmp/file.pem" }
|
15
|
+
let(:adhoc) { true }
|
15
16
|
|
16
17
|
describe "name" do
|
17
18
|
it "contains 'name'" do
|
@@ -80,6 +81,20 @@ describe Canals::CanalOptions do
|
|
80
81
|
end
|
81
82
|
end
|
82
83
|
|
84
|
+
describe "adhoc" do
|
85
|
+
it "returns 'adhoc' if 'adhoc' is availble" do
|
86
|
+
args = {"name" => name, "remote_host" => remote_host, "remote_port" => remote_port, "adhoc" => adhoc}
|
87
|
+
opt = Canals::CanalOptions.new(args)
|
88
|
+
expect(opt.adhoc).to eq adhoc
|
89
|
+
end
|
90
|
+
|
91
|
+
it "returns 'false' for 'adhoc' if 'adhoc' isn't given" do
|
92
|
+
args = {"name" => name, "remote_host" => remote_host, "remote_port" => remote_port}
|
93
|
+
opt = Canals::CanalOptions.new(args)
|
94
|
+
expect(opt.adhoc).to eq false
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
83
98
|
describe "bind_address" do
|
84
99
|
it "returns 'bind_address' if 'bind_address' is availble" do
|
85
100
|
allow(Canals.config).to receive(:[]).with(:bind_address).and_return(global_bind_address)
|
@@ -191,22 +206,60 @@ describe Canals::CanalOptions do
|
|
191
206
|
end
|
192
207
|
end
|
193
208
|
|
194
|
-
|
195
209
|
describe "to_yaml" do
|
196
210
|
it "dumps remote_port as int" do
|
197
211
|
args = {"name" => name, "remote_host" => remote_host, "remote_port" => '1234'}
|
198
212
|
yaml = Canals::CanalOptions.new(args).to_yaml
|
199
213
|
reparsed = Psych.load(yaml)
|
200
|
-
expect(reparsed[
|
201
|
-
expect(reparsed[
|
214
|
+
expect(reparsed[:remote_port]).to eq 1234
|
215
|
+
expect(reparsed[:local_port]).to eq 1234
|
202
216
|
end
|
203
217
|
|
204
218
|
it "dumps local_port as int" do
|
205
219
|
args = {"name" => name, "remote_host" => remote_host, "remote_port" => remote_port, "local_port" => "4321"}
|
206
220
|
yaml = Canals::CanalOptions.new(args).to_yaml
|
207
221
|
reparsed = Psych.load(yaml)
|
208
|
-
expect(reparsed[
|
222
|
+
expect(reparsed[:local_port]).to eq 4321
|
209
223
|
end
|
210
224
|
end
|
211
|
-
end
|
212
225
|
|
226
|
+
describe "to_hash" do
|
227
|
+
it "dumps remote_port as int" do
|
228
|
+
args = {"name" => name, "remote_host" => remote_host, "remote_port" => '1234'}
|
229
|
+
reparsed = Canals::CanalOptions.new(args).to_hash
|
230
|
+
expect(reparsed[:remote_port]).to eq 1234
|
231
|
+
expect(reparsed[:local_port]).to eq 1234
|
232
|
+
end
|
233
|
+
|
234
|
+
it "dumps local_port as int" do
|
235
|
+
args = {"name" => name, "remote_host" => remote_host, "remote_port" => remote_port, "local_port" => "4321"}
|
236
|
+
reparsed = Canals::CanalOptions.new(args).to_hash
|
237
|
+
expect(reparsed[:local_port]).to eq 4321
|
238
|
+
end
|
239
|
+
|
240
|
+
it "turns keys into symbols" do
|
241
|
+
args = {"name" => name, "remote_host" => remote_host, "remote_port" => remote_port, "local_port" => "4321"}
|
242
|
+
reparsed = Canals::CanalOptions.new(args).to_hash
|
243
|
+
expect(reparsed.keys).to all be_an(Symbol)
|
244
|
+
end
|
245
|
+
|
246
|
+
it "doesn't add function output when not passed with a 'explode' param" do
|
247
|
+
args = {"name" => name, "remote_host" => remote_host, "remote_port" => remote_port, "local_port" => "4321"}
|
248
|
+
reparsed = Canals::CanalOptions.new(args).to_hash
|
249
|
+
expect(reparsed[:bind_address]).to eq nil
|
250
|
+
end
|
251
|
+
|
252
|
+
it "doesn't add function output when passed with 'basic'" do
|
253
|
+
args = {"name" => name, "remote_host" => remote_host, "remote_port" => remote_port, "local_port" => "4321"}
|
254
|
+
reparsed = Canals::CanalOptions.new(args).to_hash :basic
|
255
|
+
expect(reparsed[:bind_address]).to eq nil
|
256
|
+
end
|
257
|
+
|
258
|
+
it "adds function output when passed with 'full'" do
|
259
|
+
allow(Canals.config).to receive(:[]).with(:bind_address).and_return(global_bind_address)
|
260
|
+
args = {"name" => name, "remote_host" => remote_host, "remote_port" => remote_port, "local_port" => "4321"}
|
261
|
+
reparsed = Canals::CanalOptions.new(args).to_hash :full
|
262
|
+
expect(reparsed[:bind_address]).to eq global_bind_address
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: canals
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ido Abramovich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
112
|
rubyforge_project: canals
|
113
|
-
rubygems_version: 2.
|
113
|
+
rubygems_version: 2.6.14
|
114
114
|
signing_key:
|
115
115
|
specification_version: 4
|
116
116
|
summary: Eases the process of creating and managing SSH tunnels
|