prefab-cloud-ruby 0.13.0 → 0.13.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -0
  3. data/Gemfile +4 -11
  4. data/Gemfile.lock +32 -52
  5. data/README.md +1 -19
  6. data/Rakefile +0 -1
  7. data/VERSION +1 -1
  8. data/compile_protos.sh +0 -3
  9. data/lib/prefab/auth_interceptor.rb +0 -1
  10. data/lib/prefab/cancellable_interceptor.rb +0 -1
  11. data/lib/prefab/client.rb +36 -49
  12. data/lib/prefab/config_client.rb +73 -145
  13. data/lib/prefab/config_loader.rb +13 -98
  14. data/lib/prefab/config_resolver.rb +49 -56
  15. data/lib/prefab/feature_flag_client.rb +11 -129
  16. data/lib/prefab/logger_client.rb +8 -10
  17. data/lib/prefab/murmer3.rb +0 -1
  18. data/lib/prefab/noop_cache.rb +0 -1
  19. data/lib/prefab/noop_stats.rb +0 -1
  20. data/lib/prefab/ratelimit_client.rb +0 -1
  21. data/lib/prefab-cloud-ruby.rb +0 -10
  22. data/lib/prefab_pb.rb +132 -214
  23. data/lib/prefab_services_pb.rb +6 -35
  24. data/prefab-cloud-ruby.gemspec +11 -30
  25. data/test/.prefab.test.config.yaml +1 -27
  26. data/test/test_config_loader.rb +25 -39
  27. data/test/test_config_resolver.rb +38 -134
  28. data/test/test_feature_flag_client.rb +35 -277
  29. data/test/test_helper.rb +4 -70
  30. data/test/test_logger.rb +29 -23
  31. metadata +15 -70
  32. data/.github/workflows/ruby.yml +0 -39
  33. data/.tool-versions +0 -1
  34. data/CODEOWNERS +0 -1
  35. data/lib/prefab/config_helper.rb +0 -29
  36. data/lib/prefab/error.rb +0 -6
  37. data/lib/prefab/errors/initialization_timeout_error.rb +0 -13
  38. data/lib/prefab/errors/invalid_api_key_error.rb +0 -19
  39. data/lib/prefab/errors/missing_default_error.rb +0 -13
  40. data/lib/prefab/internal_logger.rb +0 -29
  41. data/lib/prefab/options.rb +0 -82
  42. data/run_test_harness_server.sh +0 -8
  43. data/test/harness_server.rb +0 -64
  44. data/test/test_client.rb +0 -91
  45. data/test/test_config_client.rb +0 -56
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 70fdeb9c1e8651a918fb7700a921e23843374ee9d5f3904a09d076e4be3b3669
4
- data.tar.gz: bd1cd6750f66a4e1f1940010fdaef01596de605f84ec80034747c906203aa8fc
3
+ metadata.gz: 65817a93520de402bf25dd2ac468d3c28fe0a1a2244080f7d6e3a1b77a3aa9b7
4
+ data.tar.gz: 7853f5a5576aaf02c6d55589f8008987645c82951cc10e645e83c5e121fa988f
5
5
  SHA512:
6
- metadata.gz: 47cd4f946a8ed79956d5b7f9822eb6b4d666db234bab4767990aa9fd79402acfbe569f4708d2ce08c57b65dedeafa374d6c9f97460ded8c6307d71293ee812fa
7
- data.tar.gz: 5078a253a71a7166a00f45a325d3f5b1f3435d99f2011ad197ebeb0af8be38699caecdba18fb36d019b13b92992f6c7cef82ae14ef672cda4ae8a3ca199c7236
6
+ metadata.gz: 3ecd82c82287d357dcebc2e264873ac2046323b55aa0125dbcf0175b52c3bdd66ac39cdf71f5cfabd8ba64252bacd9ff7c07473a2e74d92bfbbff43711eef950
7
+ data.tar.gz: 61d6de1e9b218f5211dc9e18b1640583a9fcc83785665dad58e201f75f50ff63d6ea8ea0d765d23af87173bde9aca715beb2f534a957241445b3514aedb9d8d6
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.4.2
data/Gemfile CHANGED
@@ -2,20 +2,13 @@ source "https://rubygems.org"
2
2
 
