A tool for templating .env files and more.
Project description
Secret Template Renderer
This project is a Jinja template renderer that supports fetching secrets from various providers.
Features
- Load built-in and user-defined plugins to extend the functionality
- Register multiple secret providers
- Render Jinja templates with secrets
Installation
Using pip
-
Clone the repository
-
Install the required dependencies
pip install -r requirements.txt
Using pipx
pipx install secret_template_renderer
Usage
Template Utilities
import_env: import dotenv fileget_secret: retrieve secret via secret providersshell: execute shell commandrandom: generate a random string with the following parameters:- length: int = 16,
- type: string | password = 'string',
- lower_case: bool = True,
- numbers: bool = True,
- has_special_chars: bool = False,
- must_has_special_chars: bool = False,
- exclude_characters: str = "",
Command Line Interface
-d,--debug: Enable debug mode
Generate
str generate [-f <template_path>] [-o <output_path>] [-i <input_string>] [-p <password>]
-f,--file: Path to the Jinja template file-o,--output: Path to the output file-i,--input: Input string to be rendered-p,--password: Password to be used for encryption
Encryption
str encrypt|decrypt [-f <template_path>] [-o <output_path>] [-i <input_string>] [-p <password>]
-f,--file: Path to the Jinja template file-o,--output: Path to the output file-i,--input: Input string to be rendered-p,--password: Password to be used for encryption
Example
{{ import_env('.default.env') }} # Importing another dotenv file
DATABASE_PWD={{ get_secret('bitwarden', 'database_system_a', 'login.password') }} # Use the bitwarden plugins to load Bitwarden
NAME=app-{{ random(10) }} # Generate the randomised strings
PWD={{ decrypt("SfB505whBisKznrdHKLvQ0hhaESDP0MqvWFsYNkI0to=", "password") }}
UID={{ shell('echo $UID') }}
Custom plugins
To load custom plugins, place your plugin .py files in ~/.config/temv/plugins/[plugin_type]/[plugin_name]. Currently, there are 2 plugins: secrets and encryptions.
Each plugin must have a register function that takes a dictionary of secret providers as an argument.
Secret example:
import subprocess
from collections.abc import Callable
def get_custom_secret(item_name: str, path: str) -> str | None:
pass
def register(secrets_providers: dict[str, Callable[[str, str], str | None]]):
"""Register secret provider."""
secrets_providers["custom_provider"] = get_custom_secret
Encryption example:
import subprocess
from collections.abc import Callable
def encrypt(value: str, password: str) -> str | None:
pass
def decrypt(value: str, password: str) -> str | None:
pass
def register(providers: dict[str, Callable[[str, str], str | None]]):
"""Register encryption provider."""
providers["custom_provider"] = {"encrypt": encrypt, "decrypt": decrypt}
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file secret_template_renderer-0.2.3.tar.gz.
File metadata
- Download URL: secret_template_renderer-0.2.3.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.1 CPython/3.12.1 Linux/6.8.0-1021-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3cfed42c597383290a2e4f18255a073d3a598c2cc221bc3633324b3152e7631
|
|
| MD5 |
5c06c3b907a2be40101583c48ac6f1c9
|
|
| BLAKE2b-256 |
ae6b88ed45d8702c45227769c1b2a940fe1afa6bd383a43cfc9dc5548915076b
|
File details
Details for the file secret_template_renderer-0.2.3-py3-none-any.whl.
File metadata
- Download URL: secret_template_renderer-0.2.3-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.1 CPython/3.12.1 Linux/6.8.0-1021-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
055b1f867f40421621aea5d6bea8d339d72588a80ef5f66a0634e9bb78563013
|
|
| MD5 |
6360041e9837b1701a63547721f3e017
|
|
| BLAKE2b-256 |
7803dfc34dca3ad2f6dedba48daed67720975a578baf7b818f16abed2072f701
|