vayacondios-server 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,4 +4,4 @@ mongo:
4
4
  database: vayacondios_dev
5
5
 
6
6
  vayacondios:
7
- legacy: false
7
+ legacy: true
@@ -4,4 +4,4 @@ mongo:
4
4
  database: vayacondios_dev
5
5
 
6
6
  vayacondios:
7
- legacy: false
7
+ legacy: true
@@ -0,0 +1,9 @@
1
+ def ENV.root_path(*args)
2
+ File.expand_path(File.join(File.dirname(__FILE__), '../../../', *args))
3
+ end
4
+
5
+ require 'configliere'
6
+
7
+ Settings.read(ENV.root_path('config/vayacondios.yaml'))
8
+ Settings.resolve!
9
+
@@ -1,6 +1,8 @@
1
1
  require 'gorillib/logger/log'
2
2
  require 'net/http'
3
3
  require 'multi_json'
4
+ require_relative 'config'
5
+ require_relative '../legacy_switch'
4
6
 
5
7
  class Vayacondios
6
8
  class Client
@@ -15,7 +17,7 @@ class Vayacondios
15
17
 
16
18
  def fetch organization=nil, topic=nil, id=nil
17
19
  resp = execute_request(_req(:fetch, nil, organization, topic, id)) and
18
- resp["contents"]
20
+ Vayacondios.legacy_switch.extract_response(resp)
19
21
  end
20
22
 
21
23
  def update ary, organization=nil, topic=nil, id=nil
@@ -70,7 +72,10 @@ class Vayacondios
70
72
  when :remove then Net::HTTP::Delete
71
73
  else raise ArgumentError.new("invalid type: #{type}")
72
74
  end.new(the_path, headers).tap do |req|
73
- req.body = MultiJson.encode(contents: ary) unless type == :fetch
75
+ unless type == :fetch
76
+ req.body =
77
+ MultiJson.encode(Vayacondios.legacy_switch.wrap_contents(ary))
78
+ end
74
79
  end
75
80
  end
76
81
  end
@@ -1,3 +1,5 @@
1
+ require 'gorillib/logger/log'
2
+
1
3
  class Vayacondios
2
4
  # Are we operating on JSON Hashes (Vayacondios) or on JSON arrays
3
5
  # (Vayacondios Legacy)? These classes determine which to use.
@@ -5,24 +7,30 @@ class Vayacondios
5
7
  class StandardContentsHandler
6
8
  def wrap_contents(contents) {contents: contents} end
7
9
  def extract_contents(document) document['contents'] end
10
+ def extract_response(document) document['contents'] end
8
11
  def proper_request(document)
9
- result = document.is_a?(Hash) and document.fetch('_json', {}).is_a?(Hash)
10
- result
12
+ document.is_a? Hash and document.fetch('_json', {}).is_a? Hash
11
13
  end
12
14
  end
13
15
 
14
16
  class LegacyContentsHandler
15
17
  def wrap_contents(contents) contents end
16
18
  def extract_contents(document) document.fetch('_json', {}) end
19
+ def extract_response(document) document end
17
20
  def proper_request(document)
18
- result = document.is_a?(Array) or document.fetch('_json', {}).is_a?(Array)
19
- puts "proper legacy request? #{document.inspect}: #{result.inspect}"
20
- result
21
+ document.is_a? Array or document.fetch('_json', {}).is_a? Array
21
22
  end
22
23
  end
23
24
 
25
+ @@legacy_switch = nil
26
+
24
27
  def self.legacy_switch
25
- @@legacy_switch ||= get_legacy_switch(Settings[:vayacondios][:legacy])
28
+ legacy_mode_on = Settings[:vayacondios][:legacy]
29
+ if @@legacy_switch.nil?
30
+ @@legacy_switch = get_legacy_switch(legacy_mode_on)
31
+ Log.info("using #{legacy_mode_on ? 'legacy' : 'standard'} mode")
32
+ end
33
+ @@legacy_switch
26
34
  end
27
35
 
28
36
  def self.force_legacy_mode on
