Skip to content

Commit 57ec7bb

Browse files
committed
fix(create_secret): prevent moving existing credentials to root if no path is provided
1 parent 18f8ca7 commit 57ec7bb

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

galaxy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace: devolutions
22
name: dvls
3-
version: 1.2.2
3+
version: 1.2.3
44
readme: README.md
55
authors:
66
- Danny Bédard <[email protected]>

plugins/module_utils/vaults.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ def get_vault_entries(server_base_url, token, vault_id):
117117
raise Exception(f"An error occurred while getting vault entries: {e}")
118118

119119

120-
def find_entry_by_name(entries, name):
120+
def find_entry_by_name(entries, name, path=""):
121121
for entry in entries:
122-
if entry.get("name") == name:
122+
if entry.get("name") == name and entry.get("path") == path:
123123
return entry
124124
return None

plugins/modules/create_secret.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,13 @@ def run_module():
150150
password = secret.get("value")
151151
secret_type = secret.get("secret_type")
152152
secret_subtype = secret.get("secret_subtype")
153-
secret_path = secret.get("secret_path")
154153
description = secret.get("secret_description")
155154

155+
if secret.get("secret_path") is None:
156+
secret_path = ""
157+
else:
158+
secret_path = secret.get("secret_path")
159+
156160
vault_id = module.params.get("vault_id")
157161

158162
try:
@@ -178,7 +182,7 @@ def run_module():
178182
)
179183

180184
# when an existing entry is found, it gets updated. Otherwise a new entry gets created
181-
entry = find_entry_by_name(path_entries, secret_name)
185+
entry = find_entry_by_name(path_entries, secret_name, secret_path)
182186
if entry:
183187
vault_url = f"{server_base_url}/api/v1/vault/{vault_id}/entry/{entry['id']}"
184188
response = requests.put(vault_url, headers=vault_headers, json=vault_body)

0 commit comments

Comments
 (0)