xlogin 0.16.4 → 0.16.8

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
  SHA256:
3
- metadata.gz: d805b70c4f761cbca785e8fa6aeed4af49144e7d7ceff3b84f1d0bcea1f03ea3
4
- data.tar.gz: fd9c8a12f3ed2cb279ec1ddd9121a4ef286ca13a1835f39ff5e0f078df12d8a5
3
+ metadata.gz: 930939a4963bb9965bf46dc7b9483ce005162a7617afd5c72bafa601b9b68450
4
+ data.tar.gz: 70208dee6029554aff44bc6d69a2b0b827bd0a202e59a00227bc7372fb16baa7
5
5
  SHA512:
6
- metadata.gz: d0ead74a4a9d12aa71be4f87957d5725719e3dfebae3d5d285fcf781852859f2a579e5d67063944d7e1308ec652ab9c6e942fa19ecbe0b304eb6002fe0b39589
7
- data.tar.gz: 46817a1959cf69e89d80d0162713f9640de2e679431d472ce5e40454e49ea2c1f6e5efa33e4f165249aa10deda9b082159db06847cb1ce0d3aa02ab0b8b81d53
6
+ metadata.gz: 76123781d2d14c27071ac279bb70628566a67e1c0a6f642e1593f2a9497ca18870ec1abb401bf34eef8304d7e3a441820fafb7e6d261f77469f2f04a2952151e
7
+ data.tar.gz: c75f987ace037ea7701180e1e46aea9979ae7810e2bac8febe09b781c106e829e97e956e22c9b515c32edd985e6abc22ba943579d5e1bd3ec1ca94e6a6dfc6c8
data/lib/xlogin/cli.rb CHANGED
@@ -42,7 +42,7 @@ module Xlogin
42
42
  loggers << ((jobs > 1)? buffer : $stdout)
43
43
  loggers << File.expand_path(File.join(config[:logdir], "#{info[:name]}.log"), ENV['PWD']) if config[:logdir]
44
44
 
45
- session = Xlogin.get(info.merge(log: loggers))
45
+ session = Xlogin.get(info.merge(log: loggers, **config[:env]))
46
46
  session.enable(session.config.enable) if session.config.enable && Xlogin.settings.enable?
47
47
 
48
48
  command_lines = config[:command].flat_map { |e| e.to_s.split(';').map(&:strip) }
@@ -60,7 +60,7 @@ module Xlogin
60
60
 
61
61
  def run(args)
62
62
  config = Hash.new
63
- config[:env] = []
63
+ config[:env] = {}
64
64
  config[:inventory] = []
65
65
  config[:template] = []
66
66
  config[:command] = []
@@ -70,23 +70,21 @@ module Xlogin
70
70
  parser.banner = "#{File.basename($0)} HOST_PATTERN [Options]"
71
71
  parser.version = Xlogin::VERSION
72
72
 
73
- parser.on('-i PATH', '--inventory', String, 'The PATH to the inventory file.') { |v| config[:inventory] << v }
74
- parser.on('-t PATH', '--template', String, 'The PATH to the template file or directory.'){ |v| config[:template] << v }
75
- parser.on('-L PATH', '--log-dir', String, 'The PATH to the log directory.') { |v| config[:logdir] = v }
76
-
77
- parser.on('-l', '--list', TrueClass, 'List the inventory.') { |v| config[:runner] = self.method(:list) }
73
+ parser.on('-i PATH', '--inventory', String, 'The PATH to the inventory file.') { |v| config[:inventory] << v }
74
+ parser.on('-t PATH', '--template', String, 'The PATH to the template file or directory.'){ |v| config[:template] << v }
75
+ parser.on('-L PATH', '--log-dir', String, 'The PATH to the log directory.') { |v| config[:logdir] = v }
76
+ parser.on('-j NUM', '--jobs', Integer, 'The NUM of jobs to execute in parallel.') { |v| config[:jobs] = v }
77
+ parser.on( '--enable', TrueClass, 'Automatically enable privilege mode.') { |v| config[:enable] = v }
78
+ parser.on('-l', '--list', TrueClass, 'List the inventory.') { |v| config[:runner] = self.method(:list) }
78
79
  parser.on('-e COMMAND', '--exec', String, 'Execute commands and quit.'){ |v| config[:runner] = self.method(:exec); config[:command] << v }
79
-
80
- parser.on('-E KEY=VAL', '--env', /(\w+=\w+)+/, 'Environment variables.') { |v| config[:env] << v }
81
- parser.on('-j NUM', '--jobs', Integer, 'The NUM of jobs to execute in parallel.'){ |v| config[:jobs] = v }
80
+ parser.on('-E KEY=VAL', '--env', /\w+=[^=]+/, 'Environment variables.') { |v| v.split('=').tap{ |k, v| config[:env].update(k.to_sym => v) } }
82
81
 
83
82
  config[:patterns] = parser.parse!(args)
84
83
  config[:inventory] << DEFAULT_INVENTORY if config[:inventory].empty?
85
84
  config[:template] << DEFAULT_TEMPLATE if config[:template].empty?
86
85
 
87
86
  Xlogin.configure do
