xlogin 0.6.8 → 0.6.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 95893b3808428acd30e3bc7f48ea6d4b38771c97
4
- data.tar.gz: 257cdc2bfb9c90785fe629586c4d1eaccb18f285
3
+ metadata.gz: 75d402374e5972bce07f0ac01e3820b5dc2fefce
4
+ data.tar.gz: 090694e751d61df9fd82171cccc3c30cd1d7a39c
5
5
  SHA512:
6
- metadata.gz: c73ab2e886935518c13cb8be9aa085854745ecdc61c5eaa171fc4400a43ae68f9e230d8feb3f753da4ad1b1f221b11830492d2cc9b42d668c7f11f1f2eeb1afb
7
- data.tar.gz: 7603d4a210ff9b6f549833a9271d320c2cb5b6dbd19308727eafa2b5411e58a400de8cc4a37fd2cb4f2ce111fce7e6a775ffa256ba91d6ceb2e9a926efb1da06
6
+ metadata.gz: 2c889806f57f4ad19aed91669d0da9d7705971c36ea7286892cc7ef698efc909d8021e9c2e2fb4f648356e1022e847ecd268b44b77a5aafd6ccaa13dbcfbe2c5
7
+ data.tar.gz: acee4ae670d5b8af241703b1d0f896446d22482ca787ccc411a9ba9cbce1b1259c03ac86ebeb0cad2160c106ef117e2b75ac3468249ec234e9acb2023fa46eca
data/lib/xlogin/cli.rb CHANGED
@@ -35,7 +35,7 @@ module Xlogin
35
35
  parser.on('-i PATH', '--inventory', String, 'The PATH to the inventory file (default: $HOME/.xloginrc).') { |v| config.inventory = v }
36
36
  parser.on('-t PATH', '--template', String, 'The PATH to the template file.') { |v| config.templates << v }
37
37
  parser.on('-T DIRECTORY', '--template-dir', String, 'The DIRECTORY to the template files.') { |v| config.templates += Dir.glob(File.join(v, '*.rb')) }
38
- parser.on('-l [DIRECTORY]', '--log', String, 'The DIRECTORY to the output log file (default: $PWD/log).') { |v| config.logdir = v || Dir.pwd }
38
+ parser.on('-l [DIRECTORY]', '--log', String, 'The DIRECTORY to the output log file (default: $PWD/log).') { |v| config.logdir = v || ENV['PWD'] }
39
39
 
40
40
  parser.on('-p NUM', '--parallels', Integer, 'The NUM of the threads. (default: 5).') { |v| config.parallels = v }
41
41
  parser.on('-e', '--enable', TrueClass, 'Try to gain enable priviledge.') { |v| config.enable = v }
@@ -51,7 +51,7 @@ module Xlogin
51
51
  end
52
52
 
53
53
  def get_template(name)
54
- @templates[name.to_s.downcase] ||= Xlogin::Template.new
54
+ @templates[name.to_s.downcase] ||= Xlogin::Template.new(name)
55
55
  end
56
56
 
57
57
  def list_templates
@@ -23,10 +23,10 @@ module Xlogin
23
23
  end
24
24
 
25
25
  @username, @password = uri.userinfo.to_s.split(':')
26
- raise ArgumentError.new('Device hostname or port not specified.') unless @host && @port
26
+ raise ArgumentError.new("Invalid URI - '#{uri}'") unless @host && @port
27
27
 
28
- @output_logs = opts.log
29
- @output_loggers = prebuild_loggers
28
+ @output_logs = opts.log
29
+ @output_loggers = build_loggers
30
30
 
31
31
  ssh_tunnel(opts.via) if opts.via
32
32
  max_retry = opts.retry || 1
@@ -46,6 +46,10 @@ module Xlogin
46
46
  end
47
47
  end
48
48
 
49
+ def type
50
+ @template.name
51
+ end
52
+
49
53
  def prompt
50
54
  cmd('').lines.last.chomp
51
55
  end
@@ -63,14 +67,14 @@ module Xlogin
63
67
  end
64
68
 
65
69
  def respond_to_missing?(name, _)
66
- @template.methods[name]
70
+ !!@template.methods[name]
67
71
  end
68
72
 
69
73
  def waitfor(*expect, &block)
70
74
  return waitfor(Regexp.union(*@template.prompt.map(&:first)), &block) if expect.empty?
