trading_agent.journal.secret_redactor
¶
Masks secrets in text before it is written down or shown.
It knows two kinds of secret: the exact values of the agent's own secrets and of tradingmachine's passwords and keys, read from their files, and the usual shapes of tokens (Anthropic tokens, bearer tokens, token= and api-key parameters), which catch secrets it was never told about.
Typical usage example:
redactor = SecretRedactor.from_files(secrets, Path('/home/pramod/Projects/tradingmachine/.env')) safe = redactor.redact(payload)
SecretRedactor
¶
Replaces known secret values and token-shaped text with [redacted].
Creates the redactor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
secret_values
|
Iterable[str]
|
The exact secret values to mask; values shorter than 8 characters are ignored, because they would mask ordinary words. |
required |
Source code in src/trading_agent/journal/secret_redactor.py
from_files
classmethod
¶
Builds a redactor that knows the agent's secrets and tradingmachine's.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
secrets
|
Secrets
|
The agent's own secrets. |
required |
tradingmachine_environment_file
|
Path
|
tradingmachine's |
required |
Returns:
| Type | Description |
|---|---|
SecretRedactor
|
The redactor. |
Source code in src/trading_agent/journal/secret_redactor.py
redact
¶
Masks secrets in a value and everything inside it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
A string, or a dictionary or list holding strings. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
A copy with every secret replaced; other types are returned unchanged. |