train 3.8.9 → 3.10.1

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: ba990081a6ccfd78a6762b5685f7a22abfb252823f2fd185b942840450943243
4
- data.tar.gz: 965ea4c81f9bb0fd0268f9d60cff8de1c1cd65ec89254a0bbbe8e6938cf85893
3
+ metadata.gz: 7efd89c593b5d3676a3aaa39b6df6138181bc729d14e6e4fa71bda99013a83fe
4
+ data.tar.gz: db07f812a1bc3a15702b96977390dd2bd36da3f16607df1af8e348166e3b7b3d
5
5
  SHA512:
6
- metadata.gz: bebfde45aff5cafec1a39fa25aa63b429ad092911276beeed1f3ef0a3bceb3d50baa563ff52cfde417a1556b19d23f40eb97348c6c01d31aba83747fc2819284
7
- data.tar.gz: 8514f25925c060845e2e62dd73733b7d8fe03aea00e67c551067e99f4fd1388d50926bedc2fb8f2125541ecc93599562dafe276bbd4f1c32def1a73655c03f12
6
+ metadata.gz: 941b825ff06fc1766b53387cb1d7d27e72fd069e891147a13c6a89535b371488082a0f461ffd0fdd63078ea3308d52c7d0fee2566a6dcbc3c02f4d38a8e7984a
7
+ data.tar.gz: 2bb1ba30867b74b6d329ed41b2a8c3f5981259044758cda8e58749e5ddc2e41db3ead3bab682b8711fe4dcb4f8dd5fede9a6ae4d4356c2ebaf065b3640986867
@@ -83,6 +83,17 @@ class Train::Transports::Docker
83
83
  end
84
84
  end
85
85
 
86
+ def unique_identifier
87
+ uuid = @container.nil? ? @id : @container.id # default uuid set to the docker host.
88
+ unless sniff_for_windows?
89
+ cmd = run_command_via_connection("head -1 /proc/self/cgroup|cut -d/ -f3") if file("/proc/self/cgroup").exist?
90
+ unless cmd.stdout.empty?
91
+ uuid = cmd.stdout.strip
92
+ end
93
+ end
94
+ uuid
95
+ end
96
+
86
97
  private
87
98
 
88
99
  def file_via_connection(path)
