Skip to main content

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

  1. Clone the repository

  2. Install the required dependencies

    pip install -r requirements.txt
    

Using pipx

pipx install secret_template_renderer

Usage

Template Utilities

  • import_env: import dotenv file
  • get_secret: retrieve secret via secret providers
  • shell: execute shell command
  • random: 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

secret_template_renderer-0.2.0.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

secret_template_renderer-0.2.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file secret_template_renderer-0.2.0.tar.gz.

File metadata

  • Download URL: secret_template_renderer-0.2.0.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

Hashes for secret_template_renderer-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5cf04c1be1caa7cb176f5167474004b0dd946d434629b4ac4ca019241fd0be0a
MD5 8702fb636284fdcfd1b8dc0cca2c13e0
BLAKE2b-256 36ccd1a076c6c9d1c55e9d6b4313535cc6662b33b786d652b18131a4a231d70f

See more details on using hashes here.

File details

Details for the file secret_template_renderer-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for secret_template_renderer-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 311f32ec128e92dd4b71259c6784daf21a8e8b74b1c9f8510c72efdcd027dc67
MD5 57686db2b3e24f63f3a07a2467f6b04a
BLAKE2b-256 9c35994b392238531676911ec48a0691ba3af2a6fcee9470a55719636f92021f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page