3
3
  gem 'concurrent-ruby', '~> 1.0', '>= 1.0.5'
4
4
  gem 'faraday'
5
- gem 'ld-eventsource'
6
- gem 'grpc', :platforms => :ruby
7
- gem 'google-protobuf', :platforms => :ruby
8
- gem 'googleapis-common-protos-types', :platforms => :ruby
5
+ gem 'grpc'
9
6
 
10
7
  group :development do
11
- gem 'grpc-tools', :platforms => :ruby
8
+ gem 'grpc-tools', '~> 1.17.1'
9
+ gem "shoulda", ">= 0"
12
10
  gem "rdoc", "~> 3.12"
13
- gem "bundler"
11
+ gem "bundler", "~> 1.0"
14
12
  gem "juwelier", "~> 2.4.9"
15
13
  gem "simplecov", ">= 0"
16
- gem 'thin'
17
- end
18
-
19
- group :test do
20
- gem "minitest"
21
14
  end
data/Gemfile.lock CHANGED
@@ -1,27 +1,24 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- addressable (2.8.0)
4
+ activesupport (5.2.4.5)
5
+ concurrent-ruby (~> 1.0, >= 1.0.2)
6
+ i18n (>= 0.7, < 2)
7
+ minitest (~> 5.1)
8
+ tzinfo (~> 1.1)
9
+ addressable (2.7.0)
5
10
  public_suffix (>= 2.0.2, < 5.0)
6
11
  builder (3.2.4)
7
- concurrent-ruby (1.1.10)
8
- daemons (1.4.1)
12
+ concurrent-ruby (1.1.8)
9
13
  descendants_tracker (0.0.4)
10
14
  thread_safe (~> 0.3, >= 0.3.1)
11
15
  docile (1.3.5)
12
- domain_name (0.5.20190701)
13
- unf (>= 0.0.5, < 1.0.0)
14
- eventmachine (1.2.7)
15
16
  faraday (1.3.0)
16
17
  faraday-net_http (~> 1.0)
17
18
  multipart-post (>= 1.2, < 3)
18
19
  ruby2_keywords
19
20
  faraday-net_http (1.0.1)
20
- ffi (1.15.5)
21
- ffi-compiler (1.0.1)
22
- ffi (>= 1.0.0)
23
- rake
24
- git (1.11.0)
21
+ git (1.8.1)
25
22
  rchardet (~> 1.8)
26
23
  github_api (0.19.0)
27
24
  addressable (~> 2.4)
@@ -29,23 +26,17 @@ GEM
29
26
  faraday (>= 0.8, < 2)
30
27
  hashie (~> 3.5, >= 3.5.2)
31
28
  oauth2 (~> 1.0)
32
- google-protobuf (3.21.4)
33
- googleapis-common-protos-types (1.3.0)
29
+ google-protobuf (3.15.6)
30
+ googleapis-common-protos-types (1.0.6)
31
+ google-protobuf (~> 3.14)
32
+ grpc (1.36.0)
34
33
  google-protobuf (~> 3.14)
35
- grpc (1.43.1)
36
- google-protobuf (~> 3.18)
37
34
  googleapis-common-protos-types (~> 1.0)
38
- grpc-tools (1.43.1)
35
+ grpc-tools (1.17.1)
39
36
  hashie (3.6.0)
40
37
  highline (2.0.3)
41
- http (5.0.1)
42
- addressable (~> 2.3)
43
- http-cookie (~> 1.0)
44
- http-form_data (~> 2.2)
45
- llhttp-ffi (~> 0.3.0)
46
- http-cookie (1.0.4)
47
- domain_name (~> 0.5)
48
- http-form_data (2.3.0)
38
+ i18n (1.8.9)
39
+ concurrent-ruby (~> 1.0)
49
40
  json (1.8.6)
50
41
  juwelier (2.4.9)
51
42
  builder
@@ -62,20 +53,13 @@ GEM
62
53
  jwt (2.2.2)
