prefab-cloud-ruby 0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +5 -5
  2. data/.ruby-version +1 -0
  3. data/Gemfile +9 -22
  4. data/Gemfile.lock +88 -160
  5. data/LICENSE.txt +1 -1
  6. data/Rakefile +14 -14
  7. data/VERSION +1 -1
  8. data/lib/prefab/auth_interceptor.rb +25 -0
  9. data/lib/prefab/client.rb +34 -139
  10. data/lib/prefab/config_client.rb +23 -275
  11. data/lib/prefab/config_loader.rb +27 -60
  12. data/lib/prefab/config_resolver.rb +40 -53
  13. data/lib/prefab/noop_cache.rb +13 -0
  14. data/lib/prefab/noop_stats.rb +8 -0
  15. data/lib/prefab/prefab_pb.rb +39 -0
  16. data/lib/prefab/prefab_services_pb.rb +37 -0
  17. data/lib/prefab/ratelimit_client.rb +58 -0
  18. data/lib/prefab/ratelimit_pb.rb +125 -0
  19. data/lib/prefab/store.rb +29 -0
  20. data/lib/prefab_client.rb +35 -0
  21. metadata +36 -198
  22. data/.envrc.sample +0 -3
  23. data/.github/workflows/ruby.yml +0 -46
  24. data/.gitmodules +0 -3
  25. data/.rubocop.yml +0 -13
  26. data/.tool-versions +0 -1
  27. data/CHANGELOG.md +0 -169
  28. data/CODEOWNERS +0 -1
  29. data/README.md +0 -94
  30. data/bin/console +0 -21
  31. data/compile_protos.sh +0 -18
  32. data/lib/prefab/config_client_presenter.rb +0 -18
  33. data/lib/prefab/config_value_unwrapper.rb +0 -115
  34. data/lib/prefab/config_value_wrapper.rb +0 -18
  35. data/lib/prefab/context.rb +0 -179
  36. data/lib/prefab/context_shape.rb +0 -20
  37. data/lib/prefab/context_shape_aggregator.rb +0 -65
  38. data/lib/prefab/criteria_evaluator.rb +0 -136
  39. data/lib/prefab/encryption.rb +0 -65
  40. data/lib/prefab/error.rb +0 -6
  41. data/lib/prefab/errors/env_var_parse_error.rb +0 -11
  42. data/lib/prefab/errors/initialization_timeout_error.rb +0 -13
  43. data/lib/prefab/errors/invalid_api_key_error.rb +0 -19
  44. data/lib/prefab/errors/missing_default_error.rb +0 -13
  45. data/lib/prefab/errors/missing_env_var_error.rb +0 -11
  46. data/lib/prefab/errors/uninitialized_error.rb +0 -13
  47. data/lib/prefab/evaluation.rb +0 -52
  48. data/lib/prefab/evaluation_summary_aggregator.rb +0 -87
  49. data/lib/prefab/example_contexts_aggregator.rb +0 -78
  50. data/lib/prefab/exponential_backoff.rb +0 -21
  51. data/lib/prefab/feature_flag_client.rb +0 -42
  52. data/lib/prefab/http_connection.rb +0 -41
  53. data/lib/prefab/internal_logger.rb +0 -16
  54. data/lib/prefab/local_config_parser.rb +0 -151
  55. data/lib/prefab/log_path_aggregator.rb +0 -69
  56. data/lib/prefab/logger_client.rb +0 -264
  57. data/lib/prefab/murmer3.rb +0 -50
  58. data/lib/prefab/options.rb +0 -208
  59. data/lib/prefab/periodic_sync.rb +0 -69
  60. data/lib/prefab/prefab.rb +0 -56
  61. data/lib/prefab/rate_limit_cache.rb +0 -41
  62. data/lib/prefab/resolved_config_presenter.rb +0 -86
  63. data/lib/prefab/time_helpers.rb +0 -7
  64. data/lib/prefab/weighted_value_resolver.rb +0 -42
  65. data/lib/prefab/yaml_config_parser.rb +0 -34
  66. data/lib/prefab-cloud-ruby.rb +0 -57
  67. data/lib/prefab_pb.rb +0 -93
  68. data/prefab-cloud-ruby.gemspec +0 -155
  69. data/test/.prefab.default.config.yaml +0 -2
  70. data/test/.prefab.unit_tests.config.yaml +0 -28
  71. data/test/integration_test.rb +0 -150
  72. data/test/integration_test_helpers.rb +0 -151
  73. data/test/support/common_helpers.rb +0 -180
  74. data/test/support/mock_base_client.rb +0 -42
  75. data/test/support/mock_config_client.rb +0 -19
  76. data/test/support/mock_config_loader.rb +0 -1
  77. data/test/test_client.rb +0 -444
  78. data/test/test_config_client.rb +0 -109
  79. data/test/test_config_loader.rb +0 -117
  80. data/test/test_config_resolver.rb +0 -430
  81. data/test/test_config_value_unwrapper.rb +0 -224
  82. data/test/test_config_value_wrapper.rb +0 -42
  83. data/test/test_context.rb +0 -203
  84. data/test/test_context_shape.rb +0 -50
  85. data/test/test_context_shape_aggregator.rb +0 -147
  86. data/test/test_criteria_evaluator.rb +0 -726
  87. data/test/test_encryption.rb +0 -16
  88. data/test/test_evaluation_summary_aggregator.rb +0 -162
  89. data/test/test_example_contexts_aggregator.rb +0 -238
  90. data/test/test_exponential_backoff.rb +0 -18
  91. data/test/test_feature_flag_client.rb +0 -48
  92. data/test/test_helper.rb +0 -17
  93. data/test/test_integration.rb +0 -58
  94. data/test/test_local_config_parser.rb +0 -147
  95. data/test/test_log_path_aggregator.rb +0 -62
  96. data/test/test_logger.rb +0 -621
  97. data/test/test_logger_initialization.rb +0 -12
  98. data/test/test_options.rb +0 -75
  99. data/test/test_prefab.rb +0 -12
  100. data/test/test_rate_limit_cache.rb +0 -44
  101. data/test/test_weighted_value_resolver.rb +0 -71
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 1aa20885e129588b6ccf76b4fddae442b7d285495a384d3e4d2aeba11b802089
4
- data.tar.gz: 37bd9186041e1931d00f4a5c9fd518f7961a1564147b8693f03befdd9dc78dc9
2
+ SHA1:
3
+ metadata.gz: 9a9979df2d96ea510b54c6b479cba724e0ef1ae7
4
+ data.tar.gz: 8a73500c4c42dac6f4955b6bd6ff395ddf43511f
5
5
  SHA512:
