From 6d6fbad61913805005af1fa4bb007dcc8d0b1fe3 Mon Sep 17 00:00:00 2001 From: Joachim Jablon Date: Fri, 15 Oct 2021 18:07:48 +0200 Subject: [PATCH] Use a logger warning otherwise it's not displayed properly. Also move the warning to the correct location --- tests/unit/test_client_base.py | 7 ++++--- vault_cli/client.py | 12 ++++-------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/tests/unit/test_client_base.py b/tests/unit/test_client_base.py index cce3f36..5daa802 100644 --- a/tests/unit/test_client_base.py +++ b/tests/unit/test_client_base.py @@ -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): diff --git a/vault_cli/client.py b/vault_cli/client.py index ffbfad1..7527fec 100644 --- a/vault_cli/client.py +++ b/vault_cli/client.py @@ -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 @@ -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): @@ -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(