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

Commit 50d97da

Browse files
Safer cluster channel initialisation & better handling of invalid token errors (#306)
## What is the goal of this PR? When setting up a Check that the `_stub` attribute exists before we check if its value is `None`. We also update the way we handle expired tokens. ## What are the changes implemented in this PR? * Do a `hasattr` check before `self._stub is None` check in `_ClusterClient._new_channel` * Wrap errors where the server rejects authentication because the provided token is not (or no longer) valid.
1 parent 0d70c40 commit 50d97da

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

typedb/common/exception.py

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ def of_rpc(rpc_error: Union[RpcError, Call]) -> "TypeDBClientException":
4444
return TypeDBClientException(msg=UNABLE_TO_CONNECT, cause=rpc_error)
4545
elif rpc_error.code() is StatusCode.INTERNAL and "[RPL01]" in str(rpc_error):
4646
return TypeDBClientException(msg=CLUSTER_REPLICA_NOT_PRIMARY, cause=None)
47+
elif rpc_error.code() is StatusCode.UNAUTHENTICATED and "[CLS08]" in str(rpc_error):
48+
return TypeDBClientException(msg=CLUSTER_TOKEN_CREDENTIAL_INVALID, cause=None)
4749
elif rpc_error.code() is StatusCode.INTERNAL:
4850
return TypeDBClientException(msg=rpc_error.details(), cause=None)
4951
else:

typedb/connection/cluster/server_client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def _new_channel(self) -> grpc.Channel:
6060
self._channel_credentials,
6161
grpc.metadata_call_credentials(_CredentialAuth(
6262
credential=self._credential,
63-
token_fn=lambda: None if self._stub is None else self._stub.token()
63+
token_fn=lambda: None if (not hasattr(self, '_stub') or self._stub is None) else self._stub.token()
6464
))
6565
)
6666
return grpc.secure_channel(self._address, combined_credentials)

0 commit comments

Comments
 (0)