From 9a4f0e6a9f48eb60490ee14531389e703dcdff0b Mon Sep 17 00:00:00 2001 From: skyflow-shravan <121150537+skyflow-shravan@users.noreply.github.com> Date: Thu, 16 Jan 2025 21:31:58 +0530 Subject: [PATCH 1/6] SK-1815 beta release for v2 (#153) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * SK-1663 Basic scaffolding and project structure for v2 * SK-1663 Worked on feedback for scaffolding * SK-1663 Moved main dir to src dir * SK-1663 Scaffolding for java sdk v2 - Renamed packages according to design doc for sdk v2 * SK-1663 Java sdk v2 scaffolding worked on feedback * SK-1663 Update method signatures for all controllers * SK-1663 Worked on feedback for java sdk v2 scafolding - SK-1677 Worked on client intialisation for Java SDK v2 * SK-1677 Delete old vault controller implementation * SK-1677 Client Initilisation and Credentials priorotisation * SK-1677 Client initilisation and credentials prioritisation * SK-1677 Used Constants instead of hard-coded strings * SK-1678 Bearer Token uitlities - Implemented bearer token utilities for generating bearer token with or without context and roles - Implemented Token utilties to check for validity of tokens - Implemented signed data tokens utilities to generate signed data tokens * SK-1665 Generate and integrate Data API code * SK-1664 Public interfaces for vault APIs - SK-1703 Implemented public interfaces for detokenize * SK-1701 Implemented public interfaces for insert vault API * SK-1703 Worked on feedback for Detokenize public interfaces * SK-1701 Worked on feedback for Insert public interfaces * SK-1702 Implement public interfaces for Get vault API * SK-1678 Replaced use of JSONObject with Gson JsonObject SK-1703 Abstracted constructor for Detokenize Request Builder * SK-1664 Implement vault API public interfaces - SK-1701 Modified insert public interfaces - SK-1702 Modified get public interfaces - SK-1704 Implemented update public interfaces * SK-1707 Implement Delete API public interfaces * SK-1705 Implement Query API public interfaces * SK-1664 implement tokenize api public interface * SK-1666 implement invoke connection public interface * SK-1701 Add continueOnError in insert vault API public interface * SK-1681 Add validations * SK-1681 add validations for tokenize request * SK-1666 validations for invoke connection request * SK-1664 move ColumnValue class to tokens package * SK-1664 Implement vault API interfaces - Change builder pattern implementation for vault API interfaces * SK-1682 add error codes, messages and logs * SK-1681 Add validations * SK-1678 Add support for using Api Key SK-1681 Add validations for Api Key * SK-1680 Implement logging SK-1723 Add error messages and codes * SK-1684 Add unit tests - Added unit tests for Detokenize request validations - Added unit tests for Insert request validations​ ​- Added unit tests for Get request validations​ ​- Added unit tests for Update request validations​ - Added unit tests for Delete request validations​ ​​- Added unit tests for Query request validations​ * SK-1680 Changed info logs to error logs in validation checks - SK-1681 Updated validation checks for Get request interface * SK-1684 Add unit tests - Add unit tests for configs i.e. vault, connection and credentials - Add unit tests for response pojo classes for few vault API interfaces * SK-1684 Add unit tests for bearer token utilities * SK-1684 Add unit tests for signed data tokens SK-1684 Add unit tests for Tokenize request validations * SK-1684 Add unit tests for Java SDK v2 * SK-1666 Fix conflicts and build issues after merge * SK-1684 Add unit tests for invoke connection SK-1766 Add validations for invoke connection interface SK-1766 Refactor code for invoke connection, removed unnecessary components for code optimisation * SK-1623 Java SDK v2 Removed v1,v2 modules and moved all v2 code directly to parent module Removed unnecessary dependencies * SK-1623 Downgrade dotenv to work with java 8 * SK-1767 Fix unit tests not running in CI pipeline * SK-1767 Add new secret for Java SDK v2 tests * SK-1767 Fix issues in CI pipeline * SK-1767 Fix compilation issues in CI pipeline - Excluding generating code from javadoc generation * SK-1682 Modified the structure of Skyflow error * SK-1623 Fix minor issues in Java SDK v2 * SK-1685 Add samples for Java SDK v2 - Added samples for vault API interfaces - Added sample for invoke connection interface * SK-1685 Add samples for Bearer token utilities * SK-1623 Fix minor issues in Javs SDK v2 * SK-1752 workflow for internal release * SK-1752 workflow for internal release * SK-1753 add create env step * SK-1753 auto generate release version in pom.xml * SK-1753 auto generate release version in pom.xml * SK-1753 auto generate release version in pom.xml * SK-1753 auto generate release version in pom.xml * SK-1753 auto generate release version in pom.xml * SK-1753 auto generate release version in pom.xml * SK-1753 auto generate release version in pom.xml * SK-1753 restore version in pom.xml * SK-1623 Fix typos in Samples * SK-1623 Worked on feedback for Update vault API interface * SK-1633 Upgraded dependency version * SK-1623 Made constructors for Bearer token utilities builders private * SK-1750 Rewrited README for SDK v2 * SK-1750 Change tokenStrict to tokenMode * SK-1790 Changed tokenStrict to tokenMode - Changed tokenStrict to tokenMode for insert and update requests. - Changed methodName to method for invoke connection request. - Changed enum Byot to TokenMode. * SK-1786 common workflow for internal and public release * SK-1789 common workflow for public and internal release v2 * SK-1786 test common workflow * SK-1786 modify scripts path in workflow * SK-1786 fix commit step * [AUTOMATED] Private Release 1.15.0-dev-f6c7f07 * SK-1786 include secrets from github * SK-1786 modify pattern in commit message check * [AUTOMATED] Private Release 1.15.0-dev-4ea53e6 * SK-1802 Fix inconsistencies in SDK v2 * SK-1802 Fix inconsistencies in SDK v2 - Fix inconsistency between vault and connection client - Added unit tests for vault and connection clients * SK-1802 Update examples and added unit tests * SK-1802 Renamed github secret * SK-1737 Fix inconsistencies in Java SDK * [AUTOMATED] Private Release 1.15.0-dev-8339ce7 * SK-1737 Update workflow to fix build issue * [AUTOMATED] Private Release 1.15.0-dev-f146b51 * SK-1737 add stack trace to debug failures * [AUTOMATED] Private Release 1.15.0-dev-ad9b710 * SK-1737 Fix spelling in error message * [AUTOMATED] Private Release 1.15.0-dev-d2e7155 * SK-1737 Added secrets for shared workflow * [AUTOMATED] Private Release 1.15.0-dev-a0537e8 * SK-1815 workflow for beta release (#152) * SK-1815 workflow for beta release * SK-1815 workflow for beta release * SK-1815 workflow for beta release * SK-1815 workflow for beta release * SK-1829/Release/25.1.1 (#155) * SK-1829 Fix http status for validation errors in Java SDK v2 * SK-1829 Fix errors in Invoke connection flow in Java SDK v2 * [AUTOMATED] Private Release 1.15.0-dev-27ca248 --------- Co-authored-by: skyflow-vivek --------- Co-authored-by: skyflow-vivek Co-authored-by: skyflow-vivek <121149418+skyflow-vivek@users.noreply.github.com> Co-authored-by: skyflow-shravan Co-authored-by: skyflow-vivek --- .github/workflows/shared-build-and-deploy.yml | 1 + README.md | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/shared-build-and-deploy.yml b/.github/workflows/shared-build-and-deploy.yml index 89332762..7fcbbce1 100644 --- a/.github/workflows/shared-build-and-deploy.yml +++ b/.github/workflows/shared-build-and-deploy.yml @@ -91,6 +91,7 @@ jobs: fi - name: Commit changes + if: ${{ inputs.tag == 'internal' || inputs.tag == 'public' }} run: | git config user.name ${{ github.actor }} git config user.email ${{ github.actor }}@users.noreply.github.com diff --git a/README.md b/README.md index 5ed7d604..c8229684 100644 --- a/README.md +++ b/README.md @@ -327,9 +327,9 @@ static class DemoTokenProvider implements TokenProvider { String filePath = ""; res = Token.generateBearerToken(filePath); } catch (SkyflowException e) { - e.printStackTrace(); + System.out.println("Error occurred: "); + System.out.println(e); } - return res.getAccessToken(); } } ``` @@ -642,6 +642,7 @@ public class InsertSchema { } } } + ``` Insert @@ -1266,7 +1267,7 @@ There are four accepted values for RedactionType: * `REDACTED` * `DEFAULT` -## Update +- `returnTokens` set to `false` To update data in your vault, use the `update` method. The `UpdateRequest` class is used to create an update request, where you specify parameters such as the table name, data (as a map of key value pairs), tokens, returnTokens, and @@ -1694,7 +1695,8 @@ public class ChangeLogLevel { Currently, the following 5 log levels are supported: -- `DEBUG`: + When `LogLevel.INFO` is passed, INFO logs for every event that has occurred during the SDK flow execution will be + printed along with WARN and ERROR logs When `LogLevel.DEBUG` is passed, all level of logs will be printed(DEBUG, INFO, WARN, ERROR) From 00ab0928e873772ce4b0cb5f3115ee299fc09a95 Mon Sep 17 00:00:00 2001 From: skyflow-shravan Date: Thu, 16 Jan 2025 21:37:26 +0530 Subject: [PATCH 2/6] SK-1815 update beta version in pom xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 99d337e7..052dab76 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.skyflow skyflow-java - 1.15.0-dev.27ca248 + 2.0.0-beta.1 jar ${project.groupId}:${project.artifactId} From a1b4e0e4385550769124c303b7e950f5b689732d Mon Sep 17 00:00:00 2001 From: skyflow-shravan Date: Fri, 17 Jan 2025 13:43:53 +0530 Subject: [PATCH 3/6] SK-1833 update samples --- .../com/example/connection/InvokeConnectionExample.java | 4 ++-- samples/src/main/java/com/example/vault/GetExample.java | 1 - samples/src/main/java/com/example/vault/InsertExample.java | 6 +++--- samples/src/main/java/com/example/vault/UpdateExample.java | 6 +++--- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/samples/src/main/java/com/example/connection/InvokeConnectionExample.java b/samples/src/main/java/com/example/connection/InvokeConnectionExample.java index bae6a416..a730ca25 100644 --- a/samples/src/main/java/com/example/connection/InvokeConnectionExample.java +++ b/samples/src/main/java/com/example/connection/InvokeConnectionExample.java @@ -61,7 +61,7 @@ public static void main(String[] args) throws SkyflowException { // Build the POST request to invoke the connection InvokeConnectionRequest invokeConnectionRequest1 = InvokeConnectionRequest.builder() - .methodName(RequestMethod.POST) // Set the HTTP method to POST + .method(RequestMethod.POST) // Set the HTTP method to POST .requestBody(requestBody) // Set the request body .requestHeaders(requestHeaders) // Set the request headers .build(); @@ -87,7 +87,7 @@ public static void main(String[] args) throws SkyflowException { // Build the GET request to invoke the connection InvokeConnectionRequest invokeConnectionRequest2 = InvokeConnectionRequest.builder() - .methodName(RequestMethod.GET) // Set the HTTP method to GET + .method(RequestMethod.GET) // Set the HTTP method to GET .pathParams(pathParams) // Set the path parameters .queryParams(queryParams) // Set the query parameters .build(); diff --git a/samples/src/main/java/com/example/vault/GetExample.java b/samples/src/main/java/com/example/vault/GetExample.java index a25f580f..f964cfd2 100644 --- a/samples/src/main/java/com/example/vault/GetExample.java +++ b/samples/src/main/java/com/example/vault/GetExample.java @@ -56,7 +56,6 @@ public static void main(String[] args) throws SkyflowException { ids.add(""); // Replace with the Skyflow ID to fetch the record GetRequest getByIdRequest = GetRequest.builder() - .returnTokens(true) // Return tokens along with the fetched data .ids(ids) // Specify the list of Skyflow IDs .table("") // Replace with the table name .build(); diff --git a/samples/src/main/java/com/example/vault/InsertExample.java b/samples/src/main/java/com/example/vault/InsertExample.java index 3aa5309c..b84439f0 100644 --- a/samples/src/main/java/com/example/vault/InsertExample.java +++ b/samples/src/main/java/com/example/vault/InsertExample.java @@ -3,7 +3,7 @@ import com.skyflow.Skyflow; import com.skyflow.config.Credentials; import com.skyflow.config.VaultConfig; -import com.skyflow.enums.Byot; +import com.skyflow.enums.TokenMode; import com.skyflow.enums.Env; import com.skyflow.enums.LogLevel; import com.skyflow.errors.SkyflowException; @@ -68,7 +68,7 @@ public static void main(String[] args) throws SkyflowException { InsertRequest insertRequest = InsertRequest.builder() .table("") // Replace with the table name .continueOnError(true) // Continue inserting even if some records fail - .tokenStrict(Byot.ENABLE) // Enable BYOT for token validation + .tokenMode(TokenMode.ENABLE) // Enable BYOT for token validation .values(values1) // Data to insert .tokens(tokens) // Provide tokens for BYOT columns .returnTokens(true) // Return tokens along with the response @@ -92,7 +92,7 @@ public static void main(String[] args) throws SkyflowException { InsertRequest upsertRequest = InsertRequest.builder() .table("") // Replace with the table name .continueOnError(false) // Stop inserting if any record fails - .tokenStrict(Byot.DISABLE) // Disable BYOT + .tokenMode(TokenMode.DISABLE) // Disable BYOT .values(values2) // Data to insert .returnTokens(false) // Do not return tokens .upsert("") // Replace with the column name used for upsert logic diff --git a/samples/src/main/java/com/example/vault/UpdateExample.java b/samples/src/main/java/com/example/vault/UpdateExample.java index 1a220bb1..d69fbf6c 100644 --- a/samples/src/main/java/com/example/vault/UpdateExample.java +++ b/samples/src/main/java/com/example/vault/UpdateExample.java @@ -3,7 +3,7 @@ import com.skyflow.Skyflow; import com.skyflow.config.Credentials; import com.skyflow.config.VaultConfig; -import com.skyflow.enums.Byot; +import com.skyflow.enums.TokenMode; import com.skyflow.enums.Env; import com.skyflow.enums.LogLevel; import com.skyflow.errors.SkyflowException; @@ -62,7 +62,7 @@ public static void main(String[] args) throws SkyflowException { UpdateRequest updateRequest1 = UpdateRequest.builder() .table("") // Replace with the table name - .tokenStrict(Byot.ENABLE) // Enable BYOT for token validation + .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 @@ -84,7 +84,7 @@ public static void main(String[] args) throws SkyflowException { UpdateRequest updateRequest2 = UpdateRequest.builder() .table("") // Replace with the table name - .tokenStrict(Byot.DISABLE) // Disable BYOT + .tokenMode(TokenMode.DISABLE) // Disable BYOT .data(data2) // Data to update .returnTokens(false) // Do not return tokens .build(); From 8851d28582ae1080fa02a5bf2feabe397082d326 Mon Sep 17 00:00:00 2001 From: skyflow-vivek Date: Mon, 17 Mar 2025 21:04:10 +0530 Subject: [PATCH 4/6] SK-1959 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); } } } From b0658dc9f0122c4fe86976c380bcdb23a87561d2 Mon Sep 17 00:00:00 2001 From: skyflow-vivek Date: Wed, 19 Mar 2025 16:57:22 +0530 Subject: [PATCH 5/6] SK-1959 Fix README after rebase --- README.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c8229684..5ed7d604 100644 --- a/README.md +++ b/README.md @@ -327,9 +327,9 @@ static class DemoTokenProvider implements TokenProvider { String filePath = ""; res = Token.generateBearerToken(filePath); } catch (SkyflowException e) { - System.out.println("Error occurred: "); - System.out.println(e); + e.printStackTrace(); } + return res.getAccessToken(); } } ``` @@ -642,7 +642,6 @@ public class InsertSchema { } } } - ``` Insert @@ -1267,7 +1266,7 @@ There are four accepted values for RedactionType: * `REDACTED` * `DEFAULT` -- `returnTokens` set to `false` +## Update To update data in your vault, use the `update` method. The `UpdateRequest` class is used to create an update request, where you specify parameters such as the table name, data (as a map of key value pairs), tokens, returnTokens, and @@ -1695,8 +1694,7 @@ public class ChangeLogLevel { Currently, the following 5 log levels are supported: - When `LogLevel.INFO` is passed, INFO logs for every event that has occurred during the SDK flow execution will be - printed along with WARN and ERROR logs +- `DEBUG`: When `LogLevel.DEBUG` is passed, all level of logs will be printed(DEBUG, INFO, WARN, ERROR) From 57f888b0d12ed966c9bcff4a321c5e691f0ad76c Mon Sep 17 00:00:00 2001 From: skyflow-vivek Date: Wed, 19 Mar 2025 18:13:15 +0530 Subject: [PATCH 6/6] SK-1959 Fix workflow after rebase --- .github/workflows/shared-build-and-deploy.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/shared-build-and-deploy.yml b/.github/workflows/shared-build-and-deploy.yml index 7fcbbce1..89332762 100644 --- a/.github/workflows/shared-build-and-deploy.yml +++ b/.github/workflows/shared-build-and-deploy.yml @@ -91,7 +91,6 @@ jobs: fi - name: Commit changes - if: ${{ inputs.tag == 'internal' || inputs.tag == 'public' }} run: | git config user.name ${{ github.actor }} git config user.email ${{ github.actor }}@users.noreply.github.com