From b74943af1edcb7dda772b698dad0fb79bd4f4401 Mon Sep 17 00:00:00 2001 From: skyflow-vivek Date: Mon, 17 Mar 2025 21:04:10 +0530 Subject: [PATCH] SK-1954 Fix Java Samples --- .../connection/InvokeConnectionExample.java | 85 +++++++------ .../com/example/vault/ClientOperations.java | 95 ++++++++++++++ .../com/example/vault/CredentialsOptions.java | 84 +++++++++++++ .../java/com/example/vault/DeleteExample.java | 74 ++++------- .../com/example/vault/DetokenizeExample.java | 79 ++++-------- .../java/com/example/vault/GetExample.java | 35 +++--- .../java/com/example/vault/InsertExample.java | 75 +++++------ .../java/com/example/vault/QueryExample.java | 67 ++++------ .../com/example/vault/TokenizeExample.java | 116 ++++++------------ .../java/com/example/vault/UpdateExample.java | 82 ++++++------- 10 files changed, 413 insertions(+), 379 deletions(-) create mode 100644 samples/src/main/java/com/example/vault/ClientOperations.java create mode 100644 samples/src/main/java/com/example/vault/CredentialsOptions.java diff --git a/samples/src/main/java/com/example/connection/InvokeConnectionExample.java b/samples/src/main/java/com/example/connection/InvokeConnectionExample.java index a730ca25..b2e80924 100644 --- a/samples/src/main/java/com/example/connection/InvokeConnectionExample.java +++ b/samples/src/main/java/com/example/connection/InvokeConnectionExample.java @@ -13,92 +13,89 @@ import java.util.Map; /** - * This example demonstrates how to use the Skyflow SDK to invoke connections for different endpoints with different configurations. + * This example demonstrates how to use the Skyflow SDK to invoke API connections. * It includes: - * 1. Setting up connection configurations. - * 2. Creating a Skyflow client. - * 3. Sending POST and GET requests to connections. + * 1. Setting up credentials and connection configurations. + * 2. Creating a Skyflow client with multiple connections. + * 3. Sending a POST request with request body and headers. + * 4. Sending a GET request with path and query parameters. */ public class InvokeConnectionExample { public static void main(String[] args) throws SkyflowException { - // Step 1: Set up credentials for the first connection configuration + // Step 1: Set up credentials for API authentication Credentials credentials = new Credentials(); - credentials.setPath(""); // Replace with the path to the credentials file + credentials.setApiKey(""); // Replace with the actual API key - // Step 2: Configure the first connection (Connection 1) - ConnectionConfig connectionConfig1 = new ConnectionConfig(); - connectionConfig1.setConnectionId(""); // Replace with the ID of the first connection - connectionConfig1.setConnectionUrl(""); // Replace with the URL of the first connection - connectionConfig1.setCredentials(credentials); // Associate credentials for the first connection + // Step 2: Configure the first connection + ConnectionConfig primaryConnectionConfig = new ConnectionConfig(); + primaryConnectionConfig.setConnectionId(""); // Replace with first connection ID + primaryConnectionConfig.setConnectionUrl(""); // Replace with first connection URL + primaryConnectionConfig.setCredentials(credentials); // Assign credentials - // Step 3: Configure the second connection (Connection 2) - ConnectionConfig connectionConfig2 = new ConnectionConfig(); - connectionConfig2.setConnectionId(""); // Replace with the ID of the second connection - connectionConfig2.setConnectionUrl(""); // Replace with the URL of the second connection + // Step 3: Configure the second connection + ConnectionConfig secondaryConnectionConfig = new ConnectionConfig(); + secondaryConnectionConfig.setConnectionId(""); // Replace with second connection ID + secondaryConnectionConfig.setConnectionUrl(""); // Replace with second connection URL // Step 4: Set up credentials for the Skyflow client Credentials skyflowCredentials = new Credentials(); - skyflowCredentials.setPath(""); // Replace with the path to another credentials file + skyflowCredentials.setCredentialsString(""); // Replace with the credentials string - // Step 5: Create a Skyflow client and add connection configurations + // Step 5: Create a Skyflow client with connection configurations Skyflow skyflowClient = Skyflow.builder() - .setLogLevel(LogLevel.DEBUG) // Enable debugging for detailed logs - .addConnectionConfig(connectionConfig1) // Add the first connection configuration - .addConnectionConfig(connectionConfig2) // Add the second connection configuration - .addSkyflowCredentials(skyflowCredentials) // Add general Skyflow credentials + .setLogLevel(LogLevel.ERROR) // Set log level to ERROR + .addConnectionConfig(primaryConnectionConfig) // Add the first connection + .addConnectionConfig(secondaryConnectionConfig) // Add the second connection + .addSkyflowCredentials(skyflowCredentials) // Provide Skyflow credentials .build(); // Example 1: Sending a POST request to the first connection try { - // Set up the request body and headers for the POST request + // Set up request body and headers Map requestBody = new HashMap<>(); - requestBody.put("", ""); // Replace with the actual column name and value + requestBody.put("", ""); // Replace with actual column name and value requestBody.put("", ""); // Replace with another column name and value Map requestHeaders = new HashMap<>(); - requestHeaders.put("", ""); // Replace with header name and value + requestHeaders.put("", ""); // Replace with actual header name and value requestHeaders.put("", ""); // Replace with another header name and value - // Build the POST request to invoke the connection + // Build and send the POST request InvokeConnectionRequest invokeConnectionRequest1 = InvokeConnectionRequest.builder() - .method(RequestMethod.POST) // Set the HTTP method to POST - .requestBody(requestBody) // Set the request body - .requestHeaders(requestHeaders) // Set the request headers + .method(RequestMethod.POST) // HTTP method set to POST + .requestBody(requestBody) // Include request body + .requestHeaders(requestHeaders) // Include request headers .build(); - // Execute the POST request to the first connection InvokeConnectionResponse invokeConnectionResponse1 = skyflowClient.connection().invoke(invokeConnectionRequest1); - System.out.println("Invoke Connection Response (POST): " + invokeConnectionResponse1); // Print the response + System.out.println("Invoke Connection Response (POST): " + invokeConnectionResponse1); } catch (SkyflowException e) { - System.out.println("Error while invoking connection (POST):"); - e.printStackTrace(); + System.out.println("Error while invoking connection (POST):" + e); } // Example 2: Sending a GET request to the second connection try { - // Set up path parameters and query parameters for the GET request + // Set up path and query parameters Map pathParams = new HashMap<>(); - pathParams.put("", ""); // Replace with path parameters + pathParams.put("", ""); // Replace with actual path parameter pathParams.put("", ""); // Replace with another path parameter Map queryParams = new HashMap<>(); - queryParams.put("", ""); // Replace with query parameters + queryParams.put("", ""); // Replace with actual query parameter queryParams.put("", ""); // Replace with another query parameter - // Build the GET request to invoke the connection + // Build and send the GET request InvokeConnectionRequest invokeConnectionRequest2 = InvokeConnectionRequest.builder() - .method(RequestMethod.GET) // Set the HTTP method to GET - .pathParams(pathParams) // Set the path parameters - .queryParams(queryParams) // Set the query parameters + .method(RequestMethod.GET) // HTTP method set to GET + .pathParams(pathParams) // Include path parameters + .queryParams(queryParams) // Include query parameters .build(); - // Execute the GET request to the second connection InvokeConnectionResponse invokeConnectionResponse2 = skyflowClient - .connection("").invoke(invokeConnectionRequest2); // Invoke connection with ID 2 - System.out.println("Invoke Connection Response (GET): " + invokeConnectionResponse2); // Print the response + .connection("").invoke(invokeConnectionRequest2); + System.out.println("Invoke Connection Response (GET): " + invokeConnectionResponse2); } catch (SkyflowException e) { - System.out.println("Error while invoking connection (GET):"); - e.printStackTrace(); + System.out.println("Error while invoking connection (GET):" + e); } } } diff --git a/samples/src/main/java/com/example/vault/ClientOperations.java b/samples/src/main/java/com/example/vault/ClientOperations.java new file mode 100644 index 00000000..7931db34 --- /dev/null +++ b/samples/src/main/java/com/example/vault/ClientOperations.java @@ -0,0 +1,95 @@ +package com.example.vault; + +import com.skyflow.Skyflow; +import com.skyflow.config.Credentials; +import com.skyflow.config.VaultConfig; +import com.skyflow.enums.Env; +import com.skyflow.enums.LogLevel; +import com.skyflow.errors.SkyflowException; +import com.skyflow.vault.data.DeleteRequest; +import com.skyflow.vault.data.DeleteResponse; + +import java.util.ArrayList; + +/** + * This class demonstrates how to configure and interact with Skyflow vaults using the Skyflow Java SDK. + *

+ * The operations performed in this class include: + * 1. Setting up authentication credentials. + * 2. Configuring a primary vault and initializing a Skyflow client. + * 3. Adding a secondary vault to the client. + * 4. Updating vault configuration. + * 5. Updating Skyflow API credentials dynamically. + * 6. Performing a secure deletion of a record in the secondary vault. + * 7. Removing the secondary vault configuration after the operation. + *

+ * This example illustrates how to securely manage and delete sensitive data using Skyflow. + */ +public class ClientOperations { + public static void main(String[] args) throws SkyflowException { + // Step 1: Set up authentication credentials for accessing Skyflow vault + Credentials credentials = new Credentials(); + credentials.setToken(""); // Replace with the actual bearer token + // Alternative authentication methods include API key, credentials file path, or credentialsString + + // Step 2: Configure the primary vault with necessary identifiers and credentials + VaultConfig primaryVaultConfig = new VaultConfig(); + primaryVaultConfig.setVaultId(""); // Set first vault ID + primaryVaultConfig.setClusterId(""); // Set first cluster ID + primaryVaultConfig.setEnv(Env.PROD); // Define the environment (e.g., PROD, DEV, STAGE, SANDBOX) + primaryVaultConfig.setCredentials(credentials); // Attach authentication credentials + + // Step 3: Create a Skyflow client instance to interact with the vault + Skyflow skyflowClient = Skyflow.builder() + .setLogLevel(LogLevel.ERROR) // Set logging level (ERROR to reduce verbosity) + .addVaultConfig(primaryVaultConfig) // Associate the primary vault configuration + .build(); // Build the Skyflow client instance + + // Step 4: Configure the secondary vault, which will be used later for deletion operations + VaultConfig secondaryVaultConfig = new VaultConfig(); + secondaryVaultConfig.setVaultId(""); // Set second vault ID + secondaryVaultConfig.setClusterId(""); // Set second cluster ID + secondaryVaultConfig.setEnv(Env.PROD); // Define the environment + + // Add the secondary vault configuration to the existing Skyflow client + skyflowClient.addVaultConfig(secondaryVaultConfig); + + // Step 5: Update the secondary vault configuration with credentials + VaultConfig updatedVaultConfig = new VaultConfig(); + updatedVaultConfig.setVaultId(""); // Ensure update applies to the correct vault + updatedVaultConfig.setClusterId(""); // Maintain correct cluster association + updatedVaultConfig.setCredentials(credentials); // Attach authentication credentials + + // Apply the updated vault configuration + skyflowClient.updateVaultConfig(updatedVaultConfig); + + // Step 6: Update Skyflow API credentials dynamically + Credentials skyflowCredentials = new Credentials(); + skyflowCredentials.setApiKey(""); // Replace with the actual API key + + // Apply the updated credentials to the Skyflow client + skyflowClient.updateSkyflowCredentials(skyflowCredentials); // Used when individual credentials are not provided + + try { + // Step 7: Prepare a delete request to securely remove data from the secondary vault + ArrayList ids = new ArrayList<>(); + ids.add(""); // Replace with the actual ID of the record to delete + + DeleteRequest deleteRequest = DeleteRequest.builder() + .ids(ids) // Specify record IDs targeted for deletion + .table("") // Set the table name from which records should be deleted + .build(); + + // Step 8: Execute the secure delete operation on the secondary vault + DeleteResponse deleteResponse = skyflowClient.vault("").delete(deleteRequest); + System.out.println("Delete Response (Vault 2): " + deleteResponse); + + // Step 9: Remove the secondary vault configuration after the operation is completed + skyflowClient.removeVaultConfig(""); + + } catch (SkyflowException e) { + // Handle any errors that occur during the delete operation + System.out.println("Error during delete operation in vault 2: " + e); + } + } +} diff --git a/samples/src/main/java/com/example/vault/CredentialsOptions.java b/samples/src/main/java/com/example/vault/CredentialsOptions.java new file mode 100644 index 00000000..8a3ebc6a --- /dev/null +++ b/samples/src/main/java/com/example/vault/CredentialsOptions.java @@ -0,0 +1,84 @@ +package com.example.vault; + +import com.skyflow.Skyflow; +import com.skyflow.config.Credentials; +import com.skyflow.config.VaultConfig; +import com.skyflow.enums.Env; +import com.skyflow.enums.LogLevel; +import com.skyflow.errors.SkyflowException; +import com.skyflow.vault.data.DeleteRequest; +import com.skyflow.vault.data.DeleteResponse; + +import java.util.ArrayList; + +/** + * This class demonstrates multiple authentication methods and deletion operations across different Skyflow vaults. + *

+ * The operations performed in this class include: + * 1. Setting up authentication credentials with multiple options. + * 2. Configuring primary and secondary vaults. + * 3. Initializing a Skyflow client with multiple vault configurations. + * 4. Performing secure deletion of records from both vaults. + */ +public class CredentialsOptions { + public static void main(String[] args) throws SkyflowException { + // Step 1: Set up authentication credentials using an API key + Credentials credentials = new Credentials(); + credentials.setApiKey(""); // Replace with your actual API key + + // Alternative authentication methods (uncomment if needed) + // credentials.setToken(""); + // credentials.setPath(""); + // credentials.setCredentialsString(""); + + // Step 2: Configure the primary vault + VaultConfig primaryVaultConfig = new VaultConfig(); + primaryVaultConfig.setVaultId(""); // Set first vault ID + primaryVaultConfig.setClusterId(""); // Set first cluster ID + primaryVaultConfig.setEnv(Env.PROD); // Define the environment (e.g., PROD, DEV, STAGE, SANDBOX) + + // Step 3: Configure the secondary vault with credentials + VaultConfig secondaryVaultConfig = new VaultConfig(); + secondaryVaultConfig.setVaultId(""); // Set second vault ID + secondaryVaultConfig.setClusterId(""); // Set second cluster ID + secondaryVaultConfig.setEnv(Env.PROD); // Define the environment + secondaryVaultConfig.setCredentials(credentials); // Attach authentication credentials + + // Step 4: Create a Skyflow client instance with both vault configurations + Skyflow skyflowClient = Skyflow.builder() + .setLogLevel(LogLevel.ERROR) // Set logging level to ERROR + .addVaultConfig(primaryVaultConfig) // Associate the primary vault configuration + .addVaultConfig(secondaryVaultConfig) // Associate the secondary vault configuration + .build(); + + // Step 5: Perform secure deletion from the first vault + try { + ArrayList ids1 = new ArrayList<>(); + ids1.add(""); // Replace with the actual ID to delete + DeleteRequest deleteRequest1 = DeleteRequest.builder() + .ids(ids1) // Specify record IDs targeted for deletion + .table("") // Set the table name from which records should be deleted + .build(); + + DeleteResponse deleteResponse1 = skyflowClient.vault("").delete(deleteRequest1); + System.out.println("Delete Response (Vault 1): " + deleteResponse1); + } catch (SkyflowException e) { + System.out.println("Error during delete operation in Vault 1: " + e); + } + + // Step 6: Perform secure deletion from the second vault + try { + ArrayList ids2 = new ArrayList<>(); + ids2.add(""); // Replace with the actual ID to delete + DeleteRequest deleteRequest2 = DeleteRequest.builder() + .ids(ids2) // Specify record IDs targeted for deletion + .table("") // Set the table name from which records should be deleted + .build(); + + DeleteResponse deleteResponse2 = skyflowClient.vault("").delete(deleteRequest2); + System.out.println("Delete Response (Vault 2): " + deleteResponse2); + } catch (SkyflowException e) { + System.out.println("Error during delete operation in Vault 2: " + e); + } + } +} diff --git a/samples/src/main/java/com/example/vault/DeleteExample.java b/samples/src/main/java/com/example/vault/DeleteExample.java index bd6122cd..9fe41f61 100644 --- a/samples/src/main/java/com/example/vault/DeleteExample.java +++ b/samples/src/main/java/com/example/vault/DeleteExample.java @@ -16,71 +16,49 @@ * by specifying the vault configurations, credentials, and record IDs to delete. *

* Steps include: - * 1. Setting up vault configurations. - * 2. Creating a Skyflow client. - * 3. Deleting records from the specified vault(s) using record IDs and table names. + * 1. Setting up Skyflow credentials. + * 2. Configuring the vault. + * 3. Creating a Skyflow client. + * 4. Setting the log level for debugging and error tracking. + * 5. Deleting records from the specified vault(s) using record IDs and table names. */ public class DeleteExample { public static void main(String[] args) throws SkyflowException { - // Step 1: Set up credentials for the first vault configuration + // Step 1: Set up Skyflow credentials Credentials credentials = new Credentials(); - credentials.setPath(""); // Replace with the actual path to the credentials file + credentials.setPath(""); // Replace with the actual path to the credentials file - // Step 2: Configure the first vault (Blitz) - VaultConfig blitzConfig = new VaultConfig(); - blitzConfig.setVaultId(""); // Replace with the ID of the first vault - blitzConfig.setClusterId(""); // Replace with the cluster ID of the first vault - blitzConfig.setEnv(Env.DEV); // Set the environment (e.g., DEV, STAGE, PROD) - blitzConfig.setCredentials(credentials); // Associate the credentials with the vault + // Step 2: Configure the first vault + VaultConfig primaryVaultConfig = new VaultConfig(); + primaryVaultConfig.setVaultId(""); // Replace with the ID of the first vault + primaryVaultConfig.setClusterId(""); // Replace with the cluster ID of the first vault + primaryVaultConfig.setEnv(Env.PROD); // Set the environment (e.g., DEV, STAGE, PROD) + primaryVaultConfig.setCredentials(credentials); // Associate the credentials with the vault - // Step 3: Configure the second vault (Stage) - VaultConfig stageConfig = new VaultConfig(); - stageConfig.setVaultId(""); // Replace with the ID of the second vault - stageConfig.setClusterId(""); // Replace with the cluster ID of the second vault - stageConfig.setEnv(Env.STAGE); // Set the environment for the second vault - - // Step 4: Set up credentials for the Skyflow client + // Step 3: Set up credentials for the Skyflow client Credentials skyflowCredentials = new Credentials(); - skyflowCredentials.setPath(""); // Replace with the path to another credentials file + skyflowCredentials.setCredentialsString(""); // Replace with credentials string - // Step 5: Create a Skyflow client and add vault configurations + // Step 4: Create a Skyflow client and add vault configurations Skyflow skyflowClient = Skyflow.builder() - .setLogLevel(LogLevel.DEBUG) // Enable debugging for detailed logs - .addVaultConfig(blitzConfig) // Add the first vault configuration - .addVaultConfig(stageConfig) // Add the second vault configuration + .setLogLevel(LogLevel.ERROR) // Set log level for debugging and error tracking + .addVaultConfig(primaryVaultConfig) // Add the first vault configuration .addSkyflowCredentials(skyflowCredentials) // Add general Skyflow credentials .build(); - // Example 1: Delete a record from the first vault - try { - ArrayList ids1 = new ArrayList<>(); - ids1.add(""); // Replace with the ID of the record to delete - DeleteRequest deleteRequest1 = DeleteRequest.builder() - .ids(ids1) // Specify the record IDs to delete - .table("") // Replace with the table name - .build(); - - DeleteResponse deleteResponse1 = skyflowClient.vault().delete(deleteRequest1); // Perform the delete operation - System.out.println("Delete Response (Vault 1): " + deleteResponse1); - } catch (SkyflowException e) { - System.out.println("Error during delete operation in Vault 1:"); - e.printStackTrace(); - } - - // Example 2: Delete a record from the second vault + // Step 5: Delete a record from the first vault try { - ArrayList ids2 = new ArrayList<>(); - ids2.add(""); // Replace with the ID of the record to delete - DeleteRequest deleteRequest2 = DeleteRequest.builder() - .ids(ids2) // Specify the record IDs to delete + ArrayList ids = new ArrayList<>(); + ids.add(""); // Replace with the ID of the record to delete + DeleteRequest deleteRequest = DeleteRequest.builder() + .ids(ids) // Specify the record IDs to delete .table("") // Replace with the table name .build(); - DeleteResponse deleteResponse2 = skyflowClient.vault("").delete(deleteRequest2); // Perform the delete operation - System.out.println("Delete Response (Vault 2): " + deleteResponse2); + DeleteResponse deleteResponse = skyflowClient.vault().delete(deleteRequest); // Perform the delete operation + System.out.println("Delete Response: " + deleteResponse); } catch (SkyflowException e) { - System.out.println("Error during delete operation in Vault 2:"); - e.printStackTrace(); + System.out.println("Error during delete operation in Vault: " + e); } } } diff --git a/samples/src/main/java/com/example/vault/DetokenizeExample.java b/samples/src/main/java/com/example/vault/DetokenizeExample.java index f25d2be0..9a943dff 100644 --- a/samples/src/main/java/com/example/vault/DetokenizeExample.java +++ b/samples/src/main/java/com/example/vault/DetokenizeExample.java @@ -5,7 +5,6 @@ import com.skyflow.config.VaultConfig; import com.skyflow.enums.Env; import com.skyflow.enums.LogLevel; -import com.skyflow.enums.RedactionType; import com.skyflow.errors.SkyflowException; import com.skyflow.vault.tokens.DetokenizeRequest; import com.skyflow.vault.tokens.DetokenizeResponse; @@ -15,76 +14,50 @@ /** * This example demonstrates how to use the Skyflow SDK to detokenize sensitive data. * The steps include: - * 1. Setting up vault configurations. - * 2. Creating a Skyflow client. - * 3. Detokenizing tokens from specified vaults. + * 1. Setting up Skyflow credentials. + * 2. Configuring the vault. + * 3. Creating a Skyflow client. + * 4. Detokenizing tokens from specified vaults. */ public class DetokenizeExample { public static void main(String[] args) throws SkyflowException { - // Step 1: Set up credentials for the first vault configuration + // Step 1: Set up Skyflow credentials Credentials credentials = new Credentials(); - credentials.setPath(""); // Replace with the actual path to the credentials file + credentials.setToken(""); // Replace with the actual bearer token - // Step 2: Configure the first vault (Blitz) - VaultConfig blitzConfig = new VaultConfig(); - blitzConfig.setVaultId(""); // Replace with the ID of the first vault - blitzConfig.setClusterId(""); // Replace with the cluster ID of the first vault - blitzConfig.setEnv(Env.DEV); // Set the environment (e.g., DEV, STAGE, PROD) - blitzConfig.setCredentials(credentials); // Associate the credentials with the vault + // Step 2: Configure the first vault + VaultConfig primaryVaultConfig = new VaultConfig(); + primaryVaultConfig.setVaultId(""); // Replace with the ID of the first vault + primaryVaultConfig.setClusterId(""); // Replace with the cluster ID of the first vault + primaryVaultConfig.setEnv(Env.PROD); // Set the environment (e.g., DEV, STAGE, PROD) + primaryVaultConfig.setCredentials(credentials); // Associate the credentials with the vault - // Step 3: Configure the second vault (Stage) - VaultConfig stageConfig = new VaultConfig(); - stageConfig.setVaultId(""); // Replace with the ID of the second vault - stageConfig.setClusterId(""); // Replace with the cluster ID of the second vault - stageConfig.setEnv(Env.STAGE); // Set the environment for the second vault - - // Step 4: Set up credentials for the Skyflow client + // Step 3: Set up credentials for the Skyflow client Credentials skyflowCredentials = new Credentials(); - skyflowCredentials.setPath(""); // Replace with the path to another credentials file + skyflowCredentials.setCredentialsString(""); // Replace with credentials string - // Step 5: Create a Skyflow client and add vault configurations + // Step 4: Create a Skyflow client and add vault configurations Skyflow skyflowClient = Skyflow.builder() - .setLogLevel(LogLevel.DEBUG) // Enable debugging for detailed logs - .addVaultConfig(blitzConfig) // Add the first vault configuration - .addVaultConfig(stageConfig) // Add the second vault configuration + .setLogLevel(LogLevel.ERROR) // Set log level to ERROR to capture only critical logs + .addVaultConfig(primaryVaultConfig) // Add the first vault configuration .addSkyflowCredentials(skyflowCredentials) // Add general Skyflow credentials .build(); - // Example 1: Detokenize tokens from the first vault + // Step 5: Detokenize tokens from the first vault try { - ArrayList tokens1 = new ArrayList<>(); - tokens1.add(""); // Replace with the first token to detokenize - tokens1.add(""); // Replace with the second token to detokenize + ArrayList tokens = new ArrayList<>(); + tokens.add(""); // Replace with the first token to detokenize + tokens.add(""); // Replace with the second token to detokenize - DetokenizeRequest detokenizeRequest1 = DetokenizeRequest.builder() - .tokens(tokens1) // Specify the tokens to detokenize + DetokenizeRequest detokenizeRequest = DetokenizeRequest.builder() + .tokens(tokens) // Specify the tokens to detokenize .continueOnError(true) // Continue processing even if an error occurs for some tokens .build(); - DetokenizeResponse detokenizeResponse1 = skyflowClient.vault().detokenize(detokenizeRequest1); // Perform detokenization - System.out.println("Detokenize Response (Vault 1): " + detokenizeResponse1); - } catch (SkyflowException e) { - System.out.println("Error during detokenization in Vault 1:"); - e.printStackTrace(); - } - - // Example 2: Detokenize tokens from the second vault - try { - ArrayList tokens2 = new ArrayList<>(); - tokens2.add(""); // Replace with the first token to detokenize - tokens2.add(""); // Replace with the second token to detokenize - - DetokenizeRequest detokenizeRequest2 = DetokenizeRequest.builder() - .tokens(tokens2) // Specify the tokens to detokenize - .continueOnError(false) // Stop processing on the first error - .redactionType(RedactionType.DEFAULT) // Use the default redaction type for detokenization - .build(); - - DetokenizeResponse detokenizeResponse2 = skyflowClient.vault("").detokenize(detokenizeRequest2); // Perform detokenization - System.out.println("Detokenize Response (Vault 2): " + detokenizeResponse2); + DetokenizeResponse detokenizeResponse = skyflowClient.vault().detokenize(detokenizeRequest); // Perform detokenization + System.out.println("Detokenize Response: " + detokenizeResponse); } catch (SkyflowException e) { - System.out.println("Error during detokenization in Vault 2:"); - e.printStackTrace(); + System.out.println("Error during detokenization in Vault: " + e); } } } diff --git a/samples/src/main/java/com/example/vault/GetExample.java b/samples/src/main/java/com/example/vault/GetExample.java index f964cfd2..6d300752 100644 --- a/samples/src/main/java/com/example/vault/GetExample.java +++ b/samples/src/main/java/com/example/vault/GetExample.java @@ -23,30 +23,23 @@ public class GetExample { public static void main(String[] args) throws SkyflowException { // Step 1: Set up credentials for the first vault configuration Credentials credentials = new Credentials(); - credentials.setPath(""); // Replace with the actual path to the credentials file + credentials.setCredentialsString(""); // Replace with the actual credentials string - // Step 2: Configure the first vault (Blitz) - VaultConfig blitzConfig = new VaultConfig(); - blitzConfig.setVaultId(""); // Replace with the ID of the first vault - blitzConfig.setClusterId(""); // Replace with the cluster ID of the first vault - blitzConfig.setEnv(Env.DEV); // Set the environment (e.g., DEV, STAGE, PROD) - blitzConfig.setCredentials(credentials); // Associate the credentials with the vault + // Step 2: Configure the first vault + VaultConfig primaryVaultConfig = new VaultConfig(); + primaryVaultConfig.setVaultId(""); // Replace with the ID of the first vault + primaryVaultConfig.setClusterId(""); // Replace with the cluster ID of the first vault + primaryVaultConfig.setEnv(Env.PROD); // Set the environment (e.g., DEV, STAGE, PROD) + primaryVaultConfig.setCredentials(credentials); // Associate the credentials with the vault - // Step 3: Configure the second vault (Stage) - VaultConfig stageConfig = new VaultConfig(); - stageConfig.setVaultId(""); // Replace with the ID of the second vault - stageConfig.setClusterId(""); // Replace with the cluster ID of the second vault - stageConfig.setEnv(Env.STAGE); // Set the environment for the second vault - - // Step 4: Set up credentials for the Skyflow client + // Step 3: Set up credentials for the Skyflow client Credentials skyflowCredentials = new Credentials(); - skyflowCredentials.setPath(""); // Replace with the path to another credentials file + skyflowCredentials.setCredentialsString(""); // Replace with another credentials string - // Step 5: Create a Skyflow client and add vault configurations + // Step 4: Create a Skyflow client and add vault configurations Skyflow skyflowClient = Skyflow.builder() - .setLogLevel(LogLevel.DEBUG) // Enable debugging for detailed logs - .addVaultConfig(blitzConfig) // Add the first vault configuration - .addVaultConfig(stageConfig) // Add the second vault configuration + .setLogLevel(LogLevel.ERROR) // Set log level to ERROR to minimize log output + .addVaultConfig(primaryVaultConfig) // Add the first vault configuration .addSkyflowCredentials(skyflowCredentials) // Add general Skyflow credentials .build(); @@ -60,7 +53,7 @@ public static void main(String[] args) throws SkyflowException { .table("") // Replace with the table name .build(); - GetResponse getByIdResponse = skyflowClient.vault().get(getByIdRequest); // Perform the get operation + GetResponse getByIdResponse = skyflowClient.vault().get(getByIdRequest); // Fetch via skyflow IDs System.out.println("Get Response (By ID): " + getByIdResponse); } catch (SkyflowException e) { System.out.println("Error during fetch by ID:"); @@ -79,7 +72,7 @@ public static void main(String[] args) throws SkyflowException { .redactionType(RedactionType.PLAIN_TEXT) // Fetch the data in plain text format .build(); - GetResponse getByColumnResponse = skyflowClient.vault("").get(getByColumnRequest); // Fetch from the second vault + GetResponse getByColumnResponse = skyflowClient.vault().get(getByColumnRequest); // Fetch via column values System.out.println("Get Response (By Column): " + getByColumnResponse); } catch (SkyflowException e) { System.out.println("Error during fetch by column:"); diff --git a/samples/src/main/java/com/example/vault/InsertExample.java b/samples/src/main/java/com/example/vault/InsertExample.java index b84439f0..25610b2b 100644 --- a/samples/src/main/java/com/example/vault/InsertExample.java +++ b/samples/src/main/java/com/example/vault/InsertExample.java @@ -3,9 +3,9 @@ import com.skyflow.Skyflow; import com.skyflow.config.Credentials; import com.skyflow.config.VaultConfig; -import com.skyflow.enums.TokenMode; import com.skyflow.enums.Env; import com.skyflow.enums.LogLevel; +import com.skyflow.enums.TokenMode; import com.skyflow.errors.SkyflowException; import com.skyflow.vault.data.InsertRequest; import com.skyflow.vault.data.InsertResponse; @@ -18,91 +18,82 @@ * It includes: * 1. Setting up vault configurations. * 2. Creating a Skyflow client. - * 3. Performing record insertion with and without BYOT (Bring Your Own Token). + * 3. Performing record insertion with and without TokenMode. * 4. Using upsert functionality to handle conflicts. */ public class InsertExample { public static void main(String[] args) throws SkyflowException { // Step 1: Set up credentials for the first vault configuration Credentials credentials = new Credentials(); - credentials.setPath(""); // Replace with the path to the credentials file - - // Step 2: Configure the first vault (Blitz) - VaultConfig blitzConfig = new VaultConfig(); - blitzConfig.setVaultId(""); // Replace with the ID of the first vault - blitzConfig.setClusterId(""); // Replace with the cluster ID of the first vault - blitzConfig.setEnv(Env.DEV); // Set the environment (e.g., DEV, STAGE, PROD) - blitzConfig.setCredentials(credentials); // Associate the credentials with the vault + credentials.setApiKey(""); // Replace with the actual API key - // Step 3: Configure the second vault (Stage) - VaultConfig stageConfig = new VaultConfig(); - stageConfig.setVaultId(""); // Replace with the ID of the second vault - stageConfig.setClusterId(""); // Replace with the cluster ID of the second vault - stageConfig.setEnv(Env.STAGE); // Set the environment for the second vault + // Step 2: Configure the first vault + VaultConfig primaryVaultConfig = new VaultConfig(); + primaryVaultConfig.setVaultId(""); // Replace with the first vault ID + primaryVaultConfig.setClusterId(""); // Replace with the first vault cluster ID + primaryVaultConfig.setEnv(Env.PROD); // Set the environment (e.g., DEV, STAGE, SANDBOX) + primaryVaultConfig.setCredentials(credentials); // Associate credentials with the vault - // Step 4: Set up credentials for the Skyflow client + // Step 3: Set up credentials for the Skyflow client Credentials skyflowCredentials = new Credentials(); - skyflowCredentials.setPath(""); // Replace with the path to another credentials file + skyflowCredentials.setCredentialsString(""); // Replace with the actual credentials string - // Step 5: Create a Skyflow client and add vault configurations + // Step 4: Create a Skyflow client and add vault configurations Skyflow skyflowClient = Skyflow.builder() - .setLogLevel(LogLevel.DEBUG) // Enable debugging for detailed logs - .addVaultConfig(blitzConfig) // Add the first vault configuration - .addVaultConfig(stageConfig) // Add the second vault configuration + .setLogLevel(LogLevel.ERROR) // Set log level to ERROR to limit output + .addVaultConfig(primaryVaultConfig) // Add the vault configuration .addSkyflowCredentials(skyflowCredentials) // Add general Skyflow credentials .build(); - // Example 1: Insert records into the first vault with BYOT enabled + // Example 1: Insert records into the first vault with TokenMode enabled try { ArrayList> values1 = new ArrayList<>(); HashMap value1 = new HashMap<>(); - value1.put("", ""); // Replace with column name and value - value1.put("", ""); // Replace with another column name and value + value1.put("", ""); // Replace with actual column name and value + value1.put("", ""); // Replace with actual column name and value values1.add(value1); ArrayList> tokens = new ArrayList<>(); HashMap token = new HashMap<>(); - token.put("", ""); // Replace with the token for COLUMN_NAME_2 + token.put("", ""); // Replace with actual token value for COLUMN_NAME_2 tokens.add(token); InsertRequest insertRequest = InsertRequest.builder() - .table("") // Replace with the table name + .table("") // Replace with the actual table name .continueOnError(true) // Continue inserting even if some records fail - .tokenMode(TokenMode.ENABLE) // Enable BYOT for token validation + .tokenMode(TokenMode.ENABLE) // Enable TokenMode for token validation .values(values1) // Data to insert - .tokens(tokens) // Provide tokens for BYOT columns - .returnTokens(true) // Return tokens along with the response + .tokens(tokens) // Provide tokens for TokenMode columns + .returnTokens(true) // Return tokens in the response .build(); InsertResponse insertResponse = skyflowClient.vault().insert(insertRequest); // Perform the insertion - System.out.println("Insert Response (BYOT Enabled): " + insertResponse); + System.out.println("Insert Response (TokenMode Enabled): " + insertResponse); } catch (SkyflowException e) { - System.out.println("Error during insertion with BYOT enabled:"); - e.printStackTrace(); + System.out.println("Error during insertion with TokenMode enabled:" + e); } - // Example 2: Insert records into the second vault with BYOT disabled and upsert enabled + // Example 2: Insert records into the first vault with TokenMode disabled and upsert enabled try { ArrayList> values2 = new ArrayList<>(); HashMap value2 = new HashMap<>(); - value2.put("", ""); // Replace with column name and value - value2.put("", ""); // Replace with another column name and value + value2.put("", ""); // Replace with actual column name and value + value2.put("", ""); // Replace with actual column name and value values2.add(value2); InsertRequest upsertRequest = InsertRequest.builder() - .table("") // Replace with the table name + .table("") // Replace with the actual table name .continueOnError(false) // Stop inserting if any record fails - .tokenMode(TokenMode.DISABLE) // Disable BYOT + .tokenMode(TokenMode.DISABLE) // Disable TokenMode .values(values2) // Data to insert .returnTokens(false) // Do not return tokens - .upsert("") // Replace with the column name used for upsert logic + .upsert("") // Replace with the actual column name used for upsert logic .build(); - InsertResponse upsertResponse = skyflowClient.vault("").insert(upsertRequest); // Perform the insertion + InsertResponse upsertResponse = skyflowClient.vault().insert(upsertRequest); // Perform upsert operation System.out.println("Insert Response (Upsert Enabled): " + upsertResponse); } catch (SkyflowException e) { - System.out.println("Error during insertion with upsert enabled:"); - e.printStackTrace(); + System.out.println("Error during insertion with upsert enabled:" + e); } } -} +} \ No newline at end of file diff --git a/samples/src/main/java/com/example/vault/QueryExample.java b/samples/src/main/java/com/example/vault/QueryExample.java index 43f42a82..bde5c697 100644 --- a/samples/src/main/java/com/example/vault/QueryExample.java +++ b/samples/src/main/java/com/example/vault/QueryExample.java @@ -10,70 +10,47 @@ import com.skyflow.vault.data.QueryResponse; /** - * This example demonstrates how to use the Skyflow SDK to perform secure queries on multiple vaults. + * This example demonstrates how to use the Skyflow SDK to perform secure queries on a vault. * It includes: * 1. Setting up vault configurations. * 2. Creating a Skyflow client. - * 3. Performing SQL queries on the vaults. + * 3. Performing SQL queries on the vault. */ public class QueryExample { public static void main(String[] args) throws SkyflowException { - // Step 1: Set up credentials for the first vault configuration + // Step 1: Set up credentials for the vault configuration Credentials credentials = new Credentials(); - credentials.setPath(""); // Replace with the path to the credentials file + credentials.setApiKey(""); // Replace with the actual API key - // Step 2: Configure the first vault (Blitz) - VaultConfig blitzConfig = new VaultConfig(); - blitzConfig.setVaultId(""); // Replace with the ID of the first vault - blitzConfig.setClusterId(""); // Replace with the cluster ID of the first vault - blitzConfig.setEnv(Env.DEV); // Set the environment (e.g., DEV, STAGE, PROD) - blitzConfig.setCredentials(credentials); // Associate the credentials with the vault + // Step 2: Configure the vault + VaultConfig vaultConfig = new VaultConfig(); + vaultConfig.setVaultId(""); // Replace with the ID of the vault + vaultConfig.setClusterId(""); // Replace with the cluster ID of the vault + vaultConfig.setEnv(Env.PROD); // Set the environment (e.g., DEV, STAGE, PROD) + vaultConfig.setCredentials(credentials); // Associate the credentials with the vault - // Step 3: Configure the second vault (Stage) - VaultConfig stageConfig = new VaultConfig(); - stageConfig.setVaultId(""); // Replace with the ID of the second vault - stageConfig.setClusterId(""); // Replace with the cluster ID of the second vault - stageConfig.setEnv(Env.STAGE); // Set the environment for the second vault - - // Step 4: Set up credentials for the Skyflow client + // Step 3: Set up credentials for the Skyflow client Credentials skyflowCredentials = new Credentials(); - skyflowCredentials.setPath(""); // Replace with the path to another credentials file + skyflowCredentials.setCredentialsString(""); // Replace with the actual credentials string - // Step 5: Create a Skyflow client and add vault configurations + // Step 4: Create a Skyflow client and add vault configuration Skyflow skyflowClient = Skyflow.builder() - .setLogLevel(LogLevel.DEBUG) // Enable debugging for detailed logs - .addVaultConfig(blitzConfig) // Add the first vault configuration - .addVaultConfig(stageConfig) // Add the second vault configuration + .setLogLevel(LogLevel.ERROR) // Set log level to ERROR for minimal logging + .addVaultConfig(vaultConfig) // Add the vault configuration .addSkyflowCredentials(skyflowCredentials) // Add general Skyflow credentials .build(); - // Example 1: Perform a query on the first vault - try { - String query1 = ""; // Replace with a valid SQL query for the first vault - QueryRequest queryRequest1 = QueryRequest.builder() - .query(query1) // Build the query request - .build(); - - QueryResponse queryResponse1 = skyflowClient.vault().query(queryRequest1); // Execute the query - System.out.println("Query Response (Vault 1): " + queryResponse1); // Print the query response - } catch (SkyflowException e) { - System.out.println("Error while querying Vault 1:"); - e.printStackTrace(); - } - - // Example 2: Perform a query on the second vault + // Example: Perform a query on the vault try { - String query2 = ""; // Replace with a valid SQL query for the second vault - QueryRequest queryRequest2 = QueryRequest.builder() - .query(query2) // Build the query request + String query = ""; // Replace with a valid SQL query for the vault + QueryRequest queryRequest = QueryRequest.builder() + .query(query) // Build the query request .build(); - QueryResponse queryResponse2 = skyflowClient.vault("").query(queryRequest2); // Execute the query - System.out.println("Query Response (Vault 2): " + queryResponse2); // Print the query response + QueryResponse queryResponse = skyflowClient.vault().query(queryRequest); // Execute the query + System.out.println("Query Response: " + queryResponse); // Print the query response } catch (SkyflowException e) { - System.out.println("Error while querying Vault 2:"); - e.printStackTrace(); + System.out.println("Error while querying the vault: " + e); } } } - diff --git a/samples/src/main/java/com/example/vault/TokenizeExample.java b/samples/src/main/java/com/example/vault/TokenizeExample.java index 38bd806b..2c390be8 100644 --- a/samples/src/main/java/com/example/vault/TokenizeExample.java +++ b/samples/src/main/java/com/example/vault/TokenizeExample.java @@ -13,97 +13,51 @@ import java.util.ArrayList; /** - * This example demonstrates how to use the Skyflow SDK to tokenize data using multiple vault configurations. + * This example demonstrates how to use the Skyflow SDK to tokenize data using a vault configuration. * It includes: - * 1. Setting up vault configurations. + * 1. Setting up a vault configuration. * 2. Creating a Skyflow client. - * 3. Performing tokenization on the vaults. + * 3. Performing tokenization. */ public class TokenizeExample { - public static void main(String[] args) throws SkyflowException { - // Step 1: Set up credentials for the first vault configuration - Credentials credentials = new Credentials(); - credentials.setPath(""); // Replace with the path to the credentials file - - // Step 2: Configure the first vault (Blitz) - VaultConfig blitzConfig = new VaultConfig(); - blitzConfig.setVaultId(""); // Replace with the ID of the first vault - blitzConfig.setClusterId(""); // Replace with the cluster ID of the first vault - blitzConfig.setEnv(Env.DEV); // Set the environment (e.g., DEV, STAGE, PROD) - blitzConfig.setCredentials(credentials); // Associate the credentials with the vault - - // Step 3: Configure the second vault (Stage) - VaultConfig stageConfig = new VaultConfig(); - stageConfig.setVaultId(""); // Replace with the ID of the second vault - stageConfig.setClusterId(""); // Replace with the cluster ID of the second vault - stageConfig.setEnv(Env.STAGE); // Set the environment for the second vault - - // Step 4: Set up credentials for the Skyflow client - Credentials skyflowCredentials = new Credentials(); - skyflowCredentials.setPath(""); // Replace with the path to another credentials file - - // Step 5: Create a Skyflow client and add vault configurations - Skyflow skyflowClient = Skyflow.builder() - .setLogLevel(LogLevel.DEBUG) // Enable debugging for detailed logs - .addVaultConfig(blitzConfig) // Add the first vault configuration - .addVaultConfig(stageConfig) // Add the second vault configuration - .addSkyflowCredentials(skyflowCredentials) // Add general Skyflow credentials - .build(); - - // Example 1: Tokenize data for the first vault + public static void main(String[] args) { try { - ArrayList columnValues1 = new ArrayList<>(); - ColumnValue value1 = ColumnValue.builder() - .value("") // Replace with the actual value to tokenize - .columnGroup("") // Replace with the actual column group name + // Step 1: Set up credentials + Credentials credentials = new Credentials(); + credentials.setPath(""); // Replace with the path to the credentials file + + // Step 2: Configure the vault + VaultConfig vaultConfig = new VaultConfig(); + vaultConfig.setVaultId(""); // Replace with the vault ID + vaultConfig.setClusterId(""); // Replace with the cluster ID + vaultConfig.setEnv(Env.DEV); // Set the environment (e.g., DEV, STAGE, PROD) + vaultConfig.setCredentials(credentials); // Associate credentials with the vault + + Credentials skyflowCredentials = new Credentials(); + skyflowCredentials.setCredentialsString(""); // Replace with the actual credentials string + + // Step 3: Create a Skyflow client + Skyflow skyflowClient = Skyflow.builder().setLogLevel(LogLevel.ERROR) // Set log level + .addVaultConfig(vaultConfig) // Add vault configuration + .addSkyflowCredentials(skyflowCredentials) // Add general Skyflow credentials .build(); - ColumnValue value2 = ColumnValue.builder() - .value("") // Replace with another value to tokenize - .columnGroup("") // Replace with the column group name - .build(); - - columnValues1.add(value1); - columnValues1.add(value2); - // Build the tokenization request - TokenizeRequest tokenizeRequest1 = TokenizeRequest.builder() - .values(columnValues1) // Set the column values to tokenize - .build(); + // Step 4: Prepare data for tokenization + ArrayList columnValues = new ArrayList<>(); + columnValues.add(ColumnValue.builder().value("") // Replace with the actual value to tokenize + .columnGroup("") // Replace with the actual column group name + .build()); + columnValues.add(ColumnValue.builder().value("") // Replace with another value to tokenize + .columnGroup("") // Replace with the column group name + .build()); - // Execute tokenization request - TokenizeResponse tokenizeResponse1 = skyflowClient.vault().tokenize(tokenizeRequest1); - System.out.println("Tokenization Response (Vault 1): " + tokenizeResponse1); // Print the tokenization response - } catch (SkyflowException e) { - System.out.println("Error while tokenizing data for Vault 1:"); - e.printStackTrace(); - } - - // Example 2: Tokenize data for the second vault - try { - ArrayList columnValues2 = new ArrayList<>(); - ColumnValue value3 = ColumnValue.builder() - .value("") // Replace with the actual value to tokenize - .columnGroup("") // Replace with the column group name - .build(); - ColumnValue value4 = ColumnValue.builder() - .value("") // Replace with another value to tokenize - .columnGroup("") // Replace with the column group name - .build(); - - columnValues2.add(value3); - columnValues2.add(value4); - - // Build the tokenization request for the second vault - TokenizeRequest tokenizeRequest2 = TokenizeRequest.builder() - .values(columnValues2) // Set the column values to tokenize - .build(); + // Step 5: Build and execute the tokenization request + TokenizeRequest tokenizeRequest = TokenizeRequest.builder().values(columnValues).build(); - // Execute tokenization request for the second vault - TokenizeResponse tokenizeResponse2 = skyflowClient.vault("").tokenize(tokenizeRequest2); - System.out.println("Tokenization Response (Vault 2): " + tokenizeResponse2); // Print the tokenization response + TokenizeResponse tokenizeResponse = skyflowClient.vault().tokenize(tokenizeRequest); + System.out.println("Tokenization Response: " + tokenizeResponse); } catch (SkyflowException e) { - System.out.println("Error while tokenizing data for Vault 2:"); - e.printStackTrace(); + System.out.println("Error while tokenizing data for Vault:" + e); } } } diff --git a/samples/src/main/java/com/example/vault/UpdateExample.java b/samples/src/main/java/com/example/vault/UpdateExample.java index d69fbf6c..d5c5ed02 100644 --- a/samples/src/main/java/com/example/vault/UpdateExample.java +++ b/samples/src/main/java/com/example/vault/UpdateExample.java @@ -3,9 +3,9 @@ import com.skyflow.Skyflow; import com.skyflow.config.Credentials; import com.skyflow.config.VaultConfig; -import com.skyflow.enums.TokenMode; import com.skyflow.enums.Env; import com.skyflow.enums.LogLevel; +import com.skyflow.enums.TokenMode; import com.skyflow.errors.SkyflowException; import com.skyflow.vault.data.UpdateRequest; import com.skyflow.vault.data.UpdateResponse; @@ -17,83 +17,75 @@ * It includes: * 1. Setting up vault configurations. * 2. Creating a Skyflow client. - * 3. Updating records using different configurations and data. + * 3. Updating records with and without TokenMode. */ public class UpdateExample { public static void main(String[] args) throws SkyflowException { // Step 1: Set up credentials for the first vault configuration Credentials credentials = new Credentials(); - credentials.setPath(""); // Replace with the actual path to the credentials file + credentials.setApiKey(""); // Replace with the actual API key - // Step 2: Configure the first vault (Blitz) - VaultConfig blitzConfig = new VaultConfig(); - blitzConfig.setVaultId(""); // Replace with the ID of the first vault - blitzConfig.setClusterId(""); // Replace with the cluster ID of the first vault - blitzConfig.setEnv(Env.DEV); // Set the environment (e.g., DEV, STAGE, PROD) - blitzConfig.setCredentials(credentials); // Associate the credentials with the vault + // Step 2: Configure the first vault + VaultConfig primaryVaultConfig = new VaultConfig(); + primaryVaultConfig.setVaultId(""); // Replace with the ID of the first vault + primaryVaultConfig.setClusterId(""); // Replace with the cluster ID of the first vault + primaryVaultConfig.setEnv(Env.PROD); // Set the environment (e.g., DEV, STAGE, PROD) + primaryVaultConfig.setCredentials(credentials); // Associate the credentials with the vault - // Step 3: Configure the second vault (Stage) - VaultConfig stageConfig = new VaultConfig(); - stageConfig.setVaultId(""); // Replace with the ID of the second vault - stageConfig.setClusterId(""); // Replace with the cluster ID of the second vault - stageConfig.setEnv(Env.STAGE); // Set the environment for the second vault - - // Step 4: Set up credentials for the Skyflow client + // Step 3: Set up credentials for the Skyflow client Credentials skyflowCredentials = new Credentials(); - skyflowCredentials.setPath(""); // Replace with the path to another credentials file + skyflowCredentials.setCredentialsString(""); // Replace with the actual credentials string - // Step 5: Create a Skyflow client and add vault configurations + // Step 4: Create a Skyflow client and add vault configurations Skyflow skyflowClient = Skyflow.builder() - .setLogLevel(LogLevel.DEBUG) // Enable debugging for detailed logs - .addVaultConfig(blitzConfig) // Add the first vault configuration - .addVaultConfig(stageConfig) // Add the second vault configuration + .setLogLevel(LogLevel.ERROR) // Enable debugging for detailed logs + .addVaultConfig(primaryVaultConfig) // Add the first vault configuration .addSkyflowCredentials(skyflowCredentials) // Add general Skyflow credentials .build(); - // Example 1: Update records in the first vault with BYOT (Bring Your Own Token) enabled + // Step 5: Update records with TokenMode enabled try { HashMap data1 = new HashMap<>(); - data1.put("skyflow_id", ""); // Replace with the Skyflow ID of the record - data1.put("", ""); // Replace with column name and value to update - data1.put("", ""); // Replace with another column name and value + data1.put("skyflow_id", ""); // Replace with the Skyflow ID of the record + data1.put("", ""); // Replace with column name and value to update + data1.put("", ""); // Replace with another column name and value HashMap tokens = new HashMap<>(); - tokens.put("", ""); // Replace with the token for COLUMN_NAME_2 + tokens.put("", ""); // Replace with the token for COLUMN_NAME_2 UpdateRequest updateRequest1 = UpdateRequest.builder() - .table("") // Replace with the table name - .tokenMode(TokenMode.ENABLE) // Enable BYOT for token validation - .data(data1) // Data to update - .tokens(tokens) // Provide tokens for BYOT columns - .returnTokens(true) // Return tokens along with the update response + .table("") // Replace with the table name + .tokenMode(TokenMode.ENABLE) // Enable TokenMode for token validation + .data(data1) // Data to update + .tokens(tokens) // Provide tokens for TokenMode columns + .returnTokens(true) // Return tokens along with the update response .build(); UpdateResponse updateResponse1 = skyflowClient.vault().update(updateRequest1); // Perform the update - System.out.println("Update Response (BYOT Enabled): " + updateResponse1); + System.out.println("Update Response (TokenMode Enabled): " + updateResponse1); } catch (SkyflowException e) { - System.out.println("Error during update with BYOT enabled:"); + System.out.println("Error during update with TokenMode enabled:"); e.printStackTrace(); } - // Example 2: Update records in the second vault with BYOT disabled + // Step 6: Update records with TokenMode disabled try { HashMap data2 = new HashMap<>(); - data2.put("skyflow_id", ""); // Replace with the Skyflow ID of the record - data2.put("", ""); // Replace with column name and value to update - data2.put("", ""); // Replace with another column name and value + data2.put("skyflow_id", ""); // Replace with the Skyflow ID of the record + data2.put("", ""); // Replace with column name and value to update + data2.put("", ""); // Replace with another column name and value UpdateRequest updateRequest2 = UpdateRequest.builder() - .table("") // Replace with the table name - .tokenMode(TokenMode.DISABLE) // Disable BYOT - .data(data2) // Data to update - .returnTokens(false) // Do not return tokens + .table("") // Replace with the table name + .tokenMode(TokenMode.DISABLE) // Disable TokenMode + .data(data2) // Data to update + .returnTokens(false) // Do not return tokens .build(); - UpdateResponse updateResponse2 = skyflowClient.vault("").update(updateRequest2); // Perform the update - System.out.println("Update Response (BYOT Disabled): " + updateResponse2); + UpdateResponse updateResponse2 = skyflowClient.vault().update(updateRequest2); // Perform the update + System.out.println("Update Response (TokenMode Disabled): " + updateResponse2); } catch (SkyflowException e) { - System.out.println("Error during update with BYOT disabled:"); - e.printStackTrace(); + System.out.println("Error during update with TokenMode disabled:" + e); } } }