prefab-cloud-ruby 0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.ruby-version +1 -0
- data/Gemfile +9 -22
- data/Gemfile.lock +88 -160
- data/LICENSE.txt +1 -1
- data/Rakefile +14 -14
- data/VERSION +1 -1
- data/lib/prefab/auth_interceptor.rb +25 -0
- data/lib/prefab/client.rb +34 -139
- data/lib/prefab/config_client.rb +23 -275
- data/lib/prefab/config_loader.rb +27 -60
- data/lib/prefab/config_resolver.rb +40 -53
- data/lib/prefab/noop_cache.rb +13 -0
- data/lib/prefab/noop_stats.rb +8 -0
- data/lib/prefab/prefab_pb.rb +39 -0
- data/lib/prefab/prefab_services_pb.rb +37 -0
- data/lib/prefab/ratelimit_client.rb +58 -0
- data/lib/prefab/ratelimit_pb.rb +125 -0
- data/lib/prefab/store.rb +29 -0
- data/lib/prefab_client.rb +35 -0
- metadata +36 -198
- data/.envrc.sample +0 -3
- data/.github/workflows/ruby.yml +0 -46
- data/.gitmodules +0 -3
- data/.rubocop.yml +0 -13
- data/.tool-versions +0 -1
- data/CHANGELOG.md +0 -169
- data/CODEOWNERS +0 -1
- data/README.md +0 -94
- data/bin/console +0 -21
- data/compile_protos.sh +0 -18
- data/lib/prefab/config_client_presenter.rb +0 -18
- data/lib/prefab/config_value_unwrapper.rb +0 -115
- data/lib/prefab/config_value_wrapper.rb +0 -18
- data/lib/prefab/context.rb +0 -179
- data/lib/prefab/context_shape.rb +0 -20
- data/lib/prefab/context_shape_aggregator.rb +0 -65
- data/lib/prefab/criteria_evaluator.rb +0 -136
- data/lib/prefab/encryption.rb +0 -65
- data/lib/prefab/error.rb +0 -6
- data/lib/prefab/errors/env_var_parse_error.rb +0 -11
- data/lib/prefab/errors/initialization_timeout_error.rb +0 -13
- data/lib/prefab/errors/invalid_api_key_error.rb +0 -19
- data/lib/prefab/errors/missing_default_error.rb +0 -13
- data/lib/prefab/errors/missing_env_var_error.rb +0 -11
- data/lib/prefab/errors/uninitialized_error.rb +0 -13
- data/lib/prefab/evaluation.rb +0 -52
- data/lib/prefab/evaluation_summary_aggregator.rb +0 -87
- data/lib/prefab/example_contexts_aggregator.rb +0 -78
- data/lib/prefab/exponential_backoff.rb +0 -21
- data/lib/prefab/feature_flag_client.rb +0 -42
- data/lib/prefab/http_connection.rb +0 -41
- data/lib/prefab/internal_logger.rb +0 -16
- data/lib/prefab/local_config_parser.rb +0 -151
- data/lib/prefab/log_path_aggregator.rb +0 -69
- data/lib/prefab/logger_client.rb +0 -264
- data/lib/prefab/murmer3.rb +0 -50
- data/lib/prefab/options.rb +0 -208
- data/lib/prefab/periodic_sync.rb +0 -69
- data/lib/prefab/prefab.rb +0 -56
- data/lib/prefab/rate_limit_cache.rb +0 -41
- data/lib/prefab/resolved_config_presenter.rb +0 -86
- data/lib/prefab/time_helpers.rb +0 -7
- data/lib/prefab/weighted_value_resolver.rb +0 -42
- data/lib/prefab/yaml_config_parser.rb +0 -34
- data/lib/prefab-cloud-ruby.rb +0 -57
- data/lib/prefab_pb.rb +0 -93
- data/prefab-cloud-ruby.gemspec +0 -155
- data/test/.prefab.default.config.yaml +0 -2
- data/test/.prefab.unit_tests.config.yaml +0 -28
- data/test/integration_test.rb +0 -150
- data/test/integration_test_helpers.rb +0 -151
- data/test/support/common_helpers.rb +0 -180
- data/test/support/mock_base_client.rb +0 -42
- data/test/support/mock_config_client.rb +0 -19
- data/test/support/mock_config_loader.rb +0 -1
- data/test/test_client.rb +0 -444
- data/test/test_config_client.rb +0 -109
- data/test/test_config_loader.rb +0 -117
- data/test/test_config_resolver.rb +0 -430
- data/test/test_config_value_unwrapper.rb +0 -224
- data/test/test_config_value_wrapper.rb +0 -42
- data/test/test_context.rb +0 -203
- data/test/test_context_shape.rb +0 -50
- data/test/test_context_shape_aggregator.rb +0 -147
- data/test/test_criteria_evaluator.rb +0 -726
- data/test/test_encryption.rb +0 -16
- data/test/test_evaluation_summary_aggregator.rb +0 -162
- data/test/test_example_contexts_aggregator.rb +0 -238
- data/test/test_exponential_backoff.rb +0 -18
- data/test/test_feature_flag_client.rb +0 -48
- data/test/test_helper.rb +0 -17
- data/test/test_integration.rb +0 -58
- data/test/test_local_config_parser.rb +0 -147
- data/test/test_log_path_aggregator.rb +0 -62
- data/test/test_logger.rb +0 -621
- data/test/test_logger_initialization.rb +0 -12
- data/test/test_options.rb +0 -75
- data/test/test_prefab.rb +0 -12
- data/test/test_rate_limit_cache.rb +0 -44
- data/test/test_weighted_value_resolver.rb +0 -71
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9a9979df2d96ea510b54c6b479cba724e0ef1ae7
|
4
|
+
data.tar.gz: 8a73500c4c42dac6f4955b6bd6ff395ddf43511f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
1
|
+
source "https://rubygems.org"
|
2
2
|
|
3
|
-
gem
|
4
|
-
gem
|
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
|
15
|
-
gem
|
16
|
-
gem
|
17
|
-
gem
|
18
|
-
gem
|
19
|
-
|
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
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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.
|
43
|
-
|
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
|
-
|
52
|
-
|
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 (
|
22
|
+
faraday (~> 0.8)
|
64
23
|
hashie (~> 3.5, >= 3.5.2)
|
65
24
|
oauth2 (~> 1.0)
|
66
|
-
google-protobuf (3.
|
67
|
-
googleapis-common-protos-types (1.
|
68
|
-
google-protobuf (~> 3.
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
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
|
-
|
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
|
-
|
88
|
-
nokogiri
|
89
|
-
psych
|
51
|
+
highline (>= 1.6.15)
|
52
|
+
nokogiri (>= 1.5.10)
|
90
53
|
rake
|
91
54
|
rdoc
|
92
|
-
|
93
|
-
jwt (
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
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.
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
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, <
|
129
|
-
|
130
|
-
public_suffix (
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
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
|
-
|
157
|
-
|
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
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
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
|
-
|
116
|
+
1.16.0
|
data/LICENSE.txt
CHANGED
data/Rakefile
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
#
|
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
|
-
|
9
|
-
|
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 =
|
17
|
-
gem.homepage =
|
18
|
-
gem.license =
|
19
|
-
gem.summary = %
|
20
|
-
gem.description = %
|
21
|
-
gem.email =
|
22
|
-
gem.authors = [
|
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
|
34
|
+
desc "Code coverage detail"
|
35
35
|
task :simplecov do
|
36
|
-
ENV['COVERAGE'] =
|
36
|
+
ENV['COVERAGE'] = "true"
|
37
37
|
Rake::Task['test'].execute
|
38
38
|
end
|
39
39
|
|
40
|
-
task default
|
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
|
+
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
36
|
-
|
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
|
-
@
|
78
|
-
|
79
|
-
|
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
|
122
|
-
Prefab::
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
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
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
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
|
+
|