configcat 6.1.0 → 7.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/configcat/configcatclient.rb +0 -50
- data/lib/configcat/configentry.rb +34 -21
- data/lib/configcat/configfetcher.rb +1 -1
- data/lib/configcat/configservice.rb +7 -4
- data/lib/configcat/constants.rb +1 -0
- data/lib/configcat/version.rb +1 -1
- data/lib/configcat.rb +0 -160
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e0dc6578b7a148dda7c630d560098fb295eb139f237362db056b235d0feaa7e
|
4
|
+
data.tar.gz: e9f97b6d5f0af6fa72288bfeac3b13c6354bb1726af129349653b9365a10e665
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a895b147c9238dbeb7e2f02d5021002032b47e023214842fb4528bdfabdf5c6c729bc746ff630f1f5cfb325442ba70ae71e7e3ee2257b3d81cfc8cf60ad06dee
|
7
|
+
data.tar.gz: 95d70831f41b93bcfa3306e9af41de05eb27ce80df4b734c0f1a6f7f98f83da468ed8abacbd4b252c105cd807bd21859b2cd4f19699b5a426c689bf6b15eedd7
|
@@ -146,52 +146,6 @@ module ConfigCat
|
|
146
146
|
return settings.keys
|
147
147
|
end
|
148
148
|
|
149
|
-
# Gets the Variation ID (analytics) of a feature flag or setting based on it's key.
|
150
|
-
#
|
151
|
-
# :param key [String] the identifier of the feature flag or setting.
|
152
|
-
# :param default_variation_id in case of any failure, this value will be returned.
|
153
|
-
# :param user [User] the user object to identify the caller.
|
154
|
-
# :return the variation ID.
|
155
|
-
def get_variation_id(key, default_variation_id, user = nil)
|
156
|
-
ConfigCat.logger.warn("get_variation_id is deprecated and will be removed in a future major version. " \
|
157
|
-
"Please use [get_value_details] instead.")
|
158
|
-
|
159
|
-
settings, fetch_time = _get_settings()
|
160
|
-
if settings === nil
|
161
|
-
message = "Config JSON is not present when evaluating setting '#{key}'. Returning the `default_variation_id` parameter that you specified in your application: '#{default_variation_id}'."
|
162
|
-
@log.error(1000, message)
|
163
|
-
@hooks.invoke_on_flag_evaluated(EvaluationDetails.from_error(key, nil, error: message,
|
164
|
-
variation_id: default_variation_id))
|
165
|
-
return default_variation_id
|
166
|
-
end
|
167
|
-
details = _evaluate(key, user, nil, default_variation_id, settings, fetch_time)
|
168
|
-
return details.variation_id
|
169
|
-
end
|
170
|
-
|
171
|
-
# Gets the Variation IDs (analytics) of all feature flags or settings.
|
172
|
-
#
|
173
|
-
# :param user [User] the user object to identify the caller.
|
174
|
-
# :return list of variation IDs
|
175
|
-
def get_all_variation_ids(user = nil)
|
176
|
-
ConfigCat.logger.warn("get_all_variation_ids is deprecated and will be removed in a future major version. " \
|
177
|
-
"Please use [get_value_details] instead.")
|
178
|
-
|
179
|
-
settings, _ = _get_settings()
|
180
|
-
if settings === nil
|
181
|
-
@log.error(1000, "Config JSON is not present. Returning empty list.")
|
182
|
-
return []
|
183
|
-
end
|
184
|
-
|
185
|
-
variation_ids = []
|
186
|
-
for key in settings.keys
|
187
|
-
variation_id = get_variation_id(key, nil, user)
|
188
|
-
if !variation_id.equal?(nil)
|
189
|
-
variation_ids.push(variation_id)
|
190
|
-
end
|
191
|
-
end
|
192
|
-
return variation_ids
|
193
|
-
end
|
194
|
-
|
195
149
|
# Gets the key of a setting, and it's value identified by the given Variation ID (analytics)
|
196
150
|
#
|
197
151
|
# :param variation_id [String] variation ID
|
@@ -350,10 +304,6 @@ module ConfigCat
|
|
350
304
|
return @_config_service.get_settings()
|
351
305
|
end
|
352
306
|
|
353
|
-
def _get_cache_key
|
354
|
-
return Digest::SHA1.hexdigest("ruby_" + CONFIG_FILE_NAME + "_" + @_sdk_key)
|
355
|
-
end
|
356
|
-
|
357
307
|
def _evaluate(key, user, default_value, default_variation_id, settings, fetch_time)
|
358
308
|
user = user || @_default_user
|
359
309
|
value, variation_id, rule, percentage_rule, error = @_rollout_evaluator.evaluate(
|
@@ -2,37 +2,50 @@ require 'configcat/utils'
|
|
2
2
|
|
3
3
|
module ConfigCat
|
4
4
|
class ConfigEntry
|
5
|
-
|
6
|
-
ETAG = 'etag'
|
7
|
-
FETCH_TIME = 'fetch_time'
|
5
|
+
attr_accessor :config, :etag, :config_json_string, :fetch_time
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
def initialize(config = {}, etag = '', fetch_time = Utils::DISTANT_PAST)
|
7
|
+
def initialize(config = {}, etag = '', config_json_string = '{}', fetch_time = Utils::DISTANT_PAST)
|
12
8
|
@config = config
|
13
9
|
@etag = etag
|
10
|
+
@config_json_string = config_json_string
|
14
11
|
@fetch_time = fetch_time
|
15
12
|
end
|
16
13
|
|
17
|
-
def self.create_from_json(json)
|
18
|
-
return ConfigEntry::EMPTY if json.nil?
|
19
|
-
return ConfigEntry.new(
|
20
|
-
config = json.fetch(CONFIG, {}),
|
21
|
-
etag = json.fetch(ETAG, ''),
|
22
|
-
fetch_time = json.fetch(FETCH_TIME, Utils::DISTANT_PAST)
|
23
|
-
)
|
24
|
-
end
|
25
|
-
|
26
14
|
def empty?
|
27
15
|
self == ConfigEntry::EMPTY
|
28
16
|
end
|
29
17
|
|
30
|
-
def
|
31
|
-
{
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
18
|
+
def serialize
|
19
|
+
"#{(fetch_time * 1000).floor}\n#{etag}\n#{config_json_string}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.create_from_string(string)
|
23
|
+
return ConfigEntry.empty if string.nil? || string.empty?
|
24
|
+
|
25
|
+
fetch_time_index = string.index("\n")
|
26
|
+
etag_index = string.index("\n", fetch_time_index + 1)
|
27
|
+
if fetch_time_index.nil? || etag_index.nil?
|
28
|
+
raise 'Number of values is fewer than expected.'
|
29
|
+
end
|
30
|
+
|
31
|
+
begin
|
32
|
+
fetch_time = Float(string[0...fetch_time_index])
|
33
|
+
rescue ArgumentError
|
34
|
+
raise "Invalid fetch time: #{string[0...fetch_time_index]}"
|
35
|
+
end
|
36
|
+
|
37
|
+
etag = string[fetch_time_index + 1...etag_index]
|
38
|
+
if etag.nil? || etag.empty?
|
39
|
+
raise 'Empty eTag value'
|
40
|
+
end
|
41
|
+
begin
|
42
|
+
config_json = string[etag_index + 1..-1]
|
43
|
+
config = JSON.parse(config_json)
|
44
|
+
rescue => e
|
45
|
+
raise "Invalid config JSON: #{config_json}. #{e.message}"
|
46
|
+
end
|
47
|
+
|
48
|
+
ConfigEntry.new(config, etag, config_json, fetch_time / 1000.0)
|
36
49
|
end
|
37
50
|
|
38
51
|
EMPTY = ConfigEntry.new(etag: 'empty')
|
@@ -179,7 +179,7 @@ module ConfigCat
|
|
179
179
|
response_etag = ""
|
180
180
|
end
|
181
181
|
config = JSON.parse(response.body)
|
182
|
-
return FetchResponse.success(ConfigEntry.new(config, response_etag, Utils.get_utc_now_seconds_since_epoch))
|
182
|
+
return FetchResponse.success(ConfigEntry.new(config, response_etag, response.body, Utils.get_utc_now_seconds_since_epoch))
|
183
183
|
when Net::HTTPNotModified
|
184
184
|
return FetchResponse.not_modified
|
185
185
|
when Net::HTTPNotFound, Net::HTTPForbidden
|
@@ -7,14 +7,13 @@ require 'configcat/refreshresult'
|
|
7
7
|
module ConfigCat
|
8
8
|
class ConfigService
|
9
9
|
def initialize(sdk_key, polling_mode, hooks, config_fetcher, log, config_cache, is_offline)
|
10
|
-
@sdk_key = sdk_key
|
11
10
|
@cached_entry = ConfigEntry::EMPTY
|
12
11
|
@cached_entry_string = ''
|
13
12
|
@polling_mode = polling_mode
|
14
13
|
@log = log
|
15
14
|
@config_cache = config_cache
|
16
15
|
@hooks = hooks
|
17
|
-
@cache_key =
|
16
|
+
@cache_key = ConfigService.get_cache_key(sdk_key)
|
18
17
|
@config_fetcher = config_fetcher
|
19
18
|
@is_offline = is_offline
|
20
19
|
@response_future = nil
|
@@ -107,6 +106,10 @@ module ConfigCat
|
|
107
106
|
|
108
107
|
private
|
109
108
|
|
109
|
+
def self.get_cache_key(sdk_key)
|
110
|
+
Digest::SHA1.hexdigest("#{sdk_key}_#{CONFIG_FILE_NAME}.json_#{SERIALIZATION_FORMAT_VERSION}")
|
111
|
+
end
|
112
|
+
|
110
113
|
# :return [ConfigEntry, String] Returns the ConfigEntry object and error message in case of any error.
|
111
114
|
def fetch_if_older(time, prefer_cache: false)
|
112
115
|
# Sync up with the cache and use it when it's not expired.
|
@@ -201,7 +204,7 @@ module ConfigCat
|
|
201
204
|
end
|
202
205
|
|
203
206
|
@cached_entry_string = json_string
|
204
|
-
return ConfigEntry.
|
207
|
+
return ConfigEntry.create_from_string(json_string)
|
205
208
|
rescue Exception => e
|
206
209
|
@log.error(2200, "Error occurred while reading the cache. #{e}")
|
207
210
|
return ConfigEntry::EMPTY
|
@@ -210,7 +213,7 @@ module ConfigCat
|
|
210
213
|
|
211
214
|
def write_cache(config_entry)
|
212
215
|
begin
|
213
|
-
@config_cache.set(@cache_key, config_entry.
|
216
|
+
@config_cache.set(@cache_key, config_entry.serialize)
|
214
217
|
rescue Exception => e
|
215
218
|
@log.error(2201, "Error occurred while writing the cache. #{e}")
|
216
219
|
end
|
data/lib/configcat/constants.rb
CHANGED
data/lib/configcat/version.rb
CHANGED
data/lib/configcat.rb
CHANGED
@@ -24,164 +24,4 @@ module ConfigCat
|
|
24
24
|
def ConfigCat.close_all
|
25
25
|
ConfigCatClient.close_all
|
26
26
|
end
|
27
|
-
|
28
|
-
def ConfigCat.create_client(sdk_key, data_governance: DataGovernance::GLOBAL)
|
29
|
-
#
|
30
|
-
# Create an instance of ConfigCatClient and setup Auto Poll mode with default options
|
31
|
-
#
|
32
|
-
# :param sdk_key: ConfigCat SDK Key to access your configuration.
|
33
|
-
# :param data_governance:
|
34
|
-
# Default: Global. Set this parameter to be in sync with the Data Governance preference on the Dashboard:
|
35
|
-
# https://app.configcat.com/organization/data-governance
|
36
|
-
# (Only Organization Admins have access)
|
37
|
-
#
|
38
|
-
return create_client_with_auto_poll(sdk_key, data_governance: data_governance)
|
39
|
-
end
|
40
|
-
|
41
|
-
# Create an instance of ConfigCatClient and setup Auto Poll mode with custom options
|
42
|
-
#
|
43
|
-
# :param sdk_key: ConfigCat SDK Key to access your configuration.
|
44
|
-
# :param poll_interval_seconds: The client's poll interval in seconds. Default: 60 seconds.
|
45
|
-
# :param on_configuration_changed_callback: You can subscribe to configuration changes with this callback
|
46
|
-
# :param max_init_wait_time_seconds: maximum waiting time for first configuration fetch in polling mode.
|
47
|
-
# :param config_cache: If you want to use custom caching instead of the client's default,
|
48
|
-
# You can provide an implementation of ConfigCache.
|
49
|
-
# :param base_url: You can set a base_url if you want to use a proxy server between your application and ConfigCat
|
50
|
-
# :param proxy_address: Proxy address
|
51
|
-
# :param proxy_port: Proxy port
|
52
|
-
# :param proxy_user: username for proxy authentication
|
53
|
-
# :param proxy_pass: password for proxy authentication
|
54
|
-
# :param open_timeout_seconds: The number of seconds to wait for the server to make the initial connection. Default: 10 seconds.
|
55
|
-
# :param read_timeout_seconds: The number of seconds to wait for the server to respond before giving up. Default: 30 seconds.
|
56
|
-
# :param flag_overrides: A FlagOverrides implementation used to override feature flags & settings.
|
57
|
-
# :param data_governance:
|
58
|
-
# Default: Global. Set this parameter to be in sync with the Data Governance preference on the Dashboard:
|
59
|
-
# https://app.configcat.com/organization/data-governance
|
60
|
-
# (Only Organization Admins have access)
|
61
|
-
def ConfigCat.create_client_with_auto_poll(sdk_key,
|
62
|
-
poll_interval_seconds: 60,
|
63
|
-
max_init_wait_time_seconds: 5,
|
64
|
-
on_configuration_changed_callback: nil,
|
65
|
-
config_cache: nil,
|
66
|
-
base_url: nil,
|
67
|
-
proxy_address: nil,
|
68
|
-
proxy_port: nil,
|
69
|
-
proxy_user: nil,
|
70
|
-
proxy_pass: nil,
|
71
|
-
open_timeout_seconds: 10,
|
72
|
-
read_timeout_seconds: 30,
|
73
|
-
flag_overrides: nil,
|
74
|
-
data_governance: DataGovernance::GLOBAL)
|
75
|
-
options = ConfigCatOptions.new(
|
76
|
-
base_url: base_url,
|
77
|
-
polling_mode: PollingMode.auto_poll(poll_interval_seconds: poll_interval_seconds, max_init_wait_time_seconds: max_init_wait_time_seconds),
|
78
|
-
config_cache: config_cache,
|
79
|
-
proxy_address: proxy_address,
|
80
|
-
proxy_port: proxy_port,
|
81
|
-
proxy_user: proxy_user,
|
82
|
-
proxy_pass: proxy_pass,
|
83
|
-
open_timeout_seconds: open_timeout_seconds,
|
84
|
-
read_timeout_seconds: read_timeout_seconds,
|
85
|
-
flag_overrides: flag_overrides,
|
86
|
-
data_governance: data_governance
|
87
|
-
)
|
88
|
-
ConfigCat.logger.warn('create_client_with_auto_poll is deprecated. Create the ConfigCat Client as a Singleton object with `configcatclient.get()` instead')
|
89
|
-
client = ConfigCatClient.get(sdk_key, options)
|
90
|
-
client.hooks.add_on_config_changed(on_configuration_changed_callback) if on_configuration_changed_callback
|
91
|
-
return client
|
92
|
-
end
|
93
|
-
|
94
|
-
# Create an instance of ConfigCatClient and setup Lazy Load mode with custom options
|
95
|
-
#
|
96
|
-
# :param sdk_key: ConfigCat SDK Key to access your configuration.
|
97
|
-
# :param cache_time_to_live_seconds: The cache TTL.
|
98
|
-
# :param config_cache: If you want to use custom caching instead of the client's default,
|
99
|
-
# You can provide an implementation of ConfigCache.
|
100
|
-
# :param base_url: You can set a base_url if you want to use a proxy server between your application and ConfigCat
|
101
|
-
# :param proxy_address: Proxy address
|
102
|
-
# :param proxy_port: Proxy port
|
103
|
-
# :param proxy_user: username for proxy authentication
|
104
|
-
# :param proxy_pass: password for proxy authentication
|
105
|
-
# :param open_timeout_seconds: The number of seconds to wait for the server to make the initial connection. Default: 10 seconds.
|
106
|
-
# :param read_timeout_seconds: The number of seconds to wait for the server to respond before giving up. Default: 30 seconds.
|
107
|
-
# :param flag_overrides: A FlagOverrides implementation used to override feature flags & settings.
|
108
|
-
# :param data_governance:
|
109
|
-
# Default: Global. Set this parameter to be in sync with the Data Governance preference on the Dashboard:
|
110
|
-
# https://app.configcat.com/organization/data-governance
|
111
|
-
# (Only Organization Admins have access)
|
112
|
-
def ConfigCat.create_client_with_lazy_load(sdk_key,
|
113
|
-
cache_time_to_live_seconds: 60,
|
114
|
-
config_cache: nil,
|
115
|
-
base_url: nil,
|
116
|
-
proxy_address: nil,
|
117
|
-
proxy_port: nil,
|
118
|
-
proxy_user: nil,
|
119
|
-
proxy_pass: nil,
|
120
|
-
open_timeout_seconds: 10,
|
121
|
-
read_timeout_seconds: 30,
|
122
|
-
flag_overrides: nil,
|
123
|
-
data_governance: DataGovernance::GLOBAL)
|
124
|
-
options = ConfigCatOptions.new(
|
125
|
-
base_url: base_url,
|
126
|
-
polling_mode: PollingMode.lazy_load(cache_refresh_interval_seconds: cache_time_to_live_seconds),
|
127
|
-
config_cache: config_cache,
|
128
|
-
proxy_address: proxy_address,
|
129
|
-
proxy_port: proxy_port,
|
130
|
-
proxy_user: proxy_user,
|
131
|
-
proxy_pass: proxy_pass,
|
132
|
-
open_timeout_seconds: open_timeout_seconds,
|
133
|
-
read_timeout_seconds: read_timeout_seconds,
|
134
|
-
flag_overrides: flag_overrides,
|
135
|
-
data_governance: data_governance
|
136
|
-
)
|
137
|
-
ConfigCat.logger.warn('create_client_with_lazy_load is deprecated. Create the ConfigCat Client as a Singleton object with `configcatclient.get()` instead')
|
138
|
-
client = ConfigCatClient.get(sdk_key, options)
|
139
|
-
return client
|
140
|
-
end
|
141
|
-
|
142
|
-
# Create an instance of ConfigCatClient and setup Manual Poll mode with custom options
|
143
|
-
#
|
144
|
-
# :param sdk_key: ConfigCat SDK Key to access your configuration.
|
145
|
-
# :param config_cache: If you want to use custom caching instead of the client's default,
|
146
|
-
# You can provide an implementation of ConfigCache.
|
147
|
-
# :param base_url: You can set a base_url if you want to use a proxy server between your application and ConfigCat
|
148
|
-
# :param proxy_address: Proxy address
|
149
|
-
# :param proxy_port: Proxy port
|
150
|
-
# :param proxy_user: username for proxy authentication
|
151
|
-
# :param proxy_pass: password for proxy authentication
|
152
|
-
# :param open_timeout_seconds: The number of seconds to wait for the server to make the initial connection. Default: 10 seconds.
|
153
|
-
# :param read_timeout_seconds: The number of seconds to wait for the server to respond before giving up. Default: 30 seconds.
|
154
|
-
# :param flag_overrides: A FlagOverrides implementation used to override feature flags & settings.
|
155
|
-
# :param data_governance:
|
156
|
-
# Default: Global. Set this parameter to be in sync with the Data Governance preference on the Dashboard:
|
157
|
-
# https://app.configcat.com/organization/data-governance
|
158
|
-
# (Only Organization Admins have access)
|
159
|
-
def ConfigCat.create_client_with_manual_poll(sdk_key,
|
160
|
-
config_cache: nil,
|
161
|
-
base_url: nil,
|
162
|
-
proxy_address: nil,
|
163
|
-
proxy_port: nil,
|
164
|
-
proxy_user: nil,
|
165
|
-
proxy_pass: nil,
|
166
|
-
open_timeout_seconds: 10,
|
167
|
-
read_timeout_seconds: 30,
|
168
|
-
flag_overrides: nil,
|
169
|
-
data_governance: DataGovernance::GLOBAL)
|
170
|
-
options = ConfigCatOptions.new(
|
171
|
-
base_url: base_url,
|
172
|
-
polling_mode: PollingMode.manual_poll(),
|
173
|
-
config_cache: config_cache,
|
174
|
-
proxy_address: proxy_address,
|
175
|
-
proxy_port: proxy_port,
|
176
|
-
proxy_user: proxy_user,
|
177
|
-
proxy_pass: proxy_pass,
|
178
|
-
open_timeout_seconds: open_timeout_seconds,
|
179
|
-
read_timeout_seconds: read_timeout_seconds,
|
180
|
-
flag_overrides: flag_overrides,
|
181
|
-
data_governance: data_governance
|
182
|
-
)
|
183
|
-
ConfigCat.logger.warn('create_client_with_manual_poll is deprecated. Create the ConfigCat Client as a Singleton object with `configcatclient.get()` instead')
|
184
|
-
client = ConfigCatClient.get(sdk_key, options)
|
185
|
-
return client
|
186
|
-
end
|
187
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configcat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 7.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ConfigCat
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|