train 1.4.29 → 1.4.31

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 65be3294011740eca689d8b5de1273f14f37d5189eae2a29111a4d268701af3a
4
- data.tar.gz: bceb7f68344642b8f010b3e1ed5882afa4f4587fd7ebd1459635c2ca8954c3c6
3
+ metadata.gz: 41dd0a819427f0fdb0394992ca48fd80d9d67dd45d7a6c666472f48cb79cacb0
4
+ data.tar.gz: 8c05af271415f0165a1a68b2495832ba89f84864dcb5c26e498fd48e2cc4d43f
5
5
  SHA512:
6
- metadata.gz: 34e6e054bb02d891857461d62756f02f63b0f42491ed7768764c82a6f1b1c3ab9b8158878ac4a1ebf4d6482b4cec62be7de2168f2980c84f662725dca48d2490
7
- data.tar.gz: 3104bcaf1ba5edf30ed53702248c0f52e02d50435812a5eb0b6158a7873f6e85f28109e680184f22c6f445fe319113a94ccb2e0ec362150cb8ac285d2805d3e9
6
+ metadata.gz: 55719a930b672cab82cfeb76aebf0fa26643a75de1c61d618f65236d291682786a786376679a61c5533940c34391cb10d400f85852cd07b1e8d01b29f682b3f4
7
+ data.tar.gz: ab0665695a28b1e86b21fb83d2093907bb7850870603bba2fd35efb21b1b37c7e101a39dd6b4814cfea8d518ac762931275a9f578dad60c577fefc504f4ec1c0
data/.rubocop.yml CHANGED
@@ -28,6 +28,8 @@ Metrics/PerceivedComplexity:
28
28
  Max: 10
29
29
  Metrics/AbcSize:
30
30
  Max: 33
31
+ Metrics/ModuleLength:
32
+ Enabled: false
31
33
  Style/PercentLiteralDelimiters:
32
34
  PreferredDelimiters:
33
35
  '%': '{}'
data/CHANGELOG.md CHANGED
@@ -1,28 +1,34 @@
1
- <!-- latest_release 1.4.29 -->
2
- ## [v1.4.29](https://github.com/inspec/train/tree/v1.4.29) (2018-08-15)
1
+ <!-- latest_release 1.4.31 -->
2
+ ## [v1.4.31](https://github.com/inspec/train/tree/v1.4.31) (2018-08-16)
3
3
 
4
4
  #### Merged Pull Requests
