Skip to content
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

[FEATURE] Introduce SecretStr class for enhanced secret handling #164

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

dannymeijer
Copy link
Member

@dannymeijer dannymeijer commented Jan 31, 2025

Introduces an extended SecretStr class to allow concatenation and use in f-strings.

Description

This pull request introduces the SecretStr class, which extends Pydantic's SecretStr to provide additional functionality.

The enhancements include:

  • Support for concatenation with other strings and SecretStr instances.
  • Advanced f-string formatting support to ensure the secret value is only revealed in secure contexts.

The SecretStr class continues to ensure that the secret value is masked in string representations and provides methods to safely handle secret values.

Related Issue

Closes #165

Motivation and Context

The change is required to provide a more secure and flexible way to handle secret strings while allowing them to be combined with other strings and f-string. By extending Pydantic's SecretStr, we can ensure that secret values are properly masked and only revealed in secure contexts, such as within another SecretStr instance. This helps prevent accidental exposure of sensitive information.

How Has This Been Tested?

The changes have been tested by adding unit tests to verify the following:

  • The integrity of the str and repr methods in SecretStr.
  • Concatenation of SecretStr with various types, including strings, integers, floats, booleans, and more.
  • Advanced f-string formatting to ensure the secret value is only revealed in secure contexts.
  • Handling of edge cases where concatenation or string conversion might fail.

Screenshots (if appropriate):

N/A

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@dannymeijer dannymeijer added the enhancement New feature or request label Jan 31, 2025
@dannymeijer dannymeijer added this to the 0.10.0 milestone Jan 31, 2025
@dannymeijer dannymeijer self-assigned this Jan 31, 2025
@dannymeijer dannymeijer requested a review from a team as a code owner January 31, 2025 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

[FEATURE] Bigger, better, SecretStr
1 participant