j-enc 0.0.7 → 0.0.8
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/enc/collins_helper/api.rb +13 -1
- data/lib/enc/runner.rb +5 -4
- data/lib/enc/version.rb +1 -1
- data/spec/api_spec.rb +9 -3
- data/spec/factories/response.rb +23 -1
- data/spec/spec_helper.rb +10 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cedaed2d68d7e0610864d2e4bbc7c6a97e135d87
|
4
|
+
data.tar.gz: 882eeaea7bc9c284b76acf1dbfd41098edf1ad2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 389a32e8e47e2689fa3b2c6cf252111fa82f6a22501e9d4e183456b3bdf1ae3936b1f2344dc9ea7d3e5d68d14e32afd5774b7266bce09f8fb339145764199b4b
|
7
|
+
data.tar.gz: ae6199f28d9f952d5851d63089267cf8bfa84103fcd13b87f9c93db8dcef42afbc3724f2ecd59e71d6c5ae0a3f6cb7f7323a191ea4c1a1a8b2bd1c511d3b6c8c
|
@@ -40,6 +40,18 @@ module Enc
|
|
40
40
|
raise AssetNotValid, 'Asset is not valid' unless asset.is_valid?
|
41
41
|
asset
|
42
42
|
end
|
43
|
+
|
44
|
+
def safe_find_exact(options = {})
|
45
|
+
exact_options = {}
|
46
|
+
options.each do |k,v|
|
47
|
+
if v.is_a?String
|
48
|
+
exact_options[k] = "^#{v}$"
|
49
|
+
else
|
50
|
+
exact_options[k] = v
|
51
|
+
end
|
52
|
+
end
|
53
|
+
safe_find(exact_options)
|
54
|
+
end
|
43
55
|
end
|
44
56
|
end
|
45
|
-
end
|
57
|
+
end
|
data/lib/enc/runner.rb
CHANGED
@@ -28,9 +28,8 @@ module Enc
|
|
28
28
|
# It's important to handle any errors here so we know when to fall back to the cache.
|
29
29
|
begin
|
30
30
|
connection = Enc::CollinsHelper::Connection.new(@config)
|
31
|
-
return connection.api.
|
32
|
-
rescue Enc::CollinsHelper::Api::
|
33
|
-
Enc::CollinsHelper::Api::CannotConnect,
|
31
|
+
return connection.api.safe_find_exact(:hostname => hostname, :details => true), true
|
32
|
+
rescue Enc::CollinsHelper::Api::CannotConnect,
|
34
33
|
Collins::AuthenticationError,
|
35
34
|
Collins::RequestError
|
36
35
|
logger.error('Failed to connect to Collins. Attempting to read from cache')
|
@@ -44,6 +43,8 @@ module Enc
|
|
44
43
|
return Enc::CollinsHelper::Node::NodeAsset.new, true
|
45
44
|
rescue Enc::CollinsHelper::Api::AssetNotConfigured => e
|
46
45
|
bail("Asset with hostname #{hostname} is configured to use the ENC but does not have all the required tags", e)
|
46
|
+
rescue Enc::CollinsHelper::Api::TooManyAssets => e
|
47
|
+
bail("Too many assets with hostname #{hostname}", e)
|
47
48
|
end
|
48
49
|
begin
|
49
50
|
return @cache.read(hostname), false
|
@@ -59,4 +60,4 @@ module Enc
|
|
59
60
|
end
|
60
61
|
end
|
61
62
|
|
62
|
-
end
|
63
|
+
end
|
data/lib/enc/version.rb
CHANGED
data/spec/api_spec.rb
CHANGED
@@ -4,18 +4,24 @@ require 'collins_client'
|
|
4
4
|
describe 'Collins API' do
|
5
5
|
it 'gets an asset' do
|
6
6
|
api = FactoryGirl.build(:api)
|
7
|
-
asset = api.
|
8
|
-
|
7
|
+
asset = api.safe_find_exact(:hostname => FactoryDefaults::MOCK_ASSET_HOSTNAME,
|
8
|
+
:details => true)
|
9
9
|
expect(asset).to be_an_instance_of(Enc::CollinsHelper::Node::NodeAsset)
|
10
10
|
expect(asset.get_attribute('HOSTNAME')).to eq(FactoryDefaults::MOCK_ASSET_HOSTNAME)
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'searches for missing asset' do
|
14
14
|
api = FactoryGirl.build(:api)
|
15
|
-
expect{api.
|
15
|
+
expect{api.safe_find_exact(:hostname => 'missing', :details => true)}.
|
16
16
|
to raise_exception(Enc::CollinsHelper::Api::NoAssets, 'No assets found')
|
17
17
|
end
|
18
18
|
|
19
|
+
it 'searches for too many assets' do
|
20
|
+
api = FactoryGirl.build(:api)
|
21
|
+
expect{api.safe_find_exact(:hostname => 'toomany', :details => true)}.
|
22
|
+
to raise_exception(Enc::CollinsHelper::Api::TooManyAssets, 'Too many assets')
|
23
|
+
end
|
24
|
+
|
19
25
|
it 'seaches asset using invalid collins host' do
|
20
26
|
api = FactoryGirl.build(:api_timeout)
|
21
27
|
expect{api.safe_find(:hostname => FactoryDefaults::MOCK_ASSET_HOSTNAME, :details => true)}.
|
data/spec/factories/response.rb
CHANGED
@@ -21,6 +21,28 @@ FactoryGirl.define do
|
|
21
21
|
) }
|
22
22
|
end
|
23
23
|
|
24
|
+
factory :collins_response_multiple_assets, class: Hash do
|
25
|
+
skip_create
|
26
|
+
|
27
|
+
tag FactoryDefaults::MOCK_ASSET_TAG
|
28
|
+
hostname FactoryDefaults::MOCK_ASSET_HOSTNAME
|
29
|
+
datacenter FactoryDefaults::MOCK_ASSET_DATACENTER
|
30
|
+
environment FactoryDefaults::MOCK_ASSET_ENVIRONMENT
|
31
|
+
puppet_environment FactoryDefaults::MOCK_ASSET_ENVIRONMENT
|
32
|
+
puppet_enc true
|
33
|
+
|
34
|
+
initialize_with { ({ 'status' => 'success:ok',
|
35
|
+
'data' => { 'Pagination' => { 'PreviousPage' => 0,
|
36
|
+
'CurrentPage' => 0,
|
37
|
+
'NextPage' => 0,
|
38
|
+
'TotalResults' => 2},
|
39
|
+
'Data' => [Utils.get_asset_data(tag, hostname, datacenter, environment,
|
40
|
+
puppet_environment, puppet_enc),
|
41
|
+
Utils.get_asset_data(tag, hostname, datacenter, environment,
|
42
|
+
puppet_environment, puppet_enc)]}}
|
43
|
+
) }
|
44
|
+
end
|
45
|
+
|
24
46
|
factory :collins_response_headers, class: Hash do
|
25
47
|
skip_create
|
26
48
|
|
@@ -46,4 +68,4 @@ FactoryGirl.define do
|
|
46
68
|
'connection' => [connection]}
|
47
69
|
) }
|
48
70
|
end
|
49
|
-
end
|
71
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -9,22 +9,30 @@ RSpec.configure do |config|
|
|
9
9
|
good_response = FactoryGirl.build(:collins_response)
|
10
10
|
missing_asset_response = FactoryGirl.build(:collins_response, hostname: 'missing')
|
11
11
|
good_response_headers = FactoryGirl.build(:collins_response_headers)
|
12
|
+
too_many_assets_response = FactoryGirl.build(:collins_response_multiple_assets, hostname: 'toomany')
|
12
13
|
|
13
14
|
config.before(:each) do
|
14
15
|
stub_request(:get, "#{FactoryDefaults::MOCK_COLLINS_USERNAME}:#{FactoryDefaults::MOCK_COLLINS_PASSWORD}@
|
15
16
|
#{FactoryDefaults::MOCK_COLLINS_HOST}
|
16
|
-
/api/assets?attribute=hostname%3B#{FactoryDefaults::MOCK_ASSET_HOSTNAME}
|
17
|
+
/api/assets?attribute=hostname%3B%5E#{FactoryDefaults::MOCK_ASSET_HOSTNAME}$&details=true").
|
17
18
|
to_return(status: 200,
|
18
19
|
body: good_response.to_json,
|
19
20
|
headers: good_response_headers
|
20
21
|
)
|
21
22
|
stub_request(:get, "#{FactoryDefaults::MOCK_COLLINS_USERNAME}:#{FactoryDefaults::MOCK_COLLINS_PASSWORD}@
|
22
23
|
#{FactoryDefaults::MOCK_COLLINS_HOST}
|
23
|
-
/api/assets?attribute=hostname%
|
24
|
+
/api/assets?attribute=hostname%3B%5Emissing$&details=true").
|
24
25
|
to_return(status: 200,
|
25
26
|
body: missing_asset_response.to_json,
|
26
27
|
headers: good_response_headers
|
27
28
|
)
|
29
|
+
stub_request(:get, "#{FactoryDefaults::MOCK_COLLINS_USERNAME}:#{FactoryDefaults::MOCK_COLLINS_PASSWORD}@
|
30
|
+
#{FactoryDefaults::MOCK_COLLINS_HOST}
|
31
|
+
/api/assets?attribute=hostname%3B%5Etoomany$&details=true").
|
32
|
+
to_return(status: 200,
|
33
|
+
body: too_many_assets_response.to_json,
|
34
|
+
headers: good_response_headers
|
35
|
+
)
|
28
36
|
stub_request(:get, FactoryDefaults::MOCK_COLLINS_URL).
|
29
37
|
to_return(status: 200,
|
30
38
|
body: 'response body',
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: j-enc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jestin Woods
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -168,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
168
|
version: '0'
|
169
169
|
requirements: []
|
170
170
|
rubyforge_project:
|
171
|
-
rubygems_version: 2.
|
171
|
+
rubygems_version: 2.2.2
|
172
172
|
signing_key:
|
173
173
|
specification_version: 4
|
174
174
|
summary: Puppet ENC using Collins.
|