Skip to content

Conversation

@askpt
Copy link
Member

@askpt askpt commented Dec 10, 2025

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 OfrepOptions from environment variables or IConfiguration, 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:

  • Added static methods to OfrepOptions for creating instances from environment variables (FromEnvironment) or from IConfiguration with fallback to environment variables (FromConfiguration). These methods include robust parsing, validation, and logging for malformed values. (src/OpenFeature.Providers.Ofrep/Configuration/OfrepOptions.cs src/OpenFeature.Providers.Ofrep/Configuration/OfrepOptions.csR1-R27)
  • Introduced environment variable constants (OFREP_ENDPOINT, OFREP_HEADERS, OFREP_TIMEOUT_MS) and improved header parsing logic, including support for URL-encoded values. (src/OpenFeature.Providers.Ofrep/Configuration/OfrepOptions.cs src/OpenFeature.Providers.Ofrep/Configuration/OfrepOptions.csR1-R27)

Dependency injection and validation improvements:

Provider usability:

Documentation:

  • Expanded the README to document environment variable configuration, header format, and configuration precedence for the provider, including practical usage examples. (src/OpenFeature.Providers.Ofrep/README.md src/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

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 IConfiguration. This change simplifies deployment and management in containerized and CI/CD environments, providing a zero-code configuration option. It ensures that critical settings like the OFREP endpoint, request timeout, and custom HTTP headers can be easily managed outside of application code, with clear precedence rules for various configuration sources.

Highlights

  • Environment Variable Support: Introduced robust support for configuring the OFREP provider using environment variables (OFREP_ENDPOINT, OFREP_HEADERS, OFREP_TIMEOUT).
  • Flexible Configuration Loading: Added static factory methods to OfrepOptions (FromEnvironment, FromConfiguration) allowing configuration to be loaded directly from environment variables or IConfiguration with fallback logic.
  • Dependency Injection Integration: Enhanced FeatureBuilderExtensions and OfrepProviderOptionsValidator to seamlessly integrate environment variable and IConfiguration settings, ensuring proper validation and precedence.
  • Header Parsing with Escape Sequences: Implemented sophisticated parsing for the OFREP_HEADERS environment variable, supporting escape sequences for special characters like commas, equals signs, and backslashes.
  • Updated Documentation and Tests: The README.md has been updated with detailed instructions and examples for environment variable configuration, and new unit tests have been added to cover the new configuration loading and parsing logic.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

Copy link
Contributor

Copilot AI left a 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() and OfrepOptions.FromConfiguration() with robust parsing, validation, and logging
  • Introduced new parameterless and logger-accepting constructors to OfrepProvider for zero-code configuration
  • Enhanced dependency injection integration to fall back to configuration/environment variables when BaseUrl is 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.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: André Silva <[email protected]>
@askpt askpt marked this pull request as ready for review December 16, 2025 21:38
@askpt askpt requested review from a team as code owners December 16, 2025 21:38
Comment on lines 139 to 140
# Multiple headers with special characters
export OFREP_HEADERS="Authorization=Bearer token,X-Api-Key=abc123"
Copy link
Contributor

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?

Copy link
Member Author

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.
Copy link
Contributor

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)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed with: 39d6d6d

@erka
Copy link
Member

erka commented Dec 17, 2025

This might be a silly question, but are you sure HTTP headers are URL-encoded?

@askpt
Copy link
Member Author

askpt commented Dec 17, 2025

This might be a silly question, but are you sure HTTP headers are URL-encoded?

Are you asking if the headers should be URL-encoded (spec) or are you asking if this implementation is URL-encoded?

@erka
Copy link
Member

erka commented Dec 17, 2025

Are you asking if the headers should be URL-encoded (spec) or are you asking if this implementation is URL-encoded?

Why OFREP_HEADERS should Supports URL-encoded values? The HTTP header is plain text, no?

@askpt
Copy link
Member Author

askpt commented Dec 18, 2025

Are you asking if the headers should be URL-encoded (spec) or are you asking if this implementation is URL-encoded?

Why OFREP_HEADERS should Supports URL-encoded values? The HTTP header is plain text, no?

URL-encoding is needed because headers are passed via environment variables, not because of HTTP itself. Since the env var format is key1=value1,key2=value2, we need a way to escape special characters. Whitespaces and other special characters can cause issues depending on the shell.

For example:
X-Custom-Header=Hello World, the space could cause issues in some shells (e.g., Bash, PowerShell) when setting environment variables, so encoding it as Hello%20World ensures consistent behaviour across platforms
URL-encoding provides a standard, well-understood escaping mechanism that works reliably regardless of the shell or OS being used.

@erka
Copy link
Member

erka commented Dec 18, 2025

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.

@askpt
Copy link
Member Author

askpt commented Dec 18, 2025

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

OTEL spec here: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#specifying-headers-via-environment-variables

The current implementation should support:

  • export OFREP_HEADERS="Authorization=Bearer my token with spaces,X-Env=prod"
  • export OFREP_HEADERS="Authorization=Bearer%20my,X-Env=prod"

@weyert
Copy link
Contributor

weyert commented Dec 18, 2025

I think it's a good idea to match the behaviour of OpenTelemetry's .net SDK

@erka
Copy link
Member

erka commented Dec 18, 2025

       // 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[OFREP] Implement support for OFREP SDK configuration using environment variables

6 participants