Skip to content

[DE-670]: GET /_api/database/user #281

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

Merged
merged 2 commits into from
Sep 15, 2023
Merged
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
19 changes: 18 additions & 1 deletion arango/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ def response_handler(resp: Response) -> Json:
#######################

def databases(self) -> Result[List[str]]:
"""Return the names all databases.
"""Return the names of all databases.

:return: Database names.
:rtype: [str]
Expand All @@ -777,6 +777,23 @@ def response_handler(resp: Response) -> List[str]:

return self._execute(request, response_handler)

def databases_accessible_to_user(self) -> Result[List[str]]:
"""Return the names of all databases accessible by the user.

:return: Database names accesible by the current user.
:rtype: List[str]
:raise arango.exceptions.DatabaseListError: If retrieval fails.
"""
request = Request(method="get", endpoint="/_api/database/user")

def response_handler(resp: Response) -> List[str]:
if not resp.is_success:
raise DatabaseListError(resp, request)
result: List[str] = resp.body["result"]
return result

return self._execute(request, response_handler)

def has_database(self, name: str) -> Result[bool]:
"""Check if a database exists.

Expand Down
14 changes: 14 additions & 0 deletions tests/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,25 @@ def test_database_management(db, sys_db, bad_db):
# Test list databases
result = sys_db.databases()
assert "_system" in result
assert db.name in result

# Test list databases accesible to root user
result = sys_db.databases_accessible_to_user()
assert "_system" in result
assert db.name in result

# Test list databases accessible to user
result = db.databases_accessible_to_user()
assert result == [db.name]

# Test list databases with bad database
with assert_raises(DatabaseListError):
bad_db.databases()

# Test list accessible databases with bad database
with assert_raises(DatabaseListError):
bad_db.databases_accessible_to_user()

# Test create database
db_name = generate_db_name()
assert sys_db.has_database(db_name) is False
Expand Down