Skip to content

Commit 9650c05

Browse files
authored
Supply authentication credentials for keyspace operations (#29)
## 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 Java to these recent changes. ## What are the changes implemented in this PR? - Builder methods in `RequestBuilder.Keyspace` now accept `username` and `password` - `Keyspaces` constructor now accepts `username` and `password` - Bump `@graknlabs_protocol` to latest version
1 parent b116990 commit 9650c05

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

GraknClient.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public GraknClient(String address, String username, String password) {
101101
.usePlaintext().build();
102102
this.username = username;
103103
this.password = password;
104-
keyspaces = new Keyspaces(channel);
104+
keyspaces = new Keyspaces(channel, this.username, this.password);
105105
}
106106

107107
public GraknClient overrideChannel(ManagedChannel channel) {
@@ -557,20 +557,24 @@ protected final T computeNext() {
557557
*/
558558

559559
public static final class Keyspaces {
560+
private String username;
561+
private String password;
560562

561563
private KeyspaceServiceBlockingStub keyspaceBlockingStub;
562564

563-
public Keyspaces(ManagedChannel channel) {
565+
public Keyspaces(ManagedChannel channel, String username, String password) {
564566
keyspaceBlockingStub = KeyspaceServiceGrpc.newBlockingStub(channel);
567+
this.username = username;
568+
this.password = password;
565569
}
566570

567571
public void delete(String name) {
568-
KeyspaceProto.Keyspace.Delete.Req request = RequestBuilder.Keyspace.delete(name);
572+
KeyspaceProto.Keyspace.Delete.Req request = RequestBuilder.Keyspace.delete(name, this.username, this.password);
569573
keyspaceBlockingStub.delete(request);
570574
}
571575

572576
public List<String> retrieve() {
573-
KeyspaceProto.Keyspace.Retrieve.Req request = RequestBuilder.Keyspace.retrieve();
577+
KeyspaceProto.Keyspace.Retrieve.Req request = RequestBuilder.Keyspace.retrieve(this.username, this.password);
574578
return ImmutableList.copyOf(keyspaceBlockingStub.retrieve(request).getNamesList().iterator());
575579
}
576580
}

dependencies/graknlabs/dependencies.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ 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
40-
)
39+
commit = "887409713c38deeebbdae01fa00946097887d20c", # sync-marker: do not remove this comment, this is used for sync-dependencies by @graknlabs_protocol
40+
)

rpc/RequestBuilder.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,26 @@ static ConceptProto.AttributeType.DATA_TYPE dataType(AttributeType.DataType<?> d
270270
*/
271271
public static class Keyspace {
272272

273-
public static KeyspaceProto.Keyspace.Delete.Req delete(String name) {
274-
return KeyspaceProto.Keyspace.Delete.Req.newBuilder().setName(name).build();
273+
public static KeyspaceProto.Keyspace.Delete.Req delete(String name, String username, String password) {
274+
KeyspaceProto.Keyspace.Delete.Req.Builder builder = KeyspaceProto.Keyspace.Delete.Req.newBuilder();
275+
if (username != null) {
276+
builder.setUsername(username);
277+
}
278+
if (password != null) {
279+
builder.setPassword(password);
280+
}
281+
return builder.setName(name).build();
275282
}
276283

277-
public static KeyspaceProto.Keyspace.Retrieve.Req retrieve() {
278-
return KeyspaceProto.Keyspace.Retrieve.Req.newBuilder().build();
284+
public static KeyspaceProto.Keyspace.Retrieve.Req retrieve(String username, String password) {
285+
KeyspaceProto.Keyspace.Retrieve.Req.Builder builder = KeyspaceProto.Keyspace.Retrieve.Req.newBuilder();
286+
if (username != null) {
287+
builder.setUsername(username);
288+
}
289+
if (password != null) {
290+
builder.setPassword(password);
291+
}
292+
return builder.build();
279293
}
280294
}
281295
}

0 commit comments

Comments
 (0)