train 0.32.0 → 1.0.0
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 +19 -2
- data/README.md +22 -1
- data/lib/train/platforms.rb +1 -0
- data/lib/train/platforms/detect/helpers/os_common.rb +18 -0
- data/lib/train/platforms/detect/scanner.rb +1 -0
- data/lib/train/platforms/detect/specifications/api.rb +13 -0
- data/lib/train/platforms/detect/specifications/os.rb +44 -10
- data/lib/train/plugins/base_connection.rb +15 -0
- data/lib/train/transports/aws.rb +60 -0
- data/lib/train/transports/mock.rb +1 -8
- data/lib/train/transports/ssh_connection.rb +5 -0
- data/lib/train/version.rb +1 -1
- data/test/unit/platforms/os_detect_test.rb +32 -0
- data/test/unit/plugins/connection_test.rb +12 -0
- data/test/unit/transports/aws_test.rb +99 -0
- data/train.gemspec +1 -0
- metadata +21 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '008089b91adad72506c6825bad3e8b4c6837af27'
|
4
|
+
data.tar.gz: 7d584e084f13afe3ef7a915cbc7a19ee20597be3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67d87897890642480be62a48e8bc7571ebf0769f3561d85931bd524317c1503c0c4e4ff4e26b3a1d72e717a4f02c5f660956f741b0663046697d0549b3dd059d
|
7
|
+
data.tar.gz: 8c6f4246840527633d22c5aee4947cc17349cf77a8a2f742db541d11f9a371aee4f41825428ee2e163f277aabaae62ce75a5cef8abc406220da0f6b9d01934bf
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,23 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## [0.
|
4
|
-
[Full Changelog](https://github.com/chef/train/compare/v0.
|
3
|
+
## [1.0.0](https://github.com/chef/train/tree/1.0.0) (2018-02-01)
|
4
|
+
[Full Changelog](https://github.com/chef/train/compare/v0.32.0...1.0.0)
|
5
|
+
|
6
|
+
**Closed issues:**
|
7
|
+
|
8
|
+
- Add aws:// target [\#229](https://github.com/chef/train/issues/229)
|
9
|
+
|
10
|
+
**Merged pull requests:**
|
11
|
+
|
12
|
+
- cisco nexus + ios12 [\#247](https://github.com/chef/train/pull/247) ([arlimus](https://github.com/arlimus))
|
13
|
+
- Add a CONTRIBUTING.md to Train [\#245](https://github.com/chef/train/pull/245) ([miah](https://github.com/miah))
|
14
|
+
- catch detect failing to parse json [\#243](https://github.com/chef/train/pull/243) ([arlimus](https://github.com/arlimus))
|
15
|
+
- if ssh closes the session force it to reset and reopen [\#242](https://github.com/chef/train/pull/242) ([arlimus](https://github.com/arlimus))
|
16
|
+
- Add AWS transport [\#239](https://github.com/chef/train/pull/239) ([clintoncwolfe](https://github.com/clintoncwolfe))
|
17
|
+
- Fix detection of Scientific Linux [\#237](https://github.com/chef/train/pull/237) ([schrd](https://github.com/schrd))
|
18
|
+
|
19
|
+
## [v0.32.0](https://github.com/chef/train/tree/v0.32.0) (2018-01-04)
|
20
|
+
[Full Changelog](https://github.com/chef/train/compare/v0.31.1...v0.32.0)
|
5
21
|
|
6
22
|
**Fixed bugs:**
|
7
23
|
|
@@ -10,6 +26,7 @@
|
|
10
26
|
|
11
27
|
**Merged pull requests:**
|
12
28
|
|
29
|
+
- Release 0.32.0 [\#232](https://github.com/chef/train/pull/232) ([adamleff](https://github.com/adamleff))
|
13
30
|
- Set mock transport to use the platform instance variable [\#230](https://github.com/chef/train/pull/230) ([jquick](https://github.com/jquick))
|
14
31
|
|
15
32
|
## [v0.31.1](https://github.com/chef/train/tree/v0.31.1) (2017-12-06)
|
data/README.md
CHANGED
@@ -4,13 +4,14 @@
|
|
4
4
|
[](https://ci.appveyor.com/project/Chef/train/branch/master)
|
5
5
|
[](https://badge.fury.io/rb/train)
|
6
6
|
|
7
|
-
Train lets you talk to your local or remote operating systems with a unified interface.
|
7
|
+
Train lets you talk to your local or remote operating systems and APIs with a unified interface.
|
8
8
|
|
9
9
|
It allows you to:
|
10
10
|
|
11
11
|
* execute commands via `run_command`
|
12
12
|
* interact with files via `file`
|
13
13
|
* identify the target operating system via `os`
|
14
|
+
* authenticate to API-based services and treat them like a platform
|
14
15
|
|
15
16
|
Train supports:
|
16
17
|
|
@@ -19,6 +20,7 @@ Train supports:
|
|
19
20
|
* WinRM
|
20
21
|
* Docker
|
21
22
|
* Mock (for testing and debugging)
|
23
|
+
* AWS as an API
|
22
24
|
|
23
25
|
# Examples
|
24
26
|
|
@@ -61,6 +63,21 @@ require 'train'
|
|
61
63
|
train = Train.create('docker', host: 'container_id...')
|
62
64
|
```
|
63
65
|
|
66
|
+
**AWS**
|
67
|
+
|
68
|
+
To use AWS API authentication, setup an AWS client profile to store the Access Key ID and Secret Access Key.
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
require 'train'
|
72
|
+
train = Train.create('aws', region: 'us-east-2', profile: 'my-profile')
|
73
|
+
```
|
74
|
+
|
75
|
+
You may also use the standard AWS CLI environment variables, `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and `AWS_REGION`.
|
76
|
+
```ruby
|
77
|
+
require 'train'
|
78
|
+
train = Train.create('aws')
|
79
|
+
```
|
80
|
+
|
64
81
|
## Configuration
|
65
82
|
|
66
83
|
To get a list of available options for a plugin:
|
@@ -96,6 +113,10 @@ puts conn.os[:release]
|
|
96
113
|
# access files
|
97
114
|
puts conn.file('/proc/version').content
|
98
115
|
|
116
|
+
# access specific API client functionality
|
117
|
+
ec2_client = train.connection.aws_client(Aws::EC2::Client)
|
118
|
+
puts ec2_client.describe_instances
|
119
|
+
|
99
120
|
# close the connection
|
100
121
|
conn.close
|
101
122
|
```
|
data/lib/train/platforms.rb
CHANGED
@@ -52,5 +52,23 @@ module Train::Platforms::Detect::Helpers
|
|
52
52
|
return @uname[:m] if @uname.key?(:m)
|
53
53
|
@uname[:m] = command_output('uname -m')
|
54
54
|
end
|
55
|
+
|
56
|
+
def cisco_show_version
|
57
|
+
return @cache[:cisco] if @cache.key?(:cisco)
|
58
|
+
res = command_output('show version')
|
59
|
+
|
60
|
+
m = res.match(/^Cisco IOS Software, [^,]+? \(([^,]+?)\), Version (\d+\.\d+)/)
|
61
|
+
unless m.nil?
|
62
|
+
return @cache[:cisco] = { version: m[2], model: m[1], type: 'ios' }
|
63
|
+
end
|
64
|
+
|
65
|
+
m = res.match(/^Cisco Nexus Operating System \(NX-OS\) Software/)
|
66
|
+
unless m.nil?
|
67
|
+
v = res[/^\s*system:\s+version (\d+\.\d+)/, 1]
|
68
|
+
return @cache[:cisco] = { version: v, type: 'nexus' }
|
69
|
+
end
|
70
|
+
|
71
|
+
@cache[:cisco] = nil
|
72
|
+
end
|
55
73
|
end
|
56
74
|
end
|
@@ -27,12 +27,38 @@ module Train::Platforms::Detect::Specifications
|
|
27
27
|
# unix master family
|
28
28
|
plat.family('unix')
|
29
29
|
.detect {
|
30
|
-
|
30
|
+
# we want to catch a special case here where cisco commands
|
31
|
+
# don't return an exit status and still print to stdout
|
32
|
+
if unix_uname_s =~ /./ && !unix_uname_s.start_with?('Line has invalid autocommand ')
|
31
33
|
@platform[:arch] = unix_uname_m
|
32
34
|
true
|
33
35
|
end
|
34
36
|
}
|
35
37
|
|
38
|
+
# cisco_ios family
|
39
|
+
plat.family('cisco').title('Cisco Family')
|
40
|
+
.detect {
|
41
|
+
!cisco_show_version.nil?
|
42
|
+
}
|
43
|
+
|
44
|
+
plat.name('cisco_ios').title('Cisco IOS').in_family('cisco')
|
45
|
+
.detect {
|
46
|
+
v = cisco_show_version
|
47
|
+
next unless v[:type] == 'ios'
|
48
|
+
@platform[:release] = v[:version]
|
49
|
+
@platform[:arch] = nil
|
50
|
+
true
|
51
|
+
}
|
52
|
+
|
53
|
+
plat.name('cisco_nexus').title('Cisco Nexus').in_family('cisco')
|
54
|
+
.detect {
|
55
|
+
v = cisco_show_version
|
56
|
+
next unless v[:type] == 'nexus'
|
57
|
+
@platform[:release] = v[:version]
|
58
|
+
@platform[:arch] = nil
|
59
|
+
true
|
60
|
+
}
|
61
|
+
|
36
62
|
# arista_eos family
|
37
63
|
# this has to be before redhat as EOS is based off fedora
|
38
64
|
plat.family('arista_eos').title('Arista EOS Family').in_family('unix')
|
@@ -46,10 +72,14 @@ module Train::Platforms::Detect::Specifications
|
|
46
72
|
cmd = @backend.run_command('show version | json')
|
47
73
|
if cmd.exit_status == 0 && !cmd.stdout.empty?
|
48
74
|
require 'json'
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
75
|
+
begin
|
76
|
+
eos_ver = JSON.parse(cmd.stdout)
|
77
|
+
@platform[:release] = eos_ver['version']
|
78
|
+
@platform[:arch] = eos_ver['architecture']
|
79
|
+
true
|
80
|
+
rescue JSON::ParserError
|
81
|
+
nil
|
82
|
+
end
|
53
83
|
end
|
54
84
|
}
|
55
85
|
plat.name('arista_eos_bash').title('Arista EOS Bash Shell').in_family('arista_eos')
|
@@ -58,10 +88,14 @@ module Train::Platforms::Detect::Specifications
|
|
58
88
|
cmd = @backend.run_command('FastCli -p 15 -c "show version | json"')
|
59
89
|
if cmd.exit_status == 0 && !cmd.stdout.empty?
|
60
90
|
require 'json'
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
91
|
+
begin
|
92
|
+
eos_ver = JSON.parse(cmd.stdout)
|
93
|
+
@platform[:release] = eos_ver['version']
|
94
|
+
@platform[:arch] = eos_ver['architecture']
|
95
|
+
true
|
96
|
+
rescue JSON::ParserError
|
97
|
+
nil
|
98
|
+
end
|
65
99
|
end
|
66
100
|
end
|
67
101
|
}
|
@@ -158,7 +192,7 @@ module Train::Platforms::Detect::Specifications
|
|
158
192
|
plat.name('scientific').title('Scientific Linux').in_family('redhat')
|
159
193
|
.detect {
|
160
194
|
lsb = read_linux_lsb
|
161
|
-
if lsb && lsb[:id] =~ /
|
195
|
+
if lsb && lsb[:id] =~ /scientific/i
|
162
196
|
@platform[:release] = lsb[:release]
|
163
197
|
true
|
164
198
|
end
|
@@ -23,6 +23,7 @@ class Train::Plugins::Transport
|
|
23
23
|
@options = options || {}
|
24
24
|
@logger = @options.delete(:logger) || Logger.new(STDOUT)
|
25
25
|
Train::Platforms::Detect::Specifications::OS.load
|
26
|
+
Train::Platforms::Detect::Specifications::Api.load
|
26
27
|
|
27
28
|
# default caching options
|
28
29
|
@cache_enabled = {
|
@@ -76,6 +77,20 @@ class Train::Plugins::Transport
|
|
76
77
|
false
|
77
78
|
end
|
78
79
|
|
80
|
+
def direct_platform(name)
|
81
|
+
plat = Train::Platforms.name(name)
|
82
|
+
plat.backend = self
|
83
|
+
plat.family_hierarchy = family_hierarchy(plat).flatten
|
84
|
+
plat
|
85
|
+
end
|
86
|
+
|
87
|
+
def family_hierarchy(plat)
|
88
|
+
plat.families.each_with_object([]) do |(k, _v), memo|
|
89
|
+
memo << k.name
|
90
|
+
memo << family_hierarchy(k) unless k.families.empty?
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
79
94
|
# Get information on the operating system which this transport connects to.
|
80
95
|
#
|
81
96
|
# @return [Platform] system information
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'train/plugins'
|
3
|
+
require 'aws-sdk'
|
4
|
+
|
5
|
+
module Train::Transports
|
6
|
+
class Aws < Train.plugin(1)
|
7
|
+
name 'aws'
|
8
|
+
option :region, required: true, default: ENV['AWS_REGION']
|
9
|
+
option :access_key_id, default: ENV['AWS_ACCESS_KEY_ID']
|
10
|
+
option :secret_access_key, default: ENV['AWS_SECRET_ACCESS_KEY']
|
11
|
+
option :session_token, default: ENV['AWS_SESSION_TOKEN']
|
12
|
+
|
13
|
+
# This can provide the access key id and secret access key
|
14
|
+
option :profile, default: ENV['AWS_PROFILE']
|
15
|
+
|
16
|
+
def connection(_ = nil)
|
17
|
+
@connection ||= Connection.new(@options)
|
18
|
+
end
|
19
|
+
|
20
|
+
class Connection < BaseConnection
|
21
|
+
def initialize(options)
|
22
|
+
# Override for any cli options
|
23
|
+
# aws://region/my-profile
|
24
|
+
options[:region] = options[:host] || options[:region]
|
25
|
+
if options[:path]
|
26
|
+
# string the leading / from path
|
27
|
+
options[:profile] = options[:path][1..-1]
|
28
|
+
end
|
29
|
+
super(options)
|
30
|
+
|
31
|
+
@cache_enabled[:api_call] = true
|
32
|
+
@cache[:api_call] = {}
|
33
|
+
|
34
|
+
connect
|
35
|
+
end
|
36
|
+
|
37
|
+
def platform
|
38
|
+
direct_platform('aws')
|
39
|
+
end
|
40
|
+
|
41
|
+
def aws_client(klass)
|
42
|
+
return klass.new unless cache_enabled?(:api_call)
|
43
|
+
@cache[:api_call][klass.to_s.to_sym] ||= klass.new
|
44
|
+
end
|
45
|
+
|
46
|
+
def aws_resource(klass, args)
|
47
|
+
klass.new(args)
|
48
|
+
end
|
49
|
+
|
50
|
+
def connect
|
51
|
+
ENV['AWS_PROFILE'] = @options[:profile] if @options[:profile]
|
52
|
+
ENV['AWS_REGION'] = @options[:region] if @options[:region]
|
53
|
+
end
|
54
|
+
|
55
|
+
def uri
|
56
|
+
"aws://#{@options[:region]}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -75,19 +75,12 @@ class Train::Transports::Mock
|
|
75
75
|
value = { name: 'mock', family: 'mock', release: 'unknown', arch: 'unknown' }.merge(value)
|
76
76
|
|
77
77
|
platform = Train::Platforms.name(value[:name])
|
78
|
-
platform.family_hierarchy =
|
78
|
+
platform.family_hierarchy = family_hierarchy(platform).flatten
|
79
79
|
platform.platform = value
|
80
80
|
platform.add_platform_methods
|
81
81
|
@platform = platform
|
82
82
|
end
|
83
83
|
|
84
|
-
def mock_os_hierarchy(plat)
|
85
|
-
plat.families.each_with_object([]) do |(k, _v), memo|
|
86
|
-
memo << k.name
|
87
|
-
memo << mock_os_hierarchy(k) unless k.families.empty?
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
84
|
def commands=(commands)
|
92
85
|
@cache[:command] = commands
|
93
86
|
end
|
@@ -182,6 +182,7 @@ class Train::Transports::SSH
|
|
182
182
|
cmd.dup.force_encoding('binary') if cmd.respond_to?(:force_encoding)
|
183
183
|
logger.debug("[SSH] #{self} (#{cmd})")
|
184
184
|
|
185
|
+
reset_session if session.closed?
|
185
186
|
session.open_channel do |channel|
|
186
187
|
# wrap commands if that is configured
|
187
188
|
cmd = @cmd_wrapper.run(cmd) unless @cmd_wrapper.nil?
|
@@ -232,6 +233,10 @@ class Train::Transports::SSH
|
|
232
233
|
}.merge(retry_options))
|
233
234
|
end
|
234
235
|
|
236
|
+
def reset_session
|
237
|
+
@session = nil
|
238
|
+
end
|
239
|
+
|
235
240
|
# String representation of object, reporting its connection details and
|
236
241
|
# configuration.
|
237
242
|
#
|
data/lib/train/version.rb
CHANGED
@@ -44,6 +44,16 @@ describe 'os_detect' do
|
|
44
44
|
platform[:family].must_equal('redhat')
|
45
45
|
platform[:release].must_equal('7.2.1511')
|
46
46
|
end
|
47
|
+
it 'sets the correct family, name, and release on scientific linux' do
|
48
|
+
files = {
|
49
|
+
'/etc/redhat-release' => "Scientific Linux release 7.4 (Nitrogen)\n",
|
50
|
+
'/etc/os-release' => "NAME=\"Scientific Linux\"\nVERSION=\"7.4 (Nitrogen)\"\nID=\"rhel\"\nID_LIKE=\"scientific centos fedora\"\nVERSION_ID=\"7.4\"\nPRETTY_NAME=\"Scientific Linux 7.4 (Nitrogen)\"\nANSI_COLOR=\"0;31\"\nCPE_NAME=\"cpe:/o:scientificlinux:scientificlinux:7.4:GA\"\nHOME_URL=\"http://www.scientificlinux.org//\"\nBUG_REPORT_URL=\"mailto:scientific-linux-devel@listserv.fnal.gov\"\n\nREDHAT_BUGZILLA_PRODUCT=\"Scientific Linux 7\"\nREDHAT_BUGZILLA_PRODUCT_VERSION=7.4\nREDHAT_SUPPORT_PRODUCT=\"Scientific Linux\"\nREDHAT_SUPPORT_PRODUCT_VERSION=\"7.4\"\n",
|
51
|
+
}
|
52
|
+
platform = scan_with_files('linux', files)
|
53
|
+
platform[:name].must_equal('scientific')
|
54
|
+
platform[:family].must_equal('redhat')
|
55
|
+
platform[:release].must_equal('7.4')
|
56
|
+
end
|
47
57
|
end
|
48
58
|
end
|
49
59
|
|
@@ -172,4 +182,26 @@ describe 'os_detect' do
|
|
172
182
|
end
|
173
183
|
end
|
174
184
|
end
|
185
|
+
|
186
|
+
describe 'cisco' do
|
187
|
+
it 'recognizes Cisco IOS12' do
|
188
|
+
mock = Train::Transports::Mock::Connection.new
|
189
|
+
mock.mock_command('show version', "Cisco IOS Software, C3750E Software (C3750E-UNIVERSALK9-M), Version 12.2(58)SE")
|
190
|
+
platform = Train::Platforms::Detect.scan(mock)
|
191
|
+
|
192
|
+
platform[:name].must_equal('cisco_ios')
|
193
|
+
platform[:family].must_equal('cisco')
|
194
|
+
platform[:release].must_equal('12.2')
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'recognizes Cisco Nexus' do
|
198
|
+
mock = Train::Transports::Mock::Connection.new
|
199
|
+
mock.mock_command('show version', "Cisco Nexus Operating System (NX-OS) Software\n system: version 5.2(1)N1(8b)\n")
|
200
|
+
platform = Train::Platforms::Detect.scan(mock)
|
201
|
+
|
202
|
+
platform[:name].must_equal('cisco_nexus')
|
203
|
+
platform[:family].must_equal('cisco')
|
204
|
+
platform[:release].must_equal('5.2')
|
205
|
+
end
|
206
|
+
end
|
175
207
|
end
|
@@ -43,6 +43,18 @@ describe 'v1 Connection Plugin' do
|
|
43
43
|
.must_be_instance_of(Logger)
|
44
44
|
end
|
45
45
|
|
46
|
+
it 'provides direct platform' do
|
47
|
+
plat = connection.direct_platform('linux')
|
48
|
+
plat.name.must_equal 'linux'
|
49
|
+
plat.family_hierarchy.must_equal ['linux', 'unix']
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'provides family hierarchy' do
|
53
|
+
plat = Train::Platforms.name('linux')
|
54
|
+
family = connection.family_hierarchy(plat)
|
55
|
+
family.flatten.must_equal ['linux', 'unix']
|
56
|
+
end
|
57
|
+
|
46
58
|
it 'must use the user-provided logger' do
|
47
59
|
l = rand
|
48
60
|
cls.new({logger: l})
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'helper'
|
4
|
+
|
5
|
+
describe 'aws transport' do
|
6
|
+
def transport(options = nil)
|
7
|
+
ENV['AWS_REGION'] = 'test_region'
|
8
|
+
ENV['AWS_ACCESS_KEY_ID'] = 'test_key_id'
|
9
|
+
ENV['AWS_SECRET_ACCESS_KEY'] = 'test_access_key'
|
10
|
+
ENV['AWS_SESSION_TOKEN'] = 'test_session_token'
|
11
|
+
|
12
|
+
# need to require this at here as it captures the envs on load
|
13
|
+
require 'train/transports/aws'
|
14
|
+
Train::Transports::Aws.new(options)
|
15
|
+
end
|
16
|
+
let(:connection) { transport.connection }
|
17
|
+
let(:options) { connection.instance_variable_get(:@options) }
|
18
|
+
let(:cache) { connection.instance_variable_get(:@cache) }
|
19
|
+
|
20
|
+
describe 'options' do
|
21
|
+
it 'defaults to env options' do
|
22
|
+
options[:region].must_equal 'test_region'
|
23
|
+
options[:access_key_id].must_equal 'test_key_id'
|
24
|
+
options[:secret_access_key].must_equal 'test_access_key'
|
25
|
+
options[:session_token].must_equal 'test_session_token'
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'test options override' do
|
29
|
+
transport = transport(region: 'us-east-2', access_key_id: '8')
|
30
|
+
options = transport.connection.instance_variable_get(:@options)
|
31
|
+
options[:region].must_equal 'us-east-2'
|
32
|
+
options[:access_key_id].must_equal '8'
|
33
|
+
options[:secret_access_key].must_equal 'test_access_key'
|
34
|
+
options[:session_token].must_equal 'test_session_token'
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'test url parse override' do
|
38
|
+
transport = transport(host: 'us-east-2')
|
39
|
+
options = transport.connection.instance_variable_get(:@options)
|
40
|
+
options[:region].must_equal 'us-east-2'
|
41
|
+
options[:session_token].must_equal 'test_session_token'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'platform' do
|
46
|
+
it 'returns platform' do
|
47
|
+
plat = connection.platform
|
48
|
+
plat.name.must_equal 'aws'
|
49
|
+
plat.family_hierarchy.must_equal ['cloud', 'api']
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe 'aws_client' do
|
54
|
+
it 'test aws_client with caching' do
|
55
|
+
client = connection.aws_client(Object)
|
56
|
+
client.is_a?(Object).must_equal true
|
57
|
+
cache[:api_call].count.must_equal 1
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'test aws_client without caching' do
|
61
|
+
connection.disable_cache(:api_call)
|
62
|
+
client = connection.aws_client(Object)
|
63
|
+
client.is_a?(Object).must_equal true
|
64
|
+
cache[:api_call].count.must_equal 0
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe 'aws_resource' do
|
69
|
+
class AwsResource
|
70
|
+
attr_reader :hash
|
71
|
+
def initialize(hash)
|
72
|
+
@hash = hash
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'test aws_resource with arguments' do
|
77
|
+
hash = { user: 1, name: 'test_user' }
|
78
|
+
resource = connection.aws_resource(AwsResource, hash)
|
79
|
+
resource.hash.must_equal hash
|
80
|
+
cache[:api_call].count.must_equal 0
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe 'connect' do
|
85
|
+
it 'validate aws connection with profile' do
|
86
|
+
options[:profile] = 'xyz'
|
87
|
+
ENV['AWS_PROFILE'].must_be_nil
|
88
|
+
connection.connect
|
89
|
+
ENV['AWS_PROFILE'].must_equal 'xyz'
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'validate aws connection with region' do
|
93
|
+
options[:region] = 'xyz'
|
94
|
+
ENV['AWS_REGION'].must_equal 'test_region'
|
95
|
+
connection.connect
|
96
|
+
ENV['AWS_REGION'].must_equal 'xyz'
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
data/train.gemspec
CHANGED
@@ -33,6 +33,7 @@ Gem::Specification.new do |spec|
|
|
33
33
|
spec.add_dependency 'winrm', '~> 2.0'
|
34
34
|
spec.add_dependency 'winrm-fs', '~> 1.0'
|
35
35
|
spec.add_dependency 'docker-api', '~> 1.26'
|
36
|
+
spec.add_dependency 'aws-sdk', '~> 2'
|
36
37
|
|
37
38
|
spec.add_development_dependency 'mocha', '~> 1.1'
|
38
39
|
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: 0.
|
4
|
+
version: 1.0.0
|
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-01
|
11
|
+
date: 2018-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -120,6 +120,20 @@ dependencies:
|
|
120
120
|
- - "~>"
|
121
121
|
- !ruby/object:Gem::Version
|
122
122
|
version: '1.26'
|
123
|
+
- !ruby/object:Gem::Dependency
|
124
|
+
name: aws-sdk
|
125
|
+
requirement: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - "~>"
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '2'
|
130
|
+
type: :runtime
|
131
|
+
prerelease: false
|
132
|
+
version_requirements: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - "~>"
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '2'
|
123
137
|
- !ruby/object:Gem::Dependency
|
124
138
|
name: mocha
|
125
139
|
requirement: !ruby/object:Gem::Requirement
|
@@ -170,12 +184,14 @@ files:
|
|
170
184
|
- lib/train/platforms/detect/helpers/os_linux.rb
|
171
185
|
- lib/train/platforms/detect/helpers/os_windows.rb
|
172
186
|
- lib/train/platforms/detect/scanner.rb
|
187
|
+
- lib/train/platforms/detect/specifications/api.rb
|
173
188
|
- lib/train/platforms/detect/specifications/os.rb
|
174
189
|
- lib/train/platforms/family.rb
|
175
190
|
- lib/train/platforms/platform.rb
|
176
191
|
- lib/train/plugins.rb
|
177
192
|
- lib/train/plugins/base_connection.rb
|
178
193
|
- lib/train/plugins/transport.rb
|
194
|
+
- lib/train/transports/aws.rb
|
179
195
|
- lib/train/transports/docker.rb
|
180
196
|
- lib/train/transports/local.rb
|
181
197
|
- lib/train/transports/mock.rb
|
@@ -237,6 +253,7 @@ files:
|
|
237
253
|
- test/unit/plugins/transport_test.rb
|
238
254
|
- test/unit/plugins_test.rb
|
239
255
|
- test/unit/train_test.rb
|
256
|
+
- test/unit/transports/aws_test.rb
|
240
257
|
- test/unit/transports/local_test.rb
|
241
258
|
- test/unit/transports/mock_test.rb
|
242
259
|
- test/unit/transports/ssh_test.rb
|
@@ -264,7 +281,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
264
281
|
version: '0'
|
265
282
|
requirements: []
|
266
283
|
rubyforge_project:
|
267
|
-
rubygems_version: 2.
|
284
|
+
rubygems_version: 2.5.2
|
268
285
|
signing_key:
|
269
286
|
specification_version: 4
|
270
287
|
summary: Transport interface to talk to different backends.
|
@@ -322,6 +339,7 @@ test_files:
|
|
322
339
|
- test/unit/plugins/transport_test.rb
|
323
340
|
- test/unit/plugins_test.rb
|
324
341
|
- test/unit/train_test.rb
|
342
|
+
- test/unit/transports/aws_test.rb
|
325
343
|
- test/unit/transports/local_test.rb
|
326
344
|
- test/unit/transports/mock_test.rb
|
327
345
|
- test/unit/transports/ssh_test.rb
|