63
54
  kamelcase (0.0.2)
64
55
  semver2 (~> 3)
65
- ld-eventsource (2.2.0)
66
- concurrent-ruby (~> 1.0)
67
- http (>= 4.4.1, < 6.0.0)
68
- llhttp-ffi (0.3.1)
69
- ffi-compiler (~> 1.0)
70
- rake (~> 13.0)
71
- mini_portile2 (2.8.0)
72
- minitest (5.16.2)
56
+ mini_portile2 (2.4.0)
57
+ minitest (5.14.4)
73
58
  multi_json (1.15.0)
74
59
  multi_xml (0.6.0)
75
60
  multipart-post (2.1.1)
76
- nokogiri (1.13.6)
77
- mini_portile2 (~> 2.8.0)
78
- racc (~> 1.4)
61
+ nokogiri (1.10.10)
62
+ mini_portile2 (~> 2.4.0)
79
63
  oauth2 (1.4.7)
80
64
  faraday (>= 0.8, < 2.0)
81
65
  jwt (>= 1.0, < 3.0)
@@ -84,44 +68,40 @@ GEM
84
68
  rack (>= 1.2, < 3)
85
69
  psych (3.3.1)
86
70
  public_suffix (4.0.6)
87
- racc (1.6.0)
88
- rack (2.2.4)
71
+ rack (2.2.3)
89
72
  rake (13.0.3)
90
73
  rchardet (1.8.0)
91
74
  rdoc (3.12.2)
92
75
  json (~> 1.4)
93
76
  ruby2_keywords (0.0.4)
94
77
  semver2 (3.4.2)
78
+ shoulda (4.0.0)
79
+ shoulda-context (~> 2.0)
80
+ shoulda-matchers (~> 4.0)
81
+ shoulda-context (2.0.0)
82
+ shoulda-matchers (4.5.1)
83
+ activesupport (>= 4.2.0)
95
84
  simplecov (0.18.5)
96
85
  docile (~> 1.1)
97
86
  simplecov-html (~> 0.11)
98
87
  simplecov-html (0.12.3)
99
- thin (1.8.1)
100
- daemons (~> 1.0, >= 1.0.9)
101
- eventmachine (~> 1.0, >= 1.0.4)
102
- rack (>= 1, < 3)
103
88
  thread_safe (0.3.6)
104
- unf (0.1.4)
105
- unf_ext
106
- unf_ext (0.0.8)
89
+ tzinfo (1.2.9)
90
+ thread_safe (~> 0.1)
107
91
 
108
92
  PLATFORMS
109
93
  ruby
110
94
 
111
95
  DEPENDENCIES
112
- bundler
96
+ bundler (~> 1.0)
113
97
  concurrent-ruby (~> 1.0, >= 1.0.5)
114
98
  faraday
115
- google-protobuf
116
- googleapis-common-protos-types
117
99
  grpc
118
- grpc-tools
100
+ grpc-tools (~> 1.17.1)
119
101
  juwelier (~> 2.4.9)
120
- ld-eventsource
121
- minitest
122
102
  rdoc (~> 3.12)
103
+ shoulda
123
104
  simplecov
124
- thin
125
105
 
126
106
  BUNDLED WITH
127
- 2.3.5
107
+ 1.16.0
data/README.md CHANGED
@@ -43,15 +43,6 @@ on_worker_boot do
43
43
  end
