Skip to content

Commit

Permalink
Merge pull request #200 from peopledoc/warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Joachim Jablon authored Oct 18, 2021
2 parents a458826 + 6d6fbad commit bbb4b5f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
7 changes: 4 additions & 3 deletions tests/unit/test_client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,11 +522,12 @@ 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):
def test_vault_client_base_get_secret_deprecation_warning(vault, caplog):
vault.db = {"a": {"value": "!template!b"}}
caplog.set_level("WARNING")

with pytest.warns(DeprecationWarning):
assert vault.get_secret("a") == {"value": "b"}
vault.get_secret("a")
assert "Templated values are deprecated" in caplog.records[0].message


def test_vault_client_base_get_secret_template_root(vault):
Expand Down
12 changes: 4 additions & 8 deletions vault_cli/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
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 @@ -522,13 +521,6 @@ def copy_secrets(

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 All @@ -537,6 +529,10 @@ def _render_template_value(self, secret: types.JSONValue) -> types.JSONValue:
if not secret.startswith(self.template_prefix):
return secret

logger.warn(
"Templated values are deprecated and will be removed in the "
"following major versions.",
)
return self.render_template(secret[len(self.template_prefix) :])

def _render_template_dict(
Expand Down

0 comments on commit bbb4b5f

Please sign in to comment.