- Notifications
You must be signed in to change notification settings - Fork 11
[WIP] feat: Created methods to validate and register providers input #159
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
Summary of ChangesHello @Tmakinde, 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 establishes the foundational 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 Multiprovider
class to handle multiple feature flag providers, which is a great step towards implementing the multi-provider feature from the OpenFeature specification. The implementation correctly handles validation of provider data structure and generation of unique names for unnamed providers. However, I've found a high-severity issue in the provider registration logic that could lead to providers being silently overwritten if there's a name collision between an explicitly named provider and a previously registered provider with a generated name. My review includes a suggested fix to prevent this and ensure all provider names are unique as required by the specification.
$counts = []; // track how many times a base name is used | ||
| ||
foreach ($providerData as $entry) { | ||
if (isset($entry['name']) && $entry['name'] !== '') { | ||
$this->providersByName[$entry['name']] = $entry['provider']; | ||
} else { | ||
$name = $this->uniqueProviderName($entry['provider']->getMetadata()->getName(), $counts); | ||
if (isset($this->providersByName[$name])) { | ||
throw new InvalidArgumentException('Duplicate provider name detected during assignment: ' . $name); | ||
} | ||
$this->providersByName[$name] = $entry['provider']; | ||
} | ||
} |
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.
The current implementation of registerProviders
has a bug where an explicitly named provider can silently overwrite a previously registered provider if their names conflict. This happens because there's no uniqueness check for providers that have an explicit name. This violates the requirement that all provider names must be unique.
For example, if the provider data is [['provider' => $provider1], ['name' => 'TestProvider', 'provider' => $provider2]]
and $provider1->getMetadata()->getName()
returns 'TestProvider'
, the first provider will be registered with the generated name 'TestProvider'
, and then the second provider will overwrite it.
I suggest refactoring this method to determine the name first (either explicit or generated) and then perform a single check for uniqueness before registering the provider. This makes the logic cleaner and ensures no provider is ever overwritten.
$counts = []; // track how many times a base name is used foreach ($providerData as $entry) { if (isset($entry['name']) && $entry['name'] !== '') { $name = $entry['name']; } else { $name = $this->uniqueProviderName($entry['provider']->getMetadata()->getName(), $counts); } if (isset($this->providersByName[$name])) { throw new InvalidArgumentException('Duplicate provider name detected during assignment: ' . $name); } $this->providersByName[$name] = $entry['provider']; }
Hey @Tmakinde , initial thoughts here is that other languages utilized the contrib repository for implementing the multi provider. The reasoning as I understand it is it's an extension of the primary provider, not a function of it itself. That said it would be fairly straightforward to add support for it there @beeme1mr is that the expectation for all languages? |
Ooh. Please let me know the best place to implement this. Please confirm. |
We've been slowly moving the multi-providers to the SDKs themselves. The logic being that it's easier to access and manage provider state from within the SDK and it shouldn't add too much complexity to the SDKs. The .NET SDK is a good example of what we're looking for. |
Task
Multiprovider feature: https://openfeature.dev/specification/appendix-a#multi-provider