6
- metadata.gz: 1de0d80c388ceb6a68d65da6b4998c1e2a398664e3a9d04f4fce4fd8943176638f53c5b89a903d75449039fd1de713595eafeb930f3108f0fee59cdd35d176de
7
- data.tar.gz: 917f146a34fa76b8440d126ebceff1d0bd79c7944135142b944389d259ab10295b9b80937832dd6438a7a2e38e276a546f2f96bd7638427996a46ec0646324f6
6
+ metadata.gz: '0937e68bf543c496e25e9dff6ab471b5f73bc626a95899c930251dfa9cc5ccd193414e9b9aa88557dbf7716d93af569d09caf6d7be7f686a64f5a7bc6b2c68f3'
7
+ data.tar.gz: c92bb4500b4321334be5d288f99baeaba8d19ffd7d1af3b7a7e84d6b6d96e052ca88f91030498558e2af3438a168e434d333d89e2722e2a23f6fcb3637d27e0d
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.4.2
data/Gemfile CHANGED
@@ -1,26 +1,13 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
- gem 'concurrent-ruby', '~> 1.0', '>= 1.0.5'
4
- gem 'faraday'
5
- gem 'googleapis-common-protos-types', platforms: :ruby
6
- gem 'google-protobuf', platforms: :ruby
7
- gem 'ld-eventsource'
8
- gem 'uuid'
9
-
10
- gem 'activesupport', '>= 4'
11
- gem 'actionpack', '>= 4'
3
+ gem "grpc"
4
+ gem "concurrent-ruby"
12
5
 
13
6
  group :development do
14
- gem 'benchmark-ips'
15
- gem 'bundler'
16
- gem 'juwelier', '~> 2.4.9'
17
- gem 'rdoc'
18
- gem 'simplecov', '>= 0'
19
- end
20
-
21
- group :test do
22
- gem 'minitest'
23
- gem 'minitest-focus'
24
- gem 'minitest-reporters'
25
- gem 'timecop'
7
+ gem "grpc-tools"
8
+ gem "shoulda", ">= 0"
9
+ gem "rdoc", "~> 3.12"
10
+ gem "bundler", "~> 1.0"
11
+ gem "juwelier", "~> 2.1.0"
12
+ gem "simplecov", ">= 0"
26
13
  end
