Credentials
mail_intake.credentials
Summary
Credential persistence interfaces and implementations for Mail Intake.
This package defines the abstractions and concrete implementations used to persist authentication credentials across Mail Intake components.
The credential persistence layer is intentionally decoupled from authentication logic. Authentication providers are responsible for credential acquisition, validation, and refresh, while implementations within this package are responsible solely for storage and retrieval.
The package provides:
- A generic
CredentialStoreabstraction defining the persistence contract. - Local filesystem–based storage for development and single-node use.
- Distributed, Redis-backed storage for production and scaled deployments.
Credential lifecycle management, interpretation, and security policy decisions remain the responsibility of authentication providers.
Public API
CredentialStorePickleCredentialStoreRedisCredentialStore
Classes
CredentialStore
Bases: ABC, Generic[T]
Abstract base class defining a generic persistence interface.
Used for authentication credentials across different backends.
Notes
Responsibilities:
1 2 3 | |
Constraints:
1 2 3 4 | |
Functions
clear
abstractmethod
Remove any persisted credentials from the store.
Notes
Lifecycle:
1 2 | |
Guarantees:
1 | |
load
abstractmethod
Load previously persisted credentials.
Returns:
| Type | Description |
|---|---|
Optional[T]
|
Optional[T]:
An instance of type |
Notes
Guarantees:
1 2 3 4 5 | |
save
abstractmethod
Persist credentials to the underlying storage backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
credentials |
T
|
The credential object to persist. |
required |
Notes
Lifecycle:
1 | |
Responsibilities:
1 2 3 | |
PickleCredentialStore
Bases: CredentialStore[T]
Filesystem-backed credential store using pickle serialization.
This store persists credentials as a pickled object on the local filesystem. It is a simple implementation intended primarily for development, testing, and single-process execution contexts.
Notes
Guarantees:
1 2 3 | |
Constraints:
1 2 | |
Initialize a pickle-backed credential store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path |
str
|
Filesystem path where credentials will be stored. The file will be created or overwritten as needed. |
required |
Functions
clear
Remove persisted credentials from the local filesystem.
Notes
Lifecycle:
1 | |
load
Load credentials from the local filesystem.
Returns:
| Type | Description |
|---|---|
Optional[T]
|
Optional[T]:
An instance of type |
Notes
Guarantees:
1 2 3 4 | |
save
Persist credentials to the local filesystem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
credentials |
T
|
The credential object to persist. |
required |
Notes
Responsibilities:
1 | |
RedisCredentialStore
Bases: CredentialStore[T]
Redis-backed implementation of CredentialStore.
This store persists credentials in Redis and is suitable for distributed and horizontally scaled deployments where credentials must be shared across multiple processes or nodes.
Notes
Responsibilities:
1 2 3 | |
Guarantees:
1 2 3 4 | |
Initialize a Redis-backed credential store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
redis_client |
Any
|
An initialized Redis client instance (for example, |
required |
key |
str
|
The Redis key under which credentials are stored. Callers are responsible for applying appropriate namespacing to avoid collisions. |
required |
serialize |
Callable[[T], bytes]
|
A callable that converts a credential object of type |
required |
deserialize |
Callable[[bytes], T]
|
A callable that converts a |
required |
ttl_seconds |
Optional[int]
|
Optional time-to-live (TTL) for the stored credentials, expressed in seconds. When provided, Redis will automatically expire the stored credentials after the specified duration. If |
None
|
Functions
clear
Remove stored credentials from Redis.
Notes
Lifecycle:
1 2 | |
load
Load credentials from Redis.
Returns:
| Type | Description |
|---|---|
Optional[T]
|
Optional[T]:
An instance of type |
Notes
Guarantees:
1 2 3 4 5 6 | |
save
Persist credentials to Redis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
credentials |
T
|
The credential object to persist. |
required |
Notes
Responsibilities:
1 2 | |