Skip to content

Commit 1aeb49d

Browse files
chore: Sync dgo + deprecate Slash endpoint method (GRAPHQL-1141) (#167)
This PR does following things: * Make transaction context more robust (Ref: dgraph-io/dgo#146) * Deprecate `DgraphClient.clientStubfromSlashEndpoint` (Ref: https://discuss.dgraph.io/t/regarding-slash-cloud-dgraph-endpoints-in-the-clients/13492) * Fix a test to work with dgraph v21.03 * Fix typo in CHANGELOG.md
1 parent 72ce458 commit 1aeb49d

File tree

5 files changed

+39
-20
lines changed

5 files changed

+39
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ and this project adheres to [Calendar Versioning](https://calver.org/) starting
2222

2323
## [20.03.2] - 2020-10-27
2424
### Added
25-
* feat: Support for Slash GraphqQL endpoint ([#158])
25+
* feat: Support for Slash GraphQL endpoint ([#158])
2626

2727
[#158]: https://github.com/dgraph-io/dgraph4j/pull/158
2828

src/main/java/io/dgraph/AsyncTransaction.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,11 @@ public CompletableFuture<Response> doRequest(Request request) {
194194
mutated = true;
195195
}
196196

197-
Request requestStartTs = Request.newBuilder(request).setStartTs(context.getStartTs()).build();
197+
Request requestStartTs =
198+
Request.newBuilder(request)
199+
.setStartTs(context.getStartTs())
200+
.setHash(context.getHash())
201+
.build();
198202

199203
return client
200204
.runWithRetries(
@@ -294,6 +298,8 @@ public CompletableFuture<Void> discard() {
294298
private void mergeContext(final TxnContext src) {
295299
TxnContext.Builder builder = TxnContext.newBuilder(context);
296300

301+
builder.setHash(src.getHash());
302+
297303
if (context.getStartTs() == 0) {
298304
builder.setStartTs(src.getStartTs());
299305
} else if (context.getStartTs() != src.getStartTs()) {

src/main/java/io/dgraph/DgraphClient.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ public class DgraphClient {
4848
* https://your-slash-instance.cloud.dgraph.io/graphql
4949
* @param apiKey The API key used to connect to your Slash GraphQL instance.
5050
* @return A new DgraphGrpc.DgraphStub object to be used with DgraphClient/DgraphAsyncClient.
51+
* @deprecated This method will be removed in v21.07 release. For more details, see:
52+
* https://discuss.dgraph.io/t/regarding-slash-cloud-dgraph-endpoints-in-the-clients/13492
5153
*/
54+
@Deprecated
5255
public static DgraphGrpc.DgraphStub clientStubFromSlashEndpoint(
5356
String slashEndpoint, String apiKey) throws MalformedURLException {
5457
String[] parts = new URL(slashEndpoint).getHost().split("[.]", 2);

src/main/proto/api.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ message Request {
5757
RDF = 1;
5858
}
5959
RespFormat resp_format = 14;
60+
string hash = 15;
6061
}
6162

6263
message Uids {
@@ -128,6 +129,7 @@ message TxnContext {
128129
bool aborted = 3;
129130
repeated string keys = 4; // List of keys to be used for conflict detection.
130131
repeated string preds = 5; // List of predicates involved in this transaction.
132+
string hash = 6;
131133
}
132134

133135
message Check {}

src/test/java/io/dgraph/AclTest.java

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
public class AclTest extends DgraphIntegrationTest {
1717
private static final String USER_ID = "alice";
1818
private static final String USER_PASSWORD = "simplepassword";
19-
private static final String GROOT_PASSWORD = "password";
19+
private static final String GUARDIAN_CREDS = "user=groot;password=password;namespace=0";
2020
private static final String PREDICATE_TO_READ = "predicate_to_read";
2121
private static final String PREDICATE_TO_WRITE = "predicate_to_write";
2222
private static final String PREDICATE_TO_ALTER = "predicate_to_alter";
@@ -101,8 +101,8 @@ private void createGroupAndACLs(String group, boolean addUserToGroup)
101101
DGRAPH_ENDPOINT,
102102
"-g",
103103
group,
104-
"-x",
105-
GROOT_PASSWORD);
104+
"--guardian-creds",
105+
GUARDIAN_CREDS);
106106

107107
if (addUserToGroup) {
108108
checkCmd(
@@ -116,8 +116,8 @@ private void createGroupAndACLs(String group, boolean addUserToGroup)
116116
USER_ID,
117117
"--group_list",
118118
group,
119-
"-x",
120-
GROOT_PASSWORD);
119+
"--guardian-creds",
120+
GUARDIAN_CREDS);
121121
}
122122

123123
// add READ permission on the predicate_to_read to the group
@@ -134,8 +134,8 @@ private void createGroupAndACLs(String group, boolean addUserToGroup)
134134
PREDICATE_TO_READ,
135135
"-m",
136136
"4",
137-
"-x",
138-
GROOT_PASSWORD);
137+
"--guardian-creds",
138+
GUARDIAN_CREDS);
139139

140140
// also add READ permission on the attribute queryAttr, which is used inside the query block
141141
checkCmd(
@@ -151,8 +151,8 @@ private void createGroupAndACLs(String group, boolean addUserToGroup)
151151
QUERY_ATTR,
152152
"-m",
153153
"4",
154-
"-x",
155-
GROOT_PASSWORD);
154+
"--guardian-creds",
155+
GUARDIAN_CREDS);
156156

157157
checkCmd(
158158
"unable to add WRITE permission on " + PREDICATE_TO_WRITE + " to the group " + group,
@@ -167,8 +167,8 @@ private void createGroupAndACLs(String group, boolean addUserToGroup)
167167
PREDICATE_TO_WRITE,
168168
"-m",
169169
"2",
170-
"-x",
171-
GROOT_PASSWORD);
170+
"--guardian-creds",
171+
GUARDIAN_CREDS);
172172

173173
checkCmd(
174174
"unable to add ALTER permission on " + PREDICATE_TO_ALTER + " to the group " + group,
@@ -183,8 +183,8 @@ private void createGroupAndACLs(String group, boolean addUserToGroup)
183183
PREDICATE_TO_ALTER,
184184
"-m",
185185
"1",
186-
"-x",
187-
GROOT_PASSWORD);
186+
"--guardian-creds",
187+
GUARDIAN_CREDS);
188188
}
189189

190190
private void removeUserFromAllGroups() throws IOException, InterruptedException {
@@ -199,8 +199,8 @@ private void removeUserFromAllGroups() throws IOException, InterruptedException
199199
USER_ID,
200200
"--group_list",
201201
"",
202-
"-x",
203-
GROOT_PASSWORD);
202+
"--guardian-creds",
203+
GUARDIAN_CREDS);
204204
}
205205

206206
private void queryPredicateWithUserAccount(boolean shouldFail) {
@@ -280,7 +280,15 @@ private void verifyOperation(boolean shouldFail, String operation, Runnable runn
280280
private void resetUser() throws Exception {
281281
Process deleteUserCmd =
282282
new ProcessBuilder(
283-
"dgraph", "acl", "del", "-a", DGRAPH_ENDPOINT, "-u", USER_ID, "-x", GROOT_PASSWORD)
283+
"dgraph",
284+
"acl",
285+
"del",
286+
"-a",
287+
DGRAPH_ENDPOINT,
288+
"-u",
289+
USER_ID,
290+
"--guardian-creds",
291+
GUARDIAN_CREDS)
284292
.start();
285293
deleteUserCmd.waitFor();
286294

@@ -295,8 +303,8 @@ private void resetUser() throws Exception {
295303
USER_ID,
296304
"-p",
297305
USER_PASSWORD,
298-
"-x",
299-
GROOT_PASSWORD)
306+
"--guardian-creds",
307+
GUARDIAN_CREDS)
300308
.redirectErrorStream(true)
301309
.start();
302310
createUserCmd.waitFor();

0 commit comments

Comments
 (0)