data/Gemfile.lock CHANGED
@@ -1,188 +1,116 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- actionpack (7.1.2)
5
- actionview (= 7.1.2)
6
- activesupport (= 7.1.2)
7
- nokogiri (>= 1.8.5)
8
- racc
9
- rack (>= 2.2.4)
10
- rack-session (>= 1.0.1)
11
- rack-test (>= 0.6.3)
12
- rails-dom-testing (~> 2.2)
13
- rails-html-sanitizer (~> 1.6)
14
- actionview (7.1.2)
15
- activesupport (= 7.1.2)
16
- builder (~> 3.1)
17
- erubi (~> 1.11)
18
- rails-dom-testing (~> 2.2)
19
- rails-html-sanitizer (~> 1.6)
20
- activesupport (7.1.2)
21
- base64
22
- bigdecimal
4
+ activesupport (5.1.4)
23
5
  concurrent-ruby (~> 1.0, >= 1.0.2)
24
- connection_pool (>= 2.2.5)
25
- drb
26
- i18n (>= 1.6, < 2)
27
- minitest (>= 5.1)
28
- mutex_m
29
- tzinfo (~> 2.0)
30
- addressable (2.8.0)
31
- public_suffix (>= 2.0.2, < 5.0)
32
- ansi (1.5.0)
33
- base64 (0.2.0)
34
- benchmark-ips (2.10.0)
35
- bigdecimal (3.1.4)
36
- builder (3.2.4)
37
- concurrent-ruby (1.1.10)
38
- connection_pool (2.4.1)
39
- crass (1.0.6)
6
+ i18n (~> 0.7)
7
+ minitest (~> 5.1)
8
+ tzinfo (~> 1.1)
9
+ addressable (2.5.2)
10
+ public_suffix (>= 2.0.2, < 4.0)
11
+ builder (3.2.3)
12
+ concurrent-ruby (1.0.5)
40
13
  descendants_tracker (0.0.4)
41
14
  thread_safe (~> 0.3, >= 0.3.1)
42
- docile (1.3.5)
43
- domain_name (0.5.20190701)
44
- unf (>= 0.0.5, < 1.0.0)
45
- drb (2.2.0)
46
- ruby2_keywords
47
- erubi (1.12.0)
48
- faraday (1.3.0)
49
- faraday-net_http (~> 1.0)
15
+ docile (1.1.5)
16
+ faraday (0.12.2)
50
17
  multipart-post (>= 1.2, < 3)
51
- ruby2_keywords
52
- faraday-net_http (1.0.1)
53
- ffi (1.15.5)
54
- ffi-compiler (1.0.1)
55
- ffi (>= 1.0.0)
56
- rake
57
- git (1.13.0)
58
- addressable (~> 2.8)
59
- rchardet (~> 1.8)
60
- github_api (0.19.0)
18
+ git (1.3.0)
19
+ github_api (0.18.2)
61
20
  addressable (~> 2.4)
62
21
  descendants_tracker (~> 0.0.4)
63
- faraday (>= 0.8, < 2)
22
+ faraday (~> 0.8)
64
23
  hashie (~> 3.5, >= 3.5.2)
65
24
  oauth2 (~> 1.0)
66
- google-protobuf (3.22.2)
67
- googleapis-common-protos-types (1.5.0)
68
- google-protobuf (~> 3.14)
69
- hashie (3.6.0)
70
- highline (2.0.3)
71
- http (5.0.1)
72
- addressable (~> 2.3)
73
- http-cookie (~> 1.0)
74
- http-form_data (~> 2.2)
75
- llhttp-ffi (~> 0.3.0)
76
- http-cookie (1.0.4)
77
- domain_name (~> 0.5)
78
- http-form_data (2.3.0)
79
- i18n (1.14.1)
25
+ google-protobuf (3.5.0)
26
+ googleapis-common-protos-types (1.0.1)
27
+ google-protobuf (~> 3.0)
28
+ googleauth (0.6.2)
29
+ faraday (~> 0.12)
30
+ jwt (>= 1.4, < 3.0)
31
+ logging (~> 2.0)
32
+ memoist (~> 0.12)
33
+ multi_json (~> 1.11)
34
+ os (~> 0.9)
35
+ signet (~> 0.7)
36
+ grpc (1.7.2)
37
+ google-protobuf (~> 3.1)
38
+ googleapis-common-protos-types (~> 1.0.0)
39
+ googleauth (>= 0.5.1, < 0.7)
40
+ grpc-tools (1.7.2)
41
+ hashie (3.5.6)
42
+ highline (1.7.10)
43
+ i18n (0.9.1)
80
44
  concurrent-ruby (~> 1.0)
