From f7140225a87526cdb518d01daef209886706d312 Mon Sep 17 00:00:00 2001 From: Ivan Fernandez Calvo Date: Thu, 23 May 2024 12:31:26 +0200 Subject: [PATCH] fix: support more than 10 secrets versions on gcp_secret_manager --- plugins/lookup/gcp_secret_manager.py | 5 ++++- plugins/modules/gcp_secret_manager.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/lookup/gcp_secret_manager.py b/plugins/lookup/gcp_secret_manager.py index bd9ca55..b3eeaf9 100644 --- a/plugins/lookup/gcp_secret_manager.py +++ b/plugins/lookup/gcp_secret_manager.py @@ -208,7 +208,10 @@ class LookupModule(LookupBase): self.raise_error(module, f"unable to list versions of secret {response.status_code}") version_list = response.json() if "versions" in version_list: - return sorted(version_list['versions'], key=lambda d: d['name'])[-1]['name'].split('/')[-1] + versions_numbers = [] + for version in version_list['versions']: + versions_numbers.append(version['name'].split('/')[-1]) + return sorted(versions_numbers, key=int)[-1] else: self.raise_error(module, f"Unable to list secret versions via {response.request.url}: {response.json()}") diff --git a/plugins/modules/gcp_secret_manager.py b/plugins/modules/gcp_secret_manager.py index f8d5623..91b186d 100644 --- a/plugins/modules/gcp_secret_manager.py +++ b/plugins/modules/gcp_secret_manager.py @@ -261,7 +261,10 @@ def fetch_resource(module, allow_not_found=True): return None if "versions" in version_list: - latest_version = sorted(version_list['versions'], key=lambda d: d['name'])[-1]['name'].split('/')[-1] + versions_numbers = [] + for version in version_list['versions']: + versions_numbers.append(version['name'].split('/')[-1]) + latest_version = sorted(versions_numbers, key=int)[-1] module.params['calc_version'] = latest_version else: # if this occurs, there are no available secret versions