Skip to content

Commit 0a169c8

Browse files
authored
fix(get_vault_entries): implement pagination for fetching all vault entries (#22)
1 parent 57ec7bb commit 0a169c8

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

galaxy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
namespace: devolutions
22
name: dvls
3-
version: 1.2.3
3+
version: 1.2.4
44
readme: README.md
55
authors:
6-
- Danny Bédard <[email protected]>
6+
- Danny Bédard <[email protected]>
77
description: >
88
Ansible collection for interacting with Devolutions Server (DVLS). It provides modules for authentication,
99
retrieving server information and vaults, and performing create, read and update operations on secrets.

plugins/module_utils/vaults.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,34 @@ def get_vault_entry_from_type(server_base_url, token, vault_id, entry_type):
103103
def get_vault_entries(server_base_url, token, vault_id):
104104
vault_url = f"{server_base_url}/api/v1/vault/{vault_id}/entry"
105105
vault_headers = {"Content-Type": "application/json", "tokenId": token}
106+
all_entries = []
107+
page = 1
106108

107-
try:
108-
response = requests.get(vault_url, headers=vault_headers)
109-
response.raise_for_status()
109+
response = requests
110110

111-
json_data = response.json()
112-
if "data" not in json_data:
113-
raise ValueError(f"'data' key missing in response: {json_data}")
114-
115-
return json_data.get("data", [])
111+
try:
112+
while True:
113+
response = requests.get(
114+
vault_url,
115+
headers=vault_headers,
116+
params={"pageNumber": page},
117+
)
118+
response.raise_for_status()
119+
json_data = response.json()
120+
if "data" not in json_data:
121+
raise ValueError(f"'data' key missing in response: {json_data}")
122+
entries = json_data.get("data", [])
123+
if not entries:
124+
break
125+
126+
all_entries.extend(entries)
127+
128+
if page >= json_data.get("totalPage", 0):
129+
break
130+
131+
page += 1
132+
133+
return all_entries
116134
except Exception as e:
117135
raise Exception(f"An error occurred while getting vault entries: {e}")
118136

tests/integration/test_manage_secrets.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
vault_id: "{{ lookup('env', 'DVLS_VAULT_ID') }}"
1313
register: all_secrets
1414

15+
- name: Check secrets
16+
ansible.builtin.debug:
17+
msg: "{{ all_secrets }}"
18+
1519
- name: Check secrets
1620
ansible.builtin.debug:
1721
msg: "Number of secret in vault: {{ all_secrets | length }}"

0 commit comments

Comments
 (0)