81
- juwelier (2.4.9)
45
+ json (1.8.6)
46
+ juwelier (2.1.3)
82
47
  builder
83
- bundler
84
- git
48
+ bundler (>= 1.13)
49
+ git (>= 1.2.5)
85
50
  github_api
86
- highline
87
- kamelcase (~> 0)
88
- nokogiri
89
- psych
51
+ highline (>= 1.6.15)
52
+ nokogiri (>= 1.5.10)
90
53
  rake
91
54
  rdoc
92
- semver2
93
- jwt (2.2.2)
94
- kamelcase (0.0.2)
95
- semver2 (~> 3)
96
- ld-eventsource (2.2.0)
97
- concurrent-ruby (~> 1.0)
98
- http (>= 4.4.1, < 6.0.0)
99
- llhttp-ffi (0.3.1)
100
- ffi-compiler (~> 1.0)
101
- rake (~> 13.0)
102
- loofah (2.21.4)
103
- crass (~> 1.0.2)
104
- nokogiri (>= 1.12.0)
105
- macaddr (1.7.2)
106
- systemu (~> 2.6.5)
107
- mini_portile2 (2.8.2)
108
- minitest (5.16.2)
109
- minitest-focus (1.3.1)
110
- minitest (>= 4, < 6)
111
- minitest-reporters (1.5.0)
112
- ansi
113
- builder
114
- minitest (>= 5.0)
115
- ruby-progressbar
116
- multi_json (1.15.0)
55
+ semver
56
+ jwt (1.5.6)
57
+ little-plugger (1.1.4)
58
+ logging (2.2.2)
59
+ little-plugger (~> 1.1)
60
+ multi_json (~> 1.10)
61
+ memoist (0.16.0)
62
+ mini_portile2 (2.3.0)
63
+ minitest (5.10.3)
64
+ multi_json (1.12.2)
117
65
  multi_xml (0.6.0)
118
- multipart-post (2.1.1)
119
- mutex_m (0.2.0)
120
- nokogiri (1.15.2)
121
- mini_portile2 (~> 2.8.2)
122
- racc (~> 1.4)
123
- oauth2 (1.4.11)
124
- faraday (>= 0.17.3, < 3.0)
125
- jwt (>= 1.0, < 3.0)
66
+ multipart-post (2.0.0)
67
+ nokogiri (1.8.1)
68
+ mini_portile2 (~> 2.3.0)
69
+ oauth2 (1.4.0)
70
+ faraday (>= 0.8, < 0.13)
71
+ jwt (~> 1.0)
126
72
  multi_json (~> 1.3)
127
73
  multi_xml (~> 0.5)
128
- rack (>= 1.2, < 4)
129
- psych (3.3.1)
130
- public_suffix (4.0.6)
131
- racc (1.7.0)
132
- rack (3.0.6.1)
133
- rack-session (2.0.0)
134
- rack (>= 3.0.0)
135
- rack-test (2.1.0)
136
- rack (>= 1.3)
137
- rails-dom-testing (2.2.0)
138
- activesupport (>= 5.0.0)
139
- minitest
140
- nokogiri (>= 1.6)
141
- rails-html-sanitizer (1.6.0)
142
- loofah (~> 2.21)
143
- nokogiri (~> 1.14)
144
- rake (13.0.6)
145
- rchardet (1.8.0)
146
- rdoc (6.3.3)
147
- ruby-progressbar (1.11.0)
148
- ruby2_keywords (0.0.4)
149
- semver2 (3.4.2)
150
- simplecov (0.18.5)
151
- docile (~> 1.1)
152
- simplecov-html (~> 0.11)
153
- simplecov-html (0.12.3)
154
- systemu (2.6.5)
74
+ rack (>= 1.2, < 3)
75
+ os (0.9.6)
76
+ public_suffix (3.0.1)
77
+ rack (2.0.3)
78
+ rake (12.3.0)
79
+ rdoc (3.12.2)
80
+ json (~> 1.4)
81
+ semver (1.0.1)
82
+ shoulda (3.5.0)
83
+ shoulda-context (~> 1.0, >= 1.0.1)
84
+ shoulda-matchers (>= 1.4.1, < 3.0)
85
+ shoulda-context (1.2.2)
86
+ shoulda-matchers (2.8.0)
87
+ activesupport (>= 3.0.0)
88
+ signet (0.8.1)
89
+ addressable (~> 2.3)
90
+ faraday (~> 0.9)
91
+ jwt (>= 1.5, < 3.0)
92
+ multi_json (~> 1.10)
93
+ simplecov (0.15.1)
94
+ docile (~> 1.1.0)
95
+ json (>= 1.8, < 3)
96
+ simplecov-html (~> 0.10.0)
97
+ simplecov-html (0.10.2)
155
98
  thread_safe (0.3.6)
