Fix vault ext pillar return data for KV v2

This commit is contained in:
jeanluc 2022-09-12 14:17:22 +02:00 committed by Megan Wilhite
parent 468ebed676
commit 46339d9e79
2 changed files with 10 additions and 8 deletions

1
changelog/62651.fixed Normal file
View file

@ -0,0 +1 @@
Fixed vault ext pillar return data for KV v2

View file

@ -123,9 +123,9 @@ minion-passwd minionbadpasswd1
import logging import logging
log = logging.getLogger(__name__) from requests.exceptions import HTTPError
__func_alias__ = {"set_": "set"} log = logging.getLogger(__name__)
def __virtual__(): def __virtual__():
@ -162,12 +162,13 @@ def ext_pillar(
url = "v1/{}".format(path) url = "v1/{}".format(path)
response = __utils__["vault.make_request"]("GET", url) response = __utils__["vault.make_request"]("GET", url)
if response.status_code == 200: response.raise_for_status()
vault_pillar = response.json().get("data", {}) vault_pillar = response.json().get("data", {})
else:
log.info("Vault secret not found for: %s", path) if vault_pillar and version2["v2"]:
except KeyError: vault_pillar = vault_pillar["data"]
log.error("No such path in Vault: %s", path) except HTTPError:
log.info("Vault secret not found for: %s", path)
if nesting_key: if nesting_key:
vault_pillar = {nesting_key: vault_pillar} vault_pillar = {nesting_key: vault_pillar}