configdirector-openfeature-server-provider 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +39 -0
- data/LICENSE +21 -0
- data/README.md +143 -0
- data/lib/configdirector/openfeature/config_director_provider.rb +220 -0
- data/lib/configdirector/openfeature/internal/config_director_context.rb +53 -0
- data/lib/configdirector/openfeature/internal/date_text.rb +20 -0
- data/lib/configdirector/openfeature/internal/flag_reader.rb +41 -0
- data/lib/configdirector/openfeature/internal/resolution_details_by_reason.rb +61 -0
- data/lib/configdirector/openfeature/internal/startup.rb +54 -0
- data/lib/configdirector/openfeature/internal.rb +11 -0
- data/lib/configdirector/openfeature/version.rb +9 -0
- data/lib/configdirector/openfeature.rb +12 -0
- data/lib/configdirector-openfeature-server-provider.rb +3 -0
- data/sig/configdirector/openfeature/internal.rbs +90 -0
- data/sig/configdirector/openfeature.rbs +91 -0
- metadata +98 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 566334ea441b6ea778c24f958efc31a1f361af15fa4c4023fa97b05e7e19d1b2
|
|
4
|
+
data.tar.gz: 3ba12cdd7dc17e07b7eda8cf8ea167f93e2535080da4adb3fce8a5bf5d9ebe52
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: c66cd4e9ff0602e6450c49f7fd1c1f0ecc6aa7904f5a5c186b6afd419f4c0975f3db0898e83c92f598bcc051e680ed4862299565062b6f5e8bb94de296fac9e4
|
|
7
|
+
data.tar.gz: c76fa51242c169aea07038c7ebb97ab77dcc49961cad62756de689946ae9acf3e89f3ed683ed7deba7d80905e33bb58a22087840a54b69ee6981c9a4366bad63
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `configdirector-openfeature-server-provider` are recorded here.
|
|
4
|
+
|
|
5
|
+
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the gem uses
|
|
6
|
+
[semantic versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.1.0] - 2026-11-17
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- `ConfigDirector::OpenFeature::ConfigDirectorProvider.new(server_sdk_key, metadata:, connection:, logger:,
|
|
15
|
+
log_level:, telemetry:)`, required as `configdirector/openfeature`, an OpenFeature provider for
|
|
16
|
+
`openfeature-sdk` 0.8.1 or later below 0.9, built on `configdirector-server-sdk` 0.1.0 or later below 1. It takes
|
|
17
|
+
the options of `ConfigDirector.create_client` except `hooks`, raises what `create_client` raises, is named
|
|
18
|
+
`ConfigDirectorProvider` to OpenFeature, and names itself `ruby-openfeature-server-provider` with its own version
|
|
19
|
+
to ConfigDirector.
|
|
20
|
+
- The six typed reads of OpenFeature. A value served is a `TARGETING_MATCH` whose `variant` is the name of the
|
|
21
|
+
variation served, or else the ID of the value; a percentage rollout skipped for a context without an identifier
|
|
22
|
+
is a `DEFAULT` with the same `variant`; a config without a value is a `DEFAULT` without an error; a missing config
|
|
23
|
+
is `FLAG_NOT_FOUND`, a value that cannot be read as the requested type `TYPE_MISMATCH`, and a read before any config
|
|
24
|
+
arrives `PROVIDER_NOT_READY`. `fetch_number_value` reads any finite number, a whole number as an Integer and any
|
|
25
|
+
other as a Float, whatever the class of the in-code default value.
|
|
26
|
+
- The evaluation context becomes a ConfigDirector context: the targeting key, or else an `id` attribute, and the
|
|
27
|
+
`kind`, `name`, `traits` and `anonymous` attributes. An id or a name given as a Symbol, `true` or `false`, an
|
|
28
|
+
Integer, a Float or a date is read as text, any other is left out, and a date is written as UTC text, inside the
|
|
29
|
+
traits too.
|
|
30
|
+
- The provider reports its own `PROVIDER_READY` and `PROVIDER_ERROR` events. When no config arrives within the
|
|
31
|
+
connection timeout, or ConfigDirector refuses the server SDK key, `set_provider_and_wait` raises
|
|
32
|
+
`OpenFeature::SDK::ProviderInitializationError` with the error code `PROVIDER_NOT_READY` and the status is
|
|
33
|
+
`ERROR`, until config arrives and the provider reports `PROVIDER_READY`. Offline values that cannot be loaded fail
|
|
34
|
+
initialization with `GENERAL`.
|
|
35
|
+
- `PROVIDER_CONFIGURATION_CHANGED` each time configs are updated, with the keys the update carried followed by the
|
|
36
|
+
keys it removed.
|
|
37
|
+
- `track` reports the event's value, its other fields as details and its evaluation context to ConfigDirector, and
|
|
38
|
+
logs a warning instead of raising for an event it cannot pass on.
|
|
39
|
+
- `shutdown` closes the ConfigDirector client, which sends the telemetry it holds.
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ConfigDirector
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is furnished
|
|
10
|
+
to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# ConfigDirector OpenFeature Ruby Server Provider
|
|
2
|
+
|
|
3
|
+
[![CI][ci-badge]][ci] [![Gem Version][gem-badge]][gem]
|
|
4
|
+
|
|
5
|
+
[OpenFeature](https://openfeature.dev) Ruby server provider for [ConfigDirector](https://www.configdirector.com), remote config and feature flags with JSON Schema validation and safe renames of live flags. It is built on the [ConfigDirector Ruby server SDK](https://github.com/ConfigDirector/ruby-sdks/tree/main/configdirector-server-sdk).
|
|
6
|
+
|
|
7
|
+
The provider requires Ruby 3.4 or later.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
bundle add configdirector-openfeature-server-provider
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The OpenFeature Ruby SDK (`openfeature-sdk`) and the ConfigDirector Ruby server SDK come with it as dependencies.
|
|
16
|
+
|
|
17
|
+
## Retrieve a value
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
require "configdirector/openfeature"
|
|
21
|
+
|
|
22
|
+
# The server SDK key is a secret. Do not commit it to your source code.
|
|
23
|
+
OpenFeature::SDK.set_provider_and_wait(
|
|
24
|
+
ConfigDirector::OpenFeature::ConfigDirectorProvider.new(ENV.fetch("CONFIGDIRECTOR_SERVER_KEY"))
|
|
25
|
+
)
|
|
26
|
+
client = OpenFeature::SDK.build_client
|
|
27
|
+
|
|
28
|
+
new_checkout = client.fetch_boolean_value(flag_key: "new-checkout", default_value: false)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
`set_provider_and_wait` waits up to the connection timeout, 3 seconds by default, for config to arrive. If none arrives in time, or ConfigDirector rejects the server SDK key, it raises `OpenFeature::SDK::ProviderInitializationError` with the error code `PROVIDER_NOT_READY`, and OpenFeature reports the `ERROR` status. Reads then return their in-code default values with `PROVIDER_NOT_READY`. After a timeout the provider keeps connecting, and OpenFeature reports `READY` once config arrives.
|
|
32
|
+
|
|
33
|
+
To start without waiting for ConfigDirector, call `OpenFeature::SDK.set_provider` instead, which initializes the provider in the background, or rescue the error:
|
|
34
|
+
|
|
35
|
+
```ruby
|
|
36
|
+
begin
|
|
37
|
+
OpenFeature::SDK.set_provider_and_wait(
|
|
38
|
+
ConfigDirector::OpenFeature::ConfigDirectorProvider.new(ENV.fetch("CONFIGDIRECTOR_SERVER_KEY"))
|
|
39
|
+
)
|
|
40
|
+
rescue OpenFeature::SDK::ProviderInitializationError => e
|
|
41
|
+
Rails.logger.warn("Starting on in-code default values until ConfigDirector sends config: #{e.message}")
|
|
42
|
+
end
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The provider takes the same `metadata`, `connection`, `logger`, `log_level` and `telemetry` options as the server SDK's `ConfigDirector.create_client`.
|
|
46
|
+
|
|
47
|
+
A provider that was registered before the process forked, as in a Puma worker, keeps working in the forked process: its client restarts by itself there, as the [server SDK's README](https://github.com/ConfigDirector/ruby-sdks/tree/main/configdirector-server-sdk#servers-that-fork) describes.
|
|
48
|
+
|
|
49
|
+
## Evaluation context
|
|
50
|
+
|
|
51
|
+
The OpenFeature evaluation context maps onto the ConfigDirector context used by targeting rules:
|
|
52
|
+
|
|
53
|
+
| OpenFeature | ConfigDirector |
|
|
54
|
+
|---|---|
|
|
55
|
+
| `targeting_key`, or failing that an `id` attribute | `id` |
|
|
56
|
+
| `kind` attribute | `kind` |
|
|
57
|
+
| `name` attribute | `name` |
|
|
58
|
+
| `traits` attribute, a Hash | `traits` |
|
|
59
|
+
| `anonymous` attribute, `true` | `anonymous` |
|
|
60
|
+
|
|
61
|
+
```ruby
|
|
62
|
+
context = OpenFeature::SDK::EvaluationContext.new(targeting_key: "user-123", name: "Ada", traits: { "plan" => "pro" })
|
|
63
|
+
new_checkout = client.fetch_boolean_value(flag_key: "new-checkout", default_value: false, evaluation_context: context)
|
|
64
|
+
|
|
65
|
+
device = OpenFeature::SDK::EvaluationContext.new(targeting_key: "kiosk-7", kind: "device")
|
|
66
|
+
new_checkout = client.fetch_boolean_value(flag_key: "new-checkout", default_value: false, evaluation_context: device)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
An id or a name given as a Symbol, `true` or `false`, an Integer, a Float or a date is read as text, and any other id or name is left out. A date, given as a `Time`, a `DateTime` or a `Date`, is written as UTC text such as `2026-11-17T10:00:00.000Z`, or as `2026-11-17` for a `Date`, inside the traits too, so date conditions can compare it.
|
|
70
|
+
|
|
71
|
+
Without a `kind` attribute the context is a `user`, and a `kind` inside `traits` is an ordinary trait. A kind has 1 to 64 characters, using only lowercase letters, digits, `-` and `_`. When the kind is invalid, including any kind that is not text, the whole context is ignored: the read still resolves, to the value for no context, and the SDK logs an error.
|
|
72
|
+
|
|
73
|
+
A context with neither a targeting key nor an `id` attribute skips percentage rollouts: the targeting rules after the rollout are tried, and the flag resolves to the default targeting rule value when none applies. Give an anonymous context a stable targeting key, such as a session ID, to keep it in a rollout.
|
|
74
|
+
|
|
75
|
+
## Evaluation details
|
|
76
|
+
|
|
77
|
+
| Outcome | `reason` | `error_code` |
|
|
78
|
+
|---|---|---|
|
|
79
|
+
| A value was served | `TARGETING_MATCH`, with the variation's name as the `variant` when it has one, otherwise the value's ID | |
|
|
80
|
+
| A percentage rollout was skipped because the context has no targeting key or `id` | `DEFAULT`, with the `variant` of the default targeting rule value | |
|
|
81
|
+
| The config has no value | `DEFAULT` | |
|
|
82
|
+
| No config has that key | `ERROR` | `FLAG_NOT_FOUND` |
|
|
83
|
+
| The value cannot be read as the requested type | `ERROR` | `TYPE_MISMATCH` |
|
|
84
|
+
| No config has arrived yet | `ERROR` | `PROVIDER_NOT_READY` |
|
|
85
|
+
|
|
86
|
+
`fetch_number_value` reads any finite number, whatever the class of the in-code default value: a whole number comes back as an Integer and any other number as a Float. `fetch_integer_value` reads whole numbers only, and `fetch_float_value` returns a Float.
|
|
87
|
+
|
|
88
|
+
The provider emits `PROVIDER_READY` once config has arrived, and `PROVIDER_CONFIGURATION_CHANGED` each time configs are updated, with the keys the update carried followed by the keys a full update removed.
|
|
89
|
+
|
|
90
|
+
## Tracking
|
|
91
|
+
|
|
92
|
+
`client.track` reports to ConfigDirector that something happened, such as a completed checkout, with the next telemetry batch: the details' `value` as the event's value, their other fields as the event's details, and the evaluation context as the context the event happened for. An event counts for an experiment only when its evaluation context has the targeting key the experiment's flag was evaluated with.
|
|
93
|
+
|
|
94
|
+
```ruby
|
|
95
|
+
client.track(
|
|
96
|
+
"checkout-completed",
|
|
97
|
+
evaluation_context: OpenFeature::SDK::EvaluationContext.new(targeting_key: "user-123"),
|
|
98
|
+
tracking_event_details: OpenFeature::SDK::TrackingEventDetails.new(value: 49.9, plan: "pro")
|
|
99
|
+
)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
`track` never raises. An event the provider cannot pass on, for example because its evaluation context cannot be read, is logged as a warning and not reported. It does nothing in offline mode.
|
|
103
|
+
|
|
104
|
+
## Test your code
|
|
105
|
+
|
|
106
|
+
Tests of code that reads flags through OpenFeature swap the provider for the in-memory one the OpenFeature Ruby SDK ships, `OpenFeature::SDK::Provider::InMemoryProvider`, so the test controls the values and nothing from ConfigDirector is involved:
|
|
107
|
+
|
|
108
|
+
```ruby
|
|
109
|
+
provider = OpenFeature::SDK::Provider::InMemoryProvider.new("new-checkout" => true)
|
|
110
|
+
OpenFeature::SDK.set_provider_and_wait(provider)
|
|
111
|
+
client = OpenFeature::SDK.build_client
|
|
112
|
+
|
|
113
|
+
expect(client.fetch_boolean_value(flag_key: "new-checkout", default_value: false)).to be(true)
|
|
114
|
+
|
|
115
|
+
provider.add_flag(flag_key: "new-checkout", value: false)
|
|
116
|
+
expect(client.fetch_boolean_value(flag_key: "new-checkout", default_value: true)).to be(false)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Shut OpenFeature down after each test with `OpenFeature::SDK.shutdown`.
|
|
120
|
+
|
|
121
|
+
## What the provider leaves out
|
|
122
|
+
|
|
123
|
+
- **The `STALE` and `FATAL` statuses.** A provider whose connection drops stays `READY` and serves the values it has, and a rejected server SDK key is reported as `ERROR`. Every ConfigDirector OpenFeature provider behaves this way today.
|
|
124
|
+
- **Flag metadata.** Evaluation details carry none, because a ConfigDirector evaluation has nothing to add beyond the reason and the variant.
|
|
125
|
+
- **The `hooks` option of `ConfigDirector.create_client`.** The provider handles its client's events itself; an application listens to OpenFeature's events instead. The provider adds no OpenFeature hooks of its own either.
|
|
126
|
+
- **Watches, reading every config at once and the `config_evaluated` event of the server SDK.** OpenFeature has no API for them; an application that needs them uses the [server SDK](https://github.com/ConfigDirector/ruby-sdks/tree/main/configdirector-server-sdk) directly.
|
|
127
|
+
|
|
128
|
+
## Documentation
|
|
129
|
+
|
|
130
|
+
Refer to the [official documentation for the OpenFeature Ruby provider](https://docs.configdirector.com/sdks/openfeature/ruby).
|
|
131
|
+
|
|
132
|
+
There is also [a quickstart guide for ConfigDirector and any of our SDKs](https://docs.configdirector.com/getting-started/quickstart).
|
|
133
|
+
|
|
134
|
+
## Getting Help
|
|
135
|
+
|
|
136
|
+
- [Ask a question in Discussions](https://github.com/orgs/ConfigDirector/discussions)
|
|
137
|
+
- [Contact support](https://www.configdirector.com/support)
|
|
138
|
+
|
|
139
|
+
[//]: # "links"
|
|
140
|
+
[ci-badge]: https://github.com/ConfigDirector/ruby-sdks/actions/workflows/ci.yml/badge.svg
|
|
141
|
+
[ci]: https://github.com/ConfigDirector/ruby-sdks/actions/workflows/ci.yml
|
|
142
|
+
[gem-badge]: https://img.shields.io/gem/v/configdirector-openfeature-server-provider
|
|
143
|
+
[gem]: https://rubygems.org/gems/configdirector-openfeature-server-provider
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ConfigDirector
|
|
4
|
+
module OpenFeature
|
|
5
|
+
# An OpenFeature provider backed by the ConfigDirector Ruby server SDK. Register it with OpenFeature and read
|
|
6
|
+
# values through an OpenFeature client. The provider owns a ConfigDirector client: it connects when OpenFeature
|
|
7
|
+
# initializes the provider and closes when OpenFeature shuts it down. Targeting rules are evaluated in your
|
|
8
|
+
# process, so a read makes no network call.
|
|
9
|
+
#
|
|
10
|
+
# @example
|
|
11
|
+
# require "configdirector/openfeature"
|
|
12
|
+
#
|
|
13
|
+
# OpenFeature::SDK.set_provider_and_wait(
|
|
14
|
+
# ConfigDirector::OpenFeature::ConfigDirectorProvider.new(ENV.fetch("CONFIGDIRECTOR_SERVER_KEY"))
|
|
15
|
+
# )
|
|
16
|
+
#
|
|
17
|
+
# client = OpenFeature::SDK.build_client
|
|
18
|
+
# client.fetch_boolean_value(flag_key: "new-checkout", default_value: false)
|
|
19
|
+
#
|
|
20
|
+
# The OpenFeature evaluation context becomes a ConfigDirector context. The targeting key, or else an +id+
|
|
21
|
+
# attribute, becomes its id, and the +kind+, +name+, +traits+ and +anonymous+ attributes its kind, name, traits
|
|
22
|
+
# and anonymous flag. An id or a name given as a Symbol, +true+ or +false+, an Integer, a Float or a date is read
|
|
23
|
+
# as text, and any other id or name is left out. A date, given as a Time, a DateTime or a Date, is read as UTC
|
|
24
|
+
# text such as +"2026-11-17T10:00:00.000Z"+, or as +"2026-11-17"+ for a Date, inside the traits too, so date
|
|
25
|
+
# conditions can compare it. Traits other than a Hash with at least one entry are left out, a +kind+ inside the
|
|
26
|
+
# traits is an ordinary trait, and the context is anonymous only when +anonymous+ is +true+. Without a +kind+
|
|
27
|
+
# attribute the context is a user. When the kind is invalid, including a kind that is not text, the whole
|
|
28
|
+
# context is ignored: the read still resolves, to the value for no context, and the SDK logs an error. A
|
|
29
|
+
# context with neither a targeting key nor an +id+ attribute skips percentage rollouts: the flag resolves to
|
|
30
|
+
# the default targeting rule value, with the reason +DEFAULT+.
|
|
31
|
+
#
|
|
32
|
+
# The details of a read carry the name of the variation served as their +variant+, or the ID of the value
|
|
33
|
+
# served when it has no named variation.
|
|
34
|
+
#
|
|
35
|
+
# If no config arrives within the connection timeout, or ConfigDirector refuses the server SDK key,
|
|
36
|
+
# initialization fails: +set_provider_and_wait+ raises +OpenFeature::SDK::ProviderInitializationError+ with
|
|
37
|
+
# the error code +PROVIDER_NOT_READY+, the provider reports the +ERROR+ status, and reads return their in-code
|
|
38
|
+
# default value with +PROVIDER_NOT_READY+. The provider keeps connecting, and reports +READY+ once config
|
|
39
|
+
# arrives. To start without waiting for ConfigDirector, register the provider with +set_provider+, which
|
|
40
|
+
# initializes it in the background, or rescue the error.
|
|
41
|
+
#
|
|
42
|
+
# In offline mode, with <tt>connection: ConfigDirector::ConnectionOptions.new(mode: "offline", ...)</tt>, the
|
|
43
|
+
# provider never connects to ConfigDirector and needs no server SDK key. It serves the values of a JSON file or
|
|
44
|
+
# of a Hash to every read, as {ConfigDirector::ConnectionOptions} describes.
|
|
45
|
+
class ConfigDirectorProvider
|
|
46
|
+
include ::OpenFeature::SDK::Provider::EventEmitter
|
|
47
|
+
|
|
48
|
+
ProviderEvent = ::OpenFeature::SDK::ProviderEvent
|
|
49
|
+
ErrorCode = ::OpenFeature::SDK::Provider::ErrorCode
|
|
50
|
+
NO_CONFIG_IN_TIME = "No config arrived from ConfigDirector within the connection timeout. " \
|
|
51
|
+
"Flags resolve to their in-code default values until config arrives."
|
|
52
|
+
|
|
53
|
+
private_constant :ProviderEvent, :ErrorCode, :NO_CONFIG_IN_TIME
|
|
54
|
+
|
|
55
|
+
# @return [OpenFeature::SDK::Provider::ProviderMetadata] the name the provider is registered under with
|
|
56
|
+
# OpenFeature, +ConfigDirectorProvider+
|
|
57
|
+
attr_reader :metadata
|
|
58
|
+
|
|
59
|
+
# Creates a provider and its ConfigDirector client, which makes no network call until OpenFeature
|
|
60
|
+
# initializes the provider.
|
|
61
|
+
#
|
|
62
|
+
# @param server_sdk_key [String, nil] the ConfigDirector server SDK key. This is a secret value, do not
|
|
63
|
+
# commit it in your source code. It can be left out in offline mode only.
|
|
64
|
+
# @param metadata [ConfigDirector::Metadata, nil] metadata about your application. Including +app_name+ and
|
|
65
|
+
# +app_version+ is recommended, so that you can use them in targeting rules.
|
|
66
|
+
# @param connection [ConfigDirector::ConnectionOptions, nil] how the client connects to ConfigDirector
|
|
67
|
+
# @param logger [#debug, #info, #warn, #error, nil] a logger with the methods of Ruby's +Logger+, such as
|
|
68
|
+
# +Rails.logger+. Without a logger the provider writes warnings and errors to standard error.
|
|
69
|
+
# @param log_level [Integer, Symbol, String, nil] the lowest level written when no +logger+ is given, as
|
|
70
|
+
# Ruby's +Logger+ takes it, such as +:debug+ or +Logger::INFO+. Defaults to +:warn+. It has no effect when
|
|
71
|
+
# a +logger+ is given.
|
|
72
|
+
# @param telemetry [ConfigDirector::TelemetryOptions, nil] telemetry tuning
|
|
73
|
+
# @raise [ConfigDirector::ConfigDirectorValidationError] for the options that
|
|
74
|
+
# {ConfigDirector.create_client} rejects, such as a missing server SDK key outside offline mode
|
|
75
|
+
def initialize(
|
|
76
|
+
server_sdk_key = nil, metadata: nil, connection: nil, logger: nil, log_level: nil, telemetry: nil
|
|
77
|
+
)
|
|
78
|
+
@metadata = ::OpenFeature::SDK::Provider::ProviderMetadata.new(name: "ConfigDirectorProvider").freeze
|
|
79
|
+
@logger = logger || ConfigDirector::Internal::Logging::DefaultLogger.writing_from(log_level)
|
|
80
|
+
@client = ConfigDirector::Internal::Identity::Wrapper::OPENFEATURE_SERVER_PROVIDER.create_client(
|
|
81
|
+
server_sdk_key, metadata: metadata, connection: connection, logger: @logger, telemetry: telemetry
|
|
82
|
+
)
|
|
83
|
+
@startup = Internal::Startup.new(@client)
|
|
84
|
+
@flag_reader = Internal::FlagReader.new(@client)
|
|
85
|
+
@client.on(:configs_updated) { |update| report_the_configs_changed_by(update) }
|
|
86
|
+
@client.on(:client_ready) { send_the_report(@startup.report_due_when_config_arrives) }
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Tells OpenFeature that the provider reports its own +PROVIDER_READY+ and +PROVIDER_ERROR+ events.
|
|
90
|
+
#
|
|
91
|
+
# @return [true]
|
|
92
|
+
def emits_lifecycle_events?
|
|
93
|
+
true
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Connects to ConfigDirector and waits up to the connection timeout for config, or loads the offline values
|
|
97
|
+
# in offline mode. OpenFeature calls it when the provider is registered.
|
|
98
|
+
#
|
|
99
|
+
# @return [void]
|
|
100
|
+
# @raise [OpenFeature::SDK::EvaluationError] with the error code +PROVIDER_NOT_READY+, when no config arrives
|
|
101
|
+
# within the connection timeout or ConfigDirector refuses the server SDK key
|
|
102
|
+
# @raise [ConfigDirector::ConfigDirectorInitializationError] in offline mode, when the offline values cannot
|
|
103
|
+
# be loaded
|
|
104
|
+
def init
|
|
105
|
+
@startup.begin_initialization
|
|
106
|
+
initialize_the_client
|
|
107
|
+
send_the_report(@startup.report_due_after_initialization)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Closes the connection to ConfigDirector and sends the telemetry the client holds. OpenFeature calls it
|
|
111
|
+
# when it shuts down or replaces the provider.
|
|
112
|
+
#
|
|
113
|
+
# @return [void]
|
|
114
|
+
def shutdown
|
|
115
|
+
@client.close
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# Reports to ConfigDirector that something happened, such as a completed checkout, with the next telemetry
|
|
119
|
+
# batch: the details' +value+ as the event's value, their other fields as the event's details, and the
|
|
120
|
+
# evaluation context as the context the event happened for. An event counts for an experiment only when its
|
|
121
|
+
# evaluation context has the targeting key the experiment's flag was evaluated with. It never raises: an
|
|
122
|
+
# event it cannot pass on, for example because the evaluation context cannot be read, is logged as a
|
|
123
|
+
# warning and not reported. It does nothing in offline mode.
|
|
124
|
+
#
|
|
125
|
+
# @param tracking_event_name [String] the event's name, 1 to 150 characters
|
|
126
|
+
# @param evaluation_context [OpenFeature::SDK::EvaluationContext, nil] the context the event happened for
|
|
127
|
+
# @param tracking_event_details [OpenFeature::SDK::TrackingEventDetails, nil] the event's value and details
|
|
128
|
+
# @return [void]
|
|
129
|
+
def track(tracking_event_name, evaluation_context: nil, tracking_event_details: nil)
|
|
130
|
+
@client.track(
|
|
131
|
+
tracking_event_name, Internal::ConfigDirectorContext.of(evaluation_context),
|
|
132
|
+
value: value_of(tracking_event_details), details: details_of(tracking_event_details)
|
|
133
|
+
)
|
|
134
|
+
rescue StandardError => e
|
|
135
|
+
@logger.warn("A tracked event was not reported because it could not be read: #{e.message}")
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# Evaluates a flag as a boolean.
|
|
139
|
+
#
|
|
140
|
+
# @return [OpenFeature::SDK::Provider::ResolutionDetails]
|
|
141
|
+
def fetch_boolean_value(flag_key:, default_value:, evaluation_context: nil)
|
|
142
|
+
@flag_reader.read(flag_key, default_value, evaluation_context)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Evaluates a flag as a String.
|
|
146
|
+
#
|
|
147
|
+
# @return [OpenFeature::SDK::Provider::ResolutionDetails]
|
|
148
|
+
def fetch_string_value(flag_key:, default_value:, evaluation_context: nil)
|
|
149
|
+
@flag_reader.read(flag_key, default_value, evaluation_context)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# Evaluates a flag as any finite number, whatever the class of the in-code default value: a whole number is
|
|
153
|
+
# returned as an Integer and any other number as a Float. When the flag cannot be read as a number, the
|
|
154
|
+
# in-code default value is returned as given.
|
|
155
|
+
#
|
|
156
|
+
# @return [OpenFeature::SDK::Provider::ResolutionDetails]
|
|
157
|
+
def fetch_number_value(flag_key:, default_value:, evaluation_context: nil)
|
|
158
|
+
@flag_reader.read_a_number(flag_key, default_value, evaluation_context)
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
# Evaluates a flag as a whole number, returned as an Integer.
|
|
162
|
+
#
|
|
163
|
+
# @return [OpenFeature::SDK::Provider::ResolutionDetails]
|
|
164
|
+
def fetch_integer_value(flag_key:, default_value:, evaluation_context: nil)
|
|
165
|
+
@flag_reader.read(flag_key, default_value, evaluation_context)
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
# Evaluates a flag as any finite number, returned as a Float.
|
|
169
|
+
#
|
|
170
|
+
# @return [OpenFeature::SDK::Provider::ResolutionDetails]
|
|
171
|
+
def fetch_float_value(flag_key:, default_value:, evaluation_context: nil)
|
|
172
|
+
@flag_reader.read(flag_key, default_value, evaluation_context)
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
# Evaluates a flag as a JSON object, returned as a Hash, when the in-code default value is a Hash, or as a
|
|
176
|
+
# JSON array, returned as an Array, when it is an Array.
|
|
177
|
+
#
|
|
178
|
+
# @return [OpenFeature::SDK::Provider::ResolutionDetails]
|
|
179
|
+
def fetch_object_value(flag_key:, default_value:, evaluation_context: nil)
|
|
180
|
+
@flag_reader.read(flag_key, default_value, evaluation_context)
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
private
|
|
184
|
+
|
|
185
|
+
def initialize_the_client
|
|
186
|
+
@client.init
|
|
187
|
+
rescue StandardError => e
|
|
188
|
+
emit_event(ProviderEvent::PROVIDER_ERROR, error_code: ErrorCode::GENERAL, message: e.message)
|
|
189
|
+
raise
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def send_the_report(report)
|
|
193
|
+
case report
|
|
194
|
+
when :report_ready then emit_event(ProviderEvent::PROVIDER_READY)
|
|
195
|
+
when :report_the_failure then report_no_config_in_time
|
|
196
|
+
when :nothing then nil
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def report_no_config_in_time
|
|
201
|
+
emit_event(ProviderEvent::PROVIDER_ERROR, error_code: ErrorCode::PROVIDER_NOT_READY, message: NO_CONFIG_IN_TIME)
|
|
202
|
+
send_the_report(@startup.report_due_after_the_failure)
|
|
203
|
+
raise ::OpenFeature::SDK::EvaluationError.new(NO_CONFIG_IN_TIME, error_code: ErrorCode::PROVIDER_NOT_READY)
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def report_the_configs_changed_by(update)
|
|
207
|
+
emit_event(ProviderEvent::PROVIDER_CONFIGURATION_CHANGED, flags_changed: [*update.keys, *update.removed_keys])
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
def value_of(tracking_event_details)
|
|
211
|
+
tracking_event_details&.value
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
def details_of(tracking_event_details)
|
|
215
|
+
attributes = tracking_event_details&.fields
|
|
216
|
+
attributes.nil? || attributes.empty? ? nil : attributes
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ConfigDirector
|
|
4
|
+
module OpenFeature
|
|
5
|
+
module Internal
|
|
6
|
+
module ConfigDirectorContext
|
|
7
|
+
MOST_LEVELS_OF_TRAITS = 100
|
|
8
|
+
|
|
9
|
+
private_constant :MOST_LEVELS_OF_TRAITS
|
|
10
|
+
|
|
11
|
+
def self.of(evaluation_context)
|
|
12
|
+
return nil if evaluation_context.nil?
|
|
13
|
+
|
|
14
|
+
fields = evaluation_context.fields
|
|
15
|
+
ConfigDirector::Context.new(
|
|
16
|
+
id: text_of(evaluation_context.targeting_key.nil? ? fields["id"] : evaluation_context.targeting_key),
|
|
17
|
+
kind: fields["kind"], name: text_of(fields["name"]), traits: traits_of(fields["traits"]),
|
|
18
|
+
anonymous: fields["anonymous"] == true
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.text_of(value)
|
|
23
|
+
case value
|
|
24
|
+
when String then value
|
|
25
|
+
when Symbol then value.name
|
|
26
|
+
when true, false, Integer, Float then value.to_s
|
|
27
|
+
else DateText.of(value)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.traits_of(traits)
|
|
32
|
+
return nil unless traits.is_a?(Hash) && !traits.empty?
|
|
33
|
+
|
|
34
|
+
with_dates_as_text(traits, 1)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.with_dates_as_text(trait, level)
|
|
38
|
+
date_text = DateText.of(trait)
|
|
39
|
+
return date_text unless date_text.nil?
|
|
40
|
+
return trait if level > MOST_LEVELS_OF_TRAITS
|
|
41
|
+
|
|
42
|
+
case trait
|
|
43
|
+
when Hash then trait.transform_values { |member| with_dates_as_text(member, level + 1) }
|
|
44
|
+
when Array then trait.map { |element| with_dates_as_text(element, level + 1) }
|
|
45
|
+
else trait
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private_class_method :text_of, :traits_of, :with_dates_as_text
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "date"
|
|
4
|
+
|
|
5
|
+
module ConfigDirector
|
|
6
|
+
module OpenFeature
|
|
7
|
+
module Internal
|
|
8
|
+
module DateText
|
|
9
|
+
def self.of(value)
|
|
10
|
+
return ConfigDirector::Internal::Telemetry::ReportedTime.of(value) if value.is_a?(Time)
|
|
11
|
+
|
|
12
|
+
case value
|
|
13
|
+
when DateTime then ConfigDirector::Internal::Telemetry::ReportedTime.of(value.to_time)
|
|
14
|
+
when Date then value.iso8601
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ConfigDirector
|
|
4
|
+
module OpenFeature
|
|
5
|
+
module Internal
|
|
6
|
+
class FlagReader
|
|
7
|
+
def initialize(client)
|
|
8
|
+
@client = client
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def read(flag_key, default_value, evaluation_context)
|
|
12
|
+
ResolutionDetailsByReason.of_the_evaluation(
|
|
13
|
+
@client.evaluate(flag_key, default_value, ConfigDirectorContext.of(evaluation_context))
|
|
14
|
+
)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def read_a_number(flag_key, default_value, evaluation_context)
|
|
18
|
+
evaluation = @client.evaluate(
|
|
19
|
+
flag_key, float_of(default_value), ConfigDirectorContext.of(evaluation_context)
|
|
20
|
+
)
|
|
21
|
+
ResolutionDetailsByReason.of_the_evaluation(
|
|
22
|
+
evaluation.with(value: number_served_by(evaluation, default_value))
|
|
23
|
+
)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def float_of(number)
|
|
29
|
+
number.to_f
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def number_served_by(evaluation, default_value)
|
|
33
|
+
return default_value if evaluation.default_value?
|
|
34
|
+
|
|
35
|
+
served_number = evaluation.value
|
|
36
|
+
served_number.to_i == served_number ? served_number.to_i : served_number
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ConfigDirector
|
|
4
|
+
module OpenFeature
|
|
5
|
+
module Internal
|
|
6
|
+
module ResolutionDetailsByReason
|
|
7
|
+
Reason = ::OpenFeature::SDK::Provider::Reason
|
|
8
|
+
ErrorCode = ::OpenFeature::SDK::Provider::ErrorCode
|
|
9
|
+
|
|
10
|
+
RESOLUTION_DETAILS_BY_REASON = {
|
|
11
|
+
"found-match" => ->(evaluation) { served_value_resolution(evaluation, Reason::TARGETING_MATCH) },
|
|
12
|
+
"rollout-skipped-no-identifier" => ->(evaluation) { served_value_resolution(evaluation, Reason::DEFAULT) },
|
|
13
|
+
"value-missing" => lambda { |evaluation|
|
|
14
|
+
::OpenFeature::SDK::Provider::ResolutionDetails.new(value: evaluation.value, reason: Reason::DEFAULT)
|
|
15
|
+
},
|
|
16
|
+
"config-state-missing" => lambda { |evaluation|
|
|
17
|
+
failed_resolution(
|
|
18
|
+
evaluation, ErrorCode::FLAG_NOT_FOUND, "No config with the key '#{evaluation.key}' was found."
|
|
19
|
+
)
|
|
20
|
+
},
|
|
21
|
+
"client-not-ready" => lambda { |evaluation|
|
|
22
|
+
failed_resolution(
|
|
23
|
+
evaluation, ErrorCode::PROVIDER_NOT_READY, "ConfigDirector has not delivered config state yet."
|
|
24
|
+
)
|
|
25
|
+
},
|
|
26
|
+
"type-mismatch" => ->(evaluation) { type_mismatch_resolution(evaluation) },
|
|
27
|
+
"invalid-number" => ->(evaluation) { type_mismatch_resolution(evaluation) },
|
|
28
|
+
"invalid-json" => ->(evaluation) { type_mismatch_resolution(evaluation) },
|
|
29
|
+
"invalid-boolean" => ->(evaluation) { type_mismatch_resolution(evaluation) }
|
|
30
|
+
}.freeze
|
|
31
|
+
|
|
32
|
+
private_constant :Reason, :ErrorCode, :RESOLUTION_DETAILS_BY_REASON
|
|
33
|
+
|
|
34
|
+
def self.of_the_evaluation(evaluation)
|
|
35
|
+
RESOLUTION_DETAILS_BY_REASON.fetch(evaluation.reason).call(evaluation)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.served_value_resolution(evaluation, reason)
|
|
39
|
+
::OpenFeature::SDK::Provider::ResolutionDetails.new(
|
|
40
|
+
value: evaluation.value, reason: reason, variant: evaluation.variation&.name || evaluation.value_id
|
|
41
|
+
)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def self.type_mismatch_resolution(evaluation)
|
|
45
|
+
failed_resolution(
|
|
46
|
+
evaluation, ErrorCode::TYPE_MISMATCH,
|
|
47
|
+
"The value of '#{evaluation.key}' cannot be read as the requested type (#{evaluation.reason})."
|
|
48
|
+
)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def self.failed_resolution(evaluation, error_code, error_message)
|
|
52
|
+
::OpenFeature::SDK::Provider::ResolutionDetails.new(
|
|
53
|
+
value: evaluation.value, reason: Reason::ERROR, error_code: error_code, error_message: error_message
|
|
54
|
+
)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private_class_method :served_value_resolution, :type_mismatch_resolution, :failed_resolution
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ConfigDirector
|
|
4
|
+
module OpenFeature
|
|
5
|
+
module Internal
|
|
6
|
+
class Startup
|
|
7
|
+
def initialize(client)
|
|
8
|
+
@client = client
|
|
9
|
+
@lock = Mutex.new
|
|
10
|
+
@stage = :initializing
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def begin_initialization
|
|
14
|
+
@lock.synchronize { @stage = :initializing }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def report_due_after_initialization
|
|
18
|
+
@lock.synchronize do
|
|
19
|
+
if @client.ready?
|
|
20
|
+
@stage = :ready
|
|
21
|
+
:report_ready
|
|
22
|
+
else
|
|
23
|
+
@stage = :reporting_the_failure
|
|
24
|
+
:report_the_failure
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def report_due_after_the_failure
|
|
30
|
+
@lock.synchronize do
|
|
31
|
+
if @client.ready?
|
|
32
|
+
@stage = :ready
|
|
33
|
+
:report_ready
|
|
34
|
+
else
|
|
35
|
+
@stage = :awaiting_config
|
|
36
|
+
:nothing
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def report_due_when_config_arrives
|
|
42
|
+
@lock.synchronize do
|
|
43
|
+
case @stage
|
|
44
|
+
when :awaiting_config
|
|
45
|
+
@stage = :ready
|
|
46
|
+
:report_ready
|
|
47
|
+
when :initializing, :reporting_the_failure, :ready then :nothing
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "configdirector"
|
|
4
|
+
require "open_feature/sdk"
|
|
5
|
+
require_relative "openfeature/version"
|
|
6
|
+
require_relative "openfeature/internal"
|
|
7
|
+
require_relative "openfeature/internal/date_text"
|
|
8
|
+
require_relative "openfeature/internal/config_director_context"
|
|
9
|
+
require_relative "openfeature/internal/resolution_details_by_reason"
|
|
10
|
+
require_relative "openfeature/internal/startup"
|
|
11
|
+
require_relative "openfeature/internal/flag_reader"
|
|
12
|
+
require_relative "openfeature/config_director_provider"
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
module ConfigDirector
|
|
2
|
+
module OpenFeature
|
|
3
|
+
module Internal
|
|
4
|
+
module ConfigDirectorContext
|
|
5
|
+
MOST_LEVELS_OF_TRAITS: Integer
|
|
6
|
+
|
|
7
|
+
def self.of: (::OpenFeature::SDK::EvaluationContext? evaluation_context) -> Context?
|
|
8
|
+
|
|
9
|
+
private
|
|
10
|
+
|
|
11
|
+
def self.text_of: (untyped value) -> String?
|
|
12
|
+
|
|
13
|
+
def self.traits_of: (untyped traits) -> Hash[untyped, untyped]?
|
|
14
|
+
|
|
15
|
+
def self.with_dates_as_text: (untyped trait, Integer level) -> untyped
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
module DateText
|
|
19
|
+
def self.of: (untyped value) -> String?
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
module ResolutionDetailsByReason
|
|
23
|
+
Reason: singleton(::OpenFeature::SDK::Provider::Reason)
|
|
24
|
+
ErrorCode: singleton(::OpenFeature::SDK::Provider::ErrorCode)
|
|
25
|
+
RESOLUTION_DETAILS_BY_REASON: Hash[String, ^(ConfigEvaluation[config_value]) -> ::OpenFeature::SDK::Provider::ResolutionDetails]
|
|
26
|
+
|
|
27
|
+
def self.of_the_evaluation: (ConfigEvaluation[config_value] evaluation) -> ::OpenFeature::SDK::Provider::ResolutionDetails
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def self.served_value_resolution: (
|
|
32
|
+
ConfigEvaluation[config_value] evaluation,
|
|
33
|
+
String reason
|
|
34
|
+
) -> ::OpenFeature::SDK::Provider::ResolutionDetails
|
|
35
|
+
|
|
36
|
+
def self.type_mismatch_resolution: (
|
|
37
|
+
ConfigEvaluation[config_value] evaluation
|
|
38
|
+
) -> ::OpenFeature::SDK::Provider::ResolutionDetails
|
|
39
|
+
|
|
40
|
+
def self.failed_resolution: (
|
|
41
|
+
ConfigEvaluation[config_value] evaluation,
|
|
42
|
+
String error_code,
|
|
43
|
+
String error_message
|
|
44
|
+
) -> ::OpenFeature::SDK::Provider::ResolutionDetails
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
class FlagReader
|
|
48
|
+
@client: ConfigDirectorClient
|
|
49
|
+
|
|
50
|
+
def initialize: (ConfigDirectorClient client) -> void
|
|
51
|
+
|
|
52
|
+
def read: (
|
|
53
|
+
String flag_key,
|
|
54
|
+
untyped default_value,
|
|
55
|
+
::OpenFeature::SDK::EvaluationContext? evaluation_context
|
|
56
|
+
) -> ::OpenFeature::SDK::Provider::ResolutionDetails
|
|
57
|
+
|
|
58
|
+
def read_a_number: (
|
|
59
|
+
String flag_key,
|
|
60
|
+
Numeric default_value,
|
|
61
|
+
::OpenFeature::SDK::EvaluationContext? evaluation_context
|
|
62
|
+
) -> ::OpenFeature::SDK::Provider::ResolutionDetails
|
|
63
|
+
|
|
64
|
+
private
|
|
65
|
+
|
|
66
|
+
def float_of: (untyped number) -> Float
|
|
67
|
+
|
|
68
|
+
def number_served_by: (ConfigEvaluation[Float] evaluation, Numeric default_value) -> untyped
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
class Startup
|
|
72
|
+
type stage = :initializing | :reporting_the_failure | :awaiting_config | :ready
|
|
73
|
+
|
|
74
|
+
@client: ConfigDirectorClient
|
|
75
|
+
@lock: Thread::Mutex
|
|
76
|
+
@stage: stage
|
|
77
|
+
|
|
78
|
+
def initialize: (ConfigDirectorClient client) -> void
|
|
79
|
+
|
|
80
|
+
def begin_initialization: () -> void
|
|
81
|
+
|
|
82
|
+
def report_due_after_initialization: () -> (:report_ready | :report_the_failure)
|
|
83
|
+
|
|
84
|
+
def report_due_after_the_failure: () -> (:report_ready | :nothing)
|
|
85
|
+
|
|
86
|
+
def report_due_when_config_arrives: () -> (:report_ready | :nothing)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
module ConfigDirector
|
|
2
|
+
module OpenFeature
|
|
3
|
+
VERSION: String
|
|
4
|
+
|
|
5
|
+
class ConfigDirectorProvider
|
|
6
|
+
include ::OpenFeature::SDK::Provider::EventEmitter
|
|
7
|
+
|
|
8
|
+
ProviderEvent: singleton(::OpenFeature::SDK::ProviderEvent)
|
|
9
|
+
ErrorCode: singleton(::OpenFeature::SDK::Provider::ErrorCode)
|
|
10
|
+
NO_CONFIG_IN_TIME: String
|
|
11
|
+
|
|
12
|
+
@startup: Internal::Startup
|
|
13
|
+
@logger: _Logger & Object
|
|
14
|
+
@client: ConfigDirectorClient
|
|
15
|
+
@flag_reader: Internal::FlagReader
|
|
16
|
+
|
|
17
|
+
attr_reader metadata: ::OpenFeature::SDK::Provider::ProviderMetadata
|
|
18
|
+
|
|
19
|
+
def initialize: (
|
|
20
|
+
?String? server_sdk_key,
|
|
21
|
+
?metadata: Metadata?,
|
|
22
|
+
?connection: ConnectionOptions?,
|
|
23
|
+
?logger: (_Logger & Object)?,
|
|
24
|
+
?log_level: (Integer | Symbol | String)?,
|
|
25
|
+
?telemetry: TelemetryOptions?
|
|
26
|
+
) -> void
|
|
27
|
+
|
|
28
|
+
def emits_lifecycle_events?: () -> true
|
|
29
|
+
|
|
30
|
+
def init: () -> void
|
|
31
|
+
|
|
32
|
+
def shutdown: () -> void
|
|
33
|
+
|
|
34
|
+
def track: (
|
|
35
|
+
String tracking_event_name,
|
|
36
|
+
?evaluation_context: ::OpenFeature::SDK::EvaluationContext?,
|
|
37
|
+
?tracking_event_details: ::OpenFeature::SDK::TrackingEventDetails?
|
|
38
|
+
) -> void
|
|
39
|
+
|
|
40
|
+
def fetch_boolean_value: (
|
|
41
|
+
flag_key: String,
|
|
42
|
+
default_value: bool,
|
|
43
|
+
?evaluation_context: ::OpenFeature::SDK::EvaluationContext?
|
|
44
|
+
) -> ::OpenFeature::SDK::Provider::ResolutionDetails
|
|
45
|
+
|
|
46
|
+
def fetch_string_value: (
|
|
47
|
+
flag_key: String,
|
|
48
|
+
default_value: String,
|
|
49
|
+
?evaluation_context: ::OpenFeature::SDK::EvaluationContext?
|
|
50
|
+
) -> ::OpenFeature::SDK::Provider::ResolutionDetails
|
|
51
|
+
|
|
52
|
+
def fetch_number_value: (
|
|
53
|
+
flag_key: String,
|
|
54
|
+
default_value: Numeric,
|
|
55
|
+
?evaluation_context: ::OpenFeature::SDK::EvaluationContext?
|
|
56
|
+
) -> ::OpenFeature::SDK::Provider::ResolutionDetails
|
|
57
|
+
|
|
58
|
+
def fetch_integer_value: (
|
|
59
|
+
flag_key: String,
|
|
60
|
+
default_value: Integer,
|
|
61
|
+
?evaluation_context: ::OpenFeature::SDK::EvaluationContext?
|
|
62
|
+
) -> ::OpenFeature::SDK::Provider::ResolutionDetails
|
|
63
|
+
|
|
64
|
+
def fetch_float_value: (
|
|
65
|
+
flag_key: String,
|
|
66
|
+
default_value: Float,
|
|
67
|
+
?evaluation_context: ::OpenFeature::SDK::EvaluationContext?
|
|
68
|
+
) -> ::OpenFeature::SDK::Provider::ResolutionDetails
|
|
69
|
+
|
|
70
|
+
def fetch_object_value: (
|
|
71
|
+
flag_key: String,
|
|
72
|
+
default_value: Hash[String, untyped] | Array[untyped],
|
|
73
|
+
?evaluation_context: ::OpenFeature::SDK::EvaluationContext?
|
|
74
|
+
) -> ::OpenFeature::SDK::Provider::ResolutionDetails
|
|
75
|
+
|
|
76
|
+
private
|
|
77
|
+
|
|
78
|
+
def initialize_the_client: () -> void
|
|
79
|
+
|
|
80
|
+
def send_the_report: (:report_ready | :report_the_failure | :nothing report) -> void
|
|
81
|
+
|
|
82
|
+
def report_no_config_in_time: () -> bot
|
|
83
|
+
|
|
84
|
+
def report_the_configs_changed_by: (ConfigsUpdatedEvent update) -> void
|
|
85
|
+
|
|
86
|
+
def value_of: (::OpenFeature::SDK::TrackingEventDetails? tracking_event_details) -> untyped
|
|
87
|
+
|
|
88
|
+
def details_of: (::OpenFeature::SDK::TrackingEventDetails? tracking_event_details) -> Hash[String, untyped]?
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: configdirector-openfeature-server-provider
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- ConfigDirector
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: configdirector-server-sdk
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: 0.1.0
|
|
19
|
+
- - "<"
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '1'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
requirements:
|
|
26
|
+
- - ">="
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
version: 0.1.0
|
|
29
|
+
- - "<"
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: '1'
|
|
32
|
+
- !ruby/object:Gem::Dependency
|
|
33
|
+
name: openfeature-sdk
|
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: 0.8.1
|
|
39
|
+
- - "<"
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '0.9'
|
|
42
|
+
type: :runtime
|
|
43
|
+
prerelease: false
|
|
44
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - ">="
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: 0.8.1
|
|
49
|
+
- - "<"
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: '0.9'
|
|
52
|
+
description: OpenFeature server provider for ConfigDirector. ConfigDirector is a remote
|
|
53
|
+
configuration and feature flag service.
|
|
54
|
+
executables: []
|
|
55
|
+
extensions: []
|
|
56
|
+
extra_rdoc_files: []
|
|
57
|
+
files:
|
|
58
|
+
- CHANGELOG.md
|
|
59
|
+
- LICENSE
|
|
60
|
+
- README.md
|
|
61
|
+
- lib/configdirector-openfeature-server-provider.rb
|
|
62
|
+
- lib/configdirector/openfeature.rb
|
|
63
|
+
- lib/configdirector/openfeature/config_director_provider.rb
|
|
64
|
+
- lib/configdirector/openfeature/internal.rb
|
|
65
|
+
- lib/configdirector/openfeature/internal/config_director_context.rb
|
|
66
|
+
- lib/configdirector/openfeature/internal/date_text.rb
|
|
67
|
+
- lib/configdirector/openfeature/internal/flag_reader.rb
|
|
68
|
+
- lib/configdirector/openfeature/internal/resolution_details_by_reason.rb
|
|
69
|
+
- lib/configdirector/openfeature/internal/startup.rb
|
|
70
|
+
- lib/configdirector/openfeature/version.rb
|
|
71
|
+
- sig/configdirector/openfeature.rbs
|
|
72
|
+
- sig/configdirector/openfeature/internal.rbs
|
|
73
|
+
homepage: https://www.configdirector.com
|
|
74
|
+
licenses:
|
|
75
|
+
- MIT
|
|
76
|
+
metadata:
|
|
77
|
+
documentation_uri: https://docs.configdirector.com/sdks/openfeature/ruby
|
|
78
|
+
source_code_uri: https://github.com/ConfigDirector/ruby-sdks/tree/main/configdirector-openfeature-server-provider
|
|
79
|
+
changelog_uri: https://github.com/ConfigDirector/ruby-sdks/blob/main/configdirector-openfeature-server-provider/CHANGELOG.md
|
|
80
|
+
rubygems_mfa_required: 'true'
|
|
81
|
+
rdoc_options: []
|
|
82
|
+
require_paths:
|
|
83
|
+
- lib
|
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - ">="
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '3.4'
|
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
|
+
requirements:
|
|
91
|
+
- - ">="
|
|
92
|
+
- !ruby/object:Gem::Version
|
|
93
|
+
version: '0'
|
|
94
|
+
requirements: []
|
|
95
|
+
rubygems_version: 4.0.20
|
|
96
|
+
specification_version: 4
|
|
97
|
+
summary: OpenFeature server provider for ConfigDirector.
|
|
98
|
+
test_files: []
|