156
- timecop (0.9.4)
157
- tzinfo (2.0.6)
158
- concurrent-ruby (~> 1.0)
159
- unf (0.1.4)
160
- unf_ext
161
- unf_ext (0.0.8)
162
- uuid (2.3.9)
163
- macaddr (~> 1.0)
99
+ tzinfo (1.2.4)
100
+ thread_safe (~> 0.1)
164
101
 
165
102
  PLATFORMS
166
103
  ruby
167
104
 
168
105
  DEPENDENCIES
169
- actionpack (>= 4)
170
- activesupport (>= 4)
171
- benchmark-ips
172
- bundler
173
- concurrent-ruby (~> 1.0, >= 1.0.5)
174
- faraday
175
- google-protobuf
176
- googleapis-common-protos-types
177
- juwelier (~> 2.4.9)
178
- ld-eventsource
179
- minitest
180
- minitest-focus
181
- minitest-reporters
182
- rdoc
106
+ bundler (~> 1.0)
107
+ concurrent-ruby
108
+ grpc
109
+ grpc-tools
110
+ juwelier (~> 2.1.0)
111
+ rdoc (~> 3.12)
112
+ shoulda
183
113
  simplecov
184
- timecop
185
- uuid
186
114
 
187
115
  BUNDLED WITH
188
- 2.3.5
116
+ 1.16.0
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2023 Prefab, Inc.
1
+ Copyright (c) 2017 Jeff Dwyer
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -1,25 +1,25 @@
1
- # frozen_string_literal: true
1
+ # encoding: utf-8
2
2
 
3
3
  require 'rubygems'
4
4
  require 'bundler'
5
5
  begin
6
6
  Bundler.setup(:default, :development)
7
7
  rescue Bundler::BundlerError => e
8
- warn e.message
9
- warn 'Run `bundle install` to install missing gems'
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
10
  exit e.status_code
11
11
  end
12
12
  require 'rake'
13
13
  require 'juwelier'
14
14
  Juwelier::Tasks.new do |gem|
15
15
  # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
16
- gem.name = 'prefab-cloud-ruby'
17
- gem.homepage = 'http://github.com/prefab-cloud/prefab-cloud-ruby'
18
- gem.license = 'MIT'
19
- gem.summary = %(Prefab Ruby Infrastructure)
20
- gem.description = %(Feature Flags, Live Config, and Dynamic Log Levels as a service)
21
- gem.email = 'jdwyer@prefab.cloud'
22
- gem.authors = ['Jeff Dwyer']
16
+ gem.name = "prefab-cloud-ruby"
17
+ gem.homepage = "http://github.com/prefab-cloud/prefab-cloud-ruby"
18
+ gem.license = "MIT"
19
+ gem.summary = %Q{Prefab Ruby Infrastructure}
20
+ gem.description = %Q{RateLimits & Config as a service}
21
+ gem.email = "jdwyer@prefab.cloud"
22
+ gem.authors = ["Jeff Dwyer"]
23
23
 
24
24
  # dependencies defined in Gemfile
25
25
  end
@@ -31,17 +31,17 @@ Rake::TestTask.new(:test) do |test|
31
31
  test.verbose = true
32
32
  end
33
33
 
34
- desc 'Code coverage detail'
34
+ desc "Code coverage detail"
35
35
  task :simplecov do
36
- ENV['COVERAGE'] = 'true'
36
+ ENV['COVERAGE'] = "true"
37
37
  Rake::Task['test'].execute
38
38
  end
39
39
 
