Skip to content

Commit 5ca3ba4

Browse files
SK-1863: Added a migration guide section in the README for transitioning from v1 to v2. (#158)
* SK-1863: Added migration from v1 to v2 section in readme
1 parent c7ba710 commit 5ca3ba4

File tree

1 file changed

+246
-0
lines changed

1 file changed

+246
-0
lines changed

README.md

Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The Skyflow Java SDK is designed to help with integrating Skyflow into a Java ba
2020
- [Service Account Bearer Token with Context Generation](#service-account-bearer-token-with-context-generation)
2121
- [Service Account Scoped Bearer Token Generation](#service-account-scoped-bearer-token-generation)
2222
- [Signed Data Tokens Generation](#signed-data-tokens-generation)
23+
- [Migrate from v1 to v2](#migrate-from-v1-to-v2)
2324
- [Vault APIs](#vault-apis)
2425
- [Insert](#insert-data-into-the-vault)
2526
- [Detokenize](#detokenize)
@@ -300,6 +301,251 @@ Notes:
300301
- Time to live value expects time as seconds.
301302
- The default time to live value is 60 seconds.
302303

304+
## Migrate from v1 to v2
305+
306+
Below are the steps to migrate the java sdk from v1 to v2.
307+
308+
### 1. Authentication Options
309+
In V2, we have introduced multiple authentication options.
310+
You can now provide credentials in the following ways:
311+
312+
- **API Key (Recommended)**
313+
- **Passing credentials as ENV.** (`SKYFLOW_CREDENTIALS`) (**Recommended**)
314+
- **Path to your credentials JSON file**
315+
- **Stringified JSON of your credentials**
316+
- **Bearer token**
317+
318+
These options allow you to choose the authentication method that best suits your use case.
319+
320+
### V1 (Old)
321+
```java
322+
static class DemoTokenProvider implements TokenProvider {
323+
@Override
324+
public String getBearerToken() throws Exception {
325+
ResponseToken res = null;
326+
try {
327+
String filePath = "<YOUR_CREDENTIALS_FILE_HERE>";
328+
res = Token.generateBearerToken(filePath);
329+
} catch (SkyflowException e) {
330+
e.printStackTrace();
331+
}
332+
return res.getAccessToken();
333+
}
334+
}
335+
```
336+
337+
### V2 (New): Passing one of the following:
338+
```java
339+
// Option 1: API Key (Recommended)
340+
Credentials skyflowCredentials = new Credentials();
341+
skyflowCredentials.setApiKey("<YOUR_API_KEY>"); // Replace <API_KEY> with your actual API key
342+
343+
// Option 2: Environment Variables (Recommended)
344+
// Set SKYFLOW_CREDENTIALS in your environment
345+
346+
// Option 3: Credentials File
347+
skyflowCredentials.setPath("<YOUR_CREDENTIALS_FILE_PATH>"); // Replace with the path to credentials file
348+
349+
// Option 4: Stringified JSON
350+
skyflowCredentials.setCredentialsString("<YOUR_CREDENTIALS_STRING>"); // Replace with the credentials string
351+
352+
// Option 5: Bearer Token
353+
skyflowCredentials.setToken("<BEARER_TOKEN>"); // Replace <BEARER_TOKEN> with your actual authentication token.
354+
```
355+
356+
**Notes:**
357+
- Use only ONE authentication method.
358+
- API Key or Environment Variables are recommended for production use.
359+
- Secure storage of credentials is essential.
360+
- For overriding behavior and priority order of credentials, refer to the README.
361+
362+
---
363+
364+
### 2. Client Initialization
365+
In V2, we have introduced a Builder design pattern for client initialization and added support for multi-vault. This allows you to configure multiple vaults during client initialization.
366+
367+
In V2, the log level is tied to each individual client instance.
368+
369+
During client initialization, you can pass the following parameters:
370+
- `vaultId` and `clusterId`: These values are derived from the vault ID & vault URL.
371+
- `env`: Specify the environment (e.g., SANDBOX or PROD).
372+
- `credentials`: The necessary authentication credentials.
373+
374+
### V1 (Old)
375+
```java
376+
// DemoTokenProvider class is an implementation of the TokenProvider interface
377+
DemoTokenProvider demoTokenProvider = new DemoTokenProvider();
378+
SkyflowConfiguration skyflowConfig = new SkyflowConfiguration("<VAULT_ID>","<VAULT_URL>", demoTokenProvider);
379+
Skyflow skyflowClient = Skyflow.init(skyflowConfig);
380+
```
381+
382+
### V2 (New)
383+
```java
384+
Credentials credentials = new Credentials();
385+
credentials.setPath("<YOUR_CREDENTIALS_FILE_PATH_1>"); // Replace with the path to the credentials file
386+
387+
// Configure the first vault (Blitz)
388+
VaultConfig config = new VaultConfig();
389+
config.setVaultId("<YOUR_VAULT>"); // Replace with the ID of the first vault
390+
config.setClusterId("<YOUR_CLUSTER>"); // Replace with the cluster ID of the first vault
391+
config.setEnv(Env.DEV); // Set the environment (e.g., DEV, STAGE, PROD)
392+
config.setCredentials(credentials); // Associate the credentials with the vault
393+
394+
// Set up credentials for the Skyflow client
395+
Credentials skyflowCredentials = new Credentials();
396+
skyflowCredentials.setPath("<YOUR_CREDENTIALS_FILE_PATH_2>"); // Replace with the path to another credentials file
397+
398+
// Create a Skyflow client and add vault configurations
399+
Skyflow skyflowClient = Skyflow.builder()
400+
.setLogLevel(LogLevel.DEBUG) // Enable debugging for detailed logs
401+
.addVaultConfig(config) // Add the first vault configuration
402+
.addSkyflowCredentials(skyflowCredentials) // Add general Skyflow credentials
403+
.build();
404+
```
405+
406+
**Key Changes:**
407+
- `vaultUrl` replaced with `clusterId`.
408+
- Added environment specification (`env`).
409+
- Instance-specific log levels.
410+
411+
---
412+
413+
### 3. Request & Response Structure
414+
In V2, we have removed the use of JSON objects from a third-party package. Instead, we have transitioned to accepting native ArrayList and HashMap data structures and adopted the Builder pattern for request creation. This request need
415+
- `table`: The name of the table.
416+
- `values`: An array of objects containing the data to be inserted.
417+
The response will be of type InsertResponse class, which contains insertedFields and errors.
418+
419+
### V1 (Old) Request Building
420+
```java
421+
JSONObject recordsJson = new JSONObject();
422+
JSONArray recordsArrayJson = new JSONArray();
423+
424+
JSONObject recordJson = new JSONObject();
425+
recordJson.put("table", "cards");
426+
427+
JSONObject fieldsJson = new JSONObject();
428+
fields.put("cardNumber", "41111111111");
429+
fields.put("cvv", "123");
430+
431+
recordJson.put("fields", fieldsJson);
432+
recordsArrayJson.add(record);
433+
recordsJson.put("records", recordsArrayJson);
434+
try {
435+
JSONObject insertResponse = skyflowClient.insert(records);
436+
System.out.println(insertResponse);
437+
} catch (SkyflowException exception) {
438+
System.out.println(exception);
439+
}
440+
```
441+
442+
### V2 (New) Request Building
443+
```java
444+
ArrayList<HashMap<String, Object>> values = new ArrayList<>();
445+
HashMap<String, Object> value = new HashMap<>();
446+
value.put("<COLUMN_NAME_1>", "<COLUMN_VALUE_1>"); // Replace with column name and value
447+
value.put("<COLUMN_NAME_2>", "<COLUMN_VALUE_2>"); // Replace with another column name and value
448+
values.add(values);
449+
450+
ArrayList<HashMap<String, Object>> tokens = new ArrayList<>();
451+
HashMap<String, Object> token = new HashMap<>();
452+
token.put("<COLUMN_NAME_2>", "<TOKEN_VALUE_2>"); // Replace with the token for COLUMN_NAME_2
453+
tokens.add(token);
454+
455+
InsertRequest insertRequest = InsertRequest.builder()
456+
.table("<TABLE_NAME>") // Replace with the table name
457+
.continueOnError(true) // Continue inserting even if some records fail
458+
.tokenMode(TokenMode.ENABLE) // Enable BYOT for token validation
459+
.values(values) // Data to insert
460+
.tokens(tokens) // Provide tokens for BYOT columns
461+
.returnTokens(true) // Return tokens along with the response
462+
.build();
463+
```
464+
465+
### V1 (Old) Response Structure
466+
```json
467+
{
468+
"records": [
469+
{
470+
"table": "cards",
471+
"fields": {
472+
"skyflow_id": "16419435-aa63-4823-aae7-19c6a2d6a19f",
473+
"cardNumber": "f3907186-e7e2-466f-91e5-48e12c2bcbc1",
474+
"cvv": "1989cb56-63da-4482-a2df-1f74cd0dd1a5"
475+
}
476+
}
477+
]
478+
}
479+
```
480+
481+
### V2 (New) Response Structure
482+
```json
483+
{
484+
"insertedFields": [
485+
{
486+
"card_number": "5484-7829-1702-9110",
487+
"request_index": "0",
488+
"skyflow_id": "9fac9201-7b8a-4446-93f8-5244e1213bd1",
489+
"cardholder_name": "b2308e2a-c1f5-469b-97b7-1f193159399b"
490+
}
491+
],
492+
"errors": []
493+
}
494+
```
495+
496+
---
497+
498+
## 4. Request Options
499+
In V2, with the introduction of the Builder design pattern has made handling optional fields in Java more efficient and straightforward.
500+
501+
502+
### V1 (Old)
503+
```java
504+
InsertOptions insertOptions = new InsertOptions(true);
505+
```
506+
507+
### V2 (New)
508+
```java
509+
InsertRequest upsertRequest = new InsertRequest.builder()
510+
.table("<TABLE_NAME>") // Replace with the table name
511+
.continueOnError(false) // Stop inserting if any record fails
512+
.tokenMode(TokenMode.DISABLE) // Disable BYOT
513+
.values(values) // Data to insert
514+
.returnTokens(false) // Do not return tokens
515+
.upsert("<UPSERT_COLUMN>") // Replace with the column name used for upsert logic
516+
.build();
517+
```
518+
519+
---
520+
521+
## 5. Enhanced Error Details
522+
The V2 error response includes:
523+
524+
- `httpStatus`: The HTTP status code.
525+
- `grpcCode`: The gRPC code associated with the error.
526+
- `details` & `message`: A detailed description of the error.
527+
- `requestId`: A unique request identifier for easier debugging.
528+
529+
### V1 (Old) Error Structure
530+
```json
531+
{
532+
"code": "<HTTP_CODE>",
533+
"description": "<DESCRIPTION>"
534+
}
535+
```
536+
537+
### V2 (New) Error Structure
538+
```json
539+
{
540+
"httpStatus": "<HTTP_STATUS>",
541+
"grpcCode": "<GRPC_CODE>",
542+
"httpCode": "<HTTP_CODE>",
543+
"message": "<MESSAGE>",
544+
"requestId": "<REQUEST_ID>",
545+
"details": [ "<DETAILS>" ]
546+
}
547+
```
548+
303549
## Vault APIs
304550

305551
The [Vault](https://github.com/skyflowapi/skyflow-java/tree/main/src/main/java/com/skyflow/vault) module is used to

0 commit comments

Comments
 (0)