Repository: peopledoc/vault-cli

Issue:
add support for templates in dict
Currently the "template" feature of vault-cli only works when the value is a string (`{"value": "!template!..."}`

We would like to also support templates when values are dict. For example:
```
{
  "value": {
    "a": "!template!...",
    "b": "!template!...",
    "c": "value",
  }
}
```

Discussion:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9a4a438..ee0f141 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@ CHANGELOG
 - Add implicit and explicit caching (#102 / #103)
 - Add `config_file=` in lib mode
 - Add a `--flat` option to the `get-all` command (the new output uses full paths as dictionnary key)
+- Add support of templates when values are dict
 
 0.9.0 (2019-07-11)
 ------------------
diff --git a/vault_cli/client.py b/vault_cli/client.py
index d50508d..74f89d5 100644
--- a/vault_cli/client.py
+++ b/vault_cli/client.py
@@ -422,6 +422,8 @@ class VaultClientBase:
     template_prefix = "!template!"
 
     def _render_template_value(self, secret: types.JSONValue) -> types.JSONValue:
+        if isinstance(secret, dict):
+            return {k: self._render_template_value(v) for k, v in secret.items()}
         if not isinstance(secret, str):
             return secret
 


Test patch:
diff --git a/tests/unit/test_client_base.py b/tests/unit/test_client_base.py
index d8376e5..1bfff71 100644
--- a/tests/unit/test_client_base.py
+++ b/tests/unit/test_client_base.py
@@ -366,6 +366,14 @@ def test_vault_client_base_render_template_path_not_found(vault):
         ({"a": {"value": "!template!b"}, "b": {"value": "c"}}, "b"),
         # Secret is a template
         ({"a": {"value": "!template!{{ vault('b') }}"}, "b": {"value": "c"}}, "c"),
+        # Secret is a dict with containing a template
+        (
+            {
+                "a": {"value": {"x": "!template!{{ vault('b') }}", "y": "yay"}},
+                "b": {"value": "c"},
+            },
+            {"x": "c", "y": "yay"},
+        ),
         # Finite recursion
         (
             {