xlogin 0.16.3 → 0.16.4

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: 275b3d2ef47b42378243799768a5654d993a3a3f1d3c64b893367c41ea714598
4
- data.tar.gz: a4deb367df7c2c42e7330d53f4b2abfe7266d96a59dd3b4e8de0160cbe8125c9
3
+ metadata.gz: d805b70c4f761cbca785e8fa6aeed4af49144e7d7ceff3b84f1d0bcea1f03ea3
4
+ data.tar.gz: fd9c8a12f3ed2cb279ec1ddd9121a4ef286ca13a1835f39ff5e0f078df12d8a5
5
5
  SHA512:
6
- metadata.gz: 45bfb93bf676763536cb996f1f775035c14e6561888245d5d3a34eda6769da01270facb941f4c84c9a167c72cfa1440ade59c6d2bd4485d2acfeec06a138c57c
7
- data.tar.gz: 351d88211a993c21930f2e30f6435c245ee920190ba6705664cc953c79ef0640bca465b466fc10344d1e3003257adaca58001d47ec03d9bf5e3d19e5f8bfb98b
6
+ metadata.gz: d0ead74a4a9d12aa71be4f87957d5725719e3dfebae3d5d285fcf781852859f2a579e5d67063944d7e1308ec652ab9c6e942fa19ecbe0b304eb6002fe0b39589
7
+ data.tar.gz: 46817a1959cf69e89d80d0162713f9640de2e679431d472ce5e40454e49ea2c1f6e5efa33e4f165249aa10deda9b082159db06847cb1ce0d3aa02ab0b8b81d53
data/lib/xlogin.rb CHANGED
@@ -30,22 +30,16 @@ module Xlogin
30
30
  end
31
31
 
32
32
  def get(args, **opts, &block)
33
- session = case args
34
- when Hash then factory.build(**args.merge(**opts))
35
- when String then factory.build_from_hostname(args, **opts)
36
- else
37
- raise Xlogin::Error.new("Invalid argument: '#{args}'")
38
- end
39
-
40
- return session unless block
41
- begin block.call(session) ensure session.close end
33
+ case args
34
+ when Hash then factory.build(**args.merge(**opts), &block)
35
+ when String then factory.build_from_hostname(args, **opts, &block)
36
+ else
37
+ raise Xlogin::Error.new("Invalid argument: '#{args}'")
38
+ end
42
39
  end
43
40
 
44
41
  def pool(args, **opts, &block)
45
- pool = factory.build_pool(args, **opts)
46
-
47
- return pool unless block
48
- begin block.call(pool) ensure pool.close end
42
+ factory.build_pool(args, **opts, &block)
49
43
  end
50
44
 
51
45
  def configure(&block)
@@ -93,22 +93,26 @@ module Xlogin
93
93
  end
94
94
  end
95
95
 
96
- def build(type:, **opts)
96
+ def build(type:, **opts, &block)
97
97
  template = get_template(type)
98
98
  raise Xlogin::Error.new("Template not found: '#{type}'") unless template
99
99
 
100
- template.build(uri(opts), **opts)
100
+ session = template.build(uri(opts), **opts)
101
+ return session unless block
102
+ begin block.call(session) ensure session.close end
101
103
  end
102
104
 
103
- def build_pool(args, **opts)
104
- Xlogin::SessionPool.new(args, **opts)
105
+ def build_pool(args, **opts, &block)
106
+ pool = Xlogin::SessionPool.new(args, **opts)
107
+ return pool unless block
108
+ begin block.call(pool) ensure pool.close end
105
109
  end
106
110
 
107
- def build_from_hostname(args, **opts)
111
+ def build_from_hostname(args, **opts, &block)
108
112
  hostinfo = get_hostinfo(args)
109
113
  raise Xlogin::Error.new("Host not found: '#{args}'") unless hostinfo
110
114
 
111
- build(**hostinfo.merge(**opts))
115
+ build(**hostinfo.merge(**opts), &block)
112
116
  end
113
117
 
114
118
  def method_missing(method_name, *args, **opts, &block)
@@ -10,9 +10,9 @@ module Xlogin
10
10
 
11
11
  def initialize(template, uri, **opts)
12
12
  @uri = uri
13
- @host = uri.host
14
- @port = uri.port
15
- @port ||= case @uri.scheme
13
+ @host = opts[:host] || uri.host
14
+ @port = opts[:port] || uri.port
15
+ @port ||= case opts[:scheme] || uri.scheme
16
16
  when 'ssh' then 22
17
17
  when 'telnet' then 23
18
18
  end
@@ -25,7 +25,7 @@ module Xlogin
25
25
  @host, @port = Xlogin.factory.open_tunnel(@tunnel, @host, @port) if @tunnel
26
26
 
27
27
  num_try = 0
28
- username, password = uri.userinfo.to_s.split(':')
28
+ username, password = (opts[:userinfo] || uri.userinfo).to_s.split(':')
29
29
 
30
30
  begin
31
31
  args = Hash.new
@@ -64,11 +64,9 @@ module Xlogin
64
64
  Regexp.union(*@template.prompts.map(&:first))
65
65
  end
66
66
 
67
- def duplicate(type: @template.name, **args)
68
- template = Xlogin::Factory.instance.get_template(type)
69
- raise Xlogin::Error.new("Template not found: '#{type}'") unless template
70
-
71
- template.build(@uri, **@config.to_h.merge(args))
67
+ def duplicate(type: @template.name, uri: @uri.dup, **args, &block)
68
+ args = @config.to_h.merge(args)
69
+ Xlogin::Factory.instance.build(type: type, uri: uri, **args, &block)
72
70
  end
73
71
 
74
72
  def puts(string = '', &block)
@@ -1,3 +1,3 @@
1
1
  module Xlogin
2
- VERSION = "0.16.3"
2
+ VERSION = "0.16.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xlogin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.3
4
+ version: 0.16.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - haccht
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-20 00:00:00.000000000 Z
11
+ date: 2021-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-telnet