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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 528c5da28584f98eb35faa627f3d0b4fe244c95e
4
- data.tar.gz: f7646b67efeb8b32dc8e34e5350dce326e3795a5
3
+ metadata.gz: cedaed2d68d7e0610864d2e4bbc7c6a97e135d87
4
+ data.tar.gz: 882eeaea7bc9c284b76acf1dbfd41098edf1ad2c
5
5
  SHA512:
6
- metadata.gz: 5586a4e154142f0a511bf4c1cc581b4ba8794b4c92d0e8f5c066dc02c37ee472e6cca1b2a208804bfdf23e64bde504e109853a181cafa6fbf49397aee1010811
7
- data.tar.gz: 01c700871cf2b3f619a0d3c0edfb822d07d41c679ae1eab4cda9e0ed28eb4d1f029a8b7163b66793daebeaa1129519e17551635dd9e3863aee93911f51b35986
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
@@ -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.safe_find(:hostname => hostname, :details => true), true
32
- rescue Enc::CollinsHelper::Api::TooManyAssets,
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
@@ -1,3 +1,3 @@
1
1
  module Enc
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -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.safe_find(:hostname => FactoryDefaults::MOCK_ASSET_HOSTNAME,
8
- :details => true)
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.safe_find(:hostname => 'missing', :details => true)}.
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)}.
@@ -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
@@ -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}&details=true").
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%3Bmissing&details=true").
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.7
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-07 00:00:00.000000000 Z
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.4.3
171
+ rubygems_version: 2.2.2
172
172
  signing_key:
173
173
  specification_version: 4
174
174
  summary: Puppet ENC using Collins.