@@ -1,3 +1,3 @@
1
1
  class Vayacondios
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+ require_relative '../../lib/vayacondios/legacy_switch'
3
+
4
+ require 'multi_json'
5
+
6
+ require_relative '../../lib/vayacondios/client/itemset'
7
+
8
+ describe Vayacondios::Client::ItemSet do
9
+ context "after instantiation in legacy mode" do
10
+ itemset = Vayacondios::Client::ItemSet.new("foohost", 9999, "fooorg", "footopic", "fooid")
11
+ ary = ["foo", "bar", "baz"]
12
+
13
+ # testing internals here to avoid shimming up HTTP libraries.
14
+
15
+ it "generates a put request without a patch header when asked to create" do
16
+ Vayacondios.force_legacy_mode true
17
+
18
+ req = itemset.instance_eval{_req(:create, ary)}
19
+
20
+ req.method.should eql('PUT')
21
+ req.body.should eql(MultiJson.encode(ary))
22
+ req.path.should eql('/v1/fooorg/itemset/footopic/fooid')
23
+ req.each_header.to_a.should_not include(["x_method", "PATCH"])
24
+ end
25
+
26
+ it "generates a put request with a patch header when asked to update" do
27
+ Vayacondios.force_legacy_mode true
28
+
29
+ req = itemset.instance_eval{_req(:update, ary)}
30
+
31
+ req.method.should eql('PUT')
32
+ req.body.should eql(MultiJson.encode(ary))
33
+ req.path.should eql('/v1/fooorg/itemset/footopic/fooid')
34
+ req.each_header.to_a.should include(["x-method", "PATCH"])
35
+ end
36
+
37
+ it "generates a get request when asked to fetch" do
38
+ req = itemset.instance_eval{_req(:fetch)}
39
+
40
+ req.method.should eql('GET')
41
+ req.body.should be_nil
42
+ req.path.should eql('/v1/fooorg/itemset/footopic/fooid')
43
+ end
44
+
45
+ it "generates a delete request when asked to remove" do
46
+ Vayacondios.force_legacy_mode true
47
+
48
+ req = itemset.instance_eval{_req(:remove, ary)}
49
+
50
+ req.method.should eql('DELETE')
51
+ req.body.should eql(MultiJson.encode(ary))
52
+ req.path.should eql('/v1/fooorg/itemset/footopic/fooid')
53
+ end
54
+ end
55
+ end
@@ -12,13 +12,14 @@ describe Vayacondios::Client::ItemSet do
12
12
  end
13
13
 
14
14
  context "after instantiation" do
15
-
16
15
  itemset = Vayacondios::Client::ItemSet.new("foohost", 9999, "fooorg", "footopic", "fooid")
17
16
  ary = ["foo", "bar", "baz"]
18
17
 
19
18
  # testing internals here to avoid shimming up HTTP libraries.
20
19
 
21
20
  it "generates a put request without a patch header when asked to create" do
21
+ Vayacondios.force_legacy_mode false
22
+
22
23
  req = itemset.instance_eval{_req(:create, ary)}
23
24
 
24
25
  req.method.should eql('PUT')
@@ -28,6 +29,8 @@ describe Vayacondios::Client::ItemSet do
28
29
  end
29
30
 
30
31
  it "generates a put request with a patch header when asked to update" do
32
+ Vayacondios.force_legacy_mode false
33
+
31
34
  req = itemset.instance_eval{_req(:update, ary)}
32
35
 
33
36
  req.method.should eql('PUT')
@@ -45,6 +48,8 @@ describe Vayacondios::Client::ItemSet do
45
48
  end
46
49
 
47
50
  it "generates a delete request when asked to remove" do
51
+ Vayacondios.force_legacy_mode false
52
+
48
53
  req = itemset.instance_eval{_req(:remove, ary)}
49
54
 
50
55
  req.method.should eql('DELETE')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vayacondios-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -203,6 +203,7 @@ files:
203
203
  - lib/tasks/yard.rake
204
204
  - lib/vayacondios-client.rb
205
205
  - lib/vayacondios-server.rb
206
+ - lib/vayacondios/client/config.rb
206
207
  - lib/vayacondios/client/configliere.rb
207
208
  - lib/vayacondios/client/cube_client.rb
208
209
  - lib/vayacondios/client/http_client.rb
@@ -234,6 +235,7 @@ files:
234
235
  - scripts/s3_cataloger/buckets
235
236
  - scripts/s3_cataloger/foreach_bucket
236
237
  - scripts/s3_cataloger/parse_ls.py
238
+ - spec/client/itemset_legacy_spec.rb
237
239
  - spec/client/itemset_spec.rb
238
240
  - spec/client/notifier_spec.rb
239
241
  - spec/server/config_spec.rb
@@ -275,7 +277,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
275
277
  version: '0'
276
278
  segments:
277
279
  - 0
278
- hash: -3916110167630393144
280
+ hash: -2368824716653400706
279
281
  required_rubygems_version: !ruby/object:Gem::Requirement
280
282
  none: false
281
283
  requirements:
@@ -284,7 +286,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
284
286
  version: '0'
285
287
  segments:
286
288
  - 0
287
- hash: -3916110167630393144
289
+ hash: -2368824716653400706
288
290
  requirements: []
289
291
  rubyforge_project:
290
292
  rubygems_version: 1.8.25
@@ -292,6 +294,7 @@ signing_key:
292
294
  specification_version: 3
293
295
  summary: Data goes in. The right thing happens
294
296
  test_files:
297
+ - spec/client/itemset_legacy_spec.rb
295
298
  - spec/client/itemset_spec.rb
296
299
  - spec/client/notifier_spec.rb
297
300
  - spec/server/config_spec.rb