Merge pull request #634 from kuisathaverat/fix/support_more_than_10_versions

fix: support more than 10 secrets versions on gcp_secret_manager
This commit is contained in:
Chris Hawk 2024-08-01 14:07:24 -07:00 committed by GitHub
commit d2aaad7212
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 2 deletions

View file

@ -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()}")

View file

@ -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