Skip to content

Expose GCP Secret Manager case sensitive option #626

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

Merged
merged 5 commits into from
Jun 9, 2025

Conversation

bellmatthewf
Copy link
Contributor

@bellmatthewf bellmatthewf commented Jun 2, 2025

Issue 625

Issue
The "pydantic-settings[gcp-secret-manager]" integration does not expose the case_sensitive parameter in it's API. It defaults to True and cannot be changed.

class GoogleSecretManagerSettingsSource(EnvSettingsSource):
    def __init__(
        self,
        settings_cls: type[BaseSettings],
        credentials: Credentials | None = None,
        project_id: str | None = None,
        env_prefix: str | None = None,
        env_parse_none_str: str | None = None,
        env_parse_enums: bool | None = None,
        secret_client: SecretManagerServiceClient | None = None,
    ) -> None:
        
        ...

        super().__init__(
            settings_cls,
            case_sensitive=True,
            env_prefix=env_prefix,
            env_ignore_empty=False,
            env_parse_none_str=env_parse_none_str,
            env_parse_enums=env_parse_enums,
        )

Note on changes
I considered using the parse_env_vars util function to keep this source in line with others, but that function isn't ideal here because it would iteratively call the GCP API during instantiation to get each variable value.

Better to keep those calls lazy by implementing case sensitivity changes at the mapping class level

@bellmatthewf bellmatthewf marked this pull request as ready for review June 2, 2025 01:48
@@ -37,26 +37,34 @@ class GoogleSecretManagerMapping(Mapping[str, Optional[str]]):
_loaded_secrets: dict[str, str | None]
_secret_client: SecretManagerServiceClient

def __init__(self, secret_client: SecretManagerServiceClient, project_id: str) -> None:
def __init__(self, secret_client: SecretManagerServiceClient, project_id: str, case_sensitive: bool) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

Don't we need to define a default value for case_sensitive for backward compatibility?

Copy link
Contributor Author

@bellmatthewf bellmatthewf Jun 3, 2025

Choose a reason for hiding this comment

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

Users should never be instantiating this class directly. The GoogleSecretManagerMapping class is only instantiated internally within the GoogleSecretManagerSettingsSource class.

I added a default value to the new case_sensitive parameter of that class which will carry through to here.

Copy link
Contributor

Choose a reason for hiding this comment

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

@bellmatthewf - That makes sense to me.

@hramezani
Copy link
Member

Thanks @bellmatthewf for this PR.

@ezwiefel Can you take a look at this PR?

@@ -37,26 +37,34 @@ class GoogleSecretManagerMapping(Mapping[str, Optional[str]]):
_loaded_secrets: dict[str, str | None]
_secret_client: SecretManagerServiceClient

def __init__(self, secret_client: SecretManagerServiceClient, project_id: str) -> None:
def __init__(self, secret_client: SecretManagerServiceClient, project_id: str, case_sensitive: bool) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

@bellmatthewf - That makes sense to me.

@ezwiefel
Copy link
Contributor

ezwiefel commented Jun 9, 2025

@hramezani LGTM

@hramezani
Copy link
Member

Thanks @bellmatthewf for the PR and @ezwiefel for review.

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.

3 participants