train 3.5.5 → 3.6.0

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: 704c34b6ad721a82fb9259b3f3c41a550e5bc626d694d0c9e83e61d09d2cdbeb
4
+ data.tar.gz: 9bfaf284eb3eef55fc30660cc986a6805cb5a6c5fcc6bc8874faf967da69b8bd
5
5
  SHA512:
6
- metadata.gz: d005a08a696874336342e4c4701b1c7b3ae00d9e6bc2b7d0ff6fa05c101f1a05ad7d4c7e68cc07da23b65c9f04c6ac7e9ff903ad34cc9b53a7129304568d1678
7
- data.tar.gz: 956dee1653c4cea8fdd9c2b5a59bd38cd4b7af06978864ae0a81ffd53ed108403f4f117ea86aa4ecbd20c63f6d714a95fa1ae9e80586467231c2de48c9656698
6
+ metadata.gz: 617b0f37fd9b14baa18bf8b6ae568e19870412116cd8cf82886e5c452452a42be066764e6b801b5756e20cb28cff09406f646044a10a7ab404a63fe65e76712e
7
+ data.tar.gz: 531f7fef3b970d54422985424acb67ff8bbc828174acfea4ceb73385d44d34719715d891abd880a687da374f0035b647acf7be45b1817f2c5f460539631e42f3
@@ -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.6.0
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-04-07 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.6.0
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.6.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: train-winrm
29
29
  requirement: !ruby/object:Gem::Requirement