-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathGetByIdExample.java
More file actions
66 lines (53 loc) · 2.04 KB
/
GetByIdExample.java
File metadata and controls
66 lines (53 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
Copyright (c) 2022 Skyflow, Inc.
*/
package com.example;
import com.skyflow.entities.RedactionType;
import com.skyflow.entities.ResponseToken;
import com.skyflow.entities.SkyflowConfiguration;
import com.skyflow.entities.TokenProvider;
import com.skyflow.errors.SkyflowException;
import com.skyflow.serviceaccount.util.Token;
import com.skyflow.vault.Skyflow;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
public class GetByIdExample {
public static void main(String[] args) {
try {
SkyflowConfiguration config = new SkyflowConfiguration("<your_vaultID>",
"<your_vaultURL>", new DemoTokenProvider());
Skyflow skyflowClient = Skyflow.init(config);
JSONObject records = new JSONObject();
JSONArray recordsArray = new JSONArray();
JSONObject record = new JSONObject();
JSONArray ids = new JSONArray();
ids.add("<your_skyflowId>");
record.put("ids", ids);
record.put("table", "<you_table_name>");
record.put("redaction", RedactionType.PLAIN_TEXT.toString());
recordsArray.add(record);
records.put("records", recordsArray);
JSONObject response = skyflowClient.getById(records);
} catch (SkyflowException e) {
e.printStackTrace();
System.out.println(e.getData());
}
}
static class DemoTokenProvider implements TokenProvider {
private String bearerToken = null;
@Override
public String getBearerToken() throws Exception {
ResponseToken response = null;
try {
String filePath = "<YOUR_CREDENTIALS_FILE_PATH>";
if(Token.isExpired(bearerToken)) {
response = Token.generateBearerToken(filePath);
bearerToken = response.getAccessToken();
}
} catch (SkyflowException e) {
e.printStackTrace();
}
return bearerToken;
}
}
}