train 3.4.9 → 3.6.2

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: bc696c31df0f0804e64448c11d94c1be7d7a89daa005ebfbe63ad858de6f6626
4
- data.tar.gz: d063e9309efe6ec3a4d825678cac8302309b05b5fabe7eb7a3aff2a6239d3eac
3
+ metadata.gz: 19b9885778f6b955bb1239371e5192ef25e7ddd21f79a87117f38bc185b213f3
4
+ data.tar.gz: b43c04a718b9a3c9b8eac6b33b20f90a5f53d0576691a009942965b9c07eea33
5
5
  SHA512:
6
- metadata.gz: c629414eef77c95408ff641862fa992f530ffaed1f48418cc712854d79044589d675f2b80d0f2bdfa0e758ae9a40cd3a5687601f9c0b69e67cb4297efd6e1c67
7
- data.tar.gz: 2f2ac0b2f029ced0c9df62d60c3f17f5ae22517a335e9d22a5f8d3c1f3ed2284ea215b43e2bcd5158507f9af82596fa2aaed0e73b3b73dcbdf8dac92d8b9cbbc
6
+ metadata.gz: 82891e944073a70eefd4d3146863bde5897a5651710717a05e58818dd4d559de56d5e59182978b639fa58fd7b8ec14f1ae0a44a745766c860f76e4792b683616
7
+ data.tar.gz: d948d3df1b04c90f7739f8637ee4ef49b858ad3aa26ca62dde98e43086c6887b5f82d69e2c38f6b4bb5766d3e89d9609f48f2be9e99cea53d851770e6c275fc6
@@ -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
- ]
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.4.9
4
+ version: 3.6.2
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-01-27 00:00:00.000000000 Z
11
+ date: 2021-04-14 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.4.9
19
+ version: 3.6.2
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.4.9
26
+ version: 3.6.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: train-winrm
29
29
  requirement: !ruby/object:Gem::Requirement