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

Commit dd858f3

Browse files
authored
Supply authentication credentials for keyspace operations (#60)
## What is the goal of this PR? Recent changes in protocol (typedb/typedb-protocol#7) allow keyspace operations to be authenticated. This PR adapts Grakn Client Python to these recent changes. ## What are the changes implemented in this PR? - `KeyspaceService.retrieve` and `KeyspaceService.delete` now properly set credentials - Bump `@graknlabs_protocol` and `@graknlabs_grakn_core` to latest version
1 parent f7631cc commit dd858f3

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

dependencies/graknlabs/dependencies.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ def graknlabs_grakn_core():
2929
git_repository(
3030
name = "graknlabs_grakn_core",
3131
remote = "https://github.com/graknlabs/grakn",
32-
commit = "e68b03e886986846346a260346bd6743ab967f2e" # sync-marker: do not remove this comment, this is used for sync-dependencies by @graknlabs_grakn_core
32+
commit = "a1e73426c1c74155e6ab0e19d8992c22743bb579" # sync-marker: do not remove this comment, this is used for sync-dependencies by @graknlabs_grakn_core
3333
)
3434

3535
def graknlabs_protocol():
3636
git_repository(
3737
name = "graknlabs_protocol",
3838
remote = "https://github.com/graknlabs/protocol",
39-
commit = "dbbea5ae6870dc0624658091c221fe9fc292bad1" # sync-marker: do not remove this comment, this is used for sync-dependencies by @graknlabs_protocol
39+
commit = "f63c0771f37ab603f8e9f3100e06238f6cb85298" # sync-marker: do not remove this comment, this is used for sync-dependencies by @graknlabs_protocol
4040
)

grakn/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def __init__(self, uri, credentials=None):
1616
self.uri = uri
1717
self.credentials = credentials
1818
self._channel = grpc.insecure_channel(uri)
19-
self._keyspace_service = KeyspaceService(self.uri, self._channel)
19+
self._keyspace_service = KeyspaceService(self.uri, self._channel, credentials)
2020

2121
def session(self, keyspace):
2222
""" Open a session for a specific keyspace. Can be used as `with Grakn('localhost:48555').session(keyspace='test') as session: ... ` or as normal assignment"""

grakn/service/Keyspace/KeyspaceService.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,27 @@
2020
from grakn_protocol.keyspace.Keyspace_pb2_grpc import KeyspaceServiceStub
2121
import grakn_protocol.keyspace.Keyspace_pb2 as keyspace_messages
2222

23+
2324
class KeyspaceService(object):
2425

25-
def __init__(self, uri, channel):
26+
def __init__(self, uri, channel, credentials=None):
2627
self.uri = uri
2728
self.stub = KeyspaceServiceStub(channel)
29+
self.credentials = credentials
2830

2931
def retrieve(self):
3032
retrieve_request = keyspace_messages.Keyspace.Retrieve.Req()
33+
if self.credentials:
34+
retrieve_request.username = self.credentials['username']
35+
retrieve_request.password = self.credentials['password']
3136
response = self.stub.retrieve(retrieve_request)
3237
return list(response.names)
3338

3439
def delete(self, keyspace):
3540
delete_request = keyspace_messages.Keyspace.Delete.Req()
3641
delete_request.name = keyspace
42+
if self.credentials:
43+
delete_request.username = self.credentials['username']
44+
delete_request.password = self.credentials['password']
3745
self.stub.delete(delete_request)
3846
return

0 commit comments

Comments
 (0)