@@ -0,0 +1,157 @@
1
+ require "docker"
2
+ require "train/plugins"
3
+
4
+ module Train::Transports
5
+ class Podman < Train.plugin(1)
6
+
7
+ name "podman"
8
+
9
+ include_options Train::Extras::CommandWrapper
10
+ option :host, required: true
11
+ option :podman_url, required: false
12
+
13
+ def connection(state = {}, &block)
14
+ opts = merge_options(options, state || {})
15
+
16
+ validate_options(opts)
17
+
18
+ if @connection && @connection_options == opts
19
+ reuse_connection(&block)
20
+ else
21
+ create_new_connection(opts, &block)
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ # Creates a new Podman connection instance and save it for potential future
28
+ # reuse.
29
+ #
30
+ # @param options [Hash] connection options
31
+ # @return [Podman::Connection] a Podman connection instance
32
+ # @api private
33
+ def create_new_connection(options, &block)
34
+ if @connection
35
+ logger.debug("[Podman] shutting previous connection #{@connection}")
36
+ @connection.close
37
+ end
38
+
39
+ @connection_options = options
40
+ @connection = Connection.new(options, &block)
41
+ end
42
+
43
+ # Return the last saved Podman connection instance.
44
+ #
45
+ # @return [Podman::Connection] a Podman connection instance
46
+ # @api private
47
+ def reuse_connection
48
+ logger.debug("[Podman] reusing existing connection #{@connection}")
49
+ yield @connection if block_given?
50
+ @connection
51
+ end
52
+ end
53
+
54
+ class Train::Transports::Podman
55
+ class Connection < BaseConnection
56
+ def initialize(options)
57
+ super(options)
58
+
59
+ @id = options[:host]
60
+
61
+ if RUBY_PLATFORM =~ /windows|mswin|msys|mingw|cygwin/
62
+ raise "Unsupported host platform."
63
+ end
64
+
65
+ # Currently Podman url can be set using option and setting the environment variable.
66
+ uid = Process.uid
67
+ podman_url = options[:podman_url] || ENV["CONTAINER_HOST"]
68
+ podman_url ||= "unix:///run/podman/podman.sock" if uid == 0
69
+ podman_url ||= "unix:///run/user/#{uid}/podman/podman.sock"
70
+
71
+ Docker.url = podman_url
72
+
73
+ # Using docker-api ruby library to fetch the Podman container data.
74
+ @container = ::Docker::Container.get(@id) ||
75
+ raise("Can't find Podman container #{@id}")
76
+ @cmd_wrapper = nil
77
+ @cmd_wrapper = CommandWrapper.load(self, @options)
78
+ @probably_windows = nil
79
+ rescue Excon::Error::Socket
80
+ raise Train::TransportError, "Unable to connect to Podman using #{podman_url}"
81
+ rescue Docker::Error::NotFoundError => e
82
+ raise Train::TransportError, "Container Not Found: #{e.message}"
83
+ rescue Docker::Error::ServerError => e
84
+ raise Train::TransportError, "#{e.message}"
85
+ end
86
+
87
+ def close
88
+ # nothing to do at the moment
89
+ end
90
+
91
+ def uri
92
+ if @container.nil?
93
+ "podman://#{@id}"
94
+ else
95
+ "podman://#{@container.id}"
96
+ end
97
+ end
98
+
99
+ def unique_identifier
100
+ @container.nil? ? @id : @container.id # default uuid set to the podman host.
101
+ end
102
+
103
+ private
104
+
105
+ def file_via_connection(path)
106
+ if os.aix?
107
+ Train::File::Remote::Aix.new(self, path)
108
+ elsif os.solaris?
109
+ Train::File::Remote::Unix.new(self, path)
110
+ elsif os.windows?
111
+ Train::File::Remote::Windows.new(self, path)
112
+ else
113
+ Train::File::Remote::Linux.new(self, path)
114
+ end
115
+ end
116
+
117
+ def run_command_via_connection(cmd, &_data_handler)
118
+ cmd = @cmd_wrapper.run(cmd) unless @cmd_wrapper.nil?
119
+
120
+ # Cannot use os.windows? here because it calls run_command_via_connection,
121
+ # causing infinite recursion during initial platform detection
122
+ if sniff_for_windows?
123
+ invocation = cmd_run_command(cmd)
124
+ else
125
+ invocation = sh_run_command(cmd)
126
+ end
127
+ stdout, stderr, exit_status = @container.exec(
128
+ invocation, user: @options[:user]
129
+ )
130
+ CommandResult.new(stdout.join, stderr.join, exit_status)
131
+ rescue ::Docker::Error::DockerError => _
132
+ raise
133
+ rescue => _
134
+ # @TODO: differentiate any other error
135
+ raise
136
+ end
137
+
138
+ def sh_run_command(cmd)
139
+ ["/bin/sh", "-c", cmd]
140
+ end
141
+
142
+ def cmd_run_command(cmd)
143
+ ["cmd.exe", "/s", "/c", cmd]
144
+ end
145
+
146
+ def sniff_for_windows?
147
+ return @probably_windows unless @probably_windows.nil?
148
+
149
+ # Run a command using /bin/sh, which should fail under Windows
150
+ stdout, _stderr, _exit_status = @container.exec(
151
+ sh_run_command("true"), user: @options[:user]
152
+ )
153
+ @probably_windows = !!stdout.detect { |l| l.include? "failure in a Windows system call" }
154
+ end
155
+ end
156
+ end
157
+ 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.8.9
4
+ version: 3.10.1
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: 2022-03-09 00:00:00.000000000 Z
11
+ date: 2022-06-29 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.8.9
19
+ version: 3.10.1
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.8.9
26
+ version: 3.10.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: train-winrm
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -213,6 +213,7 @@ files:
213
213
  - lib/train/transports/helpers/azure/file_parser.rb
214
214
  - lib/train/transports/helpers/azure/subscription_id_file_parser.rb
215
215
  - lib/train/transports/helpers/azure/subscription_number_file_parser.rb
216
+ - lib/train/transports/podman.rb
216
217
  - lib/train/transports/vmware.rb
217
218
  homepage:
218
219
  licenses:
@@ -230,7 +231,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
230
231
  requirements:
231
232
  - - ">="
232
233
  - !ruby/object:Gem::Version
233
- version: '2.5'
234
+ version: '2.7'
234
235
  required_rubygems_version: !ruby/object:Gem::Requirement
235
236
  requirements:
236
237
  - - ">="