inventory-server 0.0.7 → 0.1.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/Dockerfile +2 -0
- data/Dockerfile-unicorn +2 -0
- data/lib/inventory/server/version.rb +1 -1
- data/plugins/index.rb +5 -2
- data/spec/unit/index_spec.rb +10 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae35d4914717ef5ffb50b58df22542cf5bfaf5fe
|
4
|
+
data.tar.gz: 33b74f421d4c148469e2450dbc191a7287f98da8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbc394386ceb1ea44fd4f511f5b5f8a8caa9e6432a0c6a4de69d1931f4ca7e616dbd2e231fa8bd6191a754982c4b1d23987db84d71cb3e448ee67d86c46153c6
|
7
|
+
data.tar.gz: fd4ca65d8efe8f2e7b9355c8fa03171507c330afcf87f690e039ab2c7aa13842f7e869b96ec42900164153eea135578779b1c73d9f9ca4f17ee868ea0e139bf1
|
data/Dockerfile
CHANGED
data/Dockerfile-unicorn
CHANGED
data/plugins/index.rb
CHANGED
@@ -28,10 +28,9 @@ module Inventory
|
|
28
28
|
raise InventoryError.new 'id is missing' if id.nil? || id.empty?
|
29
29
|
raise InventoryError.new 'facts is missing' if facts.nil?
|
30
30
|
|
31
|
-
type = facts[@config[:type_key]] || @config[:type_default]
|
32
31
|
version = facts[@config[:version_key]] || @config[:version_default]
|
33
32
|
|
34
|
-
url = clean_string "#{@config[:es_host]}/#{@config[:es_index_prefix]}#{
|
33
|
+
url = clean_string "#{@config[:es_host]}/#{@config[:es_index_prefix]}#{week_number}/#{version}/#{id}"
|
35
34
|
|
36
35
|
begin
|
37
36
|
response = RestClient.put(url, facts.to_json)
|
@@ -52,6 +51,10 @@ module Inventory
|
|
52
51
|
def clean_string(str)
|
53
52
|
str.gsub('.', '-').gsub(' ', '_').encode(Encoding.find('ASCII'), :invalid => :replace, :undef => :replace, :replace => '')
|
54
53
|
end
|
54
|
+
|
55
|
+
def week_number
|
56
|
+
Time.now.strftime('%W')
|
57
|
+
end
|
55
58
|
end
|
56
59
|
end
|
57
60
|
end
|
data/spec/unit/index_spec.rb
CHANGED
@@ -16,6 +16,10 @@ RSpec.describe Inventory::Server::Index, '#call' do
|
|
16
16
|
WebMock.allow_net_connect!
|
17
17
|
end
|
18
18
|
|
19
|
+
before() do
|
20
|
+
allow_any_instance_of(Inventory::Server::Index).to receive(:week_number).and_return 15
|
21
|
+
end
|
22
|
+
|
19
23
|
context "without id" do
|
20
24
|
env = {:facts => { :key => 'value' }}
|
21
25
|
it "should throw an error" do
|
@@ -50,7 +54,7 @@ RSpec.describe Inventory::Server::Index, '#call' do
|
|
50
54
|
env = {:id => 'MY_UUID', :facts => { :key => 'value' } }
|
51
55
|
|
52
56
|
it "should throw an error" do
|
53
|
-
stub_request(:put, "#{config[:es_host]}/
|
57
|
+
stub_request(:put, "#{config[:es_host]}/inventory_15/1-0-0/MY_UUID").to_return(:status => [500, "Internal Server Error"], :body => '{"OK": false}')
|
54
58
|
|
55
59
|
expect {
|
56
60
|
Inventory::Server::Index.new(noop, config).call(env)
|
@@ -61,7 +65,7 @@ RSpec.describe Inventory::Server::Index, '#call' do
|
|
61
65
|
context "with an ElasticSearch Server" do
|
62
66
|
it "should call ElasticSearch" do
|
63
67
|
env = {:id => 'MY_UUID', :facts => { :key => 'value' } }
|
64
|
-
stub = stub_request(:put, "#{config[:es_host]}/
|
68
|
+
stub = stub_request(:put, "#{config[:es_host]}/inventory_15/1-0-0/MY_UUID").to_return(:body => '{"OK": true}')
|
65
69
|
|
66
70
|
result = Inventory::Server::Index.new(noop, config).call(env)
|
67
71
|
expect(result).to eq({ :key => 'value' })
|
@@ -70,8 +74,8 @@ RSpec.describe Inventory::Server::Index, '#call' do
|
|
70
74
|
end
|
71
75
|
|
72
76
|
it "should change url depending on the type and version" do
|
73
|
-
env = {:id => 'MY_UUID', :facts => { 'key' => 'value', '
|
74
|
-
stub = stub_request(:put, "#{config[:es_host]}/
|
77
|
+
env = {:id => 'MY_UUID', :facts => { 'key' => 'value', 'version' => 'my_version' } }
|
78
|
+
stub = stub_request(:put, "#{config[:es_host]}/inventory_15/my_version/MY_UUID").to_return(:body => '{"OK": true}')
|
75
79
|
|
76
80
|
Inventory::Server::Index.new(noop, config).call(env)
|
77
81
|
|
@@ -79,8 +83,8 @@ RSpec.describe Inventory::Server::Index, '#call' do
|
|
79
83
|
end
|
80
84
|
|
81
85
|
it "should change not pass dot, spaces and utf8 to elasticsearch" do
|
82
|
-
env = {:id => 'MY_UUID', :facts => { 'key' => 'value', '
|
83
|
-
stub = stub_request(:put, "#{config[:es_host]}/
|
86
|
+
env = {:id => 'MY_UUID', :facts => { 'key' => 'value', 'version' => 'my vérsion.1' } }
|
87
|
+
stub = stub_request(:put, "#{config[:es_host]}/inventory_15/my_vrsion-1/MY_UUID").to_return(:body => '{"OK": true}')
|
84
88
|
|
85
89
|
Inventory::Server::Index.new(noop, config).call(env)
|
86
90
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inventory-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Filirom1
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: midi-smtp-server
|