train 1.5.4 → 1.5.6

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: 1f8a8136ef1361afa88f951fb3095bd894482ae737d5546c94a2311027383797
4
- data.tar.gz: 3214e7d84ffe45af4d0997c444a052d49607fe6fb3d79fbfc737068328b553e5
3
+ metadata.gz: ce0372a342eb1702aac1255a5cfaadfdd5af73bd46a87e8a5b34f8723a4bfc5e
4
+ data.tar.gz: 56157c304c959c95cb162fb71c6d2f9f431bf08bea2e6d893c56076d856380f0
5
5
  SHA512:
6
- metadata.gz: 80f9ff5fac3af02c41061434cef335569cb6e4d1b067027c9b7f119e844e5193655eb7d58d1f9b16504b8f8d0c28c51b008f51c7dda27597adfa346088696570
7
- data.tar.gz: fe2a5fa5de52041ffeb96d7349cd2949e98ec410bb501494f7643c48b79d546a5a393f99261f961b3dbb05948d0ee728a288b9ec4c5bbba5ed4dbf938e54d1a7
6
+ metadata.gz: d9f4a5d1598844f73eff994fee266ab5757e62cd1c2c9e3b69245d7f9db5fa3db6361151df7d1720762919644cf24c15248c18b85701c25153ee4e6d2cfd2da7
7
+ data.tar.gz: e2605fe51549fe888f22e6a16c186b1945a9630a399642eee951dc34446ae1cc461ae264db0979737fb0cd5f060b2cb03e845d7108d2c7a5cf57bcc5a3161565
@@ -1,21 +1,28 @@
1
- <!-- latest_release 1.5.4 -->
2
- ## [v1.5.4](https://github.com/inspec/train/tree/v1.5.4) (2018-10-15)
1
+ <!-- latest_release 1.5.6 -->
2
+ ## [v1.5.6](https://github.com/inspec/train/tree/v1.5.6) (2018-11-01)
3
3
 
4
4
  #### Merged Pull Requests
