train 3.2.14 → 3.2.20
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
- metadata +29 -149
- data/LICENSE +0 -201
- data/lib/train.rb +0 -193
- data/lib/train/errors.rb +0 -44
- data/lib/train/extras.rb +0 -11
- data/lib/train/extras/command_wrapper.rb +0 -201
- data/lib/train/extras/stat.rb +0 -136
- data/lib/train/file.rb +0 -212
- data/lib/train/file/local.rb +0 -82
- data/lib/train/file/local/unix.rb +0 -96
- data/lib/train/file/local/windows.rb +0 -68
- data/lib/train/file/remote.rb +0 -40
- data/lib/train/file/remote/aix.rb +0 -29
- data/lib/train/file/remote/linux.rb +0 -21
- data/lib/train/file/remote/qnx.rb +0 -41
- data/lib/train/file/remote/unix.rb +0 -110
- data/lib/train/file/remote/windows.rb +0 -110
- data/lib/train/globals.rb +0 -5
- data/lib/train/options.rb +0 -81
- data/lib/train/platforms.rb +0 -102
- data/lib/train/platforms/common.rb +0 -34
- data/lib/train/platforms/detect.rb +0 -12
- data/lib/train/platforms/detect/helpers/os_common.rb +0 -160
- data/lib/train/platforms/detect/helpers/os_linux.rb +0 -80
- data/lib/train/platforms/detect/helpers/os_windows.rb +0 -142
- data/lib/train/platforms/detect/scanner.rb +0 -85
- data/lib/train/platforms/detect/specifications/api.rb +0 -20
- data/lib/train/platforms/detect/specifications/os.rb +0 -629
- data/lib/train/platforms/detect/uuid.rb +0 -32
- data/lib/train/platforms/family.rb +0 -31
- data/lib/train/platforms/platform.rb +0 -109
- data/lib/train/plugin_test_helper.rb +0 -51
- data/lib/train/plugins.rb +0 -40
- data/lib/train/plugins/base_connection.rb +0 -198
- data/lib/train/plugins/transport.rb +0 -49
- data/lib/train/transports/cisco_ios_connection.rb +0 -133
- data/lib/train/transports/local.rb +0 -240
- data/lib/train/transports/mock.rb +0 -183
- data/lib/train/transports/ssh.rb +0 -271
- data/lib/train/transports/ssh_connection.rb +0 -342
- data/lib/train/version.rb +0 -7
@@ -1,68 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Train
|
4
|
-
class File
|
5
|
-
class Local
|
6
|
-
class Windows < Train::File::Local
|
7
|
-
# Ensures we do not use invalid characters for file names
|
8
|
-
# @see https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#naming_conventions
|
9
|
-
def sanitize_filename(path)
|
10
|
-
return if path.nil?
|
11
|
-
|
12
|
-
# we do not filter :, backslash and forward slash, since they are part of the path
|
13
|
-
@spath = path.gsub(/[<>"|?*]/, "")
|
14
|
-
end
|
15
|
-
|
16
|
-
def product_version
|
17
|
-
@product_version ||= @backend.run_command(
|
18
|
-
"[System.Diagnostics.FileVersionInfo]::GetVersionInfo(\"#{@spath}\").ProductVersion"
|
19
|
-
).stdout.chomp
|
20
|
-
end
|
21
|
-
|
22
|
-
def file_version
|
23
|
-
@file_version ||= @backend.run_command(
|
24
|
-
"[System.Diagnostics.FileVersionInfo]::GetVersionInfo(\"#{@spath}\").FileVersion"
|
25
|
-
).stdout.chomp
|
26
|
-
end
|
27
|
-
|
28
|
-
def owner
|
29
|
-
owner = @backend.run_command(
|
30
|
-
"Get-Acl \"#{@spath}\" | select -expand Owner"
|
31
|
-
).stdout.strip
|
32
|
-
return if owner.empty?
|
33
|
-
|
34
|
-
owner
|
35
|
-
end
|
36
|
-
|
37
|
-
def stat
|
38
|
-
return @stat if defined?(@stat)
|
39
|
-
|
40
|
-
begin
|
41
|
-
file_stat =
|
42
|
-
if @follow_symlink
|
43
|
-
::File.stat(@path)
|
44
|
-
else
|
45
|
-
::File.lstat(@path)
|
46
|
-
end
|
47
|
-
rescue StandardError => _err
|
48
|
-
return @stat = {}
|
49
|
-
end
|
50
|
-
|
51
|
-
@stat = {
|
52
|
-
type: type,
|
53
|
-
mode: file_stat.mode,
|
54
|
-
mtime: file_stat.mtime.to_i,
|
55
|
-
size: file_stat.size,
|
56
|
-
owner: owner,
|
57
|
-
uid: file_stat.uid,
|
58
|
-
group: nil,
|
59
|
-
gid: file_stat.gid,
|
60
|
-
selinux_label: nil,
|
61
|
-
}
|
62
|
-
|
63
|
-
@stat
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
data/lib/train/file/remote.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Train
|
4
|
-
class File
|
5
|
-
class Remote < Train::File
|
6
|
-
def basename(suffix = nil, sep = "/")
|
7
|
-
raise "Not yet supported: Suffix in file.basename" unless suffix.nil?
|
8
|
-
|
9
|
-
@basename ||= detect_filename(path, sep || "/")
|
10
|
-
end
|
11
|
-
|
12
|
-
def stat
|
13
|
-
return @stat if defined?(@stat)
|
14
|
-
|
15
|
-
@stat = Train::Extras::Stat.stat(@spath, @backend, @follow_symlink)
|
16
|
-
end
|
17
|
-
|
18
|
-
# helper methods provided to any implementing class
|
19
|
-
private
|
20
|
-
|
21
|
-
def detect_filename(path, sep)
|
22
|
-
idx = path.rindex(sep)
|
23
|
-
return path if idx.nil?
|
24
|
-
|
25
|
-
idx += 1
|
26
|
-
return detect_filename(path[0..-2], sep) if idx == path.length
|
27
|
-
|
28
|
-
path[idx..-1]
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
# subclass requires are loaded after Train::File::Remote is defined
|
35
|
-
# to avoid superclass mismatch errors
|
36
|
-
require_relative "remote/aix"
|
37
|
-
require_relative "remote/linux"
|
38
|
-
require_relative "remote/qnx"
|
39
|
-
require_relative "remote/unix"
|
40
|
-
require_relative "remote/windows"
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require_relative "unix"
|
4
|
-
|
5
|
-
module Train
|
6
|
-
class File
|
7
|
-
class Remote
|
8
|
-
class Aix < Train::File::Remote::Unix
|
9
|
-
def link_path
|
10
|
-
return nil unless symlink?
|
11
|
-
|
12
|
-
@link_path ||=
|
13
|
-
@backend.run_command("perl -e 'print readlink shift' #{@spath}").stdout.chomp
|
14
|
-
end
|
15
|
-
|
16
|
-
def shallow_link_path
|
17
|
-
return nil unless symlink?
|
18
|
-
|
19
|
-
@shallow_link_path ||=
|
20
|
-
@backend.run_command("perl -e 'print readlink shift' #{@spath}").stdout.chomp
|
21
|
-
end
|
22
|
-
|
23
|
-
def mounted
|
24
|
-
@mounted ||= @backend.run_command("lsfs -c #{@spath}")
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require_relative "unix"
|
4
|
-
|
5
|
-
module Train
|
6
|
-
class File
|
7
|
-
class Remote
|
8
|
-
class Linux < Train::File::Remote::Unix
|
9
|
-
def content
|
10
|
-
return @content if defined?(@content)
|
11
|
-
|
12
|
-
@content = @backend.run_command("cat #{@spath} || echo -n").stdout
|
13
|
-
return @content unless @content.empty?
|
14
|
-
|
15
|
-
@content = nil if directory? || size.nil? || (size > 0)
|
16
|
-
@content
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
|
-
# author: Christoph Hartmann
|
4
|
-
# author: Dominik Richter
|
5
|
-
|
6
|
-
require_relative "unix"
|
7
|
-
|
8
|
-
module Train
|
9
|
-
class File
|
10
|
-
class Remote
|
11
|
-
class Qnx < Train::File::Remote::Unix
|
12
|
-
def content
|
13
|
-
cat = "cat"
|
14
|
-
cat = "/proc/boot/cat" if @backend.os[:release].to_i >= 7
|
15
|
-
@content ||= case
|
16
|
-
when !exist?
|
17
|
-
nil
|
18
|
-
else
|
19
|
-
@backend.run_command("#{cat} #{@spath}").stdout || ""
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def type
|
24
|
-
if @backend.run_command("file #{@spath}").stdout.include?("directory")
|
25
|
-
:directory
|
26
|
-
else
|
27
|
-
:file
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
%w{
|
32
|
-
mode owner group uid gid mtime size selinux_label link_path mounted stat
|
33
|
-
}.each do |field|
|
34
|
-
define_method field.to_sym do
|
35
|
-
raise NotImplementedError, "QNX does not implement the #{field}() method yet."
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,110 +0,0 @@
|
|
1
|
-
require "shellwords"
|
2
|
-
|
3
|
-
module Train
|
4
|
-
class File
|
5
|
-
class Remote
|
6
|
-
class Unix < Train::File::Remote
|
7
|
-
def sanitize_filename(path)
|
8
|
-
@spath = Shellwords.escape(path) || @path
|
9
|
-
end
|
10
|
-
|
11
|
-
def content
|
12
|
-
@content ||=
|
13
|
-
if !exist? || directory?
|
14
|
-
nil
|
15
|
-
elsif size.nil? || size == 0
|
16
|
-
""
|
17
|
-
else
|
18
|
-
@backend.run_command("cat #{@spath}").stdout || ""
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def exist?
|
23
|
-
@exist ||= begin
|
24
|
-
f = @follow_symlink ? "" : " || test -L #{@spath}"
|
25
|
-
@backend.run_command("test -e #{@spath}" + f)
|
26
|
-
.exit_status == 0
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def mounted
|
31
|
-
@mounted ||=
|
32
|
-
@backend.run_command("mount | grep -- ' on #{@path} '")
|
33
|
-
end
|
34
|
-
|
35
|
-
%w{
|
36
|
-
type mode owner group uid gid mtime size selinux_label
|
37
|
-
}.each do |field|
|
38
|
-
define_method field.to_sym do
|
39
|
-
stat[field.to_sym]
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def mode?(sth)
|
44
|
-
mode == sth
|
45
|
-
end
|
46
|
-
|
47
|
-
def grouped_into?(sth)
|
48
|
-
group == sth
|
49
|
-
end
|
50
|
-
|
51
|
-
def linked_to?(dst)
|
52
|
-
link_path == dst
|
53
|
-
end
|
54
|
-
|
55
|
-
def link_path
|
56
|
-
symlink? ? path : nil
|
57
|
-
end
|
58
|
-
|
59
|
-
def shallow_link_path
|
60
|
-
return nil unless symlink?
|
61
|
-
|
62
|
-
@shallow_link_path ||=
|
63
|
-
@backend.run_command("readlink #{@spath}").stdout.chomp
|
64
|
-
end
|
65
|
-
|
66
|
-
def unix_mode_mask(owner, type)
|
67
|
-
o = UNIX_MODE_OWNERS[owner.to_sym]
|
68
|
-
return nil if o.nil?
|
69
|
-
|
70
|
-
t = UNIX_MODE_TYPES[type.to_sym]
|
71
|
-
return nil if t.nil?
|
72
|
-
|
73
|
-
t & o
|
74
|
-
end
|
75
|
-
|
76
|
-
def path
|
77
|
-
return @path unless @follow_symlink && symlink?
|
78
|
-
|
79
|
-
@link_path ||= read_target_path
|
80
|
-
end
|
81
|
-
|
82
|
-
private
|
83
|
-
|
84
|
-
# Returns full path of a symlink target(real dest) or '' on symlink loop
|
85
|
-
def read_target_path
|
86
|
-
full_path = @backend.run_command("readlink -n #{@spath} -f").stdout
|
87
|
-
# Needed for some OSes like OSX that returns relative path
|
88
|
-
# when the link and target are in the same directory
|
89
|
-
if !full_path.start_with?("/") && full_path != ""
|
90
|
-
full_path = ::File.expand_path("../#{full_path}", @spath)
|
91
|
-
end
|
92
|
-
full_path
|
93
|
-
end
|
94
|
-
|
95
|
-
UNIX_MODE_OWNERS = {
|
96
|
-
all: 00777,
|
97
|
-
owner: 00700,
|
98
|
-
group: 00070,
|
99
|
-
other: 00007,
|
100
|
-
}.freeze
|
101
|
-
|
102
|
-
UNIX_MODE_TYPES = {
|
103
|
-
r: 00444,
|
104
|
-
w: 00222,
|
105
|
-
x: 00111,
|
106
|
-
}.freeze
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
@@ -1,110 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Train
|
4
|
-
class File
|
5
|
-
class Remote
|
6
|
-
class Windows < Train::File::Remote
|
7
|
-
attr_reader :path
|
8
|
-
# Ensures we do not use invalid characters for file names
|
9
|
-
# @see https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#naming_conventions
|
10
|
-
def sanitize_filename(path)
|
11
|
-
return if path.nil?
|
12
|
-
|
13
|
-
# we do not filter :, backslash and forward slash, since they are part of the path
|
14
|
-
@spath = path.gsub(/[<>"|?*]/, "")
|
15
|
-
end
|
16
|
-
|
17
|
-
def basename(suffix = nil, sep = '\\')
|
18
|
-
super(suffix, sep)
|
19
|
-
end
|
20
|
-
|
21
|
-
def content
|
22
|
-
return @content if defined?(@content)
|
23
|
-
|
24
|
-
@content = @backend.run_command("Get-Content(\"#{@spath}\") | Out-String").stdout
|
25
|
-
return @content unless @content.empty?
|
26
|
-
|
27
|
-
@content = nil if directory? # or size.nil? or size > 0
|
28
|
-
@content
|
29
|
-
end
|
30
|
-
|
31
|
-
def exist?
|
32
|
-
return @exist if defined?(@exist)
|
33
|
-
|
34
|
-
@exist = @backend.run_command(
|
35
|
-
"(Test-Path -Path \"#{@spath}\").ToString()"
|
36
|
-
).stdout.chomp == "True"
|
37
|
-
end
|
38
|
-
|
39
|
-
def owner
|
40
|
-
owner = @backend.run_command(
|
41
|
-
"Get-Acl \"#{@spath}\" | select -expand Owner"
|
42
|
-
).stdout.strip
|
43
|
-
return if owner.empty?
|
44
|
-
|
45
|
-
owner
|
46
|
-
end
|
47
|
-
|
48
|
-
def type
|
49
|
-
if attributes.include?("Archive") && !attributes.include?("Directory")
|
50
|
-
return :file
|
51
|
-
elsif attributes.include?("ReparsePoint")
|
52
|
-
return :symlink
|
53
|
-
elsif attributes.include?("Directory")
|
54
|
-
return :directory
|
55
|
-
end
|
56
|
-
|
57
|
-
:unknown
|
58
|
-
end
|
59
|
-
|
60
|
-
def size
|
61
|
-
if file?
|
62
|
-
@backend.run_command("((Get-Item '#{@spath}').Length)").stdout.strip.to_i
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def product_version
|
67
|
-
@product_version ||= @backend.run_command(
|
68
|
-
"[System.Diagnostics.FileVersionInfo]::GetVersionInfo(\"#{@spath}\").ProductVersion"
|
69
|
-
).stdout.chomp
|
70
|
-
end
|
71
|
-
|
72
|
-
def file_version
|
73
|
-
@file_version ||= @backend.run_command(
|
74
|
-
"[System.Diagnostics.FileVersionInfo]::GetVersionInfo(\"#{@spath}\").FileVersion"
|
75
|
-
).stdout.chomp
|
76
|
-
end
|
77
|
-
|
78
|
-
%w{
|
79
|
-
mode group uid gid mtime selinux_label
|
80
|
-
}.each do |field|
|
81
|
-
define_method field.to_sym do
|
82
|
-
nil
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def link_path
|
87
|
-
nil
|
88
|
-
end
|
89
|
-
|
90
|
-
def shallow_link_path
|
91
|
-
nil
|
92
|
-
end
|
93
|
-
|
94
|
-
def mounted
|
95
|
-
nil
|
96
|
-
end
|
97
|
-
|
98
|
-
private
|
99
|
-
|
100
|
-
def attributes
|
101
|
-
return @attributes if defined?(@attributes)
|
102
|
-
|
103
|
-
@attributes = @backend.run_command(
|
104
|
-
"(Get-ItemProperty -Path \"#{@spath}\").attributes.ToString()"
|
105
|
-
).stdout.chomp.split(/\s*,\s*/)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
data/lib/train/globals.rb
DELETED
data/lib/train/options.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
|
-
# Author:: Dominik Richter (<dominik.richter@gmail.com>)
|
4
|
-
# Author:: Christoph Hartmann (<chris@lollyrock.com>)
|
5
|
-
|
6
|
-
module Train
|
7
|
-
module Options
|
8
|
-
def self.attach(target)
|
9
|
-
target.class.method(:include).call(ClassOptions)
|
10
|
-
target.method(:include).call(InstanceOptions)
|
11
|
-
end
|
12
|
-
|
13
|
-
module ClassOptions
|
14
|
-
def option(name, conf = nil, &block)
|
15
|
-
d = conf || {}
|
16
|
-
unless d.is_a? Hash
|
17
|
-
raise Train::ClientError,
|
18
|
-
"The transport plugin #{self} declared an option #{name} "\
|
19
|
-
"and didn't provide a valid configuration hash."
|
20
|
-
end
|
21
|
-
|
22
|
-
if !conf.nil? && !conf[:default].nil? && block_given?
|
23
|
-
raise Train::ClientError,
|
24
|
-
"The transport plugin #{self} declared an option #{name} "\
|
25
|
-
"with both a default value and block. Only use one of these."
|
26
|
-
end
|
27
|
-
|
28
|
-
d[:default] = block if block_given?
|
29
|
-
|
30
|
-
default_options[name] = d
|
31
|
-
end
|
32
|
-
|
33
|
-
def default_options
|
34
|
-
@default_options = {} unless defined? @default_options
|
35
|
-
@default_options
|
36
|
-
end
|
37
|
-
|
38
|
-
def include_options(other)
|
39
|
-
unless other.respond_to?(:default_options)
|
40
|
-
raise "Trying to include options from module #{other.inspect}, "\
|
41
|
-
"which doesn't seem to support options."
|
42
|
-
end
|
43
|
-
default_options.merge!(other.default_options)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
module InstanceOptions
|
48
|
-
# @return [Hash] options, which created this Transport
|
49
|
-
attr_reader :options
|
50
|
-
|
51
|
-
def default_options
|
52
|
-
self.class.default_options
|
53
|
-
end
|
54
|
-
|
55
|
-
def merge_options(base, opts)
|
56
|
-
res = base.merge(opts || {})
|
57
|
-
default_options.each do |field, hm|
|
58
|
-
next unless res[field].nil? && hm.key?(:default)
|
59
|
-
|
60
|
-
default = hm[:default]
|
61
|
-
if default.is_a? Proc
|
62
|
-
res[field] = default.call(res)
|
63
|
-
else
|
64
|
-
res[field] = default
|
65
|
-
end
|
66
|
-
end
|
67
|
-
res
|
68
|
-
end
|
69
|
-
|
70
|
-
def validate_options(opts)
|
71
|
-
default_options.each do |field, hm|
|
72
|
-
if opts[field].nil? && hm[:required]
|
73
|
-
raise Train::ClientError,
|
74
|
-
"You must provide a value for #{field.to_s.inspect}."
|
75
|
-
end
|
76
|
-
end
|
77
|
-
opts
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|