5
- - Add non_interactive support for SSH [#336](https://github.com/inspec/train/pull/336) ([marcparadise](https://github.com/marcparadise))
5
+ - Enable using rubygems as plugins [#335](https://github.com/inspec/train/pull/335) ([clintoncwolfe](https://github.com/clintoncwolfe))
6
6
  <!-- latest_release -->
7
7
 
8
- <!-- release_rollup since=1.4.25 -->
9
- ### Changes since 1.4.25 release
10
-
11
- #### Features & Enhancements
12
- - Pulls file credentials parsing out of Azure class [#324](https://github.com/inspec/train/pull/324) ([dmccown](https://github.com/dmccown)) <!-- 1.4.27 -->
8
+ <!-- release_rollup since=1.4.29 -->
9
+ ### Changes since 1.4.29 release
13
10
 
14
11
  #### Merged Pull Requests
15
- - Add non_interactive support for SSH [#336](https://github.com/inspec/train/pull/336) ([marcparadise](https://github.com/marcparadise)) <!-- 1.4.29 -->
16
- - Require Ruby 2.0 and allow net-ssh 5.0 [#334](https://github.com/inspec/train/pull/334) ([tas50](https://github.com/tas50)) <!-- 1.4.28 -->
17
- - Modify checksum logic to use system binaries [#251](https://github.com/inspec/train/pull/251) ([jerryaldrichiii](https://github.com/jerryaldrichiii)) <!-- 1.4.26 -->
12
+ - Enable using rubygems as plugins [#335](https://github.com/inspec/train/pull/335) ([clintoncwolfe](https://github.com/clintoncwolfe)) <!-- 1.4.31 -->
13
+ - Fixes an issue where the credential file was nil [#337](https://github.com/inspec/train/pull/337) ([dmccown](https://github.com/dmccown)) <!-- 1.4.30 -->
18
14
  <!-- release_rollup -->
19
15
 
20
16
  <!-- latest_stable_release -->
17
+ ## [v1.4.29](https://github.com/inspec/train/tree/v1.4.29) (2018-08-15)
18
+
19
+ #### Features & Enhancements
20
+ - Pulls file credentials parsing out of Azure class [#324](https://github.com/inspec/train/pull/324) ([dmccown](https://github.com/dmccown))
21
+
22
+ #### Merged Pull Requests
23
+ - Modify checksum logic to use system binaries [#251](https://github.com/inspec/train/pull/251) ([jerryaldrichiii](https://github.com/jerryaldrichiii))
24
+ - Require Ruby 2.0 and allow net-ssh 5.0 [#334](https://github.com/inspec/train/pull/334) ([tas50](https://github.com/tas50))
25
+ - Add non_interactive support for SSH [#336](https://github.com/inspec/train/pull/336) ([marcparadise](https://github.com/marcparadise))
26
+ <!-- latest_stable_release -->
27
+
21
28
  ## [v1.4.25](https://github.com/inspec/train/tree/v1.4.25) (2018-08-01)
22
29
 
23
30
  #### Merged Pull Requests
24
31
  - Remove not needed google-cloud dependency (see #328) and correct GCP … [#329](https://github.com/inspec/train/pull/329) ([skpaterson](https://github.com/skpaterson))
25
- <!-- latest_stable_release -->
26
32
 
27
33
  ## [v1.4.24](https://github.com/inspec/train/tree/v1.4.24) (2018-07-26)
28
34
 
data/Gemfile CHANGED
@@ -19,6 +19,13 @@ group :test do
19
19
  gem 'rubocop', '~> 0.36.0'
20
20
  gem 'simplecov', '~> 0.10'
21
21
  gem 'concurrent-ruby', '~> 1.0'
22
+ gem 'pry-byebug'
23
+ gem 'm'
24
+ # This is not a true gem installation
25
+ # (Gem::Specification.find_by_path('train-gem-fixture') will return nil)
26
+ # but it's close enough to show the gempath handler can find a plugin
27
+ # See test/unit/
28
+ gem 'train-gem-fixture', path: 'test/fixtures/gempath/gems'
22
29
  end
23
30
 
24
31
  group :integration do
data/lib/train.rb CHANGED
@@ -36,16 +36,29 @@ module Train
36
36
  #
37
37
  # @param [String] name of the plugin
38
38
  # @return [Train::Transport] the transport plugin
39
- def self.load_transport(name)
40
- res = Train::Plugins.registry[name.to_s]
41
- return res unless res.nil?
42
-
43
- # if the plugin wasnt loaded yet:
44
- require 'train/transports/' + name.to_s
45
- Train::Plugins.registry[name.to_s]
39
+ def self.load_transport(transport_name)
40
+ transport_name = transport_name.to_s
41
+ transport_class = Train::Plugins.registry[transport_name]
42
+ return transport_class unless transport_class.nil?
43
+
44
+ # Try to load the transport name from the core transports...
45
+ require 'train/transports/' + transport_name
46
+ return Train::Plugins.registry[transport_name]
46
47
  rescue LoadError => _
47
- raise Train::UserError,
48
- "Can't find train plugin #{name.inspect}. Please install it first."
48
+ begin
49
+ # If it's not in the core transports, try loading from a train plugin gem.
50
+ gem_name = 'train-' + transport_name
51
+ require gem_name
52
+ return Train::Plugins.registry[transport_name]
53
+ # rubocop: disable Lint/HandleExceptions
54
+ rescue LoadError => _
55
+ # rubocop: enable Lint/HandleExceptions
56
+ # Intentionally empty rescue - we're handling it below anyway
57
+ end
58
+
59
+ ex = Train::PluginLoadError.new("Can't find train plugin #{transport_name}. Please install it first.")
60
+ ex.transport_name = transport_name
61
+ raise ex
49
62
  end
50
63
 
51
64
  # Resolve target configuration in URI-scheme into
data/lib/train/errors.rb CHANGED
@@ -23,6 +23,11 @@ module Train
23
23
  # errors.
24
24
  class UserError < Error; end
25
25
 
26
+ # We could not load a plugin, because of a user error
27
+ class PluginLoadError < UserError
28
+ attr_accessor :transport_name
29
+ end
30
+
26
31
  # Base exception class for all exceptions that are caused by incorrect use
27
32
  # of an API.
28
33
  class ClientError < Error; end
@@ -5,7 +5,7 @@ require 'train/platforms/detect/helpers/os_windows'
5
5
  require 'rbconfig'
6
6
 
7
7
  module Train::Platforms::Detect::Helpers
8
- module OSCommon # rubocop:disable Metrics/ModuleLength
8
+ module OSCommon
9
9
  include Train::Platforms::Detect::Helpers::Linux
10
10
  include Train::Platforms::Detect::Helpers::Windows
11
11
 
@@ -77,7 +77,7 @@ class Train::Plugins::Transport
77
77
  false
78
78
  end
79
79
 
80
- def direct_platform(name, platform_details = nil)
80
+ def force_platform!(name, platform_details = nil)
81
81
  plat = Train::Platforms.name(name)
82
82
  plat.backend = self
83
83
  plat.platform = platform_details unless platform_details.nil?
@@ -86,6 +86,8 @@ class Train::Plugins::Transport
86
86
  plat
87
87
  end
88
88
 
89
+ alias direct_platform force_platform!
90
+
89
91
  def family_hierarchy(plat)
90
92
  plat.families.each_with_object([]) do |(k, _v), memo|
91
93
  memo << k.name
@@ -39,7 +39,7 @@ module Train::Transports
39
39
  end
40
40
 
41
41
  def platform
42
- direct_platform('aws', @platform_details)
42
+ force_platform!('aws', @platform_details)
43
43
  end
44
44
 
45
45
  def aws_client(klass)
@@ -51,7 +51,7 @@ module Train::Transports
51
51
  end
52
52
 
53
53
  def platform
54
- direct_platform('azure', @platform_details)
54
+ force_platform!('azure', @platform_details)
55
55
  end
56
56
 
57
57
  def azure_client(klass = ::Azure::Resources::Profiles::Latest::Mgmt::Client)
@@ -43,7 +43,7 @@ module Train::Transports
43
43
  end
44
44
 
45
45
  def platform
46
- direct_platform('gcp', @platform_details)
46
+ force_platform!('gcp', @platform_details)
47
47
  end
48
48
 
49
49
  # Instantiate some named classes for ease of use
@@ -12,6 +12,7 @@ module Train::Transports
12
12
  DEFAULT_FILE = ::File.join(Dir.home, '.azure', 'credentials')
13
13
 
14
14
  def self.parse(subscription_id: nil, credentials_file: DEFAULT_FILE, **_)
15
+ credentials_file = DEFAULT_FILE if credentials_file.nil?
15
16
  return {} unless ::File.readable?(credentials_file)
16
17
  credentials = IniFile.load(::File.expand_path(credentials_file))
17
18
  subscription_id = parser(subscription_id, ENV['AZURE_SUBSCRIPTION_NUMBER'], credentials).subscription_id
@@ -74,7 +74,7 @@ module Train::Transports
74
74
  end
75
75
 
76
76
  def platform
77
- direct_platform('vmware', @platform_details)
77
+ force_platform!('vmware', @platform_details)
78
78
  end
79
79
 
80
80
  def run_command_via_connection(cmd)
data/lib/train/version.rb CHANGED
@@ -3,5 +3,5 @@
3
3
  # Author:: Dominik Richter (<dominik.richter@gmail.com>)
4
4
 
5
5
  module Train
6
- VERSION = '1.4.29'.freeze
6
+ VERSION = '1.4.31'.freeze
7
7
  end
@@ -0,0 +1 @@
1
+ This is a very simple train transport plugin, laid out as though it were an installed gem. It is not a good example to use for learning, nor a good base for starting your own plugin - it's intended for for use during the testing of Train.
@@ -0,0 +1,2 @@
1
+ require 'train'
2
+ require 'train-gem-fixture/transport'
@@ -0,0 +1,7 @@
1
+ module TrainTransports
2
+ class GemFixture < Train.plugin(1)
3
+ name 'gem-fixture'
4
+
5
+ # what else do we need to implement?
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module TrainTransports
2
+ class GemFixture
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,34 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "train-gem-fixture"
7
+ spec.version = '0.1.0'
8
+ spec.authors = ["Inspec core engineering team"]
9
+ spec.email = ["hello@chef.io"]
10
+
11
+ spec.summary = %q{Test train plugin, packaged as a local gem}
12
+ spec.description = %q{Test train plugin, packaged as a local gem}
13
+ spec.homepage = "https://github.com/inspec/train"
14
+
15
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
16
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
17
+ if spec.respond_to?(:metadata)
18
+ spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
19
+ else
20
+ raise "RubyGems 2.0 or newer is required to protect against " \
21
+ "public gem pushes."
22
+ end
23
+
24
+ spec.files = %w{
25
+ README.md
26
+ lib/train-gem-fixture.rb
27
+ lib/train-gem-fixture/version.rb
28
+ lib/train-gem-fixture/transport.rb
29
+ }
30
+ spec.executables = []
31
+ spec.require_paths = ["lib"]
32
+
33
+ # No deps
34
+ end
@@ -36,7 +36,7 @@ describe 'uuid' do
36
36
  end
37
37
 
38
38
  mock.files = file_objects
39
- mock.direct_platform(name, plat_options)
39
+ mock.force_platform!(name, plat_options)
40
40
  end
41
41
 
42
42
  it 'finds a linux uuid from chef entity_uuid' do
@@ -44,7 +44,7 @@ describe 'v1 Connection Plugin' do
44
44
  end
45
45
 
46
46
  it 'provides direct platform' do
47
- plat = connection.direct_platform('mac_os_x')
47
+ plat = connection.force_platform!('mac_os_x')
48
48
  plat.name.must_equal 'mac_os_x'
49
49
  plat.linux?.must_equal false
50
50
  plat.cloud?.must_equal false
@@ -54,7 +54,7 @@ describe 'v1 Connection Plugin' do
54
54
  end
55
55
 
56
56
  it 'provides api direct platform' do
57
- plat = connection.direct_platform('aws')
57
+ plat = connection.force_platform!('aws')
58
58
  plat.name.must_equal 'aws'
59
59
  plat.linux?.must_equal false
60
60
  plat.cloud?.must_equal true
@@ -66,7 +66,7 @@ describe 'v1 Connection Plugin' do
66
66
  aws_version = Gem.loaded_specs['aws-sdk'].version
67
67
  aws_version = "aws-sdk-v#{aws_version}"
68
68
  details = { release: aws_version }
69
- plat = connection.direct_platform('aws', details)
69
+ plat = connection.force_platform!('aws', details)
70
70
  plat.name.must_equal 'aws'
71
71
  plat.release.must_equal aws_version
72
72
  plat[:release].must_equal aws_version
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  #
3
3
  # Author:: Dominik Richter (<dominik.richter@gmail.com>)
4
- require 'helper'
4
+ require_relative 'helper'
5
5
 
6
6
  describe Train do
7
7
  before do
@@ -11,9 +11,10 @@ describe Train do
11
11
  describe '#create' do
12
12
  it 'raises an error if the plugin isnt found' do
13
13
  proc { Train.create('missing') }.must_raise Train::UserError
14
+ proc { Train.create('missing') }.must_raise Train::PluginLoadError
14
15
  end
15
16
 
16
- it 'load a plugin if it isnt in the registry yet via symbol' do
17
+ it 'loads a core plugin if it isnt in the registry yet via symbol' do
17
18
  Kernel.stub :require, true do
18
19
  ex = Class.new(Train.plugin 1) { name 'existing' }
19
20
  train = Train.create(:existing)
@@ -21,18 +22,30 @@ describe Train do
21
22
  end
22
23
  end
23
24
 
24
- it 'load a plugin if it isnt in the registry yet via string' do
25
+ it 'loads a core plugin if it isnt in the registry yet via string' do
25
26
  Kernel.stub :require, true do
26
27
  ex = Class.new(Train.plugin 1) { name 'existing' }
27
28
  train = Train.create('existing')
28
29
  train.class.must_equal ex
29
30
  end
30
31
  end
32
+
33
+ it 'loads a gem plugin if it isnt in the registry yet via string' do
34
+ # The 'train-gem-fixture' gem is located in test/fixtures/gempath/gems and is
35
+ # added to the gempath via Bundler. The key difference is that it isn't under
36
+ # lib/train/trainsports, and Train will need to pre-pend 'train-' to the
37
+ # transport name to get the gem name.
38
+ transport = Train.create('gem-fixture')
39
+ # Normally one would call transport.class.name, but that's been overridden to be a write-only DSL method
40
+ # So use to_s
41
+ transport.class.to_s.must_equal 'TrainTransports::GemFixture'
42
+ end
31
43
  end
32
44
 
33
45
  describe '#options' do
34
46
  it 'raises exception if a given transport plugin isnt found' do
35
47
  proc { Train.options('missing') }.must_raise Train::UserError
48
+ proc { Train.options('missing') }.must_raise Train::PluginLoadError
36
49
  end
37
50
 
38
51
  it 'provides empty options of a transport plugin' do
@@ -38,6 +38,14 @@ describe 'parse_credentials_file' do
38
38
 
39
39
  let(:options) { { credentials_file: cred_file_multiple_entries.path } }
40
40
 
41
+ it 'handles a nil file' do
42
+ options[:credentials_file] = nil
43
+
44
+ result = Train::Transports::Helpers::Azure::FileCredentials.parse(options)
45
+
46
+ assert_empty(result)
47
+ end
48
+
41
49
  it 'returns empty hash when no credentials file detected' do
42
50
  result = Train::Transports::Helpers::Azure::FileCredentials.parse({})
43
51
 
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: 1.4.29
4
+ version: 1.4.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominik Richter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-15 00:00:00.000000000 Z
11
+ date: 2018-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -265,6 +265,11 @@ files:
265
265
  - lib/train/transports/winrm.rb
266
266
  - lib/train/transports/winrm_connection.rb
267
267
  - lib/train/version.rb
268
+ - test/fixtures/gempath/gems/train-gem-fixture-0.1.0/README.md
269
+ - test/fixtures/gempath/gems/train-gem-fixture-0.1.0/lib/train-gem-fixture.rb
270
+ - test/fixtures/gempath/gems/train-gem-fixture-0.1.0/lib/train-gem-fixture/transport.rb
271
+ - test/fixtures/gempath/gems/train-gem-fixture-0.1.0/lib/train-gem-fixture/version.rb
272
+ - test/fixtures/gempath/gems/train-gem-fixture-0.1.0/train-gem-fixture.gemspec
268
273
  - test/integration/.kitchen.yml
269
274
  - test/integration/Berksfile
270
275
  - test/integration/bootstrap.sh
@@ -360,6 +365,11 @@ signing_key:
360
365
  specification_version: 4
361
366
  summary: Transport interface to talk to different backends.
362
367
  test_files:
368
+ - test/fixtures/gempath/gems/train-gem-fixture-0.1.0/README.md
369
+ - test/fixtures/gempath/gems/train-gem-fixture-0.1.0/lib/train-gem-fixture.rb
370
+ - test/fixtures/gempath/gems/train-gem-fixture-0.1.0/lib/train-gem-fixture/transport.rb
371
+ - test/fixtures/gempath/gems/train-gem-fixture-0.1.0/lib/train-gem-fixture/version.rb
372
+ - test/fixtures/gempath/gems/train-gem-fixture-0.1.0/train-gem-fixture.gemspec
363
373
  - test/integration/.kitchen.yml
364
374
  - test/integration/Berksfile
365
375
  - test/integration/bootstrap.sh