40
- task default: :test
40
+ task :default => :test
41
41
 
42
42
  require 'rdoc/task'
43
43
  Rake::RDocTask.new do |rdoc|
44
- version = File.exist?('VERSION') ? File.read('VERSION') : ''
44
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
45
 
46
46
  rdoc.rdoc_dir = 'rdoc'
47
47
  rdoc.title = "prefab-cloud-ruby #{version}"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.5.0
1
+ 0.0.1
@@ -0,0 +1,25 @@
1
+ class AuthInterceptor < GRPC::ClientInterceptor
2
+ def initialize(api_key)
3
+ @api_key = api_key
4
+ end
5
+
6
+ def request_response(request:, call:, method:, metadata:)
7
+ metadata['auth'] = @api_key
8
+ yield
9
+ end
10
+
11
+ def client_streamer(requests:, call:, method:, metadata:)
12
+ metadata['auth'] = @api_key
13
+ yield
14
+ end
15
+
16
+ def server_streamer(request:, call:, method:, metadata:)
17
+ metadata['auth'] = @api_key
18
+ yield
19
+ end
20
+
21
+ def bidi_streamer(requests:, call:, method:, metadata:)
22
+ metadata['auth'] = @api_key
23
+ yield
24
+ end
25
+ end
data/lib/prefab/client.rb CHANGED
@@ -1,153 +1,48 @@
1
- # frozen_string_literal: true
2
-
3
- require 'uuid'
4
-
5
1
  module Prefab
6
2
  class Client
7
- MAX_SLEEP_SEC = 10
8
- BASE_SLEEP_SEC = 0.5
9
- LOG = Prefab::InternalLogger.new(Client)
10
-
11
- attr_reader :namespace, :interceptor, :api_key, :prefab_api_url, :options, :instance_hash
12
3
 
13
- def initialize(options = Prefab::Options.new)
14
- @options = options.is_a?(Prefab::Options) ? options : Prefab::Options.new(options)
15
- @namespace = @options.namespace
16
- @stubs = {}
17
- @instance_hash = UUID.new.generate
18
- Prefab::LoggerClient.new(@options.logdev, formatter: @options.log_formatter,
19
- prefix: @options.log_prefix,
20
- log_path_aggregator: log_path_aggregator
21
- )
22
-
23
- if @options.local_only?
24
- LOG.debug 'Prefab Running in Local Mode'
25
- elsif @options.datafile?
26
- LOG.debug 'Prefab Running in DataFile Mode'
27
- else
28
- @api_key = @options.api_key
29
- raise Prefab::Errors::InvalidApiKeyError, @api_key if @api_key.nil? || @api_key.empty? || api_key.count('-') < 1
30
-
31
- @prefab_api_url = @options.prefab_api_url
32
- LOG.debug "Prefab Connecting to: #{@prefab_api_url}"
4
+ attr_reader :account_id, :shared_cache, :stats, :namespace, :logger
5
+
6
+ def initialize(api_key:,
7
+ ssl_certs: "/usr/local/etc/openssl/cert.pem",
8
+ logger: nil,
9
+ stats: nil, # receives increment("prefab.limitcheck", {:tags=>["policy_group:page_view", "pass:true"]})
10
+ shared_cache: nil, # Something that quacks like Rails.cache ideally memcached
11
+ local: false,
12
+ namespace: ""
13
+ )
14
+ @logger = (logger || Logger.new($stdout)).tap do |log|
15
+ log.progname = "Prefab" if log.respond_to? :progname=
33
16
  end
17
+ @stats = (stats || NoopStats.new)
18
+ @shared_cache = (shared_cache || NoopCache.new)
19
+ @account_id = api_key.split("|")[0].to_i
20
+ @namespace = namespace
34
21
 
