Skip to content

Conversation

@RobertoPrevato
Copy link
Member

  • Add a Secret class to handle secrets in code instead of using plain str. This
    approach offers several advantages:
  1. It encourages loading secrets from environment variables, and discourages programmers
    from hardcoding secrets in source code.
  2. Avoids accidental exposure of secrets in logs or error messages, by overriding
    str and repr.
  3. It causes exception if someone tries to JSON encode it using the built-in JSON
    module, unlike str.
  4. For convenience, it can be compared directly to strings. It uses constant-time
    comparison to prevent timing attacks, with the built-in secrets.compare_digest.
  5. Environment variables can be changed at runtime, using this class applications can
    pick up secret changes without needing to be restarted.
  • Add an EnvironmentVariableNotFound exception that can be used when an expected env
    variable is not set.
  • Improve the order of if statements in the FriendlyEncoder class to prioritize the
    most frequently encountered types first, which should provide better performance in
    typical use cases.

@RobertoPrevato RobertoPrevato merged commit d79f99e into main Oct 1, 2025
6 checks passed
@RobertoPrevato RobertoPrevato deleted the feature/secrets branch October 1, 2025 07:29
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.

2 participants