Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a logger warning otherwise it's not displayed properly. #200

Merged
merged 1 commit into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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