train 3.5.5 → 3.7.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: f2a377486d9c6dbe0bd35df80d538b57f2e6e3679813c3f77a4492bca31d15be
4
- data.tar.gz: 3565142834222be0b68e765cd61642065e1639d56bfd06f9667797ca2def5643
3
+ metadata.gz: 3a635c9c1309b6c1b95a92d535773aabf7d51f25957f454f683eaa09f8a86b52
4
+ data.tar.gz: 5af13a937a6c21279d4042ba244a9d31670f9bd184b81ee067178646675a8c66
5
5
  SHA512:
6
- metadata.gz: d005a08a696874336342e4c4701b1c7b3ae00d9e6bc2b7d0ff6fa05c101f1a05ad7d4c7e68cc07da23b65c9f04c6ac7e9ff903ad34cc9b53a7129304568d1678
7
- data.tar.gz: 956dee1653c4cea8fdd9c2b5a59bd38cd4b7af06978864ae0a81ffd53ed108403f4f117ea86aa4ecbd20c63f6d714a95fa1ae9e80586467231c2de48c9656698
6
+ metadata.gz: 6f9049829dad441bce260c1d600243d8ac98a38425a7bc52f4008b7b3363f4f1206825e097bf8d71ebc756e6cc0a5fb90b88d7d0aa09c3d1e37b4be2e22a0ffc
7
+ data.tar.gz: e92f42fcd4dc1b959a886dc90c89036df0b6e88b65cd33c9f96361a93f10fd93f44e8623b74f5ba96d7fc8eb49881ea576d19f8ee0a81e356065c19c8569a252
@@ -163,12 +163,10 @@ module Train::Transports
163
163
 
164
164
  def port_open?(port, seconds = 3)
165
165
  Timeout.timeout(seconds) do
166
- begin
167
- TCPSocket.new("localhost", port).close
168
- true
169
- rescue SystemCallError
170
- false
171
- end
166
+ TCPSocket.new("localhost", port).close
167
+ true
168
+ rescue SystemCallError
169
+ false
172
170
  end
173
171
  rescue Timeout::Error
174
172
  false
@@ -6,6 +6,7 @@ module Train::Transports
6
6
 
7
7
  include_options Train::Extras::CommandWrapper
8
8
  option :host, required: true
9
+ option :docker_url, required: false
9
10
 
10
11
  def connection(state = {}, &block)
11
12
  opts = merge_options(options, state || {})
@@ -53,10 +54,21 @@ class Train::Transports::Docker
53
54
  def initialize(conf)
54
55
  super(conf)
55
56
  @id = options[:host]
57
+
58
+ docker_url = options[:docker_url]
59
+ if RUBY_PLATFORM =~ /windows|mswin|msys|mingw|cygwin/
60
+ # Docker Desktop for windows. Must override socket location.
61
+ # https://docs.docker.com/desktop/faqs/#how-do-i-connect-to-the-remote-docker-engine-api
62
+ # docker_socket ||= "npipe:////./pipe/docker_engine" # # Doesn't require a settings change, but also doesn't work
63
+ docker_url ||= "tcp://localhost:2375"
64
+ end
65
+ Docker.url = docker_url if docker_url
66
+
56
67
  @container = ::Docker::Container.get(@id) ||
57
68
  raise("Can't find Docker container #{@id}")
58
69
  @cmd_wrapper = nil
59
70
  @cmd_wrapper = CommandWrapper.load(self, @options)
71
+ @probably_windows = nil
60
72
  end
61
73
 
62
74
  def close
@@ -78,6 +90,8 @@ class Train::Transports::Docker
78
90
  Train::File::Remote::Aix.new(self, path)
79
91
  elsif os.solaris?
80
92
  Train::File::Remote::Unix.new(self, path)
93
+ elsif os.windows?
94
+ Train::File::Remote::Windows.new(self, path)
81
95
  else
82
96
  Train::File::Remote::Linux.new(self, path)
83
97
  end
@@ -85,10 +99,16 @@ class Train::Transports::Docker
85
99
 
86
100
  def run_command_via_connection(cmd, &_data_handler)
87
101
  cmd = @cmd_wrapper.run(cmd) unless @cmd_wrapper.nil?
102
+
103
+ # Cannot use os.windows? here because it calls run_command_via_connection,
104
+ # causing infinite recursion during initial platform detection
105
+ if sniff_for_windows?
106
+ invocation = cmd_run_command(cmd)
107
+ else
108
+ invocation = sh_run_command(cmd)
109
+ end
88
110
  stdout, stderr, exit_status = @container.exec(
89
- [
90
- "/bin/sh", "-c", cmd
91
- ], user: @options[:user]
111
+ invocation, user: @options[:user]
92
112
  )
93
113
  CommandResult.new(stdout.join, stderr.join, exit_status)
94
114
  rescue ::Docker::Error::DockerError => _
@@ -97,5 +117,23 @@ class Train::Transports::Docker
97
117
  # @TODO: differentiate any other error
98
118
  raise
99
119
  end
120
+
121
+ def sh_run_command(cmd)
122
+ ["/bin/sh", "-c", cmd]
123
+ end
124
+
125
+ def cmd_run_command(cmd)
126
+ ["cmd.exe", "/s", "/c", cmd]
127
+ end
128
+
129
+ def sniff_for_windows?
130
+ return @probably_windows unless @probably_windows.nil?
131
+
132
+ # Run a command using /bin/sh, which should fail under Windows
133
+ stdout, _stderr, _exit_status = @container.exec(
134
+ sh_run_command("true"), user: @options[:user]
135
+ )
136
+ @probably_windows = !!stdout.detect { |l| l.include? "failure in a Windows system call" }
137
+ end
100
138
  end
101
139
  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: 3.5.5
4
+ version: 3.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chef InSpec Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-24 00:00:00.000000000 Z
11
+ date: 2021-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: train-core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 3.5.5
19
+ version: 3.7.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 3.5.5
26
+ version: 3.7.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: train-winrm
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,20 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 5.2.4.3
48
- - - "<"
49
- - !ruby/object:Gem::Version
50
- version: 6.0.0
47
+ version: 6.0.3.1
51
48
  type: :runtime
52
49
  prerelease: false
53
50
  version_requirements: !ruby/object:Gem::Requirement
54
51
  requirements:
55
52
  - - ">="
56
53
  - !ruby/object:Gem::Version
57
- version: 5.2.4.3
58
- - - "<"
59
- - !ruby/object:Gem::Version
60
- version: 6.0.0
54
+ version: 6.0.3.1
61
55
  - !ruby/object:Gem::Dependency
62
56
  name: inifile
63
57
  requirement: !ruby/object:Gem::Requirement
@@ -236,7 +230,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
236
230
  requirements:
237
231
  - - ">="
238
232
  - !ruby/object:Gem::Version
239
- version: '2.4'
233
+ version: '2.5'
240
234
  required_rubygems_version: !ruby/object:Gem::Requirement
241
235
  requirements:
242
236
  - - ">="