35
- context.clear
36
- # start config client
37
- config_client
38
- end
39
-
40
- def with_context(properties, &block)
41
- Prefab::Context.with_context(properties, &block)
42
- end
43
-
44
- def context
45
- Prefab::Context.current
46
- end
47
-
48
- def config_client(timeout: 5.0)
49
- @config_client ||= Prefab::ConfigClient.new(self, timeout)
50
- end
51
-
52
- def feature_flag_client
53
- @feature_flag_client ||= Prefab::FeatureFlagClient.new(self)
54
- end
55
-
56
- def log_path_aggregator
57
- return nil if @options.collect_max_paths <= 0
58
-
59
- @log_path_aggregator ||= LogPathAggregator.new(client: self, max_paths: @options.collect_max_paths,
60
- sync_interval: @options.collect_sync_interval)
61
- end
62
-
63
- def log
64
- Prefab::LoggerClient.instance
65
- end
66
-
67
- def context_shape_aggregator
68
- return nil if @options.collect_max_shapes <= 0
69
-
70
- @context_shape_aggregator ||= ContextShapeAggregator.new(client: self, max_shapes: @options.collect_max_shapes,
71
- sync_interval: @options.collect_sync_interval)
72
- end
73
-
74
- def example_contexts_aggregator
75
- return nil if @options.collect_max_example_contexts <= 0
22
+ @interceptor = AuthInterceptor.new(api_key)
23
+ @creds = GRPC::Core::ChannelCredentials.new(File.open(ssl_certs).read)
76
24
 
77
- @example_contexts_aggregator ||= ExampleContextsAggregator.new(
78
- client: self,
79
- max_contexts: @options.collect_max_example_contexts,
80
- sync_interval: @options.collect_sync_interval
81
- )
82
- end
83
-
84
- def evaluation_summary_aggregator
85
- return nil if @options.collect_max_evaluation_summaries <= 0
86
-
87
- @evaluation_summary_aggregator ||= EvaluationSummaryAggregator.new(
88
- client: self,
89
- max_keys: @options.collect_max_evaluation_summaries,
90
- sync_interval: @options.collect_sync_interval
91
- )
92
- end
93
-
94
- def set_rails_loggers
95
- Rails.logger = log
96
- ActionView::Base.logger = log
97
- ActionController::Base.logger = log
98
- ActiveJob::Base.logger = log if defined?(ActiveJob)
99
- ActiveRecord::Base.logger = log
100
- ActiveStorage.logger = log if defined?(ActiveStorage)
101
-
102
- LogSubscribers::ActionControllerSubscriber.attach_to :action_controller unless @options.disable_action_controller_logging
103
- end
104
-
105
- def on_update(&block)
106
- resolver.on_update(&block)
107
- end
108
-
109
- def enabled?(feature_name, jit_context = NO_DEFAULT_PROVIDED)
110
- feature_flag_client.feature_is_on_for?(feature_name, jit_context)
111
- end
112
-
113
- def get(key, default = NO_DEFAULT_PROVIDED, jit_context = NO_DEFAULT_PROVIDED)
114
- if is_ff?(key)
115
- feature_flag_client.get(key, jit_context, default: default)
116
- else
117
- config_client.get(key, default, jit_context)
25
+ @channel = GRPC::Core::Channel.new('api.prefab.cloud:8443', nil, @creds)
26
+ if local
27
+ @channel = GRPC::Core::Channel.new('localhost:8443', nil, :this_channel_is_insecure)
118
28
  end
119
29
  end
120
30
 
121
- def post(path, body)
122
- Prefab::HttpConnection.new(@options.prefab_api_url, @api_key).post(path, body)
123
- end
124
-
125
- def inspect
126
- "#<Prefab::Client:#{object_id} namespace=#{namespace}>"
31
+ def config_client
32
+ @config_client ||= Prefab::ConfigClient.new(Prefab::ConfigService::Stub.new(nil,
33
+ @creds,
34
+ channel_override: @channel,
35
+ interceptors: [@interceptor]),
36
+ self)
127
37
  end
128
38
 
129
- def resolver
130
- config_client.resolver
131
- end
132
-
133
- # When starting a forked process, use this to re-use the options
134
- # on_worker_boot do
135
- # $prefab = $prefab.fork
136
- # $prefab.set_rails_loggers
137
- # end
138
- def fork
139
- log_options = self.log.context_keys.to_a # get keys pre-fork
140
- Prefab::Client.new(@options.for_fork).tap do |client|
141
- client.log.add_context_keys(*log_options)
142
- end
143
- end
144
-
145
- private
146
-
147
- def is_ff?(key)
148
- raw = config_client.send(:raw, key)
149
-
150
- raw && raw.allowable_values.any?
39
+ def ratelimit_client
40
+ @ratelimit_client ||= Prefab::RateLimitClient.new(Prefab::RateLimitService::Stub.new(nil,
41
+ @creds,
42
+ channel_override: @channel,
43
+ interceptors: [@interceptor]),
44
+ self)
151
45
  end
152
46
  end
153
47
  end
48
+