train-core 1.7.1 → 1.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/train.rb +61 -46
- data/lib/train/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2aa1b81d26ddba4a2a0f074d650fc9a9289afa7c2399b5c8f6a15e8c928cc431
|
4
|
+
data.tar.gz: de2f1c194c79a4bab63a26610c6bc8472d1275e00ff53155bf070925187f48f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04a84767760b02d28af78b7b1f8c6318e4f59a23832a4486d6d236cdba47955b5cca72e3bd104279fc4a6405cd982db0420c2b6c4d7ce84b26e16b1196a27a4d
|
7
|
+
data.tar.gz: e2f9f46e1015fc25de047eadd5c1f5d694fd93659c28d5e4e8b274128b1b6de3cb50c043fa8f63373ecfc7081d65f45032af088d77c18b212aae609d27d52549
|
data/lib/train.rb
CHANGED
@@ -61,53 +61,61 @@ module Train
|
|
61
61
|
raise ex
|
62
62
|
end
|
63
63
|
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
67
|
-
|
68
|
-
|
69
|
-
conf =
|
70
|
-
|
71
|
-
|
64
|
+
# Legacy code to unpack a series of items from an incoming Hash
|
65
|
+
# Inspec::Config.unpack_train_credentials now handles this in most cases that InSpec needs
|
66
|
+
# If you need to unpack a URI, use unpack_target_from_uri
|
67
|
+
# TODO: deprecate; can't issue a warning because train doesn't have a logger until the connection is setup (See base_connection.rb)
|
68
|
+
def self.target_config(config = nil)
|
69
|
+
conf = config.dup
|
70
|
+
# Symbolize keys
|
71
|
+
conf.keys.each do |key|
|
72
|
+
unless key.is_a? Symbol
|
73
|
+
conf[key.to_sym] = conf.delete(key)
|
74
|
+
end
|
75
|
+
end
|
72
76
|
|
77
|
+
group_keys_and_keyfiles(conf) # TODO: move logic into SSH plugin
|
73
78
|
return conf if conf[:target].to_s.empty?
|
79
|
+
unpack_target_from_uri(conf[:target], conf).merge(conf)
|
80
|
+
end
|
81
|
+
|
82
|
+
# Given a string that looks like a URI, unpack connection credentials.
|
83
|
+
# The name of the desired transport is always taken from the 'scheme' slot of the URI;
|
84
|
+
# the remaining portion of the URI is parsed as if it were an HTTP URL, and then
|
85
|
+
# the URL components are stored in the credentials hash. It is up to the transport
|
86
|
+
# to interpret the fields in a sensible way for that transport.
|
87
|
+
# New transport authors are encouraged to use transport://credset format (see
|
88
|
+
# inspec/inspec/issues/3661) rather than inventing a new field mapping.
|
89
|
+
def self.unpack_target_from_uri(uri_string, opts = {}) # rubocop: disable Metrics/AbcSize
|
90
|
+
creds = {}
|
91
|
+
return creds if uri_string.empty?
|
74
92
|
|
75
93
|
# split up the target's host/scheme configuration
|
76
|
-
uri = parse_uri(
|
94
|
+
uri = parse_uri(uri_string)
|
77
95
|
unless uri.host.nil? and uri.scheme.nil?
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
if
|
96
|
+
creds[:backend] ||= uri.scheme
|
97
|
+
creds[:host] ||= uri.hostname
|
98
|
+
creds[:port] ||= uri.port
|
99
|
+
creds[:user] ||= uri.user
|
100
|
+
creds[:path] ||= uri.path
|
101
|
+
creds[:password] ||=
|
102
|
+
if opts[:www_form_encoded_password] && !uri.password.nil?
|
85
103
|
URI.decode_www_form_component(uri.password)
|
86
104
|
else
|
87
105
|
uri.password
|
88
106
|
end
|
89
107
|
end
|
90
108
|
|
91
|
-
# ensure path is nil, if its empty; e.g. required to reset defaults for winrm
|
92
|
-
|
109
|
+
# ensure path is nil, if its empty; e.g. required to reset defaults for winrm # TODO: move logic into winrm plugin
|
110
|
+
creds[:path] = nil if !creds[:path].nil? && creds[:path].to_s.empty?
|
93
111
|
|
94
|
-
#
|
95
|
-
|
96
|
-
|
112
|
+
# compact! is available in ruby 2.4+
|
113
|
+
# TODO: rewrite next line using compact! once we drop support for ruby 2.3
|
114
|
+
creds = creds.delete_if { |_, value| value.nil? }
|
97
115
|
|
98
|
-
|
99
|
-
|
100
|
-
# Example: { 'a' => 123 } ==> { a: 123 }
|
101
|
-
#
|
102
|
-
# @param map [Hash]
|
103
|
-
# @return [Hash] new map with all keys being symbols
|
104
|
-
def self.symbolize_keys(map)
|
105
|
-
map.each_with_object({}) do |(k, v), acc|
|
106
|
-
acc[k.to_sym] = v
|
107
|
-
acc
|
108
|
-
end
|
116
|
+
# return the updated config
|
117
|
+
creds
|
109
118
|
end
|
110
|
-
private_class_method :symbolize_keys
|
111
119
|
|
112
120
|
# Parse a URI. Supports empty URI's with paths, e.g. `mock://`
|
113
121
|
#
|
@@ -127,34 +135,41 @@ module Train
|
|
127
135
|
raise Train::UserError, e
|
128
136
|
end
|
129
137
|
|
130
|
-
|
131
|
-
|
132
|
-
|
138
|
+
uri = URI.parse(string)
|
139
|
+
uri.host = nil
|
140
|
+
uri
|
133
141
|
end
|
134
142
|
private_class_method :parse_uri
|
135
143
|
|
136
|
-
|
137
|
-
|
138
|
-
|
144
|
+
# Examine the given credential information, and if all is well,
|
145
|
+
# return the transport name.
|
146
|
+
# TODO: this actually does no validation of the credential options whatsoever
|
147
|
+
def self.validate_backend(credentials, default_transport_name = 'local')
|
148
|
+
return default_transport_name if credentials.nil?
|
149
|
+
transport_name = credentials[:backend]
|
139
150
|
|
140
|
-
if (
|
151
|
+
# TODO: Determine if it is ever possible (or supported) for transport_name to be 'localhost'
|
152
|
+
# TODO: After inspec/inspec/pull/3750 is merged, should be able to remove nil from the list
|
153
|
+
if credentials[:sudo] && [nil, 'local', 'localhost'].include?(transport_name)
|
141
154
|
fail Train::UserError, 'Sudo is only valid when running against a remote host. '\
|
142
155
|
'To run this locally with elevated privileges, run the command with `sudo ...`.'
|
143
156
|
end
|
144
157
|
|
145
|
-
return
|
158
|
+
return transport_name if !transport_name.nil?
|
146
159
|
|
147
|
-
if !
|
160
|
+
if !credentials[:target].nil?
|
161
|
+
# We should not get here, because if target_uri unpacking was successful,
|
162
|
+
# it would have set credentials[:backend]
|
148
163
|
fail Train::UserError, 'Cannot determine backend from target '\
|
149
|
-
"configuration #{
|
164
|
+
"configuration #{credentials[:target]}. Valid example: ssh://192.168.0.1"
|
150
165
|
end
|
151
166
|
|
152
|
-
if !
|
167
|
+
if !credentials[:host].nil?
|
153
168
|
fail Train::UserError, 'Host configured, but no backend was provided. Please '\
|
154
|
-
'specify how you want to connect. Valid example: ssh://192.168.0.1
|
169
|
+
'specify how you want to connect. Valid example: ssh://192.168.0.1'
|
155
170
|
end
|
156
171
|
|
157
|
-
|
172
|
+
credentials[:backend] = default_transport_name
|
158
173
|
end
|
159
174
|
|
160
175
|
def self.group_keys_and_keyfiles(conf)
|
data/lib/train/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: train-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dominik Richter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mixlib-shellout
|