44
44
  ```
45
45
 
46
- ## Logging & Debugging
47
- In classpath or ~/.prefab.overrides.config.yaml set
48
- ```log_level.prefab: debug```
49
-
50
- To debug issues before this config file has been read, set env var
51
- ```
52
- PREFAB_LOG_CLIENT_BOOTSTRAP_LOG_LEVEL = debug
53
- ```
54
-
55
46
  ## Contributing to prefab-cloud-ruby
56
47
 
57
48
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
@@ -62,16 +53,7 @@ PREFAB_LOG_CLIENT_BOOTSTRAP_LOG_LEVEL = debug
62
53
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
63
54
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
64
55
 
65
- ## Release
66
-
67
- ```shell
68
- update VERSION
69
- bundle exec rake gemspec:generate
70
- git commit & push
71
- REMOTE_BRANCH=main LOCAL_BRANCH=main bundle exec rake release
72
- ```
73
-
74
56
  ## Copyright
75
57
 
76
- Copyright (c) 2022 Jeff Dwyer. See LICENSE.txt for
58
+ Copyright (c) 2018 Jeff Dwyer. See LICENSE.txt for
77
59
  further details.
data/Rakefile CHANGED
@@ -1,5 +1,4 @@
1
1
  # encoding: utf-8
2
- # frozen_string_literal: true
3
2
 
4
3
  require 'rubygems'
5
4
  require 'bundler'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.13.0
1
+ 0.13.1
data/compile_protos.sh CHANGED
@@ -1,5 +1,2 @@
1
1
  #!/usr/bin/env bash
2
2
  grpc_tools_ruby_protoc -I ../prefab-cloud/ --ruby_out=lib --grpc_out=lib prefab.proto
3
- # on M1 you need to
4
- # 1. run in rosetta
5
- # 2. mv gems/2.6.0/gems/grpc-tools-1.43.1/bin/x86_64-macos x86-macos
@@ -1,4 +1,3 @@
1
- # frozen_string_literal: true
2
1
  module Prefab
3
2
  class AuthInterceptor < GRPC::ClientInterceptor
4
3
  def initialize(api_key)
@@ -1,4 +1,3 @@
1
- # frozen_string_literal: true
2
1
  module Prefab
3
2
  class CancellableInterceptor < GRPC::ClientInterceptor
4
3
  WAIT_SEC = 3
data/lib/prefab/client.rb CHANGED
@@ -1,39 +1,44 @@
1
- # frozen_string_literal: true
2
1
  module Prefab
3
2
  class Client
3
+
4
4
  MAX_SLEEP_SEC = 10
5
5
  BASE_SLEEP_SEC = 0.5
6
- NO_DEFAULT_PROVIDED = :no_default_provided
7
-
8
- attr_reader :project_id, :shared_cache, :stats, :namespace, :interceptor, :api_key, :prefab_api_url, :options
9
-
10
- def initialize(options = Prefab::Options.new)
11
- @options = options
12
- @shared_cache = @options.shared_cache
13
- @stats = @options.stats
14
- @namespace = @options.namespace
6
+ DEFAULT_LOG_FORMATTER = proc {|severity, datetime, progname, msg|
7
+ "#{severity.ljust(5)} #{datetime}: #{progname} #{msg}\n"
8
+ }
9
+
10
+
11
+ attr_reader :account_id, :shared_cache, :stats, :namespace, :interceptor, :api_key
12
+
13
+ def initialize(api_key: ENV['PREFAB_API_KEY'],
14
+ logdev: nil,
15
+ stats: nil, # receives increment("prefab.limitcheck", {:tags=>["policy_group:page_view", "pass:true"]})
16
+ shared_cache: nil, # Something that quacks like Rails.cache ideally memcached
17
+ local: false,
18
+ namespace: "",
19
+ log_formatter: DEFAULT_LOG_FORMATTER
20
+ )
21
+ raise "No API key. Set PREFAB_API_KEY env var" if api_key.nil? || api_key.empty?
22
+ @logdev = (logdev || $stdout)
23
+ @log_formatter = log_formatter
24
+ @local = local
25
+ @stats = (stats || NoopStats.new)
26
+ @shared_cache = (shared_cache || NoopCache.new)
27
+ @api_key = api_key
28
+ @account_id = api_key.split("|")[0].to_i
29
+ @namespace = namespace
30
+ @interceptor = Prefab::AuthInterceptor.new(api_key)
15
31
  @stubs = {}
16
32
 
17
- if @options.local_only?
18
- @project_id = 0
19
- log_internal Logger::INFO, "Prefab Running in Local Mode"
20
- else
21
- @api_key = @options.api_key
22
- raise Prefab::Errors::InvalidApiKeyError.new(@api_key) if @api_key.nil? || @api_key.empty? || api_key.count("-") != 3
23
- @project_id = @api_key.split("-")[0].to_i # unvalidated, but that's ok. APIs only listen to the actual passwd
24
- @interceptor = Prefab::AuthInterceptor.new(@api_key)
25
- @prefab_api_url = @options.prefab_api_url
26
- @prefab_grpc_url = @options.prefab_grpc_url
27
- log_internal Logger::INFO, "Prefab Connecting to: #{@prefab_api_url} and #{@prefab_grpc_url} Secure: #{http_secure?}"
28
- at_exit do
29
- channel.destroy
30
- end
33
+ at_exit do
34
+ channel.destroy
31
35
  end
32
36
  end
33
37
 
34
38
  def channel
35
- credentials = http_secure? ? creds : :this_channel_is_insecure
36
- @_channel ||= GRPC::Core::Channel.new(@prefab_grpc_url, nil, credentials)
39
+ credentials = ENV["PREFAB_CLOUD_HTTP"] == "true" ? :this_channel_is_insecure : creds
40
+ url = ENV["PREFAB_API_URL"] || 'api.prefab.cloud:443'
41
+ @_channel ||= GRPC::Core::Channel.new(url, nil, credentials)
37
42
  end
38
43
 
39
44
  def config_client(timeout: 5.0)
@@ -49,11 +54,11 @@ module Prefab
49
54
  end
50
55
 
51
56
  def log
52
- @logger_client ||= Prefab::LoggerClient.new(@options.logdev, formatter: @options.log_formatter)
57
+ @logger_client ||= Prefab::LoggerClient.new(@logdev, formatter: @log_formatter)
53
58
  end
54
59
 
55
- def log_internal(level, msg, path = "prefab")
56
- log.log_internal msg, path, nil, level
60
+ def log_internal(level, msg)
61
+ log.log_internal msg, "prefab", nil, level
57
62
  end
58
63
 
59
64
  def request(service, method, req_options: {}, params: {})
@@ -83,7 +88,7 @@ module Prefab
83
88
  end
84
89
 
85
90
  def cache_key(post_fix)
86
- "prefab:#{project_id}:#{post_fix}"
91
+ "prefab:#{account_id}:#{post_fix}"
87
92
  end
88
93
 
89
94
  def reset!
@@ -91,26 +96,8 @@ module Prefab
91
96
  @_channel = nil
92
97
  end
93
98
 
94
- def enabled?(feature_name, lookup_key=nil, attributes={})
95
- feature_flag_client.feature_is_on_for?(feature_name, lookup_key, attributes: attributes)
96
- end
97
-
98
- def get(key, default_or_lookup_key=NO_DEFAULT_PROVIDED, attributes={}, ff_default=NO_DEFAULT_PROVIDED)
99
- result = config_client.get(key, default_or_lookup_key)
100
-
101
- if result.is_a?(Prefab::FeatureFlag)
102
- feature_flag_client.get(key, default_or_lookup_key, attributes, default: ff_default)
103
- else
104
- result
105
- end
106
- end
107
-
108
99
  private
109
100
 
110
- def http_secure?
111
- ENV["PREFAB_CLOUD_HTTP"] != "true"
112
- end
113
-
114
101
  def stub_for(service, timeout)
115
102
  @stubs["#{service}_#{timeout}"] ||= service::Stub.new(nil,
116
103
  nil,
@@ -128,7 +115,7 @@ module Prefab
128
115
  Dir["#{OpenSSL::X509::DEFAULT_CERT_DIR}/*.pem"].each do |cert|
129
116
  ssl_certs << File.open(cert).read
130
117
  end
131
- if OpenSSL::X509::DEFAULT_CERT_FILE && File.exist?(OpenSSL::X509::DEFAULT_CERT_FILE)
118
+ if OpenSSL::X509::DEFAULT_CERT_FILE && File.exists?(OpenSSL::X509::DEFAULT_CERT_FILE)
132
119
  ssl_certs << File.open(OpenSSL::X509::DEFAULT_CERT_FILE).read
133
120
  end
134
121
  ssl_certs