From 8d441604471b28dcb1b21d5279ec3d5a567f024f Mon Sep 17 00:00:00 2001 From: ku9nov Date: Thu, 30 Nov 2023 16:56:13 +0200 Subject: [PATCH] fix get single secret bug, upd secret_name variable --- README.md | 2 +- plugins/lookup/read_secrets.py | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1bcabf3..3b03a23 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ vars: read_all_secrets_within_scope: "{{ lookup('infisical.vault.read_secrets', token='<>', path='/', env_slug='dev', url='https://spotify.infisical.com') }}" # [{ "key": "HOST", "value": "google.com" }, { "key": "SMTP", "value": "gmail.smtp.edu" }] - read_secret_by_name_within_scope: "{{ lookup('infisical.vault.read_secrets', token='<>', path='/', env_slug='dev', name='HOST', url='https://spotify.infisical.com') }}" + read_secret_by_name_within_scope: "{{ lookup('infisical.vault.read_secrets', token='<>', path='/', env_slug='dev', secret_name='HOST', url='https://spotify.infisical.com') }}" # [{ "key": "HOST", "value": "google.com" }] ``` diff --git a/plugins/lookup/read_secrets.py b/plugins/lookup/read_secrets.py index 3e30077..acd89f1 100644 --- a/plugins/lookup/read_secrets.py +++ b/plugins/lookup/read_secrets.py @@ -56,7 +56,7 @@ vars: read_all_secrets_within_scope: "{{ lookup('infisical_vault', token='<>', path='/', env_slug='dev', url='https://spotify.infisical.com') }}" # [{ "key": "HOST", "value": "google.com" }, { "key": "SMTP", "value": "gmail.smtp.edu" }] - read_secret_by_name_within_scope: "{{ lookup('infisical_vault', token='<>', path='/', env_slug='dev', name='HOST', url='https://spotify.infisical.com') }}" + read_secret_by_name_within_scope: "{{ lookup('infisical_vault', token='<>', path='/', env_slug='dev', secret_name='HOST', url='https://spotify.infisical.com') }}" # [{ "key": "HOST", "value": "google.com" }] """ @@ -87,12 +87,11 @@ class LookupModule(LookupBase): def get_single_secret(self, client, secret_name, environment, path): try: - print(secret_name, environment, path) secret = client.get_secret(secret_name=secret_name, environment=environment, path=path) - return [{"value": s.secret_value, "key": s.secret_name}] + return [{"value": secret.secret_value, "key": secret.secret_name}] except Exception as e: print(e) - raise AnsibleError(f"Error fetching all secrets {e}") + raise AnsibleError(f"Error fetching single secret {e}") def get_all_secrets(self, client, environment="dev", path="/"): try: