Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Commit 756beb7

Browse files
author
James Williams
authored
Add method to Cluster client to retrieve current user (#290)
## What is the goal of this PR? Add an API to be able retrieve the currently authenticated user. ## What are the changes implemented in this PR? Added functions: * `user(self) -> User` to the `TypeDBClusterClient` abstract class. * `user(self) -> User` to the `_ClusterClient` class. Added user step: `get connected user`.
1 parent 3a74440 commit 756beb7

File tree

5 files changed

+16
-4
lines changed

5 files changed

+16
-4
lines changed

dependencies/vaticle/repositories.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ def vaticle_typedb_behaviour():
3939
git_repository(
4040
name = "vaticle_typedb_behaviour",
4141
remote = "https://github.com/vaticle/typedb-behaviour",
42-
commit = "b4cbdd3aaf28428608fc88eae0852425df57fe25" # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour
42+
commit = "fbba9fc19042460760b852b765d356c9b3f4ebf0" # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour
4343
)

tests/behaviour/connection/user/user_steps.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ def _get_client(context: Context):
3232
return client
3333

3434

35+
@step("get connected user")
36+
def step_impl(context: Context):
37+
_get_client(context).user()
38+
39+
3540
@step("users contains: {username:Words}")
3641
def step_impl(context: Context, username: str):
3742
assert_that([u.username() for u in _get_client(context).users().all()], has_item(username))

typedb/api/connection/client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from typedb.api.connection.database import DatabaseManager, ClusterDatabaseManager
2424
from typedb.api.connection.options import TypeDBOptions
2525
from typedb.api.connection.session import TypeDBSession, SessionType
26-
from typedb.api.connection.user import UserManager
26+
from typedb.api.connection.user import UserManager, User
2727

2828

2929
class TypeDBClient(ABC):
@@ -66,3 +66,7 @@ def databases(self) -> ClusterDatabaseManager:
6666
@abstractmethod
6767
def users(self) -> UserManager:
6868
pass
69+
70+
@abstractmethod
71+
def user(self) -> User:
72+
pass

typedb/connection/cluster/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from typedb.api.connection.credential import TypeDBCredential
2525
from typedb.api.connection.options import TypeDBOptions, TypeDBClusterOptions
2626
from typedb.api.connection.session import SessionType
27-
from typedb.api.connection.user import UserManager
27+
from typedb.api.connection.user import UserManager, User
2828
from typedb.connection.cluster.database import _ClusterDatabase, _FailsafeTask
2929
from typedb.connection.cluster.database_manager import _ClusterDatabaseManager
3030
from typedb.connection.cluster.server_client import _ClusterServerClient
@@ -78,6 +78,9 @@ def is_open(self) -> bool:
7878
def users(self) -> UserManager:
7979
return self._user_manager
8080

81+
def user(self) -> User:
82+
return self.users().get(self._credential.username())
83+
8184
def databases(self) -> _ClusterDatabaseManager:
8285
return self._database_managers
8386

typedb/connection/cluster/user_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def contains(self, username: str) -> bool:
7575
def get(self, username: str) -> User:
7676
failsafe_task = _UserManagerFailsafeTask(
7777
self._client,
78-
lambda replica: _ClusterUser.of(self._client._stub(replica.address()).users_get(cluster_user_manager_get_req(username)).get_user(), self._client)
78+
lambda replica: _ClusterUser.of(self._client._stub(replica.address()).users_get(cluster_user_manager_get_req(username)).user, self._client)
7979
)
8080
return failsafe_task.run_primary_replica()
8181

0 commit comments

Comments
 (0)