Skip to content

Commit

Permalink
Merge pull request #199 from peopledoc/templates-phase-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Joachim Jablon authored Oct 15, 2021
2 parents 1de6736 + b0281ab commit a458826
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/howto/templated_secrets.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Make a secret point to dynamic content
======================================

.. warning::

This feature will be removed from Vault-CLI in the next major version.

With ``vault-cli``, it's possible to have secret values be Jinja2_ templates. This is
useful if you have multiple related secrets that you would like to retrieve as a single
string.
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/test_client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,13 @@ def test_vault_client_base_get_secret(vault, vault_contents, expected):
assert vault.get_secret("a") == expected


def test_vault_client_base_get_secret_deprecation_warning(vault):
vault.db = {"a": {"value": "!template!b"}}

with pytest.warns(DeprecationWarning):
assert vault.get_secret("a") == {"value": "b"}


def test_vault_client_base_get_secret_template_root(vault):
vault.base_path = "base"
vault.db = {"/base/a": {"value": '!template!{{ vault("a").value }} yay'}}
Expand Down
9 changes: 9 additions & 0 deletions vault_cli/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import logging
import pathlib
import warnings
from typing import Dict, Iterable, List, Optional, Set, Tuple, Type, Union, cast

import hvac # type: ignore
Expand Down Expand Up @@ -520,6 +521,14 @@ def copy_secrets(
template_prefix = "!template!"

def _render_template_value(self, secret: types.JSONValue) -> types.JSONValue:

warnings.warn(
DeprecationWarning(
"Templated values are deprecated and will be removed in the "
"following major versions."
)
)

if isinstance(secret, dict):
return {k: self._render_template_value(v) for k, v in secret.items()}
if not isinstance(secret, str):
Expand Down

0 comments on commit a458826

Please sign in to comment.