prefab-cloud-ruby 0.3.0 → 0.4.0

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
  SHA1:
3
- metadata.gz: 67f20b7bcbe0cb24df27ec2e6cee485469dfeb15
4
- data.tar.gz: 9f298fdd808db6787e89814ef01e750870ae2f7f
3
+ metadata.gz: 9c342824c82e95d283502c651dc00f331cf16d60
4
+ data.tar.gz: c0bd693c52c833155ba15b64fffe73addcb09786
5
5
  SHA512:
6
- metadata.gz: 2c1d7f77547a3c66e62dd9dda07c8e5cf74a374f1335f6318bfdd6c138999692c7ef1d231a7c8cea988eaa2888c63af46ee9779650d4eab2ab2d486f3de5a212
7
- data.tar.gz: 3c3d1be6a3c50f2d9550612277b4b969547a89393fcdfb3c9cf98ce138579668bc68f24a672892d100ee7ac9df941f0773fbc2a7d6d92b866854393b6b4fd453
6
+ metadata.gz: 369f79bd3bdec23b408b1d01dcba47e54b7ba72fdc8c4d0bc09032ec118cf18262839b0a9d8a1e7a220a593824bfac205ccec63498df940f1cfd8f54679f0d1d
7
+ data.tar.gz: 48a74a43324b96a9fe22c8d040ab69edf19285ee64ac2352b102eff70ec3777a89146f8a363e1fdf74ed5ee5c1fd3b19eea937396ac1f425c70297f33d668b01
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
@@ -100,7 +100,6 @@ module Prefab
100
100
 
101
101
  def load_checkpoint_from_s3
102
102
  url = "#{@s3_cloud_front}/#{@base_client.api_key.gsub("|", "/")}"
103
- puts url
104
103
  resp = Faraday.get url
105
104
  if resp.status == 200
106
105
  deltas = Prefab::ConfigDeltas.decode(resp.body)
@@ -1,5 +1,7 @@
1
1
  module Prefab
2
2
  class ConfigResolver
3
+ NAMESPACE_DELIMITER = ".".freeze
4
+ NAME_KEY_DELIMITER = ":".freeze
3
5
 
4
6
  def initialize(base_client, config_loader)
5
7
  @lock = Concurrent::ReadWriteLock.new
@@ -14,7 +16,7 @@ module Prefab
14
16
  @lock.with_read_lock do
15
17
  @local_store.each do |k, v|
16
18
  value = v[:value]
17
- str << "|#{k}| |#{value_of(value)}|#{value_of(value).class}\n"
19
+ str << "|#{k}| in #{v[:namespace]} |#{value_of(value)}|#{value_of(value).class}\n"
18
20
  end
19
21
  end
20
22
  str
@@ -52,24 +54,37 @@ module Prefab
52
54
  end
53
55
  end
54
56
 
57
+ # Should client a.b.c see key in namespace a.b? yes
58
+ # Should client a.b.c see key in namespace a.b.c? yes
59
+ # Should client a.b.c see key in namespace a.b.d? no
60
+ # Should client a.b.c see key in namespace ""? yes
61
+ #
62
+ def starts_with_ns?(key_namespace, client_namespace)
63
+ zipped = key_namespace.split(NAMESPACE_DELIMITER).zip(client_namespace.split(NAMESPACE_DELIMITER))
64
+ zipped.map do |k, c|
65
+ (k.nil? || k.empty?) || c == k
66
+ end.all?
67
+ end
68
+
55
69
  def make_local
56
70
  store = {}
57
71
  @config_loader.calc_config.each do |prop, value|
58
72
  property = prop
59
- namespace = ""
60
- split = prop.split(":")
73
+ key_namespace = ""
74
+
75
+ split = prop.split(NAME_KEY_DELIMITER)
61
76
 
62
77
  if split.size > 1
63
- property = split[1..-1].join
64
- namespace = split[0]
78
+ property = split[1..-1].join(NAME_KEY_DELIMITER)
79
+ key_namespace = split[0]
65
80
  end
66
81
 
67
- if (namespace == "") || @namespace.start_with?(namespace)
82
+ if starts_with_ns?(key_namespace, @namespace)
68
83
  existing = store[property]
69
84
  if existing.nil?
70
- store[property] = { namespace: namespace, value: value }
71
- elsif existing[:namespace].split(".").size < namespace.split(".").size
72
- store[property] = { namespace: namespace, value: value }
85
+ store[property] = { namespace: key_namespace, value: value }
86
+ elsif existing[:namespace].split(NAMESPACE_DELIMITER).size < key_namespace.split(NAMESPACE_DELIMITER).size
87
+ store[property] = { namespace: key_namespace, value: value }
73
88
  end
74
89
  end
75
90
  end
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: prefab-cloud-ruby 0.3.0 ruby lib
5
+ # stub: prefab-cloud-ruby 0.4.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "prefab-cloud-ruby".freeze
9
- s.version = "0.3.0"
9
+ s.version = "0.4.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Jeff Dwyer".freeze]
14
- s.date = "2019-01-30"
14
+ s.date = "2019-02-16"
15
15
  s.description = "RateLimits & Config as a service".freeze
