train 3.5.4 → 3.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/train/transports/docker.rb +41 -3
  3. metadata +7 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ab5b05d9f070f46d6447e23dc7dd9a4fc2981f9f8bd330391cfcb729093f97e
4
- data.tar.gz: 44f1c231c100201860f3076b0aa338bc3f8054f8779070f1df045806e3bddf25
3
+ metadata.gz: 7cc8b0938a9260b0b811cc132c94c8db514c59ab5fcabf88c07de31cdcc90f18
4
+ data.tar.gz: 4a9404300b20e64dcfb65b1fdba7b92b992cdb2153952643abdc08870e8d4e0d
5
5
  SHA512:
6
- metadata.gz: 436cc1af1db2f8206d1c8c7295030b4ef5cb9d9fca983646de7686af4844a8959471a46e065d2c91bf9d2578cb34010415b2da3fe23f290028918ab8684781bb
7
- data.tar.gz: f1907e45cf7eee624fb8ded3d2f25fbb1b20cc65611efb48a975fc5a064525fdadfe28c1ab0c2051b55b8b133760e3470cb01632fc0ee844ec4065f16435ed97
6
+ metadata.gz: 85d5ffd5072c547c66fbadc86affdb1bcd305ad76b4c8ed9658e65bafdd0d936faadbe1071081447c3ab86f5085cca90c5b2a42fbfa7353c3c4e66fdabedb05a
7
+ data.tar.gz: 3925c95d221b89e40810df95652ec91e2716957e92f60a2a69b872079b90719e96dfde2d88f53d23741f69cb8cf46f7aa40838394a2f5a809c910a497f31d905
@@ -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.4
4
+ version: 3.7.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-03-15 00:00:00.000000000 Z
11
+ date: 2021-05-24 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.4
19
+ version: 3.7.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.5.4
26
+ version: 3.7.2
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
  - - ">="