-
Notifications
You must be signed in to change notification settings - Fork 41
feat: Add environment variable support for OFREP configuration #525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: André Silva <[email protected]>
…fallback for BaseUrl Signed-off-by: André Silva <[email protected]>
Signed-off-by: André Silva <[email protected]>
… and OfrepOptions Signed-off-by: André Silva <[email protected]>
Signed-off-by: André Silva <[email protected]>
Signed-off-by: André Silva <[email protected]>
…ons to use a centralized default value Signed-off-by: André Silva <[email protected]>
…ation handling Signed-off-by: André Silva <[email protected]>
Summary of ChangesHello @askpt, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the flexibility of the OFREP provider by enabling configuration through environment variables and Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a valuable feature by adding support for configuring the OFREP provider through environment variables and IConfiguration. The implementation is robust, covering configuration classes, dependency injection, and the provider itself, with proper handling of configuration precedence. The inclusion of comprehensive tests and detailed documentation significantly enhances the quality of this contribution. I've provided a few suggestions to further refine the code by simplifying a method and removing some code duplication for better long-term maintainability. Overall, this is an excellent addition to the project.
src/OpenFeature.Providers.Ofrep/DependencyInjection/OfrepProviderOptionsValidator.cs
Outdated
Show resolved
Hide resolved
test/OpenFeature.Providers.Ofrep.Test/Configuration/OfrepOptionsEnvironmentTest.cs
Outdated
Show resolved
Hide resolved
Signed-off-by: André Silva <[email protected]>
…n OfrepProviderOptionsValidator Signed-off-by: André Silva <[email protected]>
…strings in OfrepOptions Signed-off-by: André Silva <[email protected]>
157bce9 to
7f4a25a
Compare
…ion in net462 target framework Signed-off-by: André Silva <[email protected]>
…econds Signed-off-by: André Silva <[email protected]>
…prove documentation Signed-off-by: André Silva <[email protected]>
…MS for clarity Signed-off-by: André Silva <[email protected]>
…ure sequential execution Signed-off-by: André Silva <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request adds comprehensive environment variable and configuration support for the OFREP provider, enabling zero-code configuration for containerized and cloud-native deployments. The changes introduce static factory methods for building OfrepOptions from environment variables or IConfiguration, update dependency injection logic to support configuration fallback, enhance validation, and expand documentation with practical examples.
Key changes:
- Added environment variable support through new static methods
OfrepOptions.FromEnvironment()andOfrepOptions.FromConfiguration()with robust parsing, validation, and logging - Introduced new parameterless and logger-accepting constructors to
OfrepProviderfor zero-code configuration - Enhanced dependency injection integration to fall back to configuration/environment variables when
BaseUrlis not explicitly set, with proper merging of programmatic overrides
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/OpenFeature.Providers.Ofrep/Configuration/OfrepOptions.cs |
Added environment variable constants, static factory methods for configuration loading, and header parsing with URL-encoding support |
src/OpenFeature.Providers.Ofrep/OfrepProvider.cs |
Added parameterless and ILogger<OfrepProvider> constructors that automatically load configuration from environment variables |
src/OpenFeature.Providers.Ofrep/DependencyInjection/FeatureBuilderExtensions.cs |
Updated CreateProvider to fall back to IConfiguration/environment variables when BaseUrl is not set, with proper header and timeout merging |
src/OpenFeature.Providers.Ofrep/DependencyInjection/OfrepProviderOptionsValidator.cs |
Enhanced validator to accept IConfiguration and validate configuration/environment variable fallback values |
src/OpenFeature.Providers.Ofrep/DependencyInjection/OfrepProviderOptions.cs |
Updated default timeout to use shared constant from OfrepOptions for consistency |
src/OpenFeature.Providers.Ofrep/README.md |
Added comprehensive documentation for environment variable configuration, header format, URL encoding behavior, and configuration precedence |
test/OpenFeature.Providers.Ofrep.Test/Configuration/OfrepOptionsEnvironmentTest.cs |
Added comprehensive test coverage for environment variable parsing, configuration loading, and edge cases |
test/OpenFeature.Providers.Ofrep.Test/Configuration/EnvironmentVariableTestCollection.cs |
Added test collection definition to ensure environment variable tests run sequentially |
test/OpenFeature.Providers.Ofrep.Test/OpenFeature.Providers.Ofrep.Test.csproj |
Added Microsoft.Extensions.Configuration package reference for net462 to support configuration tests |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/OpenFeature.Providers.Ofrep/DependencyInjection/OfrepProviderOptionsValidator.cs
Outdated
Show resolved
Hide resolved
test/OpenFeature.Providers.Ofrep.Test/OpenFeature.Providers.Ofrep.Test.csproj
Show resolved
Hide resolved
src/OpenFeature.Providers.Ofrep/DependencyInjection/FeatureBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]> Signed-off-by: André Silva <[email protected]>
| # Multiple headers with special characters | ||
| export OFREP_HEADERS="Authorization=Bearer token,X-Api-Key=abc123" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a special character in the value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with: 39d6d6d
|
|
||
| ### Header Format and URL Encoding | ||
|
|
||
| The `OFREP_HEADERS` environment variable uses a simple `Key=Value` format separated by commas. URL encoding is supported for compatibility with systems that encode the entire value, but note that commas are used as header separators and cannot be included in values. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the phrasing here is ambiguous. Before looking at the tests, I would have assumed that e.g. a%3Db=c%2Cd would result in a key a=b and value a,d, but this is not the case. We should explain that even url encoded commas are not allowed, and that equals signs (no matter if url encoded or not) are only allowed in the value (as a consequence of assuming that the first = separates the key from the value)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with: 39d6d6d
…L encoding behavior Signed-off-by: André Silva <[email protected]>
test/OpenFeature.Providers.Ofrep.Test/Configuration/OfrepOptionsEnvironmentTest.cs
Show resolved
Hide resolved
|
This might be a silly question, but are you sure HTTP headers are URL-encoded? |
…lid values Signed-off-by: André Silva <[email protected]>
…ble flow analysis Signed-off-by: André Silva <[email protected]>
Are you asking if the headers should be URL-encoded (spec) or are you asking if this implementation is URL-encoded? |
Why |
URL-encoding is needed because headers are passed via environment variables, not because of HTTP itself. Since the env var format is For example: |
|
export OFREP_HEADERS="Authorization=Bearer my token with spaces,X-Env=prod" I believe it's usually done like that. I don't see such approach anywhere else. OTEL has plain text for their environment headers even in .net implementation for example. |
That is incorrect. I followed the OTEL guidelines. I started by trying to do "escaping" but it wouldn't sort the issue so I researched what OTEL does. dotnet implementation here: https://github.com/open-telemetry/opentelemetry-dotnet/blob/58519b76b5365ef4352c2583711da3e61bd67259/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs#L25 The current implementation should support:
|
|
I think it's a good idea to match the behaviour of OpenTelemetry's .net SDK |
// URL-decode the entire string to support encoded special characters
var decoded = Uri.UnescapeDataString(headersString);The spec states that the header value may contain special characters, not the header key. You decode the full input from the start. Another issue is that the OFREP spec doesn’t say anything about this, which could lead to inconsistent implementations within OFREP ecosystem. |
Signed-off-by: André Silva [email protected]
This PR
This pull request introduces comprehensive support for environment variable and configuration-based setup for the OFREP provider, making it much easier to configure the provider in containerized and cloud-native environments. The changes add static factory methods for building
OfrepOptionsfrom environment variables orIConfiguration, update dependency injection and validation logic to support configuration fallback, and expand documentation to explain these features.Key changes include:
Environment variable and configuration support:
OfrepOptionsfor creating instances from environment variables (FromEnvironment) or fromIConfigurationwith fallback to environment variables (FromConfiguration). These methods include robust parsing, validation, and logging for malformed values. (src/OpenFeature.Providers.Ofrep/Configuration/OfrepOptions.cssrc/OpenFeature.Providers.Ofrep/Configuration/OfrepOptions.csR1-R27)OFREP_ENDPOINT,OFREP_HEADERS,OFREP_TIMEOUT_MS) and improved header parsing logic, including support for URL-encoded values. (src/OpenFeature.Providers.Ofrep/Configuration/OfrepOptions.cssrc/OpenFeature.Providers.Ofrep/Configuration/OfrepOptions.csR1-R27)Dependency injection and validation improvements:
FeatureBuilderExtensionsto use configuration/environment variable fallback whenBaseUrlis not explicitly set, and to merge DI-provided overrides. (src/OpenFeature.Providers.Ofrep/DependencyInjection/FeatureBuilderExtensions.cssrc/OpenFeature.Providers.Ofrep/DependencyInjection/FeatureBuilderExtensions.csR45-R75)OfrepProviderOptionsValidatorto allowBaseUrlto be omitted if it is available via configuration or environment variable, with appropriate validation and error messages. (src/OpenFeature.Providers.Ofrep/DependencyInjection/OfrepProviderOptionsValidator.cssrc/OpenFeature.Providers.Ofrep/DependencyInjection/OfrepProviderOptionsValidator.csR12-R49)OfrepProviderOptionsto use the newDefaultTimeoutconstant for consistency. (src/OpenFeature.Providers.Ofrep/DependencyInjection/OfrepProviderOptions.cssrc/OpenFeature.Providers.Ofrep/DependencyInjection/OfrepProviderOptions.csL25-R27)Provider usability:
OfrepProviderto enable zero-code configuration via environment variables, with optional logging for malformed values. (src/OpenFeature.Providers.Ofrep/OfrepProvider.cssrc/OpenFeature.Providers.Ofrep/OfrepProvider.csR22-R60)Documentation:
src/OpenFeature.Providers.Ofrep/README.mdsrc/OpenFeature.Providers.Ofrep/README.mdR90-R168)These changes make the OFREP provider more flexible and easier to configure in modern deployment scenarios.
Related Issues
Fixes #520