import jinja2
from typing import Optional
from typing import Mapping


def template_rendered(
    template_env: jinja2.Environment,
    template_file: str,
    template_data: Optional[Mapping[str, str]] = None,
) -> str:
    """
    Utilize Jinja2 to produce a data field for a ConfigMap resource.
    Mostly useful for taking templates and turning them into fields used in
    the data: {} payload.
    """
    template = template_env.get_template(template_file)
    return template.render(template_data)