71
75
 
72
76
  line = super(*expect) do |recvdata|
73
- output(recvdata, &block)
77
+ output_log(recvdata, &block)
74
78
  end
75
79
 
76
80
  _, process = @template.prompt.find { |r, p| r =~ line && p }
@@ -89,22 +93,22 @@ module Xlogin
89
93
 
90
94
  def dup
91
95
  uri = URI::Generic.build(@scheme, [@username, @password].compact.join(':'), @host, @port)
92
- self.class.new(@template, uri, **opts.to_h)
96
+ @template.build(uri, **opts.to_h)
93
97
  end
94
98
 
95
99
  def enable_log(out = $stdout)
96
- @output_loggers = prebuild_loggers(@output_logs + [out])
100
+ @output_loggers = build_loggers(@output_logs + [out])
97
101
  if block_given?
98
102
  yield
99
- @output_loggers = prebuild_loggers
103
+ @output_loggers = build_loggers
100
104
  end
101
105
  end
102
106
 
103
107
  def disable_log(out = $stdout)
104
- @output_loggers = prebuild_loggers(@output_logs - [out])
108
+ @output_loggers = build_loggers(@output_logs - [out])
105
109
  if block_given?
106
110
  yield
107
- @output_loggers = prebuild_loggers
111
+ @output_loggers = build_loggers
108
112
  end
109
113
  end
110
114
 
@@ -126,11 +130,11 @@ module Xlogin
126
130
  end
127
131
  end
128
132
 
129
- def output(text, &block)
133
+ def output_log(text, &block)
130
134
  [*@output_loggers, block].compact.each { |logger| logger.call(text) }
131
135
  end
132
136
 
133
- def prebuild_loggers(output_logs = @output_logs)
137
+ def build_loggers(output_logs = @output_logs)
134
138
  [output_logs].flatten.compact.uniq.map do |output_log|
135
139
  logger = case output_log
136
140
  when String
data/lib/xlogin/ssh.rb CHANGED
@@ -4,7 +4,7 @@ require 'xlogin/session'
4
4
  module Xlogin
5
5
  class Ssh < Net::SSH::Telnet
6
6
 
7
- include SessionModule
7
+ prepend SessionModule
8
8
 
9
9
  def interact!
10
10
  raise 'Not implemented'
data/lib/xlogin/telnet.rb CHANGED
@@ -16,8 +16,8 @@ module Xlogin
16
16
  super(params)
17
17
 
18
18
  if username || password
19
- return login(username, password) if respond_to?(:login)
20
- telnet_login(username, password)
19
+ return login(*[username, password].compact) if respond_to?(:login)
20
+ telnet_login(*[username, password].compact)
21
21
  end
22
22
  end
23
23
 
@@ -7,11 +7,12 @@ module Xlogin
7
7
 
8
8
  DEFAULT_TIMEOUT = 10
9
9
  DEFAULT_PROMPT = /[$%#>] ?\z/n
10
- BINDABLE_METHODS = %i( login logout enable delegate )
10
+ RESERVED_METHODS = %i( login logout enable delegate )
11
11
 
12
12
  attr_reader :methods
13
13
 
14
- def initialize
14
+ def initialize(name)
15
+ @name = name
15
16
  @timeout = DEFAULT_TIMEOUT
16
17
  @prompts = Array.new
17
18
  @methods = Hash.new
@@ -45,7 +46,7 @@ module Xlogin
45
46
  end
46
47
 
47
48
  def method_missing(name, *, &block)
48
- super unless BINDABLE_METHODS.include? name
49
+ super unless RESERVED_METHODS.include? name
49
50
  bind(name) { |*args| instance_exec(*args, &block) }
50
51
  end
51
52
  end
@@ -1,3 +1,3 @@
1
1
  module Xlogin
2
- VERSION = "0.6.8"
2
+ VERSION = "0.6.9"
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.6.8
4
+ version: 0.6.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - haccht
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-25 00:00:00.000000000 Z
11
+ date: 2017-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-telnet
@@ -164,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
164
  version: '0'
165
165
  requirements: []
166
166
  rubyforge_project:
167
- rubygems_version: 2.6.11
167
+ rubygems_version: 2.4.5.2
168
168
  signing_key:
169
169
  specification_version: 4
170
170
  summary: rancid clogin alternative