train 0.20.0 → 0.20.1
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/CHANGELOG.md +9 -2
- data/lib/train.rb +40 -7
- data/lib/train/version.rb +1 -1
- data/test/integration/test-one.yaml +4 -0
- data/test/integration/test-two.yaml +4 -0
- data/test/unit/train_test.rb +29 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04b361d035e2f468512b7a2daf50ee16be2b69e7
|
4
|
+
data.tar.gz: 53d547202564642c4adbfa6bd4995c1ada9831e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12d486c2d8cb2d7e7b80d2220dd9f53f92571e7a5c97333b80670aa8e4e920c5e01b6531416fdecfd62d972ff2a6534eb5a1bca0eae2df6cb2732d7cc919b66d
|
7
|
+
data.tar.gz: f45f67cbe240440d9fb832f23dc626154a839a9949de25aeba19f7a70dbd7a2d178f13ea7fe1ebe209ca67ada5021b5732b6b04786f0783136bf5f5389445c7f
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,14 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## [0.20.
|
4
|
-
[Full Changelog](https://github.com/chef/train/compare/v0.
|
3
|
+
## [0.20.1](https://github.com/chef/train/tree/0.20.1) (2016-10-15)
|
4
|
+
[Full Changelog](https://github.com/chef/train/compare/v0.20.0...0.20.1)
|
5
|
+
|
6
|
+
**Fixed bugs:**
|
7
|
+
|
8
|
+
- support empty URIs [\#154](https://github.com/chef/train/pull/154) ([arlimus](https://github.com/arlimus))
|
9
|
+
|
10
|
+
## [v0.20.0](https://github.com/chef/train/tree/v0.20.0) (2016-09-21)
|
11
|
+
[Full Changelog](https://github.com/chef/train/compare/v0.19.1...v0.20.0)
|
5
12
|
|
6
13
|
**Fixed bugs:**
|
7
14
|
|
data/lib/train.rb
CHANGED
@@ -51,19 +51,14 @@ module Train
|
|
51
51
|
# e.g. ssh://bob@remote => backend: ssh, user: bob, host: remote
|
52
52
|
def self.target_config(config = nil) # rubocop:disable Metrics/AbcSize
|
53
53
|
conf = config.nil? ? {} : config.dup
|
54
|
-
|
55
|
-
# symbolize keys
|
56
|
-
conf = conf.each_with_object({}) do |(k, v), acc|
|
57
|
-
acc[k.to_sym] = v
|
58
|
-
acc
|
59
|
-
end
|
54
|
+
conf = symbolize_keys(conf)
|
60
55
|
|
61
56
|
group_keys_and_keyfiles(conf)
|
62
57
|
|
63
58
|
return conf if conf[:target].to_s.empty?
|
64
59
|
|
65
60
|
# split up the target's host/scheme configuration
|
66
|
-
uri =
|
61
|
+
uri = parse_uri(conf[:target].to_s)
|
67
62
|
unless uri.host.nil? and uri.scheme.nil?
|
68
63
|
conf[:backend] ||= uri.scheme
|
69
64
|
conf[:host] ||= uri.host
|
@@ -80,6 +75,44 @@ module Train
|
|
80
75
|
conf
|
81
76
|
end
|
82
77
|
|
78
|
+
# Takes a map of key-value pairs and turns all keys into symbols. For this
|
79
|
+
# to work, only keys are supported that can be turned into symbols.
|
80
|
+
# Example: { 'a' => 123 } ==> { a: 123 }
|
81
|
+
#
|
82
|
+
# @param map [Hash]
|
83
|
+
# @return [Hash] new map with all keys being symbols
|
84
|
+
def self.symbolize_keys(map)
|
85
|
+
map.each_with_object({}) do |(k, v), acc|
|
86
|
+
acc[k.to_sym] = v
|
87
|
+
acc
|
88
|
+
end
|
89
|
+
end
|
90
|
+
private_class_method :symbolize_keys
|
91
|
+
|
92
|
+
# Parse a URI. Supports empty URI's with paths, e.g. `mock://`
|
93
|
+
#
|
94
|
+
# @param string [string] URI string, e.g. `schema://domain.com`
|
95
|
+
# @return [URI::Generic] parsed URI object
|
96
|
+
def self.parse_uri(string)
|
97
|
+
URI.parse(string)
|
98
|
+
rescue URI::InvalidURIError => e
|
99
|
+
# A use-case we want to catch is parsing empty URIs with a schema
|
100
|
+
# e.g. mock://. To do this, we match it manually and fake the hostname
|
101
|
+
case string
|
102
|
+
when %r{^([a-z]+)://$}
|
103
|
+
string += 'dummy'
|
104
|
+
when /^([a-z]+):$/
|
105
|
+
string += '//dummy'
|
106
|
+
else
|
107
|
+
raise Train::UserError, e
|
108
|
+
end
|
109
|
+
|
110
|
+
u = URI.parse(string)
|
111
|
+
u.host = nil
|
112
|
+
u
|
113
|
+
end
|
114
|
+
private_class_method :parse_uri
|
115
|
+
|
83
116
|
def self.validate_backend(conf, default = :local)
|
84
117
|
return default if conf.nil?
|
85
118
|
res = conf[:backend]
|
data/lib/train/version.rb
CHANGED
data/test/unit/train_test.rb
CHANGED
@@ -128,6 +128,35 @@ describe Train do
|
|
128
128
|
res = Train.target_config(org)
|
129
129
|
res.must_equal nu
|
130
130
|
end
|
131
|
+
|
132
|
+
it 'supports empty URIs with schema://' do
|
133
|
+
org = { target: 'mock://' }
|
134
|
+
res = Train.target_config(org)
|
135
|
+
res[:backend].must_equal 'mock'
|
136
|
+
res[:host].must_be_nil
|
137
|
+
res[:user].must_be_nil
|
138
|
+
res[:password].must_be_nil
|
139
|
+
res[:port].must_be_nil
|
140
|
+
res[:path].must_be_nil
|
141
|
+
res[:target].must_equal org[:target]
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'supports empty URIs with schema:' do
|
145
|
+
org = { target: 'mock:' }
|
146
|
+
res = Train.target_config(org)
|
147
|
+
res[:backend].must_equal 'mock'
|
148
|
+
res[:host].must_be_nil
|
149
|
+
res[:user].must_be_nil
|
150
|
+
res[:password].must_be_nil
|
151
|
+
res[:port].must_be_nil
|
152
|
+
res[:path].must_be_nil
|
153
|
+
res[:target].must_equal org[:target]
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'it raises UserError on invalid URIs' do
|
157
|
+
org = { target: 'mock world' }
|
158
|
+
proc { Train.target_config(org) }.must_raise Train::UserError
|
159
|
+
end
|
131
160
|
end
|
132
161
|
|
133
162
|
describe '#validate_backend' do
|
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: 0.20.
|
4
|
+
version: 0.20.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dominik Richter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -195,11 +195,13 @@ files:
|
|
195
195
|
- test/integration/sudo/passwd.rb
|
196
196
|
- test/integration/sudo/reqtty.rb
|
197
197
|
- test/integration/sudo/run_as.rb
|
198
|
+
- test/integration/test-one.yaml
|
198
199
|
- test/integration/test-travis-centos.yml
|
199
200
|
- test/integration/test-travis-debian.yml
|
200
201
|
- test/integration/test-travis-fedora.yml
|
201
202
|
- test/integration/test-travis-oel.yml
|
202
203
|
- test/integration/test-travis-ubuntu.yml
|
204
|
+
- test/integration/test-two.yaml
|
203
205
|
- test/integration/test_local.rb
|
204
206
|
- test/integration/test_ssh.rb
|
205
207
|
- test/integration/tests/path_block_device_test.rb
|
@@ -251,7 +253,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
251
253
|
version: '0'
|
252
254
|
requirements: []
|
253
255
|
rubyforge_project:
|
254
|
-
rubygems_version: 2.
|
256
|
+
rubygems_version: 2.5.1
|
255
257
|
signing_key:
|
256
258
|
specification_version: 4
|
257
259
|
summary: Transport interface to talk to different backends.
|
@@ -272,11 +274,13 @@ test_files:
|
|
272
274
|
- test/integration/sudo/passwd.rb
|
273
275
|
- test/integration/sudo/reqtty.rb
|
274
276
|
- test/integration/sudo/run_as.rb
|
277
|
+
- test/integration/test-one.yaml
|
275
278
|
- test/integration/test-travis-centos.yml
|
276
279
|
- test/integration/test-travis-debian.yml
|
277
280
|
- test/integration/test-travis-fedora.yml
|
278
281
|
- test/integration/test-travis-oel.yml
|
279
282
|
- test/integration/test-travis-ubuntu.yml
|
283
|
+
- test/integration/test-two.yaml
|
280
284
|
- test/integration/test_local.rb
|
281
285
|
- test/integration/test_ssh.rb
|
282
286
|
- test/integration/tests/path_block_device_test.rb
|