train 2.1.13 → 2.1.19

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.
@@ -19,8 +19,13 @@ module Train::Platforms
19
19
 
20
20
  def title(title = nil)
21
21
  return @title if title.nil?
22
+
22
23
  @title = title
23
24
  self
24
25
  end
26
+
27
+ def inspect
28
+ "%p[%s]" % [self.class, name]
29
+ end
25
30
  end
26
31
  end
@@ -65,6 +65,7 @@ module Train::Platforms
65
65
 
66
66
  def title(title = nil)
67
67
  return @title if title.nil?
68
+
68
69
  @title = title
69
70
  self
70
71
  end
@@ -73,10 +74,6 @@ module Train::Platforms
73
74
  @platform
74
75
  end
75
76
 
76
- def cisco_ios? # TODO: kinda a hack. needed to prevent tests from corrupting.
77
- false
78
- end
79
-
80
77
  # Add generic family? and platform methods to an existing platform
81
78
  #
82
79
  # This is done later to add any custom
@@ -88,8 +85,11 @@ module Train::Platforms
88
85
  # Add in family methods
89
86
  family_list = Train::Platforms.families
90
87
  family_list.each_value do |k|
91
- next if respond_to?(k.name + "?")
92
- define_singleton_method(k.name + "?") do
88
+ name = "#{k.name}?"
89
+
90
+ next if respond_to?(name)
91
+
92
+ define_singleton_method(name) do
93
93
  family_hierarchy.include?(k.name)
94
94
  end
95
95
  end
@@ -97,6 +97,7 @@ module Train::Platforms
97
97
  # Helper methods for direct platform info
98
98
  @platform.each_key do |m|
99
99
  next if respond_to?(m)
100
+
100
101
  define_singleton_method(m) do
101
102
  @platform[m]
102
103
  end
@@ -105,6 +106,7 @@ module Train::Platforms
105
106
  # Create method for name if its not already true
106
107
  m = name + "?"
107
108
  return if respond_to?(m)
109
+
108
110
  define_singleton_method(m) do
109
111
  true
110
112
  end
@@ -31,9 +31,9 @@ module Train
31
31
  def self.plugin(version = 1)
32
32
  if version != 1
33
33
  raise ClientError,
34
- "Only understand train plugin version 1. You are trying to "\
35
- "initialize a train plugin #{version}, which is not supported "\
36
- "in the current release of train."
34
+ "Only understand train plugin version 1. You are trying to "\
35
+ "initialize a train plugin #{version}, which is not supported "\
36
+ "in the current release of train."
37
37
  end
38
38
  ::Train::Plugins::Transport
39
39
  end
@@ -65,11 +65,13 @@ class Train::Plugins::Transport
65
65
  # :api_call, :file and :command types
66
66
  def enable_cache(type)
67
67
  raise Train::UnknownCacheType, "#{type} is not a valid cache type" unless @cache_enabled.keys.include?(type.to_sym)
68
+
68
69
  @cache_enabled[type.to_sym] = true
69
70
  end
70
71
 
71
72
  def disable_cache(type)
72
73
  raise Train::UnknownCacheType, "#{type} is not a valid cache type" unless @cache_enabled.keys.include?(type.to_sym)
74
+
73
75
  @cache_enabled[type.to_sym] = false
74
76
  clear_cache(type.to_sym)
75
77
  end
@@ -101,6 +103,10 @@ class Train::Plugins::Transport
101
103
  plat
102
104
  end
103
105
 
106
+ def inspect
107
+ "%s[%s]" % [self.class, (@options[:backend] || "Unknown")]
108
+ end
109
+
104
110
  alias direct_platform force_platform!
105
111
 
106
112
  # Get information on the operating system which this transport connects to.
@@ -69,6 +69,7 @@ class Train::Transports::SSH
69
69
  if @buf =~ /Bad (secrets|password)|Access denied/
70
70
  raise BadEnablePassword
71
71
  end
72
+
72
73
  session.connection.process(0)
73
74
  end
74
75
 
@@ -123,6 +124,7 @@ class Train::Transports::SSH
123
124
 
124
125
  ch.send_channel_request("shell") do |_, success|
125
126
  raise "Failed to open SSH shell" unless success
127
+
126
128
  logger.debug("[SSH] shell opened")
127
129
  end
128
130
  end
@@ -88,7 +88,8 @@ class Train::Transports::Docker
88
88
  stdout, stderr, exit_status = @container.exec(
89
89
  [
90
90
  "/bin/sh", "-c", cmd
91
- ])
91
+ ]
92
+ )
92
93
  CommandResult.new(stdout.join, stderr.join, exit_status)
93
94
  rescue ::Docker::Error::DockerError => _
94
95
  raise
@@ -84,6 +84,7 @@ module Train::Transports
84
84
  # Let's allow for other clients too
85
85
  def gcp_client(klass)
86
86
  return klass.new unless cache_enabled?(:api_call)
87
+
87
88
  @cache[:api_call][klass.to_s.to_sym] ||= klass.new
88
89
  end
89
90
 
