Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added get_child_folder_ids_by_folderid #44

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions delinea/secrets/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,37 @@ def get_secret_ids_by_folderid(self, folder_id):
secret_ids.append(secret["id"])

return secret_ids

def get_child_folder_ids_by_folderid(self, folder_id):
"""Gets a list of child folder ids by folder_id

:param folder_id: the id of the folder
:type id: int
:return: a ``list`` of the child folder id's
:rtype: ``list``
:raise: :class:`SecretServerAccessError` when the caller does not have
permission to access the secret
:raise: :class:`SecretServerError` when the REST API call fails for
any other reason
"""

params = {"getAllChildren": True}
endpoint_url = f"{self.api_url}/folders/{folder_id}"
params["take"] = self.process(
requests.get(endpoint_url, params=params, headers=self.headers())
).text
response = self.search_secrets(query_params=params)

try:
response = json.loads(response)
except json.JSONDecodeError:
raise SecretServerError(response)

child_folder_ids = []
for childFolder in response["childFolders"]:
child_folder_ids.append(childFolder["id"])

return child_folder_ids

class SecretServerV0(SecretServer):
"""A class that uses an *OAuth2 Bearer Token* to access the Secret Server
Expand Down
4 changes: 4 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ def test_nonexistent_secret(secret_server):

def test_server_secret_ids_by_folderid(env_vars, secret_server):
assert type(secret_server.get_secret_ids_by_folderid(env_vars["folder_id"])) is list


def test_server_child_folder_ids_by_folderid(env_vars, secret_server):
assert type(secret_server.get_child_folder_ids_by_folderid(env_vars["folder_id"])) is list
Loading