-
Notifications
You must be signed in to change notification settings - Fork 64
Feature: Add Support for Programatic Credentials #1020
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
Closed
+630
−95
Closed
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7350cbc
Feature: Add support for programatic credentials
fabiankaegy 04312b9
fix use 3.8 version
fabiankaegy b1def44
Minor code cleanup
dkotter 4819e50
Merge branch 'develop' into feature/support-programatic-credentials
dkotter d0a87e6
Add credentials filtering to TogetherAI
dkotter f92b3f9
Ensure the API URL has a trailing slash, even if not manually entered
dkotter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| <?php | ||
| /** | ||
| * Helper class for credential management functionality. | ||
| * | ||
| * @package Classifai\Helpers | ||
| */ | ||
|
|
||
| namespace Classifai\Helpers; | ||
|
|
||
| /** | ||
| * Credentials class. | ||
| * | ||
| * Centralized credential management for all providers. | ||
| * Allows programmatic override of credentials via filters for integration | ||
| * with external secret management services. | ||
| * | ||
| * @since 3.7.0 | ||
| */ | ||
| class Credentials { | ||
|
|
||
| /** | ||
| * Get credentials for a provider. | ||
| * | ||
| * @param string $provider_id The provider ID (e.g., 'azure_openai', 'openai_chatgpt'). | ||
| * @param string $feature_id The feature ID (e.g., 'feature_title_generation'). | ||
| * @param array $settings The provider settings from the database. | ||
| * @return array Filtered credentials array. | ||
| */ | ||
| public static function get_credentials( string $provider_id, string $feature_id, array $settings ): array { | ||
| /** | ||
| * Filter provider credentials before making an API request. | ||
| * | ||
| * This is the primary hook for integrating external secret management | ||
| * services like Azure Key Vault, AWS Secrets Manager, or HashiCorp Vault. | ||
| * | ||
| * @since 3.7.0 | ||
| * @hook classifai_provider_credentials | ||
| * | ||
| * @param array $credentials The credentials array from settings. | ||
| * @param string $provider_id The provider ID (e.g., 'azure_openai', 'openai_chatgpt'). | ||
| * @param string $feature_id The feature ID making the request. | ||
| * | ||
| * @return array Filtered credentials array. | ||
| */ | ||
| return apply_filters( | ||
| 'classifai_provider_credentials', | ||
| $settings, | ||
| $provider_id, | ||
| $feature_id | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Get a specific credential value. | ||
| * | ||
| * @param string $provider_id The provider ID. | ||
| * @param string $feature_id The feature ID. | ||
| * @param array $settings The provider settings. | ||
| * @param string $credential_key The specific credential key (e.g., 'api_key'). | ||
| * @return mixed The credential value. | ||
| */ | ||
| public static function get_credential( | ||
| string $provider_id, | ||
| string $feature_id, | ||
| array $settings, | ||
| string $credential_key | ||
| ) { | ||
| $credentials = self::get_credentials( $provider_id, $feature_id, $settings ); | ||
| return $credentials[ $credential_key ] ?? ''; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 new
Credentialshelper class lacks test coverage. Consider adding unit tests to verify:get_credentials()method correctly applies theclassifai_provider_credentialsfilterget_credential()method returns the correct individual credential value