5
- - Correct example plugin link [#363](https://github.com/inspec/train/pull/363) ([jerryaldrichiii](https://github.com/jerryaldrichiii))
5
+ - Adds cached_client method in BaseConnection [#371](https://github.com/inspec/train/pull/371) ([dmccown](https://github.com/dmccown))
6
6
  <!-- latest_release -->
7
7
 
8
- <!-- release_rollup since=1.5.0 -->
9
- ### Changes since 1.5.0 release
8
+ <!-- release_rollup since=1.5.4 -->
9
+ ### Changes since 1.5.4 release
10
10
 
11
11
  #### Merged Pull Requests
12
- - Correct example plugin link [#363](https://github.com/inspec/train/pull/363) ([jerryaldrichiii](https://github.com/jerryaldrichiii)) <!-- 1.5.4 -->
13
- - Adds Azure Vault Client [#351](https://github.com/inspec/train/pull/351) ([r-fennell](https://github.com/r-fennell)) <!-- 1.5.3 -->
14
- - Remove the legacy version bumping from the rakefile [#359](https://github.com/inspec/train/pull/359) ([tas50](https://github.com/tas50)) <!-- 1.5.2 -->
15
- - Fixes the link pointing back to the plugin docs [#362](https://github.com/inspec/train/pull/362) ([cattywampus](https://github.com/cattywampus)) <!-- 1.5.1 -->
12
+ - Adds cached_client method in BaseConnection [#371](https://github.com/inspec/train/pull/371) ([dmccown](https://github.com/dmccown)) <!-- 1.5.6 -->
13
+ - Fix Cisco IOS detection when banners lack a `\r\n` [#372](https://github.com/inspec/train/pull/372) ([jerryaldrichiii](https://github.com/jerryaldrichiii)) <!-- 1.5.5 -->
16
14
  <!-- release_rollup -->
17
15
 
18
16
  <!-- latest_stable_release -->
17
+ ## [v1.5.4](https://github.com/inspec/train/tree/v1.5.4) (2018-10-18)
18
+
19
+ #### Merged Pull Requests
20
+ - Fixes the link pointing back to the plugin docs [#362](https://github.com/inspec/train/pull/362) ([cattywampus](https://github.com/cattywampus))
21
+ - Remove the legacy version bumping from the rakefile [#359](https://github.com/inspec/train/pull/359) ([tas50](https://github.com/tas50))
22
+ - Adds Azure Vault Client [#351](https://github.com/inspec/train/pull/351) ([r-fennell](https://github.com/r-fennell))
23
+ - Correct example plugin link [#363](https://github.com/inspec/train/pull/363) ([jerryaldrichiii](https://github.com/jerryaldrichiii))
24
+ <!-- latest_stable_release -->
25
+
19
26
  ## [v1.5.0](https://github.com/inspec/train/tree/v1.5.0) (2018-09-27)
20
27
 
21
28
  #### Merged Pull Requests
@@ -23,7 +30,6 @@
23
30
  - Adding GCP admin_client helper. [#349](https://github.com/inspec/train/pull/349) ([skpaterson](https://github.com/skpaterson))
24
31
  - Plugins: Test harness, test fixture, docs, and local-type example [#356](https://github.com/inspec/train/pull/356) ([clintoncwolfe](https://github.com/clintoncwolfe))
25
32
  - Bump minor version. [#357](https://github.com/inspec/train/pull/357) ([jquick](https://github.com/jquick))
26
- <!-- latest_stable_release -->
27
33
 
28
34
  ## [v1.4.37](https://github.com/inspec/train/tree/v1.4.37) (2018-09-13)
29
35
 
@@ -69,17 +69,17 @@ module Train::Platforms::Detect::Helpers
69
69
  return @cache[:cisco] if @cache.key?(:cisco)
70
70
  res = command_output('show version')
71
71
 
72
- m = res.match(/^Cisco IOS Software, [^,]+? \(([^,]+?)\), Version (\d+\.\d+)/)
72
+ m = res.match(/Cisco IOS Software, [^,]+? \(([^,]+?)\), Version (\d+\.\d+)/)
73
73
  unless m.nil?
74
74
  return @cache[:cisco] = { version: m[2], model: m[1], type: 'ios' }
75
75
  end
76
76
 
77
- m = res.match(/^Cisco IOS Software, IOS-XE Software, [^,]+? \(([^,]+?)\), Version (\d+\.\d+\.\d+[A-Z]*)/)
77
+ m = res.match(/Cisco IOS Software, IOS-XE Software, [^,]+? \(([^,]+?)\), Version (\d+\.\d+\.\d+[A-Z]*)/)
78
78
  unless m.nil?
79
79
  return @cache[:cisco] = { version: m[2], model: m[1], type: 'ios-xe' }
80
80
  end
81
81
 
82
- m = res.match(/^Cisco Nexus Operating System \(NX-OS\) Software/)
82
+ m = res.match(/Cisco Nexus Operating System \(NX-OS\) Software/)
83
83
  unless m.nil?
84
84
  v = res[/^\s*system:\s+version (\d+\.\d+)/, 1]
85
85
  return @cache[:cisco] = { version: v, type: 'nexus' }
@@ -37,6 +37,25 @@ class Train::Plugins::Transport
37
37
  end
38
38
  end
39
39
 
40
+ # Returns cached client if caching enabled. Otherwise returns whatever is
41
+ # given in the block.
42
+ #
43
+ # @example
44
+ #
45
+ # def demo_client
46
+ # cached_client(:api_call, :demo_connection) do
47
+ # DemoClient.new(args)
48
+ # end
49
+ # end
50
+ #
51
+ # @param [symbol] type one of [:api_call, :file, :command]
52
+ # @param [symbol] key for your cached connection
53
+ def cached_client(type, key)
54
+ return yield unless cache_enabled?(type)
55
+
56
+ @cache[type][key] ||= yield
57
+ end
58
+
40
59
  def cache_enabled?(type)
41
60
  @cache_enabled[type.to_sym]
42
61
  end
@@ -3,5 +3,5 @@
3
3
  # Author:: Dominik Richter (<dominik.richter@gmail.com>)
4
4
 
5
5
  module Train
6
- VERSION = '1.5.4'.freeze
6
+ VERSION = '1.5.6'.freeze
7
7
  end
@@ -78,6 +78,54 @@ describe 'v1 Connection Plugin' do
78
78
  .method(:logger).call.must_equal(l)
79
79
  end
80
80
 
81
+ describe 'cached_client helper' do
82
+ class DemoConnection < Train::Plugins::Transport::BaseConnection
83
+ def initialize(options = {})
84
+ super(options)
85
+ @cache_enabled[:api_call] = true
86
+ @cache[:api_call] = {}
87
+ end
88
+
89
+ def demo_client
90
+ cached_client(:api_call, :demo_client) do
91
+ DemoClient.new
92
+ end
93
+ end
94
+
95
+ class DemoClient
96
+ end
97
+ end
98
+
99
+ it 'returns a new connection when cached disabled' do
100
+ conn = DemoConnection.new
101
+ conn.disable_cache(:api_call)
102
+
103
+ client1 = conn.demo_client
104
+ client2 = conn.demo_client
105
+
106
+ client1.wont_be_same_as client2
107
+ end
108
+
109
+ it 'returns a new connection when cache enabled and not hydrated' do
110
+ conn = DemoConnection.new
111
+ conn.enable_cache(:api_call)
112
+
113
+ client1 = conn.demo_client
114
+
115
+ client1.must_be_instance_of DemoConnection::DemoClient
116
+ end
117
+
118
+ it 'returns a cached connection when cache enabled and hydrated' do
119
+ conn = DemoConnection.new
120
+ conn.enable_cache(:api_call)
121
+
122
+ client1 = conn.demo_client
123
+ client2 = conn.demo_client
124
+
125
+ client1.must_be_same_as client2
126
+ end
127
+ end
128
+
81
129
  describe 'create cache connection' do
82
130
  it 'default connection cache settings' do
83
131
  connection.cache_enabled?(:file).must_equal true
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.5.4
4
+ version: 1.5.6
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-10-15 00:00:00.000000000 Z
11
+ date: 2018-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json