@@ -12,6 +12,7 @@ module Train::Transports
12
12
  def self.parse(subscription_id: nil, credentials_file: nil, **_)
13
13
  return {} if credentials_file.nil?
14
14
  return {} unless ::File.readable?(credentials_file)
15
+
15
16
  credentials = IniFile.load(::File.expand_path(credentials_file))
16
17
  subscription_id = parser(subscription_id, ENV["AZURE_SUBSCRIPTION_NUMBER"], credentials).subscription_id
17
18
  creds(subscription_id, credentials)
@@ -42,7 +42,7 @@ module Train::Transports
42
42
  if os.windows?
43
43
  # Force a 64 bit poweshell if needed
44
44
  if RUBY_PLATFORM == "i386-mingw32" && os.arch == "x86_64"
45
- powershell_cmd = "#{ENV['SystemRoot']}\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe"
45
+ powershell_cmd = "#{ENV["SystemRoot"]}\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe"
46
46
  else
47
47
  powershell_cmd = "powershell"
48
48
  end
@@ -40,10 +40,12 @@ module Train::Transports
40
40
  interface_methods[classname.to_s].include?(id)
41
41
  next
42
42
  end
43
+
43
44
  # kindly borrowed from the wonderful simple-tracer by matugm
44
45
  arg_names = eval(
45
46
  "method(__method__).parameters.map { |arg| arg[1].to_s }",
46
- binding)
47
+ binding
48
+ )
47
49
  args = eval("#{arg_names}.map { |arg| eval(arg) }", binding).join(", ")
48
50
  prefix = "-" * (classname.to_s.count(":") - 2) + "> "
49
51
  puts("#{prefix}#{id} #{args}")
@@ -141,8 +143,8 @@ class Train::Transports::Mock::Connection
141
143
  class File < Train::File
142
144
  def self.from_json(json)
143
145
  res = new(json["backend"],
144
- json["path"],
145
- json["follow_symlink"])
146
+ json["path"],
147
+ json["follow_symlink"])
146
148
  res.type = json["type"]
147
149
  Train::File::DATA_FIELDS.each do |f|
148
150
  m = (f.tr("?", "") + "=").to_sym
@@ -104,7 +104,7 @@ module Train::Transports
104
104
  if options[:auth_methods] == ["none"]
105
105
  if ssh_known_identities.empty?
106
106
  raise Train::ClientError,
107
- "Your SSH Agent has no keys added, and you have not specified a password or a key file"
107
+ "Your SSH Agent has no keys added, and you have not specified a password or a key file"
108
108
  else
109
109
  logger.debug("[SSH] Using Agent keys as no password or key file have been specified")
110
110
  options[:auth_methods].push("publickey")
@@ -56,6 +56,7 @@ class Train::Transports::SSH
56
56
  # (see Base::Connection#close)
57
57
  def close
58
58
  return if @session.nil?
59
+
59
60
  logger.debug("[SSH] closing connection to #{self}")
60
61
  session.close
61
62
  ensure
@@ -84,6 +85,7 @@ class Train::Transports::SSH
84
85
 
85
86
  def generate_proxy_command
86
87
  return @proxy_command unless @proxy_command.nil?
88
+
87
89
  args = %w{ ssh }
88
90
  args += ssh_opts
89
91
  args += %W{ #{@bastion_user}@#{@bastion_host} }
@@ -176,7 +176,7 @@ module Train::Transports
176
176
  " `gem 'winrm-fs', '#{spec_version}'`."
177
177
  )
178
178
  raise Train::UserError,
179
- "Could not load or activate WinRM::FS (#{e.message})"
179
+ "Could not load or activate WinRM::FS (#{e.message})"
180
180
  end
181
181
 
182
182
  # Load WinRM::Transport code.
@@ -42,6 +42,7 @@ class Train::Transports::WinRM
42
42
  # (see Base::Connection#close)
43
43
  def close
44
44
  return if @session.nil?
45
+
45
46
  session.close
46
47
  ensure
47
48
  @session = nil
@@ -58,8 +59,8 @@ class Train::Transports::WinRM
58
59
  login_command_for_linux
59
60
  else
60
61
  raise ActionFailed,
61
- "Remote login not supported in #{self.class} " \
62
- "from host OS '#{RbConfig::CONFIG['host_os']}'."
62
+ "Remote login not supported in #{self.class} " \
63
+ "from host OS '#{RbConfig::CONFIG["host_os"]}'."
63
64
  end
64
65
  end
65
66
 
@@ -98,6 +99,7 @@ class Train::Transports::WinRM
98
99
 
99
100
  def run_command_via_connection(command, &data_handler)
100
101
  return if command.nil?
102
+
101
103
  logger.debug("[WinRM] #{self} (#{command})")
102
104
  out = ""
103
105
 
@@ -3,5 +3,5 @@
3
3
  # Author:: Dominik Richter (<dominik.richter@gmail.com>)
4
4
 
5
5
  module Train
6
- VERSION = "2.1.13".freeze
6
+ VERSION = "2.1.19".freeze
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: train
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.13
4
+ version: 2.1.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominik Richter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-01 00:00:00.000000000 Z
11
+ date: 2019-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json