Skip to content

Commit fa78cf5

Browse files
SK-2067 flow db sdk with examples
1 parent bca7793 commit fa78cf5

137 files changed

Lines changed: 7130 additions & 6128 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 0 additions & 1380 deletions
This file was deleted.

pom.xml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,24 @@
5151
<dependency>
5252
<groupId>com.fasterxml.jackson.core</groupId>
5353
<artifactId>jackson-core</artifactId>
54-
<version>2.13.0</version>
54+
<version>2.15.3</version> <!-- or the latest stable version -->
5555
</dependency>
56+
<dependency>
57+
<groupId>com.fasterxml.jackson.core</groupId>
58+
<artifactId>jackson-databind</artifactId>
59+
<version>2.13.4.2</version>
60+
</dependency>
61+
<dependency>
62+
<groupId>com.fasterxml.jackson.datatype</groupId>
63+
<artifactId>jackson-datatype-jdk8</artifactId>
64+
<version>2.17.2</version>
65+
</dependency>
66+
<dependency>
67+
<groupId>com.fasterxml.jackson.datatype</groupId>
68+
<artifactId>jackson-datatype-jsr310</artifactId>
69+
<version>2.17.2</version>
70+
</dependency>
71+
5672
<dependency>
5773
<groupId>com.googlecode.json-simple</groupId>
5874
<artifactId>json-simple</artifactId>
@@ -103,6 +119,11 @@
103119
<version>2.0.9</version>
104120
<scope>test</scope>
105121
</dependency>
122+
<dependency>
123+
<groupId>com.squareup.okhttp3</groupId>
124+
<artifactId>okhttp</artifactId>
125+
<version>4.12.0</version>
126+
</dependency>
106127
</dependencies>
107128

108129
<build>
@@ -184,6 +205,14 @@
184205
</execution>
185206
</executions>
186207
</plugin>
208+
<plugin>
209+
<groupId>org.apache.maven.plugins</groupId>
210+
<artifactId>maven-compiler-plugin</artifactId>
211+
<configuration>
212+
<source>8</source>
213+
<target>8</target>
214+
</configuration>
215+
</plugin>
187216
</plugins>
188217
</build>
189218

samples/src/main/java/com/example/BearerTokenGenerationUsingThreadsExample.java

Lines changed: 0 additions & 48 deletions
This file was deleted.

samples/src/main/java/com/example/BearerTokenWithContextGenerationExample.java

Lines changed: 0 additions & 46 deletions
This file was deleted.

samples/src/main/java/com/example/DeleteExample.java

Lines changed: 0 additions & 72 deletions
This file was deleted.
Lines changed: 54 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,61 @@
1-
/*
2-
Copyright (c) 2022 Skyflow, Inc.
3-
*/
4-
package com.example;
1+
package com.skyflow;
52

6-
import com.skyflow.entities.RedactionType;
7-
import com.skyflow.entities.ResponseToken;
8-
import com.skyflow.entities.SkyflowConfiguration;
9-
import com.skyflow.entities.TokenProvider;
10-
import com.skyflow.errors.SkyflowException;
11-
import com.skyflow.serviceaccount.util.Token;
12-
import com.skyflow.vault.Skyflow;
13-
import org.json.simple.JSONArray;
14-
import org.json.simple.JSONObject;
3+
// Required imports for Skyflow API and HTTP client functionality
4+
import java.util.ArrayList;
5+
import java.util.List;
156

7+
import com.skyflow.api.ApiClient;
8+
import com.skyflow.api.resources.flowservice.requests.V1DetokenizeRequest;
9+
import com.skyflow.api.types.V1DetokenizeResponse;
10+
import com.skyflow.api.types.V1TokenGroupRedactions;
1611

17-
public class DetokenizeExample {
12+
import okhttp3.OkHttpClient;
13+
import okhttp3.Request;
1814

15+
/**
16+
* Example demonstrating detokenization operations using Skyflow API
17+
*/
18+
public class DetokenizeSample {
1919
public static void main(String[] args) {
20-
21-
try {
22-
SkyflowConfiguration config = new SkyflowConfiguration(
23-
"<your_vaultID>",
24-
"<your_vaultURL>",
25-
new DemoTokenProvider()
26-
);
27-
Skyflow skyflowClient = Skyflow.init(config);
28-
JSONObject records = new JSONObject();
29-
JSONArray recordsArray = new JSONArray();
30-
31-
JSONObject record1 = new JSONObject();
32-
record1.put("token", "<your_token>");
33-
record1.put("redaction", RedactionType.MASKED.toString());
34-
35-
JSONObject record2 = new JSONObject();
36-
record2.put("token", "<your_token>"); // default Redaction "PLAIN_TEXT" will be applied for record2
37-
38-
recordsArray.add(record1);
39-
recordsArray.add(record2);
40-
records.put("records", recordsArray);
41-
42-
JSONObject response = skyflowClient.detokenize(records);
43-
System.out.println(response);
44-
} catch (SkyflowException e) {
45-
e.printStackTrace();
46-
System.out.println(e.getData());
47-
}
48-
49-
}
50-
51-
static class DemoTokenProvider implements TokenProvider {
52-
53-
private String bearerToken = null;
54-
55-
@Override
56-
public String getBearerToken() throws Exception {
57-
ResponseToken response = null;
58-
try {
59-
String filePath = "<YOUR_CREDENTIALS_FILE_PATH>";
60-
if(Token.isExpired(bearerToken)) {
61-
response = Token.generateBearerToken(filePath);
62-
bearerToken = response.getAccessToken();
63-
}
64-
} catch (SkyflowException e) {
65-
e.printStackTrace();
66-
}
67-
68-
return bearerToken;
69-
}
20+
// Initialize HTTP client with Bearer token authentication for API requests
21+
// This client will automatically add the Bearer token to all requests
22+
OkHttpClient authClient = new OkHttpClient.Builder()
23+
.addInterceptor(chain -> {
24+
Request original = chain.request();
25+
Request requestWithAuth = original.newBuilder()
26+
.header("Authorization", "Bearer " + "<BEARER_TOKEN>")
27+
.build();
28+
return chain.proceed(requestWithAuth);
29+
})
30+
.build();
31+
32+
// Create Skyflow API client with vault URL and auth client
33+
ApiClient client = ApiClient.builder().url("<VAULT_URL>").httpClient(authClient).build();
34+
35+
// Create a list to store tokens that need to be detokenized
36+
List<String> tokens = new ArrayList<>();
37+
tokens.add("<TOKEN>");
38+
39+
// Configure redaction settings for token groups
40+
List<V1TokenGroupRedactions> red = new ArrayList<>();
41+
// Create redaction configuration for specific token group
42+
V1TokenGroupRedactions r = V1TokenGroupRedactions.builder()
43+
.redaction("<REDACTION_TYPE>")
44+
.tokenGroupName("<TOKEN_GROUP_NAME>")
45+
.build();
46+
red.add(r);
47+
48+
// Build the detokenize request with vault ID, tokens and redaction settings
49+
V1DetokenizeRequest req = V1DetokenizeRequest.builder()
50+
.vaultId("<VAULT_ID>")
51+
.tokens(tokens)
52+
.tokenGroupRedactions(red)
53+
.build();
54+
55+
// Execute the detokenize operation and get the response
56+
V1DetokenizeResponse res = client.flowservice().detokenize(req);
57+
58+
// Print the operation result
59+
System.out.println("response is" + res);
7060
}
7161
}

0 commit comments

Comments
 (0)