88
- set Hash[config[:env].map{ |v| v.split('=') }]
89
-
87
+ set enable: config[:enable]
90
88
  source *config[:inventory].map{ |e| File.expand_path(e, ENV['PWD']) }
91
89
  template *config[:template].map { |e| File.expand_path(e, ENV['PWD']) }
92
90
  end
@@ -6,6 +6,10 @@ require 'xlogin/session_pool'
6
6
  require 'xlogin/template'
7
7
 
8
8
  module Xlogin
9
+
10
+ # gateway tunnel
11
+ Tunnel = Struct.new('Tunnel', :gateway, :ports)
12
+
9
13
  class Factory
10
14
 
11
15
  include Singleton
@@ -70,7 +74,7 @@ module Xlogin
70
74
  port: uri.port || 22
71
75
  )
72
76
 
73
- @tunnels[name] = Struct.new('Tunnel', :gateway, :ports).new(gateway, [])
77
+ @tunnels[name] = Xlogin::Tunnel.new(gateway, [])
74
78
  end
75
79
  end
76
80
 
@@ -10,21 +10,21 @@ module Xlogin
10
10
  class << self
11
11
  include Rake::DSL
12
12
 
13
- def all(*patterns, &block)
13
+ def all(*patterns, **opts, &block)
14
14
  description = Rake.application.last_description
15
15
  task all: Xlogin.list(*patterns).map{ |e| e[:name] }
16
16
 
17
17
  desc description
18
- generate(*patterns, &block)
18
+ generate(*patterns, **opts, &block)
19
19
  end
20
20
 
21
- def generate(*patterns, &block)
21
+ def generate(*patterns, **opts, &block)
22
22
  description = Rake.application.last_description
23
23
 
24
24
  hostnames = Xlogin.list(*patterns).map{ |e| e[:name] }
25
25
  hostnames.each do |hostname|
26
26
  desc "#{description} - #{hostname}" if description
27
- RakeTask.new(hostname, &block)
27
+ RakeTask.new(hostname, **opts, &block)
28
28
  end
29
29
  end
30
30
 
@@ -40,14 +40,13 @@ module Xlogin
40
40
  attr_reader :name
41
41
  attr_accessor :log
42
42
  attr_accessor :lock
43
- attr_accessor :timeout
44
43
  attr_accessor :silent
45
44
  attr_accessor :fail_on_error
46
45
 
47
- def initialize(name)
46
+ def initialize(name, **opts)
48
47
  @name = name
48
+ @opts = opts
49
49
  @runner = nil
50
- @timeout = nil
51
50
  @silent ||= Rake.application.options.silent
52
51
  @fail_on_error = true
53
52
 
@@ -91,7 +90,7 @@ module Xlogin
91
90
  loggers << log if log
92
91
  loggers << STDOUT if !silent && !Rake.application.options.always_multitask
93
92
 
94
- session = Xlogin.get(name, log: loggers, timeout: timeout)
93
+ session = Xlogin.get(name, log: loggers, **@opts)
95
94
  instance_exec(session, &@runner)
96
95
 
97
96
  print(buffer.string) if !silent && Rake.application.options.always_multitask
@@ -100,27 +99,25 @@ module Xlogin
100
99
  RakeTask.shutdown! if fail_on_error
101
100
 
102
101
  session.log_message(e.to_s.colorize(color: :red)) if session
103
- print(buffer.string + "\n", color: :red) if Rake.application.options.always_multitask
102
+ print(buffer.string.colorize(color: :red) + "\n") if Rake.application.options.always_multitask
104
103
  return false
105
104
  ensure
106
105
  session.close rescue nil
107
106
  end
108
107
 
109
- def puts(text, **opts)
110
- return text.each { |e| puts(e, **opts) } if text.kind_of?(Array)
111
-
112
- text = text.to_s
113
- text = text + "\n" unless text[-1] == "\n"
114
- print(text, **opts)
108
+ def puts(text)
109
+ strio = StringIO.new.tap{ |io| io.puts text }
110
+ print(strio.string)
115
111
  end
116
112
 
117
- def print(text, **opts)
118
- text = text.to_s
113
+ def print(text)
114
+ text = text.to_s.gsub("\r", '')
119
115
  return if text.empty?
120
116
 
121
- text = text.gsub("\r", '')
122
- text = text.lines.map{ |text| "#{name}\t|#{text}" }.join if Rake.application.options.always_multitask
123
- text = text.colorize(**opts)
117
+ if Rake.application.options.always_multitask
118
+ strio = StringIO.new.tap{ |io| io.puts text.lines.map{ |line| "#{name}\t|#{line}" } }
119
+ text = strio.string
120
+ end
124
121
  $stdout.print(text)
125
122
  end
126
123
 
@@ -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 = (opts[:userinfo] || uri.userinfo).to_s.split(':')
28
+ username, password = (opts[:userinfo] || ENV['USERINFO'] || uri.userinfo).to_s.split(':')
29
29
 
30
30
  begin
31
31
  args = Hash.new
@@ -1,3 +1,3 @@
1
1
  module Xlogin
2
- VERSION = "0.16.4"
2
+ VERSION = "0.16.8"
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.4
4
+ version: 0.16.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - haccht
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-11 00:00:00.000000000 Z
11
+ date: 2021-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-telnet