16
16
  s.email = "jdwyer@prefab.cloud".freeze
17
17
  s.extra_rdoc_files = [
@@ -25,8 +25,6 @@ class TestConfigLoader < Minitest::Test
25
25
  assert_equal 5, @loader.highwater_mark
26
26
  end
27
27
 
28
-
29
-
30
28
  def test_keeps_most_recent
31
29
  assert_equal 0, @loader.highwater_mark
32
30
  @loader.set(Prefab::ConfigDelta.new(id: 1, key: "sample_int", value: Prefab::ConfigValue.new(int: 1)))
@@ -18,7 +18,6 @@ class TestConfigResolver < Minitest::Test
18
18
  @resolver = Prefab::ConfigResolver.new(MockBaseClient.new, @loader)
19
19
  assert_equal "value_none", @resolver.get("key")
20
20
 
21
-
22
21
  @resolverA = resolver_for_namespace("projectA", @loader)
23
22
  assert_equal "valueA", @resolverA.get("key")
24
23
 
@@ -37,6 +36,71 @@ class TestConfigResolver < Minitest::Test
37
36
  end
38
37
  end
39
38
 
39
+ def test_starts_with_ns
40
+ @loader = MockConfigLoader.new
41
+ @loader.stub :calc_config, {} do
42
+ resolver = Prefab::ConfigResolver.new(MockBaseClient.new, @loader)
43
+ assert resolver.send(:starts_with_ns?, "", "a")
44
+ assert resolver.send(:starts_with_ns?, "a", "a")
45
+ assert resolver.send(:starts_with_ns?, "a", "a.b")
46
+ assert !resolver.send(:starts_with_ns?, "a.b", "a")
47
+
48
+ assert resolver.send(:starts_with_ns?, "corp", "corp.proj.proja")
49
+ assert resolver.send(:starts_with_ns?, "corp.proj", "corp.proj.proja")
50
+ assert resolver.send(:starts_with_ns?, "corp.proj.proja", "corp.proj.proja")
51
+ assert !resolver.send(:starts_with_ns?, "corp.proj.projb", "corp.proj.proja")
52
+
53
+ # corp:a:b is not a real delimited namespace
54
+ assert !resolver.send(:starts_with_ns?, "corp", "corp:a:b")
55
+ assert resolver.send(:starts_with_ns?, "foo", "foo.baz")
56
+ assert resolver.send(:starts_with_ns?, "foo.baz", "foo.baz")
57
+ assert !resolver.send(:starts_with_ns?, "foo.baz", "foo.bazz")
58
+ end
59
+ end
60
+
61
+ # colons are not allowed in keys, but verify behavior anyway
62
+ def test_keys_with_colons
63
+ @loader = MockConfigLoader.new
64
+ loaded_values = {
65
+ "Key:With:Colons" => Prefab::ConfigValue.new(string: "value"),
66
+ "proj:apikey" => Prefab::ConfigValue.new(string: "v2")
67
+ }
68
+
69
+ @loader.stub :calc_config, loaded_values do
70
+
71
+ r = resolver_for_namespace("foo", @loader)
72
+ assert_nil r.get("apikey")
73
+
74
+ r = resolver_for_namespace("proj", @loader)
75
+ assert_equal "v2", r.get("apikey")
76
+
77
+ r = resolver_for_namespace("", @loader)
78
+ assert_nil r.get("apikey")
79
+
80
+
81
+ @resolverKeyWith = resolver_for_namespace("Ket:With", @loader)
82
+ assert_nil @resolverKeyWith.get("Colons")
83
+ assert_nil @resolverKeyWith.get("With:Colons")
84
+ assert_nil @resolverKeyWith.get("Key:With:Colons")
85
+
86
+ @resolverKeyWithExtra = resolver_for_namespace("Key:With:Extra", @loader)
87
+ puts @resolverKeyWithExtra.to_s
88
+ assert_nil @resolverKeyWithExtra.get("Colons")
89
+ assert_nil @resolverKeyWithExtra.get("With:Colons")
90
+ assert_nil @resolverKeyWithExtra.get("Key:With:Colons")
91
+
92
+ @resolverKey = resolver_for_namespace("Key", @loader)
93
+ assert_equal "value", @resolverKey.get("With:Colons")
94
+ assert_nil @resolverKey.get("Colons")
95
+ assert_nil @resolverKey.get("Key:With:Colons")
96
+
97
+ @resolverWithProperlySegmentedNamespace = resolver_for_namespace("Key.With.Extra", @loader)
98
+ assert_nil @resolverWithProperlySegmentedNamespace.get("Colons")
99
+ assert_equal "value", @resolverWithProperlySegmentedNamespace.get("With:Colons")
100
+ assert_nil @resolverWithProperlySegmentedNamespace.get("Key:With:Colons")
101
+ end
102
+ end
103
+
40
104
  def resolver_for_namespace(namespace, loader)
41
105
  Prefab::ConfigResolver.new(MockBaseClient.new(namespace: namespace), loader)
42
106
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prefab-cloud-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Dwyer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-30 00:00:00.000000000 Z
11
+ date: 2019-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby