diff --git a/.github/workflows/beta-release.yml b/.github/workflows/beta-release.yml index b30cc27f..d68c1671 100644 --- a/.github/workflows/beta-release.yml +++ b/.github/workflows/beta-release.yml @@ -7,9 +7,10 @@ jobs: uses: ./.github/workflows/shared-build-and-deploy.yml with: ref: ${{ github.ref_name }} - server-id: ossrh + server-id: central profile: maven-central tag: 'beta' + module: 'v3' secrets: server-username: ${{ secrets.CENTRAL_PUBLISHER_PORTAL_USERNAME }} server-password: ${{ secrets.CENTRAL_PUBLISHER_PORTAL_PASSWORD }} @@ -17,4 +18,4 @@ jobs: gpg-passphrase: ${{ secrets.MAVEN_GPG_PASSPHRASE }} skyflow-credentials: ${{ secrets.SKYFLOW_CREDENTIALS }} >> .env test-expired-token: ${{ secrets.TEST_EXPIRED_TOKEN }} >> .env - test-reusable-token: ${{ secrets.TEST_REUSABLE_TOKEN }} >> .env + test-reusable-token: ${{ secrets.TEST_REUSABLE_TOKEN }} >> .env \ No newline at end of file diff --git a/.github/workflows/internal-release.yml b/.github/workflows/internal-release.yml index e8b8ee61..ce1145b3 100644 --- a/.github/workflows/internal-release.yml +++ b/.github/workflows/internal-release.yml @@ -1,4 +1,4 @@ -name: Publish package to the JFROG Artifactory +name: Publish v3 module to the JFROG Artifactory on: push: tags-ignore: @@ -6,16 +6,17 @@ on: paths-ignore: - "*.md" branches: - - release/* + - v3-release/* jobs: - build-and-deploy: + build-and-deploy-v3: uses: ./.github/workflows/shared-build-and-deploy.yml with: ref: ${{ github.ref_name }} server-id: central profile: jfrog tag: 'internal' + module: 'v3' secrets: server-username: ${{ secrets.ARTIFACTORY_USERNAME }} server-password: ${{ secrets.ARTIFACTORY_PASSWORD }} @@ -23,4 +24,4 @@ jobs: gpg-passphrase: ${{ secrets.JFROG_GPG_PASSPHRASE }} skyflow-credentials: ${{ secrets.SKYFLOW_CREDENTIALS }} >> .env test-expired-token: ${{ secrets.TEST_EXPIRED_TOKEN }} >> .env - test-reusable-token: ${{ secrets.TEST_REUSABLE_TOKEN }} >> .env + test-reusable-token: ${{ secrets.TEST_REUSABLE_TOKEN }} >> .env \ No newline at end of file diff --git a/.github/workflows/shared-build-and-deploy.yml b/.github/workflows/shared-build-and-deploy.yml index c9cadd2c..d33f908a 100644 --- a/.github/workflows/shared-build-and-deploy.yml +++ b/.github/workflows/shared-build-and-deploy.yml @@ -21,6 +21,13 @@ on: description: 'Release Tag' required: true type: string + + module: + description: 'Module to build and publish' + required: false + type: string + default: '' + secrets: server-username: required: true @@ -54,7 +61,7 @@ jobs: - name: Set up maven or jfrog repository uses: actions/setup-java@v1 with: - java-version: "1.8" + java-version: "11" distribution: "adopt" server-id: ${{ inputs.server-id }} server-username: SERVER_USERNAME @@ -87,7 +94,7 @@ jobs: if ${{ inputs.tag == 'internal' }}; then ./scripts/bump_version.sh "${{ steps.previoustag.outputs.tag }}" "$(git rev-parse --short "$GITHUB_SHA")" else - ./scripts/bump_version.sh "${{ steps.previoustag.outputs.tag }}" + ./scripts/bump_version.sh "${{ steps.previoustag.outputs.tag }}" "" "${{ inputs.module }}" fi - name: Commit changes @@ -99,7 +106,7 @@ jobs: git checkout ${{ env.branch_name }} fi - git add pom.xml + git add v3/pom.xml if [[ "${{ inputs.tag }}" == "internal" ]]; then git commit -m "[AUTOMATED] Private Release ${{ steps.previoustag.outputs.tag }}-dev-$(git rev-parse --short $GITHUB_SHA)" git push origin ${{ github.ref_name }} -f @@ -125,9 +132,14 @@ jobs: json: ${{ secrets.TEST_CREDENTIALS_FILE_STRING }} - name: Publish package - run: mvn --batch-mode deploy -P ${{ inputs.profile }} + run: | + if [[ "${{ inputs.tag }}" == "internal" ]]; then + mvn --batch-mode -pl ${{ inputs.module }} -am deploy -P jfrog + elif [[ "${{ inputs.tag }}" == "beta" || "${{ inputs.tag }}" == "public" ]]; then + mvn --batch-mode -pl ${{ inputs.module }} -am deploy -P ${{ inputs.profile }} + fi env: SERVER_USERNAME: ${{ secrets.server-username }} SERVER_PASSWORD: ${{ secrets.server-password }} - GPG_PASSPHRASE: ${{ secrets.gpg-passphrase }} + GPG_PASSPHRASE: ${{ secrets.gpg-passphrase }} \ No newline at end of file diff --git a/README.md b/README.md index 7c80d174..a5bd66c8 100644 --- a/README.md +++ b/README.md @@ -15,35 +15,12 @@ The Skyflow Java SDK is designed to help with integrating Skyflow into a Java ba - [Configuration](#configuration) - [Gradle users](#gradle-users) - [Maven users](#maven-users) -- [Migration from v1 to v2](#migration-from-v1-to-v2) - - [Authentication options](#authentication-options) - - [Initializing the client](#initializing-the-client) - - [Request & response structure](#request--response-structure) - - [Request options](#request-options) - - [Error structure](#error-structure) - [Quickstart](#quickstart) - [Authenticate](#authenticate) - [Initialize the client](#initialize-the-client) - - [Insert data into the vault](#insert-data-into-the-vault) - [Vault](#vault) - - [Insert data into the vault](#insert-data-into-the-vault-1) - - [Detokenize](#detokenize) - - [Tokenize](#tokenize) - - [Get](#get) - - [Get by skyflow IDS](#get-by-skyflow-ids) - - [Get tokens](#get-tokens) - - [Get by column name and column values](#get-by-column-name-and-column-values) - - [Redaction types](#redaction-types) - - [Update](#update) - - [Delete](#delete) - - [Query](#query) -- [Detect](#detect) - - [Deidentify Text](#deidentify-text) - - [Reidentify Text](#reidentify-text) - - [Deidentify File](#deidentify-file) - - [Get Run](#get-run) -- [Connections](#connections) - - [Invoke a connection](#invoke-a-connection) + - [Bulk insert data into the vault](#bulk-insert-data-into-the-vault) + - [Bulk Detokenize](#bulk-detokenize) - [Authenticate with bearer tokens](#authenticate-with-bearer-tokens) - [Generate a bearer token](#generate-a-bearer-token) - [Generate bearer tokens with context](#generate-bearer-tokens-with-context) @@ -56,8 +33,7 @@ The Skyflow Java SDK is designed to help with integrating Skyflow into a Java ba # Overview - Authenticate using a Skyflow service account and generate bearer tokens for secure access. -- Perform Vault API operations such as inserting, retrieving, and tokenizing sensitive data with ease. -- Invoke connections to third-party APIs without directly handling sensitive data, ensuring compliance and data protection. +- Perform Vault API operations such as inserting, and detokenizing sensitive data with ease. # Install @@ -74,7 +50,7 @@ The Skyflow Java SDK is designed to help with integrating Skyflow into a Java ba Add this dependency to your project's `build.gradle` file: ``` -implementation 'com.skyflow:skyflow-java:2.0.0' +implementation 'com.skyflow:skyflow-java:3.0.0-beta.3' ``` ### Maven users @@ -85,277 +61,15 @@ Add this dependency to your project's `pom.xml` file: com.skyflow skyflow-java - 2.0.0 + 3.0.0-beta.3 ``` --- -# Migrate from v1 to v2 - -Below are the steps to migrate the java sdk from v1 to v2. - -### Authentication options - -In V2, we have introduced multiple authentication options. You can now provide credentials in the following ways: - -- Passing credentials in ENV. (`SKYFLOW_CREDENTIALS`) _(Recommended)_ -- API Key -- Path to your credentials JSON file -- Stringified JSON of your credentials -- Bearer token - -These options allow you to choose the authentication method that best suits your use case. - -**V1 (Old)** - -```java -static class DemoTokenProvider implements TokenProvider { - @Override - public String getBearerToken() throws Exception { - ResponseToken res = null; - try { - String filePath = ""; - res = Token.generateBearerToken(filePath); - } catch (SkyflowException e) { - e.printStackTrace(); - } - return res.getAccessToken(); - } -} -``` - -**V2 (New): Passing one of the following:** - -```java -// Option 1: API Key (Recommended) -Credentials skyflowCredentials = new Credentials(); -skyflowCredentials.setApiKey(""); // Replace with your actual API key - -// Option 2: Environment Variables (Recommended) -// Set SKYFLOW_CREDENTIALS in your environment - -// Option 3: Credentials File -skyflowCredentials.setPath(""); // Replace with the path to credentials file - -// Option 4: Stringified JSON -skyflowCredentials.setCredentialsString(""); // Replace with the credentials string - -// Option 5: Bearer Token -skyflowCredentials.setToken(""); // Replace with your actual authentication token. -``` - -Notes: - -- Use only ONE authentication method. -- API Key or environment variables are recommended for production use. -- Secure storage of credentials is essential. -- For overriding behavior and priority order of credentials, please refer to [Initialize the client](#initialize-the-client) section in [Quickstart](#quickstart). - ---- - -### Initializing the client - -In V2, we have introduced a builder design pattern for client initialization and added support for multi-vault. This allows you to configure multiple vaults during client initialization. In V2, the log level is tied to each individual client instance. During client initialization, you can pass the following parameters: - -- `vaultId` and `clusterId`: These values are derived from the vault ID & vault URL. -- `env`: Specify the environment (e.g., SANDBOX or PROD). -- `credentials`: The necessary authentication credentials. - -**V1 (Old)** - -```java -// DemoTokenProvider class is an implementation of the TokenProvider interface -DemoTokenProvider demoTokenProvider = new DemoTokenProvider(); -SkyflowConfiguration skyflowConfig = new SkyflowConfiguration("","", demoTokenProvider); -Skyflow skyflowClient = Skyflow.init(skyflowConfig); -``` - -**V2 (New)** - -```java -Credentials credentials = new Credentials(); -credentials.setPath(""); // Replace with the path to the credentials file - -// Configure the first vault (Blitz) -VaultConfig config = new VaultConfig(); -config.setVaultId(""); // Replace with the ID of the first vault -config.setClusterId(""); // Replace with the cluster ID of the first vault -config.setEnv(Env.DEV); // Set the environment (e.g., DEV, STAGE, PROD) -config.setCredentials(credentials); // Associate the credentials with the vault - -// Set up credentials for the Skyflow client -Credentials skyflowCredentials = new Credentials(); -skyflowCredentials.setPath(""); // Replace with the path to another credentials file - -// Create a Skyflow client and add vault configurations -Skyflow skyflowClient = Skyflow.builder() - .setLogLevel(LogLevel.DEBUG) // Enable debugging for detailed logs - .addVaultConfig(config) // Add the first vault configuration - .addSkyflowCredentials(skyflowCredentials) // Add general Skyflow credentials - .build(); -``` - -**Key Changes:** - -- `vaultUrl` replaced with `clusterId`. -- Added environment specification (`env`). -- Instance-specific log levels. - ---- - -### Request & response structure - -In V2, we have removed the use of JSON objects from a third-party package. Instead, we have transitioned to accepting native ArrayList and HashMap data structures and adopted the builder pattern for request creation. This request needs: - -- `table`: The name of the table. -- `values`: An array list of objects containing the data to be inserted. - -The response will be of type `InsertResponse` class, which contains `insertedFields` and `errors`. - -**V1 (Old):** Request building - -```java -JSONObject recordsJson = new JSONObject(); -JSONArray recordsArrayJson = new JSONArray(); - -JSONObject recordJson = new JSONObject(); -recordJson.put("table", "cards"); - -JSONObject fieldsJson = new JSONObject(); -fields.put("cardNumber", "41111111111"); -fields.put("cvv", "123"); - -recordJson.put("fields", fieldsJson); -recordsArrayJson.add(record); -recordsJson.put("records", recordsArrayJson); -try { - JSONObject insertResponse = skyflowClient.insert(records); - System.out.println(insertResponse); -} catch (SkyflowException exception) { - System.out.println(exception); -} -``` - -**V2 (New):** Request building - -```java -ArrayList> values = new ArrayList<>(); -HashMap value = new HashMap<>(); -value.put("", ""); // Replace with column name and value -value.put("", ""); // Replace with another column name and value -values.add(values); - -ArrayList> tokens = new ArrayList<>(); -HashMap token = new HashMap<>(); -token.put("", ""); // Replace with the token for COLUMN_NAME_2 -tokens.add(token); - -InsertRequest insertRequest = InsertRequest.builder() - .table("") // Replace with the table name - .continueOnError(true) // Continue inserting even if some records fail - .tokenMode(TokenMode.ENABLE) // Enable BYOT for token validation - .values(values) // Data to insert - .tokens(tokens) // Provide tokens for BYOT columns - .returnTokens(true) // Return tokens along with the response - .build(); -``` - -**V1 (Old):** Response structure - -```json -{ - "records": [ - { - "table": "cards", - "fields": { - "skyflow_id": "16419435-aa63-4823-aae7-19c6a2d6a19f", - "cardNumber": "f3907186-e7e2-466f-91e5-48e12c2bcbc1", - "cvv": "1989cb56-63da-4482-a2df-1f74cd0dd1a5" - } - } - ] -} -``` - -**V2 (New):** Response structure - -```json -{ - "insertedFields": [ - { - "card_number": "5484-7829-1702-9110", - "request_index": "0", - "skyflow_id": "9fac9201-7b8a-4446-93f8-5244e1213bd1", - "cardholder_name": "b2308e2a-c1f5-469b-97b7-1f193159399b" - } - ], - "errors": [] -} -``` - ---- - -### Request options - -In V2, with the introduction of the builder design pattern has made handling optional fields in Java more efficient and straightforward. - -**V1 (Old)** - -```java -InsertOptions insertOptions = new InsertOptions(true); -``` - -**V2 (New)** - -```java -InsertRequest upsertRequest = new InsertRequest.builder() - .table("") // Replace with the table name - .continueOnError(false) // Stop inserting if any record fails - .tokenMode(TokenMode.DISABLE) // Disable BYOT - .values(values) // Data to insert - .returnTokens(false) // Do not return tokens - .upsert("") // Replace with the column name used for upsert logic - .build(); -``` - ---- - -### Error structure - -In V2, we have enriched the error details to provide better debugging capabilities. -The error response now includes: - -- `httpStatus`: The HTTP status code. -- `grpcCode`: The gRPC code associated with the error. -- `details` & `message`: A detailed description of the error. -- `requestId`: A unique request identifier for easier debugging. - -**V1 (Old):** Error structure - -```json -{ - "code": "", - "description": "" -} -``` - -**V2 (New):** Error structure - -```js -{ - "httpStatus": "", - "grpcCode": , - "httpCode": , - "message": "", - "requestId": "", - "details": ["
"] -} -``` - # Quickstart -Get started quickly with the essential steps: authenticate, initialize the client, and perform a basic vault operation. This section provides a minimal setup to help you integrate the SDK efficiently. +Get started quickly with the essential steps: authenticate and initialize the client. This section provides a minimal setup to help you integrate the SDK efficiently. ### Authenticate @@ -394,7 +108,7 @@ import com.skyflow.enums.LogLevel; import com.skyflow.errors.SkyflowException; /** - * Example program to initialize the Skyflow client with various configurations. + * Example program to initialize the Skyflow client with a vault configuration. * The Skyflow client facilitates secure interactions with the Skyflow vault, * such as securely managing sensitive data. */ @@ -408,16 +122,16 @@ public class InitSkyflowClient { // - A file path to a credentials file. // Initialize primary credentials using a Bearer token for authentication. - Credentials primaryCredentials = new Credentials(); - primaryCredentials.setToken(""); // Replace with your actual authentication token. + Credentials credentials = new Credentials(); + credentials.setToken(""); // Replace with your actual authentication token. // Step 2: Configure the primary vault details. // VaultConfig stores all necessary details to connect to a specific Skyflow vault. - VaultConfig primaryConfig = new VaultConfig(); - primaryConfig.setVaultId(""); // Replace with your primary vault's ID. + VaultConfig config = new VaultConfig(); + primaryConfig.setVaultId(""); // Replace with your vault's ID. primaryConfig.setClusterId(""); // Replace with the cluster ID (part of the vault URL, e.g., https://{clusterId}.vault.skyflowapis.com). primaryConfig.setEnv(Env.PROD); // Set the environment (PROD, SANDBOX, STAGE, DEV). - primaryConfig.setCredentials(primaryCredentials); // Attach the primary credentials to this vault configuration. + primaryConfig.setCredentials(credentials); // Attach the credentials to this vault configuration. // Step 3: Create credentials as a JSON object (if a Bearer Token is not provided). // Demonstrates an alternate approach to authenticate with Skyflow using a credentials object. @@ -433,46 +147,18 @@ public class InitSkyflowClient { Credentials skyflowCredentials = new Credentials(); skyflowCredentials.setCredentialsString(credentialsObject.toString()); // Converts JSON object to string for use as credentials. - // Step 5: Define secondary credentials (API key-based authentication as an example). - // Demonstrates a different type of authentication mechanism for Skyflow vaults. - Credentials secondaryCredentials = new Credentials(); - secondaryCredentials.setApiKey(""); // Replace with your API Key for authentication. - - // Step 6: Configure the secondary vault details. - // A secondary vault configuration can be used for operations involving multiple vaults. - VaultConfig secondaryConfig = new VaultConfig(); - secondaryConfig.setVaultId(""); // Replace with your secondary vault's ID. - secondaryConfig.setClusterId(""); // Replace with the corresponding cluster ID. - secondaryConfig.setEnv(Env.SANDBOX); // Set the environment for this vault. - secondaryConfig.setCredentials(secondaryCredentials); // Attach the secondary credentials to this configuration. - - // Step 7: Define tertiary credentials using a path to a credentials JSON file. - // This method demonstrates an alternative authentication method. - Credentials tertiaryCredentials = new Credentials(); - tertiaryCredentials.setPath(""); // Replace with the path to your credentials file. - - // Step 8: Configure the tertiary vault details. - VaultConfig tertiaryConfig = new VaultConfig(); - tertiaryConfig.setVaultId(""); // Replace with the tertiary vault ID. - tertiaryConfig.setClusterId(""); // Replace with the corresponding cluster ID. - tertiaryConfig.setEnv(Env.STAGE); // Set the environment for this vault. - tertiaryConfig.setCredentials(tertiaryCredentials); // Attach the tertiary credentials. - - // Step 9: Build and initialize the Skyflow client. + // Step 5: Build and initialize the Skyflow client. // Skyflow client is configured with multiple vaults and credentials. Skyflow skyflowClient = Skyflow.builder() .setLogLevel(LogLevel.INFO) // Set log level for debugging or monitoring purposes. - .addVaultConfig(primaryConfig) // Add the primary vault configuration. - .addVaultConfig(secondaryConfig) // Add the secondary vault configuration. - .addVaultConfig(tertiaryConfig) // Add the tertiary vault configuration. + .addVaultConfig(config) // Add the vault configuration. .addSkyflowCredentials(skyflowCredentials) // Add JSON-formatted credentials if applicable. .build(); // The Skyflow client is now fully initialized. // Use the `skyflowClient` object to perform secure operations such as: // - Inserting data - // - Retrieving data - // - Deleting data + // - Detokenizing data // within the configured Skyflow vaults. } } @@ -484,86 +170,13 @@ Notes: - If neither Skyflow common credentials nor individual configuration-level credentials are provided, the SDK attempts to retrieve credentials from the `SKYFLOW_CREDENTIALS` environment variable. - All Vault operations require a client instance. -### Insert data into the vault - -To insert data into your vault, use the `insert` method. The `InsertRequest` class creates an insert request, which includes the values to be inserted as a list of records. Below is a simple example to get started. For advanced options, check out [Insert data into the vault](#insert-data-into-the-vault-1) section. - -```java -import com.skyflow.errors.SkyflowException; -import com.skyflow.vault.data.InsertRequest; -import com.skyflow.vault.data.InsertResponse; - -import java.util.ArrayList; -import java.util.HashMap; - -/** - * This example demonstrates how to insert sensitive data (e.g., card information) into a Skyflow vault using the Skyflow client. - * - * 1. Initializes the Skyflow client. - * 2. Prepares a record with sensitive data (e.g., card number and cardholder name). - * 3. Creates an insert request for inserting the data into the Skyflow vault. - * 4. Prints the response of the insert operation. - */ -public class InsertExample { - public static void main(String[] args) { - try { - // Initialize Skyflow client - // Step 1: Initialize data to be inserted into the Skyflow vault - ArrayList> insertData = new ArrayList<>(); - - // Create a HashMap for a single record with card number and cardholder name as fields - HashMap insertRecord = new HashMap<>(); - insertRecord.put("card_number", "4111111111111111"); // Replace with actual card number (sensitive data) - insertRecord.put("cardholder_name", "john doe"); // Replace with actual cardholder name (sensitive data) - - // Add the created record to the list of data to be inserted - insertData.add(insertRecord); - - // Step 2: Build the InsertRequest object with the table name and data to insert - InsertRequest insertRequest = InsertRequest.builder() - .table("table1") // Specify the table in the vault where the data will be inserted - .values(insertData) // Attach the data (records) to be inserted - .returnTokens(true) // Specify if tokens should be returned upon successful insertion - .build(); // Build the insert request object - - // Step 3: Perform the insert operation using the Skyflow client - InsertResponse insertResponse = skyflowClient.vault("9f27764a10f7946fe56b3258e117").insert(insertRequest); - // Replace the vault ID "9f27764a10f7946fe56b3258e117" with your actual Skyflow vault ID - - // Step 4: Print the response from the insert operation - System.out.println(insertResponse); - } catch (SkyflowException e) { - // Step 5: Handle any exceptions that may occur during the insert operation - System.out.println("Error occurred: "); - e.printStackTrace(); // Print the stack trace for debugging purposes - } - } -} -``` - -Skyflow returns tokens for the record that was just inserted. - -```json -{ - "insertedFields": [ - { - "card_number": "5484-7829-1702-9110", - "request_index": "0", - "skyflow_id": "9fac9201-7b8a-4446-93f8-5244e1213bd1", - "cardholder_name": "b2308e2a-c1f5-469b-97b7-1f193159399b" - } - ], - "errors": [] -} -``` - # Vault -The [Vault](https://github.com/skyflowapi/skyflow-java/tree/main/src/main/java/com/skyflow/vault) module performs operations on the vault, including inserting records, detokenizing tokens, and retrieving tokens associated with a `skyflow_id`. +The [Vault](https://github.com/skyflowapi/skyflow-java/tree/main/src/main/java/com/skyflow/vault) module performs operations on the vault, including inserting records and detokenizing tokens. -## Insert data into the vault +## Bulk insert data into the vault -Apart from using the `insert` method to insert data into your vault covered in [Quickstart](#quickstart), you can also specify options in `InsertRequest`, such as returning tokenized data, upserting records, or continuing the operation in case of errors. +To insert data into your vault, use the `bulkinsert` or `bulkInsertAsync` methods. The `InsertRequest` class creates an insert request, which includes the values to be inserted as a list of records. ### Construct an insert request @@ -582,7 +195,8 @@ import java.util.HashMap; public class InsertSchema { public static void main(String[] args) { try { - // Initialize Skyflow client + // Initialize Skyflow client + // Step 1: Prepare the data to be inserted into the Skyflow vault ArrayList> insertData = new ArrayList<>(); @@ -606,9 +220,8 @@ public class InsertSchema { .values(insertData) // Attach the data to be inserted .build(); - // Step 3: Use the Skyflow client to perform the insert operation - InsertResponse insertResponse = skyflowClient.vault("").insert(insertRequest); - // Replace with your actual vault ID + // Step 3: Use the Skyflow client to perform the sync bulk insert operation + InsertResponse insertResponse = skyflowClient.vault().bulkInsert(insertRequest); // Print the response from the insert operation System.out.println("Insert Response: " + insertResponse); @@ -621,95 +234,107 @@ public class InsertSchema { } ``` -### Insert call [example](https://github.com/skyflowapi/skyflow-java/blob/SK-1893-update-readme-for-v2/samples/src/main/java/com/example/vault/InsertExample.java) with `continueOnError` option +### An [example](https://github.com/skyflowapi/skyflow-java/blob/v3/samples/src/main/java/com/example/vault/BulkInsertSync.java) of a sync bulkInsert call -The `continueOnError` flag is a boolean that determines whether insert operation should proceed despite encountering partial errors. Set to `true` to allow the process to continue even if some errors occur. +The `bulkInsert` operation operation will insert the data synchronously into the vault. ```java -import com.skyflow.errors.SkyflowException; -import com.skyflow.vault.data.InsertRequest; -import com.skyflow.vault.data.InsertResponse; - -import java.util.ArrayList; -import java.util.HashMap; - /** - * This example demonstrates how to insert multiple records into a Skyflow vault using the Skyflow client. - * - * 1. Initializes the Skyflow client. - * 2. Prepares multiple records with sensitive data (e.g., card number and cardholder name). - * 3. Creates an insert request with the records to insert into the Skyflow vault. - * 4. Specifies options to continue on error and return tokens. - * 5. Prints the response of the insert operation. + * Example program to demonstrate how to perform a synchronous bulk insert operation using the Skyflow Java SDK. + * The process involves: + * 1. Setting up credentials and vault configuration + * 2. Creating multiple records to be inserted + * 3. Building and executing a bulk insert request + * 4. Handling the insert response or any potential errors */ -public class InsertExample { +public class BulkInsertSync { public static void main(String[] args) { try { - // Initialize Skyflow client - // Step 1: Initialize a list to hold the data records to be inserted into the vault + // Initialize Skyflow client + + // Step 1: Prepare the data to be inserted into the Skyflow vault ArrayList> insertData = new ArrayList<>(); - // Step 2: Create the first record with card number and cardholder name + // Create the first record with field names and their respective values HashMap insertRecord1 = new HashMap<>(); - insertRecord1.put("card_number", "4111111111111111"); // Replace with actual card number (sensitive data) - insertRecord1.put("cardholder_name", "john doe"); // Replace with actual cardholder name (sensitive data) + insertRecord1.put("name", "John doe"); // Replace with actual field name and value + insertRecord1.put("email", "john.doe@example.com"); // Replace with actual field name and value - // Step 3: Create the second record with card number and cardholder name + // Create the second record with field names and their respective values HashMap insertRecord2 = new HashMap<>(); - insertRecord2.put("card_number", "4111111111111111"); // Ensure field name matches ("card_number") - insertRecord2.put("cardholder_name", "jane doe"); // Replace with actual cardholder name (sensitive data) + insertRecord2.put("name", "Jane doe"); // Replace with actual field name and value + insertRecord2.put("email", "jane.doe@example.com"); // Replace with actual field name and value - // Step 4: Add the records to the insertData list + // Add the records to the list of data to be inserted insertData.add(insertRecord1); insertData.add(insertRecord2); - // Step 5: Build the InsertRequest object with the data records to insert + // Step 2: Build an InsertRequest object with the table name and the data to insert InsertRequest insertRequest = InsertRequest.builder() - .table("table1") // Specify the table in the vault where data will be inserted - .values(insertData) // Attach the data records to be inserted - .returnTokens(true) // Specify if tokens should be returned upon successful insertion - .continueOnError(true) // Specify to continue inserting records even if an error occurs for some records - .build(); // Build the insert request object - - // Step 6: Perform the insert operation using the Skyflow client - InsertResponse insertResponse = skyflowClient.vault("9f27764a10f7946fe56b3258e117").insert(insertRequest); - // Replace the vault ID "9f27764a10f7946fe56b3258e117" with your actual Skyflow vault ID - - // Step 7: Print the response from the insert operation - System.out.println(insertResponse); + .table("table1") // Replace with the actual table name in your Skyflow vault + .values(insertData) // Attach the data to be inserted + .build(); + + // Step 3: Use the Skyflow client to perform the sync bulk insert operation + InsertResponse insertResponse = skyflowClient.vault().bulkInsert(insertRequest); + + // Print the response from the insert operation + System.out.println("Insert Response: " + insertResponse); } catch (SkyflowException e) { - // Step 8: Handle any exceptions that may occur during the insert operation - System.out.println("Error occurred: "); - e.printStackTrace(); // Print the stack trace for debugging purposes + // Step 4: Handle any exceptions that occur during the insert operation + System.out.println("Error occurred while inserting data: "); + e.printStackTrace(); // Print the stack trace for debugging } } } ``` -Sample response: +Skyflow returns tokens and data for the records that were just inserted. ```json { - "insertedFields": [ + "summary": { + "totalRecords": 2, + "totalInserted": 2, + "totalFailed": 0 + }, + "sucess": [ { - "card_number": "5484-7829-1702-9110", - "request_index": "0", + "index": 0, "skyflow_id": "9fac9201-7b8a-4446-93f8-5244e1213bd1", - "cardholder_name": "b2308e2a-c1f5-469b-97b7-1f193159399b" - } - ], - "errors": [ + "tokens": { + "name": [{ "token": "token_name", "tokenGroupName": "deterministic_string" }], + "email": [ + { + "token": "augn0@xebggri.lmp", + "tokenGroupName": "nondeterministic_string" + } + ] + }, + "data": { "email": "john.doe@example.com", "name": "john doe" } + }, { - "request_index": "1", - "error": "Insert failed. Column card_numbe is invalid. Specify a valid column." - } - ] + "index": 1, + "skyflow_id": "9fac9201-7b8a-4446-93f8-5244e1213bd3", + "tokens": { + "name": [{ "token": "token_name", "tokenGroupName": "deterministic_string" }], + "email": [ + { + "token": "buhn0@xebggrj.lmt", + "tokenGroupName": "nondeterministic_string" + } + ] + }, + "data": { "email": "jane.doe@example.com", "name": "Jane doe" } + }, + ], + "errors": [] } ``` -### Insert call example with `upsert` option +### An [example](https://github.com/skyflowapi/skyflow-java/blob/v3/samples/src/main/java/com/example/vault/BulkInsertAsync.java) of an async bulkInsert call -An upsert operation checks for a record based on a unique column's value. If a match exists, the record is updated; otherwise, a new record is inserted. +The `bulkInsertAsync` operation operation will insert the data asynchronously into the vault. ```java import com.skyflow.errors.SkyflowException; @@ -720,42 +345,49 @@ import java.util.ArrayList; import java.util.HashMap; /** - * This example demonstrates how to insert or upsert a record into a Skyflow vault using the Skyflow client, with the option to return tokens. - * - * 1. Initializes the Skyflow client. - * 2. Prepares a record to insert or upsert (e.g., cardholder name). - * 3. Creates an insert request with the data to be inserted or upserted into the Skyflow vault. - * 4. Specifies the field (cardholder_name) for upsert operations. - * 5. Prints the response of the insert or upsert operation. + * Example program to demonstrate how to perform an asynchronous bulk insert operation using the Skyflow Java SDK. + * The process involves: + * 1. Setting up credentials and vault configuration + * 2. Creating multiple records to be inserted + * 3. Building and executing an async bulk insert request + * 4. Handling the insert response or errors using CompletableFuture */ -public class UpsertExample { +public class BulkInsertAsync { public static void main(String[] args) { try { // Initialize Skyflow client - // Step 1: Initialize a list to hold the data records for the insert/upsert operation - ArrayList> upsertData = new ArrayList<>(); + // Step 1: Prepare the data to be inserted into the Skyflow vault + ArrayList> insertData = new ArrayList<>(); + + // Create the first record with field names and their respective values + HashMap insertRecord1 = new HashMap<>(); + insertRecord1.put("name", "John doe"); // Replace with actual field name and value + insertRecord1.put("email", "john.doe@example.com"); // Replace with actual field name and value - // Step 2: Create a record with the field 'cardholder_name' to insert or upsert - HashMap upsertRecord = new HashMap<>(); - upsertRecord.put("cardholder_name", "jane doe"); // Replace with the actual cardholder name + // Create the second record with field names and their respective values + HashMap insertRecord2 = new HashMap<>(); + insertRecord2.put("name", "Jane doe"); // Replace with actual field name and value + insertRecord2.put("email", "jane.doe@example.com"); // Replace with actual field name and value - // Step 3: Add the record to the upsertData list - upsertData.add(upsertRecord); + // Add the records to the list of data to be inserted + insertData.add(insertRecord1); + insertData.add(insertRecord2); - // Step 4: Build the InsertRequest object with the upsertData + // Step 2: Build an InsertRequest object with the table name and the data to insert InsertRequest insertRequest = InsertRequest.builder() - .table("table1") // Specify the table in the vault where data will be inserted/upserted - .values(upsertData) // Attach the data records to be inserted/upserted - .returnTokens(true) // Specify if tokens should be returned upon successful operation - .upsert("cardholder_name") // Specify the field to be used for upsert operations (e.g., cardholder_name) - .build(); // Build the insert request object - - // Step 5: Perform the insert/upsert operation using the Skyflow client - InsertResponse insertResponse = skyflowClient.vault("9f27764a10f7946fe56b3258e117").insert(insertRequest); - // Replace the vault ID "9f27764a10f7946fe56b3258e117" with your actual Skyflow vault ID - - // Step 6: Print the response from the insert/upsert operation - System.out.println(insertResponse); + .table("table1") // Replace with the actual table name in your Skyflow vault + .values(insertData) // Attach the data to be inserted + .build(); + + // Step 3: Perform the async bulk insert operation using the Skyflow client + CompletableFuture future = skyflowClient.vault().bulkInsertAsync(insertRequest); + // Add success and error callbacks + future.thenAccept(response -> { + System.out.println("Async bulk insert resolved with response:\t" + response); + }).exceptionally(throwable -> { + System.err.println("Async bulk insert rejected with error:\t" + throwable.getMessage()); + throw new CompletionException(throwable); + }); } catch (SkyflowException e) { // Step 7: Handle any exceptions that may occur during the insert/upsert operation System.out.println("Error occurred: "); @@ -765,23 +397,55 @@ public class UpsertExample { } ``` -Skyflow returns tokens, with `upsert` support, for the record you just inserted. +Skyflow returns tokens and data for the records you just inserted. ```json { - "insertedFields": [ + "summary": { + "totalRecords": 2, + "totalInserted": 2, + "totalFailed": 0 + }, + "sucess": [ { - "skyflowId": "9fac9201-7b8a-4446-93f8-5244e1213bd1", - "cardholder_name": "73ce45ce-20fd-490e-9310-c1d4f603ee83" - } + "index": 0, + "skyflow_id": "9fac9201-7b8a-4446-93f8-5244e1213bd1", + "tokens": { + "name": [{ "token": "token_name", "tokenGroupName": "deterministic_string" }], + "email": [ + { + "token": "augn0@xebggri.lmp", + "tokenGroupName": "nondeterministic_string" + } + ] + }, + "data": { "email": "john.doe@example.com", "name": "john doe" } + }, + { + "index": 1, + "skyflow_id": "9fac9201-7b8a-4446-93f8-5244e1213bd3", + "tokens": { + "name": [{ "token": "token_name", "tokenGroupName": "deterministic_string" }], + "email": [ + { + "token": "buhn0@xebggrj.lmt", + "tokenGroupName": "nondeterministic_string" + } + ] + }, + "data": { "email": "jane.doe@example.com", "name": "Jane doe" } + }, ], "errors": [] } ``` -## Detokenize +## Bulk detokenize + +To retrieve tokens from your vault, use the `bulkDetokenize` or `bulkDetokenizeAsync` methods. You can specify how the data should be redacted based on token groups. The `DetokenizeRequest` has two main components: -To retrieve tokens from your vault, use the `detokenize` method. The `DetokenizeRequest` class requires a list of detokenization data as input. Additionally, you can provide optional parameters, such as the redaction type and the option to continue on error. +- `tokens`: List of token strings to detokenize +- `tokenGroupRedactions`: List of redaction rules for specific token groups ### Construct a detokenize request @@ -800,23 +464,28 @@ import java.util.ArrayList; public class DetokenizeSchema { public static void main(String[] args) { try { - // Initialize Skyflow client + // Initialize Skyflow client // Step 1: Initialize a list of tokens to be detokenized (replace with actual tokens) ArrayList tokens = new ArrayList<>(); tokens.add(""); // Replace with your actual token value tokens.add(""); // Replace with your actual token value tokens.add(""); // Replace with your actual token value - // Step 2: Create the DetokenizeRequest object with the tokens and redaction type + TokenGroupRedactions tokenGroupRedaction = TokenGroupRedactions.builder() + .tokenGroupName("") + .redaction("") + .build(); + List tokenGroupRedactions = new ArrayList<>(); + tokenGroupRedactions.add(tokenGroupRedaction); + + // Step 2: Create the DetokenizeRequest object with the tokens and token group redactions DetokenizeRequest detokenizeRequest = DetokenizeRequest.builder() - .tokens(tokens) // Provide the list of tokens to be detokenized - .continueOnError(true) // Continue even if one token cannot be detokenized - .redactionType(RedactionType.PLAIN_TEXT) // Specify how the detokenized data should be returned (plain text) - .build(); // Build the detokenization request + .tokens(tokens) // Provide the list of tokens to be detokenized + .tokenGroupredactions(tokenGroupRedactions) // Provide a list of token grpup redactions + .build(); // Build the detokenization request // Step 3: Call the Skyflow vault to detokenize the provided tokens - DetokenizeResponse detokenizeResponse = skyflowClient.vault("").detokenize(detokenizeRequest); - // Replace with your actual Skyflow vault ID + DetokenizeResponse detokenizeResponse = skyflowClient.vault().bulkDetokenize(detokenizeRequest); // Step 4: Print the detokenization response, which contains the detokenized data System.out.println(detokenizeResponse); @@ -829,50 +498,50 @@ public class DetokenizeSchema { } ``` -Notes: - -- `redactionType` defaults to [`RedactionType.PLAIN_TEXT`](#redaction-types). -- `continueOnError` defaults to `true`. - -### An [example](https://github.com/skyflowapi/skyflow-java/blob/main/samples/src/main/java/com/example/vault/DetokenizeExample.java) of a detokenize call: +### An [example](https://github.com/skyflowapi/skyflow-java/blob/v3/samples/src/main/java/com/example/vault/BulkDetokenizeSync.java) of a sync bulkDetokenize call: ```java -import com.skyflow.enums.RedactionType; import com.skyflow.errors.SkyflowException; -import com.skyflow.vault.tokens.DetokenizeRequest; -import com.skyflow.vault.tokens.DetokenizeResponse; +import com.skyflow.vault.data.DetokenizeRequest; +import com.skyflow.vault.data.DetokenizeResponse; +import com.skyflow.vault.data.TokenGroupRedactions; import java.util.ArrayList; +import java.util.List; /** - * This example demonstrates how to detokenize sensitive data from tokens stored in a Skyflow vault. - * - * 1. Initializes the Skyflow client. - * 2. Creates a list of tokens (e.g., credit card tokens) that represent the sensitive data. - * 3. Builds a detokenization request using the provided tokens and specifies how the redacted data should be returned. - * 4. Calls the Skyflow vault to detokenize the tokens and retrieves the detokenized data. - * 5. Prints the detokenization response, which contains the detokenized values or errors. + * This sample demonstrates how to perform a synchronous bulk detokenize operation using the Skyflow Java SDK. + * The process involves: + * 1. Setting up credentials and vault configuration + * 2. Creating a list of tokens to detokenize + * 3. Configuring token group redactions + * 4. Building and executing a bulk detokenize request + * 5. Handling the detokenize response or any potential errors */ -public class DetokenizeExample { +public class BulkDetokenizeSync { public static void main(String[] args) { try { - // Initialize Skyflow client + // Initialize Skyflow client // Step 1: Initialize a list of tokens to be detokenized (replace with actual token values) ArrayList tokens = new ArrayList<>(); - tokens.add("9738-1683-0486-1480"); // Replace with your actual token value - tokens.add("6184-6357-8409-6668"); // Replace with your actual token value - tokens.add("4914-9088-2814-3840"); // Replace with your actual token value + tokens.add("b8eea77a-47e1-4d67-a560-fd395cabc82f"); // Replace with your actual token value + tokens.add("6ffb412b-a79d"); // Replace with your actual token value - // Step 2: Create the DetokenizeRequest object with the tokens and redaction type + TokenGroupRedactions tokenGroupRedaction = TokenGroupRedactions.builder() + .tokenGroupName("deterministic_regex") + .redaction("MASKED") + .build(); + List tokenGroupRedactions = new ArrayList<>(); + tokenGroupRedactions.add(tokenGroupRedaction); + + // Step 2: Create the DetokenizeRequest object with the tokens and token group redactions DetokenizeRequest detokenizeRequest = DetokenizeRequest.builder() - .tokens(tokens) // Provide the list of tokens to be detokenized - .continueOnError(false) // Stop the process if any token cannot be detokenized - .redactionType(RedactionType.PLAIN_TEXT) // Specify how the detokenized data should be returned (plain text) - .build(); // Build the detokenization request + .tokens(tokens) // Provide the list of tokens to be detokenized + .tokenGroupredactions(tokenGroupRedactions) // Provide a list of token grpup redactions + .build(); // Build the detokenization request - // Step 3: Call the Skyflow vault to detokenize the provided tokens - DetokenizeResponse detokenizeResponse = skyflowClient.vault("9f27764a10f7946fe56b3258e117").detokenize(detokenizeRequest); - // Replace "9f27764a10f7946fe56b3258e117" with your actual Skyflow vault ID + // Step 3: Call the Skyflow vault to bulk detokenize the provided tokens synchronously + DetokenizeResponse detokenizeResponse = skyflowClient.vault().bulkDetokenizeAsync(detokenizeRequest); // Step 4: Print the detokenization response, which contains the detokenized data System.out.println(detokenizeResponse); @@ -889,65 +558,80 @@ Sample response: ```json { - "detokenizedFields": [{ - "token": "9738-1683-0486-1480", - "value": "4111111111111115", - "type": "STRING", - }, { - "token": "6184-6357-8409-6668", - "value": "4111111111111119", - "type": "STRING", - }, { - "token": "4914-9088-2814-3840", - "value": "4111111111111118", - "type": "STRING", - }] - "errors": [] + "summary": { + "total_tokens": 2, + "total_detokenized": 2, + "total_failed": 0, + }, + "success": [ + { + "index": 0, + "token": "b8eea77a-47e1-4d67-a560-fd395cabc82f", + "value": "xxxx@skyflow.com", + "tokenGroupName": "nondeterministic_regex", + "metadata": { + "skyflowID": "5ddc71a6-3bdb-47e4-9723-259452946349", + "tableName": "table1" + } + }, + ], + "errors": [ + { + "index": 1, + "code": 404, + "error": "Detokenize failed. Token 6ffb412b-a79d is invalid. Specify a valid token.", + } + ] } - ``` -### An example of a detokenize call with `continueOnError` option: +### An [example]() of an async bulkDetokenize call + ```java -import com.skyflow.enums.RedactionType; import com.skyflow.errors.SkyflowException; -import com.skyflow.vault.tokens.DetokenizeRequest; -import com.skyflow.vault.tokens.DetokenizeResponse; +import com.skyflow.vault.data.DetokenizeRequest; +import com.skyflow.vault.data.DetokenizeResponse; +import com.skyflow.vault.data.TokenGroupRedactions; import java.util.ArrayList; +import java.util.List; /** - * This example demonstrates how to detokenize sensitive data (e.g., credit card numbers) from tokens in a Skyflow vault. - * - * 1. Initializes the Skyflow client. - * 2. Creates a list of tokens (e.g., credit card tokens) to be detokenized. - * 3. Builds a detokenization request with the tokens and specifies the redaction type for the detokenized data. - * 4. Calls the Skyflow vault to detokenize the tokens and retrieves the detokenized data. - * 5. Prints the detokenization response, which includes the detokenized values or errors. + * This sample demonstrates how to perform an asynchronous bulk detokenize operation using the Skyflow Java SDK. + * The process involves: + * 1. Setting up credentials and vault configuration + * 2. Creating a list of tokens to detokenize + * 3. Configuring token group redactions + * 4. Building and executing a bulk detokenize request + * 5. Handling the detokenize response or errors using CompletableFuture */ -public class DetokenizeExample { +public class BulkDetokenizeAsync { public static void main(String[] args) { try { - // Initialize Skyflow client + // Initialize Skyflow client // Step 1: Initialize a list of tokens to be detokenized (replace with actual token values) ArrayList tokens = new ArrayList<>(); - tokens.add("9738-1683-0486-1480"); // Example token value 1 - tokens.add("6184-6357-8409-6668"); // Example token value 2 - tokens.add("4914-9088-2814-384"); // Example token value 3 + tokens.add("b8eea77a-47e1-4d67-a560-fd395cabc82f"); // Replace with your actual token value + tokens.add("6ffb412b-a79d"); // Replace with your actual token value + + TokenGroupRedactions tokenGroupRedaction = TokenGroupRedactions.builder() + .tokenGroupName("deterministic_string") + .redaction("MASKED") + .build(); + List tokenGroupRedactions = new ArrayList<>(); + tokenGroupRedactions.add(tokenGroupRedaction); // Step 2: Create the DetokenizeRequest object with the tokens and redaction type DetokenizeRequest detokenizeRequest = DetokenizeRequest.builder() - .tokens(tokens) // Provide the list of tokens to detokenize - .continueOnError(true) // Continue even if some tokens cannot be detokenized - .redactionType(RedactionType.PLAIN_TEXT) // Specify the format for the detokenized data (plain text) - .build(); // Build the detokenization request + .tokens(tokens) // Provide the list of tokens to be detokenized + .tokenGroupredactions(tokenGroupRedactions) // Provide a list of token grpup redactions + .build(); // Build the detokenization request - // Step 3: Call the Skyflow vault to detokenize the provided tokens - DetokenizeResponse detokenizeResponse = skyflowClient.vault("9f27764a10f7946fe56b3258e117").detokenize(detokenizeRequest); - // Replace "9f27764a10f7946fe56b3258e117" with your actual Skyflow vault ID + // Step 3: Call the Skyflow vault to bulk detokenize the provided tokens asynchronously + DetokenizeResponse detokenizeResponse = skyflowClient.vault().bulkDetokenizeAsync(detokenizeRequest); - // Step 4: Print the detokenization response, which contains the detokenized data or errors + // Step 4: Print the detokenization response, which contains the detokenized data System.out.println(detokenizeResponse); } catch (SkyflowException e) { // Step 5: Handle any errors that occur during the detokenization process @@ -962,1632 +646,30 @@ Sample response: ```json { - "detokenizedFields": [{ - "token": "9738-1683-0486-1480", - "value": "4111111111111115", - "type": "STRING", - }, { - "token": "6184-6357-8409-6668", - "value": "4111111111111119", - "type": "STRING", - }] - "errors": [{ - "token": "4914-9088-2814-384", - "error": "Token Not Found", - }] -} -``` - -## Tokenize - -Tokenization replaces sensitive data with unique identifier tokens. This approach protects sensitive information by securely storing the original data while allowing the use of tokens within your application. - -To tokenize data, use the `tokenize` method. The `TokenizeRequest` class creates a tokenize request. In this request, you specify the `values` parameter, which is a list of `ColumnValue` objects. Each `ColumnValue` contains two properties: `value` and `columnGroup`. - -### Construct a tokenize request - -```java -import com.skyflow.errors.SkyflowException; -import com.skyflow.vault.tokens.ColumnValue; -import com.skyflow.vault.tokens.TokenizeRequest; -import com.skyflow.vault.tokens.TokenizeResponse; - -import java.util.ArrayList; - -/** - * This example demonstrates how to tokenize sensitive data (e.g., credit card information) using the Skyflow client, along with corresponding TokenizeRequest schema. - * - */ -public class TokenizeSchema { - public static void main(String[] args) { - try { - // Initialize Skyflow client - // Step 1: Initialize a list of column values to be tokenized (replace with actual sensitive data) - ArrayList columnValues = new ArrayList<>(); - - // Step 2: Create column values for each sensitive data field (e.g., card number and cardholder name) - ColumnValue columnValue1 = ColumnValue.builder().value("").columnGroup("").build(); // Replace and with actual data - ColumnValue columnValue2 = ColumnValue.builder().value("").columnGroup("").build(); // Replace and with actual data - - // Add the created column values to the list - columnValues.add(columnValue1); - columnValues.add(columnValue2); - - // Step 3: Build the TokenizeRequest with the column values - TokenizeRequest tokenizeRequest = TokenizeRequest.builder().values(columnValues).build(); - - // Step 4: Call the Skyflow vault to tokenize the sensitive data - TokenizeResponse tokenizeResponse = skyflowClient.vault("").tokenize(tokenizeRequest); - // Replace with your actual Skyflow vault ID - - // Step 5: Print the tokenization response, which contains the generated tokens or errors - System.out.println(tokenizeResponse); - } catch (SkyflowException e) { - // Step 6: Handle any errors that occur during the tokenization process - System.out.println("Error occurred: "); - e.printStackTrace(); // Print the exception for debugging purposes - } - } -} -``` - -### An [example](https://github.com/skyflowapi/skyflow-java/blob/main/samples/src/main/java/com/example/vault/TokenizeExample.java) of Tokenize call: - -```java -import com.skyflow.errors.SkyflowException; -import com.skyflow.vault.tokens.ColumnValue; -import com.skyflow.vault.tokens.TokenizeRequest; -import com.skyflow.vault.tokens.TokenizeResponse; - -import java.util.ArrayList; - -/** - * This example demonstrates how to tokenize sensitive data (e.g., credit card information) using the Skyflow client. - * - * 1. Initializes the Skyflow client. - * 2. Creates a column value for sensitive data (e.g., credit card number). - * 3. Builds a tokenize request with the column value to be tokenized. - * 4. Sends the request to the Skyflow vault for tokenization. - * 5. Prints the tokenization response, which includes the token or errors. - */ -public class TokenizeExample { - public static void main(String[] args) { - try { - // Initialize Skyflow client - // Step 1: Initialize a list of column values to be tokenized (replace with actual sensitive data) - ArrayList columnValues = new ArrayList<>(); - - // Step 2: Create a column value for the sensitive data (e.g., card number with its column group) - ColumnValue columnValue = ColumnValue.builder() - .value("4111111111111111") // Replace with the actual sensitive data (e.g., card number) - .columnGroup("card_number_cg") // Replace with the actual column group name - .build(); - - // Add the created column value to the list - columnValues.add(columnValue); - - // Step 3: Build the TokenizeRequest with the column value - TokenizeRequest tokenizeRequest = TokenizeRequest.builder().values(columnValues).build(); - - // Step 4: Call the Skyflow vault to tokenize the sensitive data - TokenizeResponse tokenizeResponse = skyflowClient.vault("9f27764a10f7946fe56b3258e117").tokenize(tokenizeRequest); - // Replace "9f27764a10f7946fe56b3258e117" with your actual Skyflow vault ID - - // Step 5: Print the tokenization response, which contains the generated token or any errors - System.out.println(tokenizeResponse); - } catch (SkyflowException e) { - // Step 6: Handle any errors that occur during the tokenization process - System.out.println("Error occurred: "); - e.printStackTrace(); // Print the exception for debugging purposes - } - } -} -``` - -Sample response: - -```json -{ - "tokens": [5479-4229-4622-1393] -} -``` - -## Get - -To retrieve data using Skyflow IDs or unique column values, use the `get` method. The `GetRequest` class creates a get request, where you specify parameters such as the table name, redaction type, Skyflow IDs, column names, column values, and whether to return tokens. If you specify Skyflow IDs, you can't use column names and column values, and the inverse is true—if you specify column names and column values, you can't use Skyflow IDs. - -### Construct a get request - -```java -import com.skyflow.enums.RedactionType; -import com.skyflow.errors.SkyflowException; -import com.skyflow.vault.data.GetRequest; -import com.skyflow.vault.data.GetResponse; - -import java.util.ArrayList; - -/** - * This example demonstrates how to retrieve data from the Skyflow vault using different methods, along with corresponding GetRequest schema. - * - */ -public class GetSchema { - public static void main(String[] args) { - try { - // Initialize Skyflow client - // Step 1: Initialize a list of Skyflow IDs to retrieve records (replace with actual Skyflow IDs) - ArrayList ids = new ArrayList<>(); - ids.add(""); // Replace with actual Skyflow ID - ids.add(""); // Replace with actual Skyflow ID - - // Step 2: Create a GetRequest to retrieve records by Skyflow ID without returning tokens - GetRequest getByIdRequest = GetRequest.builder() - .ids(ids) - .table("") // Replace with the actual table name - .returnTokens(false) // Set to false to avoid returning tokens - .redactionType(RedactionType.PLAIN_TEXT) // Redact data as plain text - .build(); - - // Send the request to the Skyflow vault and retrieve the records - GetResponse getByIdResponse = skyflowClient.vault("").get(getByIdRequest); // Replace with actual Vault ID - System.out.println(getByIdResponse); - - // Step 3: Create another GetRequest to retrieve records by Skyflow ID with tokenized values - GetRequest getTokensRequest = GetRequest.builder() - .ids(ids) - .table("") // Replace with the actual table name - .returnTokens(true) // Set to true to return tokenized values - .build(); - - // Send the request to the Skyflow vault and retrieve the tokenized records - GetResponse getTokensResponse = skyflowClient.vault("").get(getTokensRequest); // Replace with actual Vault ID - System.out.println(getTokensResponse); - - // Step 4: Create a GetRequest to retrieve records based on specific column values - ArrayList columnValues = new ArrayList<>(); - columnValues.add(""); // Replace with the actual column value - columnValues.add(""); // Replace with the actual column value - - GetRequest getByColumnRequest = GetRequest.builder() - .table("") // Replace with the actual table name - .columnName("") // Replace with the column name - .columnValues(columnValues) // Add the list of column values to filter by - .redactionType(RedactionType.PLAIN_TEXT) // Redact data as plain text - .build(); - - // Send the request to the Skyflow vault and retrieve the records filtered by column values - GetResponse getByColumnResponse = skyflowClient.vault("").get(getByColumnRequest); // Replace with actual Vault ID - System.out.println(getByColumnResponse); - } catch (SkyflowException e) { - // Step 5: Handle any errors that occur during the retrieval process - System.out.println("Error occurred: "); - e.printStackTrace(); // Print the exception for debugging purposes - } - } -} -``` - -### Get by skyflow IDs - -Retrieve specific records using `skyflow_ids`. Ideal for fetching exact records when IDs are known. - -An [example](https://github.com/skyflowapi/skyflow-java/blob/main/samples/src/main/java/com/example/vault/GetExample.java) of a get call to retrieve data using Redaction type: - -```java -import com.skyflow.enums.RedactionType; -import com.skyflow.errors.SkyflowException; -import com.skyflow.vault.data.GetRequest; -import com.skyflow.vault.data.GetResponse; - -import java.util.ArrayList; - -/** - * This example demonstrates how to retrieve data from the Skyflow vault using a list of Skyflow IDs. - * - * 1. Initializes the Skyflow client with a given vault ID. - * 2. Creates a request to retrieve records based on Skyflow IDs. - * 3. Specifies that the response should not return tokens. - * 4. Uses plain text redaction type for the retrieved records. - * 5. Prints the response to display the retrieved records. - */ -public class GetExample { - public static void main(String[] args) { - try { - // Initialize Skyflow client - // Step 1: Initialize a list of Skyflow IDs (replace with actual Skyflow IDs) - ArrayList ids = new ArrayList<>(); - ids.add("a581d205-1969-4350-acbe-a2a13eb871a6"); // Replace with actual Skyflow ID - ids.add("5ff887c3-b334-4294-9acc-70e78ae5164a"); // Replace with actual Skyflow ID - - // Step 2: Create a GetRequest to retrieve records based on Skyflow IDs - // The request specifies: - // - `ids`: The list of Skyflow IDs to retrieve - // - `table`: The table from which the records will be retrieved - // - `returnTokens`: Set to false, meaning tokens will not be returned in the response - // - `redactionType`: Set to PLAIN_TEXT, meaning the retrieved records will have data redacted as plain text - GetRequest getByIdRequest = GetRequest.builder() - .ids(ids) - .table("table1") // Replace with the actual table name - .returnTokens(false) // Set to false to avoid returning tokens - .redactionType(RedactionType.PLAIN_TEXT) // Redact data as plain text - .build(); - - // Step 3: Send the request to the Skyflow vault and retrieve the records - GetResponse getByIdResponse = skyflowClient.vault("9f27764a10f7946fe56b3258e117").get(getByIdRequest); // Replace with actual Vault ID - System.out.println(getByIdResponse); // Print the response to the console - - } catch (SkyflowException e) { - // Step 4: Handle any errors that occur during the data retrieval process - System.out.println("Error occurred: "); - e.printStackTrace(); // Print the exception for debugging purposes - } - } -} -``` - -Sample response: - -```json -{ - "data": [ - { - "card_number": "4555555555555553", - "email": "john.doe@gmail.com", - "name": "john doe", - "skyflow_id": "a581d205-1969-4350-acbe-a2a13eb871a6" - }, - { - "card_number": "4555555555555559", - "email": "jane.doe@gmail.com", - "name": "jane doe", - "skyflow_id": "5ff887c3-b334-4294-9acc-70e78ae5164a" - } - ], - "errors": [] -} -``` - -### Get tokens - -Return tokens for records. Ideal for securely processing sensitive data while maintaining data privacy. - -An [example](https://github.com/skyflowapi/skyflow-java/blob/main/samples/src/main/java/com/example/vault/getExample.java) of get call to retrieve tokens using Skyflow IDs: - -```java -import com.skyflow.enums.RedactionType; -import com.skyflow.errors.SkyflowException; -import com.skyflow.vault.data.GetRequest; -import com.skyflow.vault.data.GetResponse; - -import java.util.ArrayList; - -/** - * This example demonstrates how to retrieve data from the Skyflow vault and return tokens along with the records. - * - * 1. Initializes the Skyflow client with a given vault ID. - * 2. Creates a request to retrieve records based on Skyflow IDs and ensures tokens are returned. - * 3. Prints the response to display the retrieved records along with the tokens. - */ -public class GetExample { - public static void main(String[] args) { - try { - // Initialize Skyflow client - // Step 1: Initialize a list of Skyflow IDs (replace with actual Skyflow IDs) - ArrayList ids = new ArrayList<>(); - ids.add("a581d205-1969-4350-acbe-a2a13eb871a6"); // Replace with actual Skyflow ID - ids.add("5ff887c3-b334-4294-9acc-70e78ae5164a"); // Replace with actual Skyflow ID - - // Step 2: Create a GetRequest to retrieve records based on Skyflow IDs - // The request specifies: - // - `ids`: The list of Skyflow IDs to retrieve - // - `table`: The table from which the records will be retrieved - // - `returnTokens`: Set to true, meaning tokens will be included in the response - GetRequest getTokensRequest = GetRequest.builder() - .ids(ids) - .table("table1") // Replace with the actual table name - .returnTokens(true) // Set to true to include tokens in the response - .build(); - - // Step 3: Send the request to the Skyflow vault and retrieve the records with tokens - GetResponse getTokensResponse = skyflowClient.vault("9f27764a10f7946fe56b3258e117").get(getTokensRequest); // Replace with actual Vault ID - System.out.println(getTokensResponse); // Print the response to the console - - } catch (SkyflowException e) { - // Step 4: Handle any errors that occur during the data retrieval process - System.out.println("Error occurred: "); - e.printStackTrace(); // Print the exception for debugging purposes - } - } -} -``` - -Sample response: - -```json -{ - "data": [ - { - "card_number": "3998-2139-0328-0697", - "email": "c9a6c9555060@82c092e7.bd52", - "name": "82c092e7-74c0-4e60-bd52-c9a6c9555060", - "skyflow_id": "a581d205-1969-4350-acbe-a2a13eb871a6" - }, - { - "card_number": "3562-0140-8820-7499", - "email": "6174366e2bc6@59f82e89.93fc", - "name": "59f82e89-138e-4f9b-93fc-6174366e2bc6", - "skyflow_id": "5ff887c3-b334-4294-9acc-70e78ae5164a" - } - ], - "errors": [] -} -``` - -### Get By column name and column values - -Retrieve records by unique column values. Ideal for querying data without knowing Skyflow IDs, using alternate unique identifiers. - -An [example](https://github.com/skyflowapi/skyflow-java/blob/main/samples/src/main/java/com/example/vault/GetExample.java) of get call to retrieve data using column name and column values: - -```java -import com.skyflow.enums.RedactionType; -import com.skyflow.errors.SkyflowException; -import com.skyflow.vault.data.GetRequest; -import com.skyflow.vault.data.GetResponse; - -import java.util.ArrayList; - -/** - * This example demonstrates how to retrieve data from the Skyflow vault based on column values. - * - * 1. Initializes the Skyflow client with a given vault ID. - * 2. Creates a request to retrieve records based on specific column values (e.g., email addresses). - * 3. Prints the response to display the retrieved records after redacting sensitive data based on the specified redaction type. - */ -public class GetExample { - public static void main(String[] args) { - try { - // Initialize Skyflow client - // Step 1: Initialize a list of column values (email addresses in this case) - ArrayList columnValues = new ArrayList<>(); - columnValues.add("john.doe@gmail.com"); // Example email address - columnValues.add("jane.doe@gmail.com"); // Example email address - - // Step 2: Create a GetRequest to retrieve records based on column values - // The request specifies: - // - `table`: The table from which the records will be retrieved - // - `columnName`: The column to filter the records by (e.g., "email") - // - `columnValues`: The list of values to match in the specified column - // - `redactionType`: Defines how sensitive data should be redacted (set to PLAIN_TEXT here) - GetRequest getByColumnRequest = GetRequest.builder() - .table("table1") // Replace with the actual table name - .columnName("email") // The column name to filter by (e.g., "email") - .columnValues(columnValues) // The list of column values to match - .redactionType(RedactionType.PLAIN_TEXT) // Set the redaction type (e.g., PLAIN_TEXT) - .build(); - - // Step 3: Send the request to the Skyflow vault and retrieve the records - GetResponse getByColumnResponse = skyflowClient.vault("9f27764a10f7946fe56b3258e117").get(getByColumnRequest); // Replace with actual Vault ID - System.out.println(getByColumnResponse); // Print the response to the console - - } catch (SkyflowException e) { - // Step 4: Handle any errors that occur during the data retrieval process - System.out.println("Error occurred: "); - e.printStackTrace(); // Print the exception for debugging purposes - } - } -} -``` - -Sample response: - -```json -{ - "data": [ - { - "card_number": "4555555555555553", - "email": "john.doe@gmail.com", - "name": "john doe", - "skyflow_id": "a581d205-1969-4350-acbe-a2a13eb871a6" - }, - { - "card_number": "4555555555555559", - "email": "jane.doe@gmail.com", - "name": "jane doe", - "skyflow_id": "5ff887c3-b334-4294-9acc-70e78ae5164a" - } - ], - "errors": [] -} -``` - -### Redaction types - -Redaction types determine how sensitive data is displayed when retrieved from the vault. - -#### **Available Redaction Types** - -- `DEFAULT`: Applies the vault-configured default redaction setting. -- `REDACTED`: Completely removes sensitive data from view. -- `MASKED`: Partially obscures sensitive information. -- `PLAIN_TEXT`: Displays the full, unmasked data. - -#### **Choosing the Right Redaction Type** - -- Use `REDACTED` for scenarios requiring maximum data protection to prevent exposure of sensitive information. -- Use `MASKED` to provide partial visibility of sensitive data for less critical use cases. -- Use `PLAIN_TEXT` for internal, authorized access where full data visibility is necessary. - -## 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 -tokenStrict. If `returnTokens` is set to `true`, Skyflow returns tokens for the updated records. If `returnTokens` is -set to `false`, Skyflow returns IDs for the updated records. - -### Construct an update request - -```java -import com.skyflow.enums.TokenMode; -import com.skyflow.errors.SkyflowException; -import com.skyflow.vault.data.UpdateRequest; -import com.skyflow.vault.data.UpdateResponse; - -import java.util.HashMap; - -/** - * This example demonstrates how to update records in the Skyflow vault by providing new data and/or tokenized values, along with corresponding UpdateRequest schema. - * - */ -public class UpdateSchema { - public static void main(String[] args) { - try { - // Initialize Skyflow client - // Step 1: Prepare the data to update in the vault - // Use a HashMap to store the data that will be updated in the specified table - HashMap data = new HashMap<>(); - data.put("skyflow_id", ""); // Skyflow ID for identifying the record to update - data.put("", ""); // Example of a column name and its value to update - data.put("", ""); // Another example of a column name and its value to update - - // Step 2: Prepare the tokens (if necessary) for certain columns that require tokenization - // Use a HashMap to specify columns that need tokens in the update request - HashMap tokens = new HashMap<>(); - tokens.put("", ""); // Example of a column name that should be tokenized - - // Step 3: Create an UpdateRequest to specify the update operation - // The request includes the table name, token mode, data, tokens, and the returnTokens flag - UpdateRequest updateRequest = UpdateRequest.builder() - .table("") // Replace with the actual table name to update - .tokenMode(TokenMode.ENABLE) // Specifies the tokenization mode (ENABLE means tokenization is applied) - .data(data) // The data to update in the record - .tokens(tokens) // The tokens associated with specific columns - .returnTokens(true) // Specify whether to return tokens in the response - .build(); - - // Step 4: Send the request to the Skyflow vault and update the record - UpdateResponse updateResponse = skyflowClient.vault("").update(updateRequest); // Replace with actual Vault ID - System.out.println(updateResponse); // Print the response to confirm the update result - - } catch (SkyflowException e) { - // Step 5: Handle any errors that occur during the update operation - System.out.println("Error occurred: "); - e.printStackTrace(); // Print the exception for debugging purposes - } - } -} -``` - -### An [example](https://github.com/skyflowapi/skyflow-java/blob/main/samples/src/main/java/com/example/vault/UpdateExample.java) of update call - -```java -import com.skyflow.enums.TokenMode; -import com.skyflow.errors.SkyflowException; -import com.skyflow.vault.data.UpdateRequest; -import com.skyflow.vault.data.UpdateResponse; - -import java.util.HashMap; - -/** - * This example demonstrates how to update a record in the Skyflow vault with specified data and tokens. - * - * 1. Initializes the Skyflow client with a given vault ID. - * 2. Constructs an update request with data to modify and tokens to include. - * 3. Sends the request to update the record in the vault. - * 4. Prints the response to confirm the success or failure of the update operation. - */ -public class UpdateExample { - public static void main(String[] args) { - try { - // Initialize Skyflow client - // Step 1: Prepare the data to update in the vault - // A HashMap is used to store the data that will be updated in the specified table - HashMap data = new HashMap<>(); - data.put("skyflow_id", "5b699e2c-4301-4f9f-bcff-0a8fd3057413"); // Skyflow ID identifies the record to update - data.put("name", "john doe"); // Updating the "name" column with a new value - data.put("card_number", "4111111111111115"); // Updating the "card_number" column with a new value - - // Step 2: Prepare the tokens to include in the update request - // Tokens can be included to update sensitive data with tokenized values - HashMap tokens = new HashMap<>(); - tokens.put("name", "72b8ffe3-c8d3-4b4f-8052-38b2a7405b5a"); // Tokenized value for the "name" column - - // Step 3: Create an UpdateRequest to define the update operation - // The request specifies the table name, token mode, data, and tokens for the update - UpdateRequest updateRequest = UpdateRequest.builder() - .table("table1") // Replace with the actual table name to update - .tokenMode(TokenMode.ENABLE) // Token mode enabled to allow tokenization of sensitive data - .data(data) // The data to update in the record - .tokens(tokens) // The tokenized values for sensitive columns - .build(); - - // Step 4: Send the update request to the Skyflow vault - UpdateResponse updateResponse = skyflowClient.vault("9f27764a10f7946fe56b3258e117").update(updateRequest); // Replace with your actual Vault ID - System.out.println(updateResponse); // Print the response to confirm the update result - - } catch (SkyflowException e) { - // Step 5: Handle any exceptions that occur during the update operation - System.out.println("Error occurred: "); - e.printStackTrace(); // Print the exception stack trace for debugging purposes - } - } -} -``` - -Sample response: - -- When `returnTokens` is set to `true` - -```json -{ - "skyflowId": "5b699e2c-4301-4f9f-bcff-0a8fd3057413", - "name": "72b8ffe3-c8d3-4b4f-8052-38b2a7405b5a", - "card_number": "4315-7650-1359-9681" -} -``` - -- When `returnTokens` is set to `false` - -```json -{ - "skyflowId": "5b699e2c-4301-4f9f-bcff-0a8fd3057413" -} -``` - -## Delete - -To delete records using Skyflow IDs, use the `delete` method. The `DeleteRequest` class accepts a list of Skyflow IDs -that you want to delete, as shown below: - -### Construct a delete request - -```java -import com.skyflow.errors.SkyflowException; -import com.skyflow.vault.data.DeleteRequest; -import com.skyflow.vault.data.DeleteResponse; - -import java.util.ArrayList; - -/** - * This example demonstrates how to delete records from a Skyflow vault using specified Skyflow IDs, along with corresponding DeleteRequest schema. - * - */ -public class DeleteSchema { - public static void main(String[] args) { - try { - // Initialize Skyflow client - // Step 1: Prepare a list of Skyflow IDs for the records to delete - // The list stores the Skyflow IDs of the records that need to be deleted from the vault - ArrayList ids = new ArrayList<>(); - ids.add(""); // Replace with actual Skyflow ID 1 - ids.add(""); // Replace with actual Skyflow ID 2 - ids.add(""); // Replace with actual Skyflow ID 3 - - // Step 2: Create a DeleteRequest to define the delete operation - // The request specifies the table from which to delete the records and the IDs of the records to delete - DeleteRequest deleteRequest = DeleteRequest.builder() - .ids(ids) // List of Skyflow IDs to delete - .table("") // Replace with the actual table name from which to delete - .build(); - - // Step 3: Send the delete request to the Skyflow vault - DeleteResponse deleteResponse = skyflowClient.vault("").delete(deleteRequest); // Replace with your actual Vault ID - System.out.println(deleteResponse); // Print the response to confirm the delete result - - } catch (SkyflowException e) { - // Step 4: Handle any exceptions that occur during the delete operation - System.out.println("Error occurred: "); - e.printStackTrace(); // Print the exception stack trace for debugging purposes - } - } -} -``` - -### An [example](https://github.com/skyflowapi/skyflow-java/blob/main/samples/src/main/java/com/example/vault/DeleteExample.java) of delete call: - -```java -import com.skyflow.errors.SkyflowException; -import com.skyflow.vault.data.DeleteRequest; -import com.skyflow.vault.data.DeleteResponse; - -import java.util.ArrayList; - -/** - * This example demonstrates how to delete records from a Skyflow vault using specified Skyflow IDs. - * - * 1. Initializes the Skyflow client with a given Vault ID. - * 2. Constructs a delete request by specifying the IDs of the records to delete. - * 3. Sends the delete request to the Skyflow vault to delete the specified records. - * 4. Prints the response to confirm the success or failure of the delete operation. - */ -public class DeleteExample { - public static void main(String[] args) { - try { - // Initialize Skyflow client - // Step 1: Prepare a list of Skyflow IDs for the records to delete - // The list stores the Skyflow IDs of the records that need to be deleted from the vault - ArrayList ids = new ArrayList<>(); - ids.add("9cbf66df-6357-48f3-b77b-0f1acbb69280"); // Replace with actual Skyflow ID 1 - ids.add("ea74bef4-f27e-46fe-b6a0-a28e91b4477b"); // Replace with actual Skyflow ID 2 - ids.add("47700796-6d3b-4b54-9153-3973e281cafb"); // Replace with actual Skyflow ID 3 - - // Step 2: Create a DeleteRequest to define the delete operation - // The request specifies the table from which to delete the records and the IDs of the records to delete - DeleteRequest deleteRequest = DeleteRequest.builder() - .ids(ids) // List of Skyflow IDs to delete - .table("table1") // Replace with the actual table name from which to delete - .build(); - - // Step 3: Send the delete request to the Skyflow vault - DeleteResponse deleteResponse = skyflowClient.vault("9f27764a10f7946fe56b3258e117").delete(deleteRequest); // Replace with your actual Vault ID - System.out.println(deleteResponse); // Print the response to confirm the delete result - - } catch (SkyflowException e) { - // Step 4: Handle any exceptions that occur during the delete operation - System.out.println("Error occurred: "); - e.printStackTrace(); // Print the exception stack trace for debugging purposes - } - } -} -``` - -Sample response: - -```json -{ - "deletedIds": [ - "9cbf66df-6357-48f3-b77b-0f1acbb69280", - "ea74bef4-f27e-46fe-b6a0-a28e91b4477b", - "47700796-6d3b-4b54-9153-3973e281cafb" - ] -} -``` - -## Query - -To retrieve data with SQL queries, use the `query` method. The `QueryRequest` class accepts a `query` parameter, as shown below. - -### Construct a query request - -Refer to [Query your data](https://docs.skyflow.com/query-data/) and [Execute Query](https://docs.skyflow.com/record/#QueryService_ExecuteQuery) for guidelines and restrictions on supported SQL statements, operators, and keywords. - -```java -import com.skyflow.errors.SkyflowException; -import com.skyflow.vault.data.QueryRequest; -import com.skyflow.vault.data.QueryResponse; - -/** - * This example demonstrates how to execute a custom SQL query on a Skyflow vault, along with QueryRequest schema. - * - */ -public class QuerySchema { - public static void main(String[] args) { - try { - // Initialize Skyflow client - // Step 1: Define the SQL query to execute on the Skyflow vault - // Replace "" with the actual SQL query you want to run - String query = ""; // Example: "SELECT * FROM table1 WHERE column1 = 'value'" - - // Step 2: Create a QueryRequest with the specified SQL query - QueryRequest queryRequest = QueryRequest.builder() - .query(query) // SQL query to execute - .build(); - - // Step 3: Execute the query request on the specified Skyflow vault - QueryResponse queryResponse = skyflowClient.vault("").query(queryRequest); // Replace with your actual Vault ID - System.out.println(queryResponse); // Print the response containing the query results - - } catch (SkyflowException e) { - // Step 4: Handle any exceptions that occur during the query execution - System.out.println("Error occurred: "); - e.printStackTrace(); // Print the exception stack trace for debugging - } - } -} -``` - -### An [example](https://github.com/skyflowapi/skyflow-java/blob/main/samples/src/main/java/com/example/vault/QueryExample.java) of query call - -```java -import com.skyflow.errors.SkyflowException; -import com.skyflow.vault.data.QueryRequest; -import com.skyflow.vault.data.QueryResponse; - -/** - * This example demonstrates how to execute a SQL query on a Skyflow vault to retrieve data. - * - * 1. Initializes the Skyflow client with the Vault ID. - * 2. Constructs a query request with a specified SQL query. - * 3. Executes the query against the Skyflow vault. - * 4. Prints the response from the query execution. - */ -public class QueryExample { - public static void main(String[] args) { - try { - // Initialize Skyflow client - // Step 1: Define the SQL query - // Example query: Retrieve all records from the "cards" table with a specific skyflow_id - String query = "SELECT * FROM cards WHERE skyflow_id='3ea3861-x107-40w8-la98-106sp08ea83f'"; - - // Step 2: Create a QueryRequest with the SQL query - QueryRequest queryRequest = QueryRequest.builder() - .query(query) // SQL query to execute - .build(); - - // Step 3: Execute the query request on the specified Skyflow vault - QueryResponse queryResponse = skyflowClient.vault("9f27764a10f7946fe56b3258e117").query(queryRequest); // Vault ID: 9f27764a10f7946fe56b3258e117 - System.out.println(queryResponse); // Print the query response (contains query results) - - } catch (SkyflowException e) { - // Step 4: Handle any exceptions that occur during the query execution - System.out.println("Error occurred: "); - e.printStackTrace(); // Print the exception stack trace for debugging - } - } -} -``` - -Sample response: - -```json -{ - "fields": [ - { - "card_number": "XXXXXXXXXXXX1112", - "name": "S***ar", - "skyflow_id": "3ea3861-x107-40w8-la98-106sp08ea83f", - "tokenizedData": null - } - ] -} -``` - -# Detect -Skyflow Detect enables you to deidentify and reidentify sensitive data in text and files, supporting advanced privacy-preserving workflows. The Detect API supports the following operations: - -## Deidentify Text -To deidentify text, use the `deidentifyText` method. The `DeidentifyTextRequest` class creates a deidentify text request, which includes the text to be deidentified. Additionally, you can provide optional parameters using the `DeidentifyTextOptions` class. - -### Construct an deidentify text request - -```java -import com.skyflow.enums.DetectEntities; -import com.skyflow.vault.detect.DateTransformation; -import com.skyflow.vault.detect.DeidentifyTextRequest; -import com.skyflow.vault.detect.TokenFormat; -import com.skyflow.vault.detect.Transformations; -import com.skyflow.vault.detect.DeidentifyTextResponse; - -import java.util.ArrayList; -import java.util.List; - -/** - * This example demonstrate to build deidentify text request. - */ -public class DeidentifyTextSchema { - - public static void main(String[] args) { - - // Step 1: Initialise the Skyflow client by configuring the credentials & vault config. - - // Step 2: Configure the options for deidentify text - - // Replace with the entity you want to detect - List detectEntitiesList = new ArrayList<>(); - detectEntitiesList.add(DetectEntities.SSN); - - // Replace with the entity you want to detect with vault token - List vaultTokenList = new ArrayList<>(); - vaultTokenList.add(DetectEntities.CREDIT_CARD); - - // Replace with the entity you want to detect with entity only - List entityOnlyList = new ArrayList<>(); - entityOnlyList.add(DetectEntities.SSN); - - // Replace with the entity you want to detect with entity unique counter - List entityUniqueCounterList = new ArrayList<>(); - entityUniqueCounterList.add(DetectEntities.SSN); - - // Replace with the regex patterns you want to allow during deidentification - List allowRegexList = new ArrayList<>(); - allowRegexList.add(""); - - // Replace with the regex patterns you want to restrict during deidentification - List restrictRegexList = new ArrayList<>(); - restrictRegexList.add("YOUR_RESTRICT_REGEX_LIST"); - - // Configure Token Format - TokenFormat tokenFormat = TokenFormat.builder() - .vaultToken(vaultTokenList) - .entityOnly(entityOnlyList) - .entityUniqueCounter(entityUniqueCounterList) - .build(); - - // Configure Transformation - List detectEntitiesTransformationList = new ArrayList<>(); - detectEntitiesTransformationList.add(DetectEntities.DOB); // Replace with the entity you want to transform - - DateTransformation dateTransformation = new DateTransformation(20, 5, detectEntitiesTransformationList); - Transformations transformations = new Transformations(dateTransformation); - - // Step 3: Create a deidentify text request for the vault - DeidentifyTextRequest deidentifyTextRequest = DeidentifyTextRequest.builder() - .text("") // Replace with the text you want to deidentify - .entities(detectEntitiesList) - .allowRegexList(allowRegexList) - .restrictRegexList(restrictRegexList) - .tokenFormat(tokenFormat) - .transformations(transformations) - .build(); - - // Step 4: Use the Skyflow client to perform the deidentifyText operation - // Replace with your actual vault ID - DeidentifyTextResponse deidentifyTextResponse = skyflowClient.detect("").deidentifyText(deidentifyTextRequest); - - // Step 5: Print the response - System.out.println("Deidentify text Response: " + deidentifyTextResponse); - } -} - -``` - -## An [example](https://github.com/skyflowapi/skyflow-java/blob/beta-release/25.6.2/samples/src/main/java/com/example/detect/DeidentifyTextExample.java) of deidentify text: -```java -import java.util.ArrayList; -import java.util.List; - -import com.skyflow.enums.DetectEntities; -import com.skyflow.errors.SkyflowException; -import com.skyflow.vault.detect.DateTransformation; -import com.skyflow.vault.detect.DeidentifyTextRequest; -import com.skyflow.vault.detect.DeidentifyTextResponse; -import com.skyflow.vault.detect.TokenFormat; -import com.skyflow.vault.detect.Transformations; - -/** - * Skyflow Deidentify Text Example - *

- * This example demonstrates how to use the Skyflow SDK to deidentify text data - * across multiple vaults. It includes: - * 1. Setting up credentials and vault configurations. - * 2. Creating a Skyflow client with multiple vaults. - * 3. Performing deidentify of text with various options. - * 4. Handling responses and errors. - */ - -public class DeidentifyTextExample { - public static void main(String[] args) throws SkyflowException { - - // Step 1: Initialise the Skyflow client by configuring the credentials & vault config. - - // Step 2: Configuring the different options for deidentify - - // Replace with the entity you want to detect - List detectEntitiesList = new ArrayList<>(); - detectEntitiesList.add(DetectEntities.SSN); - detectEntitiesList.add(DetectEntities.CREDIT_CARD); - - // Replace with the entity you want to detect with vault token - List vaultTokenList = new ArrayList<>(); - vaultTokenList.add(DetectEntities.SSN); - vaultTokenList.add(DetectEntities.CREDIT_CARD); - - // Configure Token Format - TokenFormat tokenFormat = TokenFormat.builder() - .vaultToken(vaultTokenList) - .build(); - - // Configure Transformation for deidentified entities - List detectEntitiesTransformationList = new ArrayList<>(); - detectEntitiesTransformationList.add(DetectEntities.DOB); // Replace with the entity you want to transform - - DateTransformation dateTransformation = new DateTransformation(20, 5, detectEntitiesTransformationList); - Transformations transformations = new Transformations(dateTransformation); - - // Step 3: invoking Deidentify text on the vault - try { - // Create a deidentify text request for the vault - DeidentifyTextRequest deidentifyTextRequest = DeidentifyTextRequest.builder() - .text("My SSN is 123-45-6789 and my card is 4111 1111 1111 1111.") // Replace with your deidentify text - .entities(detectEntitiesList) - .tokenFormat(tokenFormat) - .transformations(transformations) - .build(); - // Replace `9f27764a10f7946fe56b3258e117` with the acutal vault id - DeidentifyTextResponse deidentifyTextResponse = skyflowClient.detect("9f27764a10f7946fe56b3258e117").deidentifyText(deidentifyTextRequest); - - System.out.println("Deidentify text Response: " + deidentifyTextResponse); - } catch (SkyflowException e) { - System.err.println("Error occurred during deidentify: "); - e.printStackTrace(); // Print the exception for debugging purposes - } - } -} -``` - -Sample Response: -```json -{ - "processedText": "My SSN is [SSN_IWdexZe] and my card is [CREDIT_CARD_rUzMjdQ].", - "entities": [ + "summary": { + "total_tokens": 2, + "total_detokenized": 2, + "total_failed": 0, + }, + "success": [ { - "token": "SSN_IWdexZe", - "value": "123-45-6789", - "textIndex": { - "start": 10, - "end": 21 - }, - "processedIndex": { - "start": 10, - "end": 23 - }, - "entity": "SSN", - "scores": { - "SSN": 0.9384 + "index": 0, + "token": "b8eea77a-47e1-4d67-a560-fd395cabc82f", + "value": "xxxx@skyflow.com", + "tokenGroupName": "nondeterministic_regex", + "metadata": { + "skyflowID": "5ddc71a6-3bdb-47e4-9723-259452946349", + "tableName": "table1" } }, - { - "token": "CREDIT_CARD_rUzMjdQ", - "value": "4111 1111 1111 1111", - "textIndex": { - "start": 37, - "end": 56 - }, - "processedIndex": { - "start": 39, - "end": 60 - }, - "entity": "CREDIT_CARD", - "scores": { - "CREDIT_CARD": 0.9051 - } - } - ], - "wordCount": 9, - "charCount": 57 -} -``` - -## Reidentify Text -To reidentify text, use the `reidentifyText` method. The `ReidentifyTextRequest` class creates a reidentify text request, which includes the redacted or deidentified text to be reidentified. Additionally, you can provide optional parameters using the ReidentifyTextOptions class to control how specific entities are returned (as redacted, masked, or plain text). - -### Construct an reidentify text request - -```java -import com.skyflow.enums.DetectEntities; -import com.skyflow.vault.detect.ReidentifyTextRequest; -import com.skyflow.vault.detect.ReidentifyTextResponse; - -import java.util.ArrayList; -import java.util.List; - -/** - * This example demonstrates how to build a reidentify text request. - */ -public class ReidentifyTextSchema { - public static void main(String[] args) { - // Step 1: Initialise the Skyflow client by configuring the credentials & vault config. - - // Step 2: Configuring the different options for reidentify - List maskedEntity = new ArrayList<>(); - maskedEntity.add(DetectEntities.CREDIT_CARD); // Replace with the entity you want to mask - - List plainTextEntity = new ArrayList<>(); - plainTextEntity.add(DetectEntities.SSN); // Replace with the entity you want to keep in plain text - - // List redactedEntity = new ArrayList<>(); - // redactedEntity.add(DetectEntities.SSN); // Replace with the entity you want to redact - - - // Step 3: Create a reidentify text request with the configured entities - ReidentifyTextRequest reidentifyTextRequest = ReidentifyTextRequest.builder() - .text("My SSN is [SSN_IWdexZe] and my card is [CREDIT_CARD_rUzMjdQ].") // Replace with your deidentify text - .maskedEntities(maskedEntity) -// .redactedEntities(redactedEntity) - .plainTextEntities(plainTextEntity) - .build(); - - // Step 4: Invoke reidentify text on the vault - ReidentifyTextResponse reidentifyTextResponse = skyflowClient.detect("").reidentifyText(reidentifyTextRequest); - System.out.println("Reidentify text Response: " + reidentifyTextResponse); - } -} -``` - -## An [example](https://github.com/skyflowapi/skyflow-java/blob/beta-release/25.6.2/samples/src/main/java/com/example/detect/ReidentifyTextExample.java) of Reidentify text - -```java -import com.skyflow.enums.DetectEntities; -import com.skyflow.errors.SkyflowException; -import com.skyflow.vault.detect.ReidentifyTextRequest; -import com.skyflow.vault.detect.ReidentifyTextResponse; - -import java.util.ArrayList; -import java.util.List; - -/** - * Skyflow Reidentify Text Example - *

- * This example demonstrates how to use the Skyflow SDK to reidentify text data - * across multiple vaults. It includes: - * 1. Setting up credentials and vault configurations. - * 2. Creating a Skyflow client with multiple vaults. - * 3. Performing reidentify of text with various options. - * 4. Handling responses and errors. - */ - -public class ReidentifyTextExample { - public static void main(String[] args) throws SkyflowException { - // Step 1: Initialise the Skyflow client by configuring the credentials & vault config. - - // Step 2: Configuring the different options for reidentify - List maskedEntity = new ArrayList<>(); - maskedEntity.add(DetectEntities.CREDIT_CARD); // Replace with the entity you want to mask - - List plainTextEntity = new ArrayList<>(); - plainTextEntity.add(DetectEntities.SSN); // Replace with the entity you want to keep in plain text - - try { - // Step 3: Create a reidentify text request with the configured options - ReidentifyTextRequest reidentifyTextRequest = ReidentifyTextRequest.builder() - .text("My SSN is [SSN_IWdexZe] and my card is [CREDIT_CARD_rUzMjdQ].") // Replace with your deidentify text - .maskedEntities(maskedEntity) - .plainTextEntities(plainTextEntity) - .build(); - - // Step 4: Invoke Reidentify text on the vault - // Replace `9f27764a10f7946fe56b3258e117` with the acutal vault id - ReidentifyTextResponse reidentifyTextResponse = skyflowClient.detect("9f27764a10f7946fe56b3258e117").reidentifyText(reidentifyTextRequest); - - // Handle the response from the reidentify text request - System.out.println("Reidentify text Response: " + reidentifyTextResponse); - } catch (SkyflowException e) { - System.err.println("Error occurred during reidentify : "); - e.printStackTrace(); - } - } -} -``` - -Sample Response: - -```json -{ - "processedText":"My SSN is 123-45-6789 and my card is XXXXX1111." -} -``` - -## Deidentify file -To deidentify files, use the `deidentifyFile` method. The `DeidentifyFileRequest` class creates a deidentify file request, which includes the file to be deidentified (such as images, PDFs, audio, documents, spreadsheets, or presentations). Additionally, you can provide optional parameters using the DeidentifyFileOptions class to control how entities are detected and deidentified, as well as how the output is generated for different file types. - -### Construct an deidentify file request - -```java -import com.skyflow.config.Credentials; -import com.skyflow.config.VaultConfig; -import com.skyflow.enums.Env; -import com.skyflow.enums.LogLevel; -import com.skyflow.enums.MaskingMethod; -import com.skyflow.errors.SkyflowException; -import com.skyflow.vault.detect.DeidentifyFileRequest; -import com.skyflow.vault.detect.DeidentifyFileResponse; - -import java.io.File; - -/** - * This example demonstrates how to build a deidentify file request. - */ - -public class DeidentifyFileSchema { - - public static void main(String[] args) { - // Step 1: Initialise the Skyflow client by configuring the credentials & vault config. - - // Step 2: Create a deidentify file request with all options - - // Create file object - File file = new File(""); // Replace with the path to the file you want to deidentify - - // Create file input using the file object - FileInput fileInput = FileInput.builder() - .file(file) - // .filePath("") // Alternatively, you can use .filePath() - .build(); - - // Output configuration - String outputDirectory = ""; // Replace with the desired output directory to save the deidentified file - - // Entities to detect - // List detectEntities = new ArrayList<>(); - // detectEntities.add(DetectEntities.IP_ADDRESS); // Replace with the entities you want to detect - - // Image-specific options - // Boolean outputProcessedImage = true; // Include processed image in output - // Boolean outputOcrText = true; // Include OCR text in output - MaskingMethod maskingMethod = MaskingMethod.BLACKBOX; // Masking method for images - - // PDF-specific options - // Integer pixelDensity = 15; // Pixel density for PDF processing - // Integer maxResolution = 2000; // Max resolution for PDF - - // Audio-specific options - // Boolean outputProcessedAudio = true; // Include processed audio - // DetectOutputTranscriptions outputTanscription = DetectOutputTranscriptions.PLAINTEXT_TRANSCRIPTION; // Transcription type - - // Audio bleep configuration - // AudioBleep audioBleep = AudioBleep.builder() - // .frequency(5D) // Pitch in Hz - // .startPadding(7D) // Padding at start (seconds) - // .stopPadding(8D) // Padding at end (seconds) - // .build(); - - Integer waitTime = 20; // Max wait time for response (max 64 seconds) - - DeidentifyFileRequest deidentifyFileRequest = DeidentifyFileRequest.builder() - .file(fileInput) - .waitTime(waitTime) - .entities(detectEntities) - .outputDirectory(outputDirectory) - .maskingMethod(maskingMethod) - // .outputProcessedImage(outputProcessedImage) - // .outputOcrText(outputOcrText) - // .pixelDensity(pixelDensity) - // .maxResolution(maxResolution) - // .outputProcessedAudio(outputProcessedAudio) - // .outputTranscription(outputTanscription) - // .bleep(audioBleep) - .build(); - - - DeidentifyFileResponse deidentifyFileResponse = skyflowClient.detect("").deidentifyFile(deidentifyFileRequest); - System.out.println("Deidentify file response: " + deidentifyFileResponse.toString()); - } -} -``` - -## An [example](https://github.com/skyflowapi/skyflow-java/blob/beta-release/25.6.2/samples/src/main/java/com/example/detect/DeidentifyFileExample.java) of Deidentify file - -```java -import java.io.File; - -import com.skyflow.enums.MaskingMethod; -import com.skyflow.errors.SkyflowException; -import com.skyflow.vault.detect.DeidentifyFileRequest; -import com.skyflow.vault.detect.DeidentifyFileResponse; - -/** - * Skyflow Deidentify File Example - *

- * This example demonstrates how to use the Skyflow SDK to deidentify file - * It has all available options for deidentifying files. - * Supported file types: images (jpg, png, etc.), pdf, audio (mp3, wav), documents, spreadsheets, presentations, structured text. - * It includes: - * 1. Configure credentials - * 2. Set up vault configuration - * 3. Create a deidentify file request with all options - * 4. Call deidentifyFile to deidentify file. - * 5. Handle response and errors - */ -public class DeidentifyFileExample { - - public static void main(String[] args) throws SkyflowException { - // Step 1: Initialise the Skyflow client by configuring the credentials & vault config. - try { - // Step 2: Create a deidentify file request with all options - - - // Create file object - File file = new File("sensitive-folder/personal-info.txt"); // Replace with the path to the file you want to deidentify - - // Create file input using the file object - FileInput fileInput = FileInput.builder() - .file(file) - // .filePath("") // Alternatively, you can use .filePath() - .build(); - - // Output configuration - String outputDirectory = "deidenfied-file/"; // Replace with the desired output directory to save the deidentified file - - // Entities to detect - // List detectEntities = new ArrayList<>(); - // detectEntities.add(DetectEntities.IP_ADDRESS); // Replace with the entities you want to detect - - // Image-specific options - // Boolean outputProcessedImage = true; // Include processed image in output - // Boolean outputOcrText = true; // Include OCR text in output - MaskingMethod maskingMethod = MaskingMethod.BLACKBOX; // Masking method for images - - Integer waitTime = 20; // Max wait time for response (max 64 seconds) - - DeidentifyFileRequest deidentifyFileRequest = DeidentifyFileRequest.builder() - .file(fileInput) - .waitTime(waitTime) - .outputDirectory(outputDirectory) - .maskingMethod(maskingMethod) - .build(); - - // Step 3: Invoking deidentifyFile - // Replace `9f27764a10f7946fe56b3258e117` with the acutal vault id - DeidentifyFileResponse deidentifyFileResponse = skyflowClient.detect("9f27764a10f7946fe56b3258e117").deidentifyFile(deidentifyFileRequest); - System.out.println("Deidentify file response: " + deidentifyFileResponse.toString()); - } catch (SkyflowException e) { - System.err.println("Error occurred during deidentify file: "); - e.printStackTrace(); - } - } -} - -``` - -Sample response: - -```json -{ - "file": { - "name": "deidentified.txt", - "size": 33, - "type": "", - "lastModified": 1751355183039 - }, - "fileBase64": "bXkgY2FyZCBudW1iZXIgaXMgW0NSRURJVF", - "type": "redacted_file", - "extension": "txt", - "wordCount": 11, - "charCount": 61, - "sizeInKb": 0, - "entities": [ - { - "file": "bmFtZTogW05BTUVfMV0gCm==", - "type": "entities", - "extension": "json" - } ], - "runId": "undefined", - "status": "success" -} - -``` - -**Supported file types:** -- Documents: `doc`, `docx`, `pdf` -- PDFs: `pdf` -- Images: `bmp`, `jpeg`, `jpg`, `png`, `tif`, `tiff` -- Structured text: `json`, `xml` -- Spreadsheets: `csv`, `xls`, `xlsx` -- Presentations: `ppt`, `pptx` -- Audio: `mp3`, `wav` - -**Note:** -- Transformations cannot be applied to Documents, Images, or PDFs file formats. - -- The `waitTime` option must be ≤ 64 seconds; otherwise, an error is thrown. - -- If the API takes more than 64 seconds to process the file, it will return only the run ID in the response. - -Sample response (when the API takes more than 64 seconds): -```json -{ - "file": null, - "fileBase64": null, - "type": null, - "extension": null, - "wordCount": null, - "charCount": null, - "sizeInKb": null, - "durationInSeconds": null, - "pageCount": null, - "slideCount": null, - "entities": null, - "runId": "1273a8c6-c498-4293-a9d6-389864cd3a44", - "status": "IN_PROGRESS", - "errors": null -} -``` - -## Get run: -To retrieve the results of a previously started file `deidentification operation`, use the `getDetectRun` method. -The `GetDetectRunRequest` class is initialized with the `runId` returned from a prior deidentifyFile call. -This method allows you to fetch the final results of the file processing operation once they are available. - -### Construct an get run request - -```java -import com.skyflow.errors.SkyflowException; -import com.skyflow.vault.detect.DeidentifyFileResponse; -import com.skyflow.vault.detect.GetDetectRunRequest; - -/** - * Skyflow Get Detect Run Example - */ - -public class GetDetectRunSchema { - - public static void main(String[] args) { - try { - // Step 1: Initialise the Skyflow client by configuring the credentials & vault config. - - // Step 2: Create a get detect run request - GetDetectRunRequest getDetectRunRequest = GetDetectRunRequest.builder() - .runId("") // Replace with the runId from deidentifyFile call - .build(); - - // Step 3: Call getDetectRun to poll for file processing results - // Replace with your actual vault ID - DeidentifyFileResponse deidentifyFileResponse = skyflowClient.detect("").getDetectRun(getDetectRunRequest); - System.out.println("Get Detect Run Response: " + deidentifyFileResponse); - } catch (SkyflowException e) { - System.err.println("Error occurred during get detect run: "); - e.printStackTrace(); - } - } -} - -``` - -## An [example](https://github.com/skyflowapi/skyflow-java/blob/beta-release/25.6.2/samples/src/main/java/com/example/detect/GetDetectRunExample.java) of get run -```java -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.detect.DeidentifyFileResponse; -import com.skyflow.vault.detect.GetDetectRunRequest; - -/** - * Skyflow Get Detect Run Example - *

- * This example demonstrates how to: - * 1. Configure credentials - * 2. Set up vault configuration - * 3. Create a get detect run request - * 4. Call getDetectRun to poll for file processing results - * 5. Handle response and errors - */ -public class GetDetectRunExample { - public static void main(String[] args) throws SkyflowException { - // Step 1: Initialise the Skyflow client by configuring the credentials & vault config. - try { - - // Step 2: Create a get detect run request - GetDetectRunRequest getDetectRunRequest = GetDetectRunRequest.builder() - .runId("e0038196-4a20-422b-bad7-e0477117f9bb") // Replace with the runId from deidentifyFile call - .build(); - - // Step 3: Call getDetectRun to poll for file processing results - // Replace `9f27764a10f7946fe56b3258e117` with the acutal vault id - DeidentifyFileResponse deidentifyFileResponse = skyflowClient.detect("9f27764a10f7946fe56b3258e117").getDetectRun(getDetectRunRequest); - System.out.println("Get Detect Run Response: " + deidentifyFileResponse); - } catch (SkyflowException e) { - System.err.println("Error occurred during get detect run: "); - e.printStackTrace(); - } - } -} -``` - -Sample Response: - -```json -{ - "file": "bmFtZTogW05BTET0JfMV0K", - "type": "redacted_file", - "extension": "txt", - "wordCount": 11, - "charCount": 61, - "sizeInKb": 0.0, - "entities": [ + "errors": [ { - "file": "gW05BTUVfMV0gCmNhcmQ0K", - "type": "entities", - "extension": "json" - } - ], - "runId": "e0038196-4a20-422b-bad7-e0477117f9bb", - "status": "success" -} - -``` - -# Connections - -Skyflow Connections is a gateway service that uses tokenization to securely send and receive data between your systems and first- or third-party services. The [connections](https://github.com/skyflowapi/skyflow-java/tree/main/src/main/java/com/skyflow/vault/connection) module invokes both inbound and/or outbound connections. - -- **Inbound connections**: Act as intermediaries between your client and server, tokenizing sensitive data before it reaches your backend, ensuring downstream services handle only tokenized data. -- **Outbound connections**: Enable secure extraction of data from the vault and transfer it to third-party services via your backend server, such as processing checkout or card issuance flows. - -## Invoke a connection - -To invoke a connection, use the `invoke` method of the Skyflow client. - -### Construct an invoke connection request - -```java -import com.skyflow.enums.RequestMethod; -import com.skyflow.errors.SkyflowException; -import com.skyflow.vault.connection.InvokeConnectionRequest; -import com.skyflow.vault.connection.InvokeConnectionResponse; - -import java.util.HashMap; -import java.util.Map; - -/** - * This example demonstrates how to invoke an external connection using the Skyflow SDK, along with corresponding InvokeConnectionRequest schema. - * - */ -public class InvokeConnectionSchema { - public static void main(String[] args) { - try { - // Initialize Skyflow client - // Step 1: Define the request body parameters - // These are the values you want to send in the request body - Map requestBody = new HashMap<>(); - requestBody.put("", ""); - requestBody.put("", ""); - - // Step 2: Define the request headers - // Add any required headers that need to be sent with the request - Map requestHeaders = new HashMap<>(); - requestHeaders.put("", ""); - requestHeaders.put("", ""); - - // Step 3: Define the path parameters - // Path parameters are part of the URL and typically used in RESTful APIs - Map pathParams = new HashMap<>(); - pathParams.put("", ""); - pathParams.put("", ""); - - // Step 4: Define the query parameters - // Query parameters are included in the URL after a '?' and are used to filter or modify the response - Map queryParams = new HashMap<>(); - queryParams.put("", ""); - queryParams.put("", ""); - - // Step 5: Build the InvokeConnectionRequest using the provided parameters - InvokeConnectionRequest invokeConnectionRequest = InvokeConnectionRequest.builder() - .method(RequestMethod.POST) // The HTTP method to use for the request (POST in this case) - .requestBody(requestBody) // The body of the request - .requestHeaders(requestHeaders) // The headers to include in the request - .pathParams(pathParams) // The path parameters for the URL - .queryParams(queryParams) // The query parameters to append to the URL - .build(); - - // Step 6: Invoke the connection using the request - // Replace "" with the actual connection ID you are using - InvokeConnectionResponse invokeConnectionResponse = skyflowClient.connection("").invoke(invokeConnectionRequest); - - // Step 7: Print the response from the invoked connection - // This response contains the result of the request sent to the external system - System.out.println(invokeConnectionResponse); - - } catch (SkyflowException e) { - // Step 8: Handle any exceptions that occur during the connection invocation - System.out.println("Error occurred: "); - e.printStackTrace(); // Print the exception stack trace for debugging - } - } -} -``` - -`method` supports the following methods: - -- GET -- POST -- PUT -- PATCH -- DELETE - -**pathParams, queryParams, requestHeader, requestBody** are the JSON objects represented as HashMaps, that will be sent through the connection integration url. - -### An [example](https://github.com/skyflowapi/skyflow-java/blob/main/samples/src/main/java/com/example/connection/InvokeConnectionExample.java) of invokeConnection - -```java -import com.skyflow.Skyflow; -import com.skyflow.config.ConnectionConfig; -import com.skyflow.config.Credentials; -import com.skyflow.enums.LogLevel; -import com.skyflow.enums.RequestMethod; -import com.skyflow.errors.SkyflowException; -import com.skyflow.vault.connection.InvokeConnectionRequest; -import com.skyflow.vault.connection.InvokeConnectionResponse; - -import java.util.HashMap; -import java.util.Map; - -/** - * This example demonstrates how to invoke an external connection using the Skyflow SDK. - * It configures a connection, sets up the request, and sends a POST request to the external service. - * - * 1. Initialize Skyflow client with connection details. - * 2. Define the request body, headers, and method. - * 3. Execute the connection request. - * 4. Print the response from the invoked connection. - */ -public class InvokeConnectionExample { - public static void main(String[] args) { - try { - // Initialize Skyflow client - // Step 1: Set up credentials and connection configuration - // Load credentials from a JSON file (you need to provide the correct path) - Credentials credentials = new Credentials(); - credentials.setPath("/path/to/credentials.json"); - - // Define the connection configuration (URL and credentials) - ConnectionConfig connectionConfig = new ConnectionConfig(); - connectionConfig.setConnectionId(""); // Replace with actual connection ID - connectionConfig.setConnectionUrl("https://connection.url.com"); // Replace with actual connection URL - connectionConfig.setCredentials(credentials); // Set credentials for the connection - - // Initialize the Skyflow client with the connection configuration - Skyflow skyflowClient = Skyflow.builder() - .setLogLevel(LogLevel.DEBUG) // Set log level to DEBUG for detailed logs - .addConnectionConfig(connectionConfig) // Add connection configuration to client - .build(); // Build the Skyflow client instance - - // Step 2: Define the request body and headers - // Map for request body parameters - Map requestBody = new HashMap<>(); - requestBody.put("card_number", "4337-1696-5866-0865"); // Example card number - requestBody.put("ssn", "524-41-4248"); // Example SSN - - // Map for request headers - Map requestHeaders = new HashMap<>(); - requestHeaders.put("Content-Type", "application/json"); // Set content type for the request - - // Step 3: Build the InvokeConnectionRequest with required parameters - // Set HTTP method to POST, include the request body and headers - InvokeConnectionRequest invokeConnectionRequest = InvokeConnectionRequest.builder() - .method(RequestMethod.POST) // HTTP POST method - .requestBody(requestBody) // Add request body parameters - .requestHeaders(requestHeaders) // Add headers - .build(); // Build the request - - // Step 4: Invoke the connection and capture the response - // Replace "" with the actual connection ID - InvokeConnectionResponse invokeConnectionResponse = skyflowClient.connection("").invoke(invokeConnectionRequest); - - // Step 5: Print the response from the connection invocation - System.out.println(invokeConnectionResponse); // Print the response to the console - - } catch (SkyflowException e) { - // Step 6: Handle any exceptions that occur during the connection invocation - System.out.println("Error occurred: "); - e.printStackTrace(); // Print the exception stack trace for debugging - } + "index": 1, + "code": 404, + "error": "Detokenize failed. Token 6ffb412b-a79d is invalid. Specify a valid token.", } -} -``` - -Sample response: - -```json -{ - "data": { - "card_number": "4337-1696-5866-0865", - "ssn": "524-41-4248" - }, - "metadata": { - "requestId": "4a3453b5-7aa4-4373-98d7-cf102b1f6f97" - } + ] } ``` @@ -2606,11 +688,11 @@ This section covers methods for generating and managing tokens to authenticate A ## Generate a bearer token -The [Service Account](https://github.com/skyflowapi/skyflow-java/tree/v2/src/main/java/com/skyflow/serviceaccount/util) Java module generates service account tokens using a service account credentials file, which is provided when a service account is created. The tokens generated by this module are valid for 60 minutes and can be used to make API calls to the [Data](https://docs.skyflow.com/record/) and [Management](https://docs.skyflow.com/management/) APIs, depending on the permissions assigned to the service account. +The [Service Account](https://github.com/skyflowapi/skyflow-java/tree/v3/common/src/main/java/com/skyflow/serviceaccount/util) Java module generates service account tokens using a service account credentials file, which is provided when a service account is created. The tokens generated by this module are valid for 60 minutes and can be used to make API calls to the [Data](https://docs.skyflow.com/api/data/) and [Management](https://docs.skyflow.com/management/) APIs, depending on the permissions assigned to the service account. The `BearerToken` utility class generates bearer tokens using a credentials JSON file. Alternatively, you can pass the credentials as a string. -[Example](https://github.com/skyflowapi/skyflow-java/blob/main/samples/src/main/java/com/example/serviceaccount/BearerTokenGenerationExample.java): +Example: ```java /** @@ -2679,7 +761,7 @@ public class BearerTokenGenerationExample { A service account with the `context_id` identifier generates bearer tokens containing context information, represented as a JWT claim in a Skyflow-generated bearer token. Tokens generated from such service accounts include a `context_identifier` claim, are valid for 60 minutes, and can be used to make API calls to the Data and Management APIs, depending on the service account's permissions. -[Example](https://github.com/skyflowapi/skyflow-java/blob/main/samples/src/main/java/com/example/serviceaccount/BearerTokenGenerationWithContextExample.java): +Example: ```java import com.skyflow.errors.SkyflowException; @@ -2747,7 +829,7 @@ public class BearerTokenGenerationWithContextExample { A service account with multiple roles can generate bearer tokens with access limited to a specific role by specifying the appropriate `roleID`. This can be used to limit access to specific roles for services with multiple responsibilities, such as segregating access for billing and analytics. The generated bearer tokens are valid for 60 minutes and can only execute operations permitted by the permissions associated with the designated role. -[Example](https://github.com/skyflowapi/skyflow-java/blob/main/samples/src/main/java/com/example/serviceaccount/ScopedTokenGenerationExample.java): +Example: ```java import com.skyflow.errors.SkyflowException; @@ -2798,7 +880,6 @@ Notes: - You can pass either the file path of a service account key credentials file or the service account key credentials as a string to the `setCredentials` method of the `BearerTokenBuilder` class. - If both a file path and a string are provided, the last method used takes precedence. -- To generate multiple bearer tokens concurrently using threads, refer to the following [example](https://github.com/skyflowapi/skyflow-java/blob/main/samples/src/main/java/com/example/serviceaccount/BearerTokenGenerationUsingThreadsExample.java). ## Generate Signed Data Tokens @@ -2807,7 +888,7 @@ with the private key of the service account credentials, which adds an additiona be detokenized by passing the signed data token and a bearer token generated from service account credentials. The service account must have appropriate permissions and context to detokenize the signed data tokens. -[Example](https://github.com/skyflowapi/skyflow-java/blob/main/samples/src/main/java/com/example/serviceaccount/SignedTokenGenerationExample.java): +Example: ```java import com.skyflow.errors.SkyflowException; @@ -2887,7 +968,7 @@ message: Authentication failed. Bearer token is expired. Use a valid bearer toke If you encounter this kind of error, retry the request. During the retry, the SDK detects that the previous bearer token has expired and generates a new one for the current and subsequent requests. -#### [Example](https://github.com/skyflowapi/skyflow-java/blob/v2/samples/src/main/java/com/example/serviceaccount/BearerTokenExpiryExample.java): +#### Example: ```java package com.example.serviceaccount; @@ -2965,8 +1046,6 @@ public class DetokenizeExample { // Building a detokenization request with the token list and configuration DetokenizeRequest detokenizeRequest = DetokenizeRequest.builder() .tokens(tokenList) // Adding tokens to the request - .continueOnError(false) // Stop on error - .redactionType(RedactionType.PLAIN_TEXT) // Redaction type (e.g., PLAIN_TEXT) .build(); // Sending the detokenization request and receiving the response @@ -3058,4 +1137,4 @@ public class ChangeLogLevel { # Reporting a Vulnerability -If you discover a potential security issue in this project, please reach out to us at **security@skyflow.com**. Please do not create public GitHub issues or Pull Requests, as malicious actors could potentially view them. +If you discover a potential security issue in this project, please reach out to us at **security@skyflow.com**. Please do not create public GitHub issues or Pull Requests, as malicious actors could potentially view them. \ No newline at end of file diff --git a/common/pom.xml b/common/pom.xml index d971c1b5..df90bb58 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -5,14 +5,18 @@ 4.0.0 com.skyflow - skyflow-java + skyflow 1.0.0 + ../pom.xml common - 1.0.0 + 1.0.1 + ${project.groupId}:${project.artifactId} + + true 8 8 UTF-8 diff --git a/common/src/main/java/com/skyflow/errors/ErrorMessage.java b/common/src/main/java/com/skyflow/errors/ErrorMessage.java index e3b0bbbe..f4b2ce7b 100644 --- a/common/src/main/java/com/skyflow/errors/ErrorMessage.java +++ b/common/src/main/java/com/skyflow/errors/ErrorMessage.java @@ -6,6 +6,7 @@ public enum ErrorMessage { // Client initialization VaultIdAlreadyInConfigList("%s0 Validation error. VaultId is present in an existing config. Specify a new vaultId in config."), VaultIdNotInConfigList("%s0 Validation error. VaultId is missing from the config. Specify the vaultIds from configs."), + OnlySingleVaultConfigAllowed("%s0 Validation error. A vault config already exists. Cannot add another vault config."), ConnectionIdAlreadyInConfigList("%s0 Validation error. ConnectionId is present in an existing config. Specify a connectionId in config."), ConnectionIdNotInConfigList("%s0 Validation error. ConnectionId is missing from the config. Specify the connectionIds from configs."), EmptyCredentials("%s0 Validation error. Invalid credentials. Credentials must not be empty."), @@ -51,6 +52,7 @@ public enum ErrorMessage { JwtDecodeError("%s0 Validation error. Invalid access token. Verify your credentials."), MissingAccessToken("%s0 Validation error. Access token not present in the response from bearer token generation. Verify your credentials."), MissingTokenType("%s0 Validation error. Token type not present in the response from bearer token generation. Verify your credentials."), + BearerTokenExpired("%s0 Validation error. Bearer token is invalid or expired. Please provide a valid bearer token."), // Insert TableKeyError("%s0 Validation error. 'table' key is missing from the payload. Specify a 'table' key."), @@ -148,7 +150,16 @@ public enum ErrorMessage { FailedToSaveProcessedFile("%s0 Validation error. Failed to save the processed file. Ensure the output directory is valid and writable."), InvalidAudioFileType("%s0 Validation error. The file type is not supported. Specify a valid file type mp3 or wav."), // Generic - ErrorOccurred("%s0 API error. Error occurred.") + ErrorOccurred("%s0 API error. Error occurred."), + + DetokenizeRequestNull("%s0 Validation error. DetokenizeRequest object is null. Specify a valid DetokenizeRequest object."), + + NullTokenGroupRedactions("%s0 Validation error. TokenGroupRedaction in the list is null. Specify a valid TokenGroupRedactions object."), + + NullRedactionInTokenGroup("%s0 Validation error. Redaction in TokenGroupRedactions is null or empty. Specify a valid redaction."), + + NullTokenGroupNameInTokenGroup("%s0 Validation error. TokenGroupName in TokenGroupRedactions is null or empty. Specify a valid tokenGroupName."), + ; ; private final String message; diff --git a/common/src/main/java/com/skyflow/generated/rest/ApiClient.java b/common/src/main/java/com/skyflow/generated/auth/rest/ApiClient.java similarity index 73% rename from common/src/main/java/com/skyflow/generated/rest/ApiClient.java rename to common/src/main/java/com/skyflow/generated/auth/rest/ApiClient.java index f49fc4c3..721942e9 100644 --- a/common/src/main/java/com/skyflow/generated/rest/ApiClient.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/ApiClient.java @@ -1,11 +1,11 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest; +package com.skyflow.generated.auth.rest; -import com.skyflow.generated.rest.core.ClientOptions; -import com.skyflow.generated.rest.core.Suppliers; -import com.skyflow.generated.rest.resources.authentication.AuthenticationClient; +import com.skyflow.generated.auth.rest.core.ClientOptions; +import com.skyflow.generated.auth.rest.core.Suppliers; +import com.skyflow.generated.auth.rest.resources.authentication.AuthenticationClient; import java.util.function.Supplier; public class ApiClient { diff --git a/common/src/main/java/com/skyflow/generated/rest/ApiClientBuilder.java b/common/src/main/java/com/skyflow/generated/auth/rest/ApiClientBuilder.java similarity index 91% rename from common/src/main/java/com/skyflow/generated/rest/ApiClientBuilder.java rename to common/src/main/java/com/skyflow/generated/auth/rest/ApiClientBuilder.java index b361812a..aed3ed24 100644 --- a/common/src/main/java/com/skyflow/generated/rest/ApiClientBuilder.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/ApiClientBuilder.java @@ -1,10 +1,10 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest; +package com.skyflow.generated.auth.rest; -import com.skyflow.generated.rest.core.ClientOptions; -import com.skyflow.generated.rest.core.Environment; +import com.skyflow.generated.auth.rest.core.ClientOptions; +import com.skyflow.generated.auth.rest.core.Environment; import okhttp3.OkHttpClient; public final class ApiClientBuilder { diff --git a/common/src/main/java/com/skyflow/generated/rest/AsyncApiClient.java b/common/src/main/java/com/skyflow/generated/auth/rest/AsyncApiClient.java similarity index 73% rename from common/src/main/java/com/skyflow/generated/rest/AsyncApiClient.java rename to common/src/main/java/com/skyflow/generated/auth/rest/AsyncApiClient.java index d9163e14..674a9ef9 100644 --- a/common/src/main/java/com/skyflow/generated/rest/AsyncApiClient.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/AsyncApiClient.java @@ -1,11 +1,11 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest; +package com.skyflow.generated.auth.rest; -import com.skyflow.generated.rest.core.ClientOptions; -import com.skyflow.generated.rest.core.Suppliers; -import com.skyflow.generated.rest.resources.authentication.AsyncAuthenticationClient; +import com.skyflow.generated.auth.rest.core.ClientOptions; +import com.skyflow.generated.auth.rest.core.Suppliers; +import com.skyflow.generated.auth.rest.resources.authentication.AsyncAuthenticationClient; import java.util.function.Supplier; public class AsyncApiClient { diff --git a/common/src/main/java/com/skyflow/generated/rest/AsyncApiClientBuilder.java b/common/src/main/java/com/skyflow/generated/auth/rest/AsyncApiClientBuilder.java similarity index 91% rename from common/src/main/java/com/skyflow/generated/rest/AsyncApiClientBuilder.java rename to common/src/main/java/com/skyflow/generated/auth/rest/AsyncApiClientBuilder.java index 8e4b8474..2e30d45a 100644 --- a/common/src/main/java/com/skyflow/generated/rest/AsyncApiClientBuilder.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/AsyncApiClientBuilder.java @@ -1,10 +1,10 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest; +package com.skyflow.generated.auth.rest; -import com.skyflow.generated.rest.core.ClientOptions; -import com.skyflow.generated.rest.core.Environment; +import com.skyflow.generated.auth.rest.core.ClientOptions; +import com.skyflow.generated.auth.rest.core.Environment; import okhttp3.OkHttpClient; public final class AsyncApiClientBuilder { diff --git a/common/src/main/java/com/skyflow/generated/rest/core/ApiClientApiException.java b/common/src/main/java/com/skyflow/generated/auth/rest/core/ApiClientApiException.java similarity index 97% rename from common/src/main/java/com/skyflow/generated/rest/core/ApiClientApiException.java rename to common/src/main/java/com/skyflow/generated/auth/rest/core/ApiClientApiException.java index a4487b1e..dc4c008c 100644 --- a/common/src/main/java/com/skyflow/generated/rest/core/ApiClientApiException.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/core/ApiClientApiException.java @@ -1,7 +1,7 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest.core; +package com.skyflow.generated.auth.rest.core; import java.util.ArrayList; import java.util.HashMap; diff --git a/common/src/main/java/com/skyflow/generated/rest/core/ApiClientException.java b/common/src/main/java/com/skyflow/generated/auth/rest/core/ApiClientException.java similarity index 89% rename from common/src/main/java/com/skyflow/generated/rest/core/ApiClientException.java rename to common/src/main/java/com/skyflow/generated/auth/rest/core/ApiClientException.java index 7987eba6..f08afa2e 100644 --- a/common/src/main/java/com/skyflow/generated/rest/core/ApiClientException.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/core/ApiClientException.java @@ -1,7 +1,7 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest.core; +package com.skyflow.generated.auth.rest.core; /** * This class serves as the base exception for all errors in the SDK. diff --git a/common/src/main/java/com/skyflow/generated/rest/core/ApiClientHttpResponse.java b/common/src/main/java/com/skyflow/generated/auth/rest/core/ApiClientHttpResponse.java similarity index 95% rename from common/src/main/java/com/skyflow/generated/rest/core/ApiClientHttpResponse.java rename to common/src/main/java/com/skyflow/generated/auth/rest/core/ApiClientHttpResponse.java index 9c81f1f5..733c056c 100644 --- a/common/src/main/java/com/skyflow/generated/rest/core/ApiClientHttpResponse.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/core/ApiClientHttpResponse.java @@ -1,7 +1,7 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest.core; +package com.skyflow.generated.auth.rest.core; import java.util.ArrayList; import java.util.HashMap; diff --git a/common/src/main/java/com/skyflow/generated/rest/core/ClientOptions.java b/common/src/main/java/com/skyflow/generated/auth/rest/core/ClientOptions.java similarity index 99% rename from common/src/main/java/com/skyflow/generated/rest/core/ClientOptions.java rename to common/src/main/java/com/skyflow/generated/auth/rest/core/ClientOptions.java index e7388551..4dd049dd 100644 --- a/common/src/main/java/com/skyflow/generated/rest/core/ClientOptions.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/core/ClientOptions.java @@ -1,7 +1,7 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest.core; +package com.skyflow.generated.auth.rest.core; import java.util.HashMap; import java.util.Map; diff --git a/common/src/main/java/com/skyflow/generated/rest/core/DateTimeDeserializer.java b/common/src/main/java/com/skyflow/generated/auth/rest/core/DateTimeDeserializer.java similarity index 97% rename from common/src/main/java/com/skyflow/generated/rest/core/DateTimeDeserializer.java rename to common/src/main/java/com/skyflow/generated/auth/rest/core/DateTimeDeserializer.java index 6be10979..a5a2fbe8 100644 --- a/common/src/main/java/com/skyflow/generated/rest/core/DateTimeDeserializer.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/core/DateTimeDeserializer.java @@ -1,7 +1,7 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest.core; +package com.skyflow.generated.auth.rest.core; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; diff --git a/common/src/main/java/com/skyflow/generated/rest/core/Environment.java b/common/src/main/java/com/skyflow/generated/auth/rest/core/Environment.java similarity index 92% rename from common/src/main/java/com/skyflow/generated/rest/core/Environment.java rename to common/src/main/java/com/skyflow/generated/auth/rest/core/Environment.java index c5a294b7..098667c0 100644 --- a/common/src/main/java/com/skyflow/generated/rest/core/Environment.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/core/Environment.java @@ -1,7 +1,7 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest.core; +package com.skyflow.generated.auth.rest.core; public final class Environment { public static final Environment PRODUCTION = new Environment("https://manage.skyflowapis.com"); diff --git a/common/src/main/java/com/skyflow/generated/rest/core/FileStream.java b/common/src/main/java/com/skyflow/generated/auth/rest/core/FileStream.java similarity index 97% rename from common/src/main/java/com/skyflow/generated/rest/core/FileStream.java rename to common/src/main/java/com/skyflow/generated/auth/rest/core/FileStream.java index 6b459431..b1aad352 100644 --- a/common/src/main/java/com/skyflow/generated/rest/core/FileStream.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/core/FileStream.java @@ -1,7 +1,7 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest.core; +package com.skyflow.generated.auth.rest.core; import java.io.InputStream; import java.util.Objects; diff --git a/common/src/main/java/com/skyflow/generated/rest/core/InputStreamRequestBody.java b/common/src/main/java/com/skyflow/generated/auth/rest/core/InputStreamRequestBody.java similarity index 98% rename from common/src/main/java/com/skyflow/generated/rest/core/InputStreamRequestBody.java rename to common/src/main/java/com/skyflow/generated/auth/rest/core/InputStreamRequestBody.java index 545f6088..22b17b14 100644 --- a/common/src/main/java/com/skyflow/generated/rest/core/InputStreamRequestBody.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/core/InputStreamRequestBody.java @@ -1,7 +1,7 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest.core; +package com.skyflow.generated.auth.rest.core; import java.io.IOException; import java.io.InputStream; diff --git a/common/src/main/java/com/skyflow/generated/rest/core/MediaTypes.java b/common/src/main/java/com/skyflow/generated/auth/rest/core/MediaTypes.java similarity index 84% rename from common/src/main/java/com/skyflow/generated/rest/core/MediaTypes.java rename to common/src/main/java/com/skyflow/generated/auth/rest/core/MediaTypes.java index 11714cb8..d4374647 100644 --- a/common/src/main/java/com/skyflow/generated/rest/core/MediaTypes.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/core/MediaTypes.java @@ -1,7 +1,7 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest.core; +package com.skyflow.generated.auth.rest.core; import okhttp3.MediaType; diff --git a/common/src/main/java/com/skyflow/generated/rest/core/Nullable.java b/common/src/main/java/com/skyflow/generated/auth/rest/core/Nullable.java similarity index 98% rename from common/src/main/java/com/skyflow/generated/rest/core/Nullable.java rename to common/src/main/java/com/skyflow/generated/auth/rest/core/Nullable.java index 5929c12d..efabe806 100644 --- a/common/src/main/java/com/skyflow/generated/rest/core/Nullable.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/core/Nullable.java @@ -1,7 +1,7 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest.core; +package com.skyflow.generated.auth.rest.core; import java.util.Optional; import java.util.function.Function; diff --git a/common/src/main/java/com/skyflow/generated/rest/core/NullableNonemptyFilter.java b/common/src/main/java/com/skyflow/generated/auth/rest/core/NullableNonemptyFilter.java similarity index 90% rename from common/src/main/java/com/skyflow/generated/rest/core/NullableNonemptyFilter.java rename to common/src/main/java/com/skyflow/generated/auth/rest/core/NullableNonemptyFilter.java index 98c33be4..dd32d66c 100644 --- a/common/src/main/java/com/skyflow/generated/rest/core/NullableNonemptyFilter.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/core/NullableNonemptyFilter.java @@ -1,7 +1,7 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest.core; +package com.skyflow.generated.auth.rest.core; import java.util.Optional; diff --git a/common/src/main/java/com/skyflow/generated/rest/core/ObjectMappers.java b/common/src/main/java/com/skyflow/generated/auth/rest/core/ObjectMappers.java similarity index 96% rename from common/src/main/java/com/skyflow/generated/rest/core/ObjectMappers.java rename to common/src/main/java/com/skyflow/generated/auth/rest/core/ObjectMappers.java index 3b7894e0..ee160b93 100644 --- a/common/src/main/java/com/skyflow/generated/rest/core/ObjectMappers.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/core/ObjectMappers.java @@ -1,7 +1,7 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest.core; +package com.skyflow.generated.auth.rest.core; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.DeserializationFeature; diff --git a/common/src/main/java/com/skyflow/generated/rest/core/QueryStringMapper.java b/common/src/main/java/com/skyflow/generated/auth/rest/core/QueryStringMapper.java similarity index 99% rename from common/src/main/java/com/skyflow/generated/rest/core/QueryStringMapper.java rename to common/src/main/java/com/skyflow/generated/auth/rest/core/QueryStringMapper.java index e9e18fb9..b35c7174 100644 --- a/common/src/main/java/com/skyflow/generated/rest/core/QueryStringMapper.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/core/QueryStringMapper.java @@ -1,7 +1,7 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest.core; +package com.skyflow.generated.auth.rest.core; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/common/src/main/java/com/skyflow/generated/rest/core/RequestOptions.java b/common/src/main/java/com/skyflow/generated/auth/rest/core/RequestOptions.java similarity index 98% rename from common/src/main/java/com/skyflow/generated/rest/core/RequestOptions.java rename to common/src/main/java/com/skyflow/generated/auth/rest/core/RequestOptions.java index edc6d0ae..b70c02df 100644 --- a/common/src/main/java/com/skyflow/generated/rest/core/RequestOptions.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/core/RequestOptions.java @@ -1,7 +1,7 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest.core; +package com.skyflow.generated.auth.rest.core; import java.util.HashMap; import java.util.Map; diff --git a/common/src/main/java/com/skyflow/generated/rest/core/ResponseBodyInputStream.java b/common/src/main/java/com/skyflow/generated/auth/rest/core/ResponseBodyInputStream.java similarity index 97% rename from common/src/main/java/com/skyflow/generated/rest/core/ResponseBodyInputStream.java rename to common/src/main/java/com/skyflow/generated/auth/rest/core/ResponseBodyInputStream.java index d8df7715..5bb66b4a 100644 --- a/common/src/main/java/com/skyflow/generated/rest/core/ResponseBodyInputStream.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/core/ResponseBodyInputStream.java @@ -1,7 +1,7 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest.core; +package com.skyflow.generated.auth.rest.core; import java.io.FilterInputStream; import java.io.IOException; diff --git a/common/src/main/java/com/skyflow/generated/rest/core/ResponseBodyReader.java b/common/src/main/java/com/skyflow/generated/auth/rest/core/ResponseBodyReader.java similarity index 97% rename from common/src/main/java/com/skyflow/generated/rest/core/ResponseBodyReader.java rename to common/src/main/java/com/skyflow/generated/auth/rest/core/ResponseBodyReader.java index ed894407..e3052b4c 100644 --- a/common/src/main/java/com/skyflow/generated/rest/core/ResponseBodyReader.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/core/ResponseBodyReader.java @@ -1,7 +1,7 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest.core; +package com.skyflow.generated.auth.rest.core; import java.io.FilterReader; import java.io.IOException; diff --git a/common/src/main/java/com/skyflow/generated/rest/core/RetryInterceptor.java b/common/src/main/java/com/skyflow/generated/auth/rest/core/RetryInterceptor.java similarity index 98% rename from common/src/main/java/com/skyflow/generated/rest/core/RetryInterceptor.java rename to common/src/main/java/com/skyflow/generated/auth/rest/core/RetryInterceptor.java index eda7d265..93e86644 100644 --- a/common/src/main/java/com/skyflow/generated/rest/core/RetryInterceptor.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/core/RetryInterceptor.java @@ -1,7 +1,7 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest.core; +package com.skyflow.generated.auth.rest.core; import java.io.IOException; import java.time.Duration; diff --git a/common/src/main/java/com/skyflow/generated/rest/core/Stream.java b/common/src/main/java/com/skyflow/generated/auth/rest/core/Stream.java similarity index 98% rename from common/src/main/java/com/skyflow/generated/rest/core/Stream.java rename to common/src/main/java/com/skyflow/generated/auth/rest/core/Stream.java index f037712a..4a984faa 100644 --- a/common/src/main/java/com/skyflow/generated/rest/core/Stream.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/core/Stream.java @@ -1,7 +1,7 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest.core; +package com.skyflow.generated.auth.rest.core; import java.io.Reader; import java.util.Iterator; diff --git a/common/src/main/java/com/skyflow/generated/rest/core/Suppliers.java b/common/src/main/java/com/skyflow/generated/auth/rest/core/Suppliers.java similarity index 93% rename from common/src/main/java/com/skyflow/generated/rest/core/Suppliers.java rename to common/src/main/java/com/skyflow/generated/auth/rest/core/Suppliers.java index 307d5852..d3ab5e53 100644 --- a/common/src/main/java/com/skyflow/generated/rest/core/Suppliers.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/core/Suppliers.java @@ -1,7 +1,7 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest.core; +package com.skyflow.generated.auth.rest.core; import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; diff --git a/common/src/main/java/com/skyflow/generated/rest/errors/BadRequestError.java b/common/src/main/java/com/skyflow/generated/auth/rest/errors/BadRequestError.java similarity index 86% rename from common/src/main/java/com/skyflow/generated/rest/errors/BadRequestError.java rename to common/src/main/java/com/skyflow/generated/auth/rest/errors/BadRequestError.java index d4b2d99f..ec08ddf2 100644 --- a/common/src/main/java/com/skyflow/generated/rest/errors/BadRequestError.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/errors/BadRequestError.java @@ -1,9 +1,9 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest.errors; +package com.skyflow.generated.auth.rest.errors; -import com.skyflow.generated.rest.core.ApiClientApiException; +import com.skyflow.generated.auth.rest.core.ApiClientApiException; import java.util.Map; import okhttp3.Response; diff --git a/common/src/main/java/com/skyflow/generated/rest/errors/HttpStatus.java b/common/src/main/java/com/skyflow/generated/auth/rest/errors/HttpStatus.java similarity index 83% rename from common/src/main/java/com/skyflow/generated/rest/errors/HttpStatus.java rename to common/src/main/java/com/skyflow/generated/auth/rest/errors/HttpStatus.java index dc9aecfe..2e1c45d2 100644 --- a/common/src/main/java/com/skyflow/generated/rest/errors/HttpStatus.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/errors/HttpStatus.java @@ -1,4 +1,4 @@ -package com.skyflow.generated.rest.errors; +package com.skyflow.generated.auth.rest.errors; public enum HttpStatus { BAD_REQUEST("Bad Request"); diff --git a/common/src/main/java/com/skyflow/generated/rest/errors/NotFoundError.java b/common/src/main/java/com/skyflow/generated/auth/rest/errors/NotFoundError.java similarity index 86% rename from common/src/main/java/com/skyflow/generated/rest/errors/NotFoundError.java rename to common/src/main/java/com/skyflow/generated/auth/rest/errors/NotFoundError.java index 46291af6..b889e1b0 100644 --- a/common/src/main/java/com/skyflow/generated/rest/errors/NotFoundError.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/errors/NotFoundError.java @@ -1,9 +1,9 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest.errors; +package com.skyflow.generated.auth.rest.errors; -import com.skyflow.generated.rest.core.ApiClientApiException; +import com.skyflow.generated.auth.rest.core.ApiClientApiException; import java.util.Map; import okhttp3.Response; diff --git a/common/src/main/java/com/skyflow/generated/rest/errors/UnauthorizedError.java b/common/src/main/java/com/skyflow/generated/auth/rest/errors/UnauthorizedError.java similarity index 86% rename from common/src/main/java/com/skyflow/generated/rest/errors/UnauthorizedError.java rename to common/src/main/java/com/skyflow/generated/auth/rest/errors/UnauthorizedError.java index 1e90cfc2..40ea9c25 100644 --- a/common/src/main/java/com/skyflow/generated/rest/errors/UnauthorizedError.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/errors/UnauthorizedError.java @@ -1,9 +1,9 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest.errors; +package com.skyflow.generated.auth.rest.errors; -import com.skyflow.generated.rest.core.ApiClientApiException; +import com.skyflow.generated.auth.rest.core.ApiClientApiException; import java.util.Map; import okhttp3.Response; diff --git a/common/src/main/java/com/skyflow/generated/rest/resources/authentication/AsyncAuthenticationClient.java b/common/src/main/java/com/skyflow/generated/auth/rest/resources/authentication/AsyncAuthenticationClient.java similarity index 84% rename from common/src/main/java/com/skyflow/generated/rest/resources/authentication/AsyncAuthenticationClient.java rename to common/src/main/java/com/skyflow/generated/auth/rest/resources/authentication/AsyncAuthenticationClient.java index 43ffab73..e75fad24 100644 --- a/common/src/main/java/com/skyflow/generated/rest/resources/authentication/AsyncAuthenticationClient.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/resources/authentication/AsyncAuthenticationClient.java @@ -1,12 +1,13 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest.resources.authentication; +package com.skyflow.generated.auth.rest.resources.authentication; + +import com.skyflow.generated.auth.rest.core.ClientOptions; +import com.skyflow.generated.auth.rest.core.RequestOptions; +import com.skyflow.generated.auth.rest.types.V1GetAuthTokenResponse; +import com.skyflow.generated.auth.rest.resources.authentication.requests.V1GetAuthTokenRequest; -import com.skyflow.generated.rest.core.ClientOptions; -import com.skyflow.generated.rest.core.RequestOptions; -import com.skyflow.generated.rest.resources.authentication.requests.V1GetAuthTokenRequest; -import com.skyflow.generated.rest.types.V1GetAuthTokenResponse; import java.util.concurrent.CompletableFuture; public class AsyncAuthenticationClient { diff --git a/common/src/main/java/com/skyflow/generated/rest/resources/authentication/AsyncRawAuthenticationClient.java b/common/src/main/java/com/skyflow/generated/auth/rest/resources/authentication/AsyncRawAuthenticationClient.java similarity index 87% rename from common/src/main/java/com/skyflow/generated/rest/resources/authentication/AsyncRawAuthenticationClient.java rename to common/src/main/java/com/skyflow/generated/auth/rest/resources/authentication/AsyncRawAuthenticationClient.java index 10ad0c01..61ff4335 100644 --- a/common/src/main/java/com/skyflow/generated/rest/resources/authentication/AsyncRawAuthenticationClient.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/resources/authentication/AsyncRawAuthenticationClient.java @@ -1,22 +1,23 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest.resources.authentication; +package com.skyflow.generated.auth.rest.resources.authentication; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; -import com.skyflow.generated.rest.core.ApiClientApiException; -import com.skyflow.generated.rest.core.ApiClientException; -import com.skyflow.generated.rest.core.ApiClientHttpResponse; -import com.skyflow.generated.rest.core.ClientOptions; -import com.skyflow.generated.rest.core.MediaTypes; -import com.skyflow.generated.rest.core.ObjectMappers; -import com.skyflow.generated.rest.core.RequestOptions; -import com.skyflow.generated.rest.errors.BadRequestError; -import com.skyflow.generated.rest.errors.NotFoundError; -import com.skyflow.generated.rest.errors.UnauthorizedError; -import com.skyflow.generated.rest.resources.authentication.requests.V1GetAuthTokenRequest; -import com.skyflow.generated.rest.types.V1GetAuthTokenResponse; +import com.skyflow.generated.auth.rest.errors.BadRequestError; +import com.skyflow.generated.auth.rest.errors.NotFoundError; +import com.skyflow.generated.auth.rest.errors.UnauthorizedError; +import com.skyflow.generated.auth.rest.resources.authentication.requests.V1GetAuthTokenRequest; +import com.skyflow.generated.auth.rest.types.V1GetAuthTokenResponse; +import com.skyflow.generated.auth.rest.core.ApiClientApiException; +import com.skyflow.generated.auth.rest.core.ApiClientException; +import com.skyflow.generated.auth.rest.core.ApiClientHttpResponse; +import com.skyflow.generated.auth.rest.core.ClientOptions; +import com.skyflow.generated.auth.rest.core.MediaTypes; +import com.skyflow.generated.auth.rest.core.ObjectMappers; +import com.skyflow.generated.auth.rest.core.RequestOptions; + import java.io.IOException; import java.util.Map; import java.util.concurrent.CompletableFuture; diff --git a/common/src/main/java/com/skyflow/generated/rest/resources/authentication/AuthenticationClient.java b/common/src/main/java/com/skyflow/generated/auth/rest/resources/authentication/AuthenticationClient.java similarity index 82% rename from common/src/main/java/com/skyflow/generated/rest/resources/authentication/AuthenticationClient.java rename to common/src/main/java/com/skyflow/generated/auth/rest/resources/authentication/AuthenticationClient.java index 662bfb3d..a0ba860a 100644 --- a/common/src/main/java/com/skyflow/generated/rest/resources/authentication/AuthenticationClient.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/resources/authentication/AuthenticationClient.java @@ -1,12 +1,12 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest.resources.authentication; +package com.skyflow.generated.auth.rest.resources.authentication; -import com.skyflow.generated.rest.core.ClientOptions; -import com.skyflow.generated.rest.core.RequestOptions; -import com.skyflow.generated.rest.resources.authentication.requests.V1GetAuthTokenRequest; -import com.skyflow.generated.rest.types.V1GetAuthTokenResponse; +import com.skyflow.generated.auth.rest.core.ClientOptions; +import com.skyflow.generated.auth.rest.core.RequestOptions; +import com.skyflow.generated.auth.rest.resources.authentication.requests.V1GetAuthTokenRequest; +import com.skyflow.generated.auth.rest.types.V1GetAuthTokenResponse; public class AuthenticationClient { protected final ClientOptions clientOptions; diff --git a/common/src/main/java/com/skyflow/generated/rest/resources/authentication/RawAuthenticationClient.java b/common/src/main/java/com/skyflow/generated/auth/rest/resources/authentication/RawAuthenticationClient.java similarity index 84% rename from common/src/main/java/com/skyflow/generated/rest/resources/authentication/RawAuthenticationClient.java rename to common/src/main/java/com/skyflow/generated/auth/rest/resources/authentication/RawAuthenticationClient.java index c30cf003..f3211ad1 100644 --- a/common/src/main/java/com/skyflow/generated/rest/resources/authentication/RawAuthenticationClient.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/resources/authentication/RawAuthenticationClient.java @@ -1,22 +1,23 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest.resources.authentication; +package com.skyflow.generated.auth.rest.resources.authentication; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; -import com.skyflow.generated.rest.core.ApiClientApiException; -import com.skyflow.generated.rest.core.ApiClientException; -import com.skyflow.generated.rest.core.ApiClientHttpResponse; -import com.skyflow.generated.rest.core.ClientOptions; -import com.skyflow.generated.rest.core.MediaTypes; -import com.skyflow.generated.rest.core.ObjectMappers; -import com.skyflow.generated.rest.core.RequestOptions; -import com.skyflow.generated.rest.errors.BadRequestError; -import com.skyflow.generated.rest.errors.NotFoundError; -import com.skyflow.generated.rest.errors.UnauthorizedError; -import com.skyflow.generated.rest.resources.authentication.requests.V1GetAuthTokenRequest; -import com.skyflow.generated.rest.types.V1GetAuthTokenResponse; +import com.skyflow.generated.auth.rest.errors.BadRequestError; +import com.skyflow.generated.auth.rest.errors.NotFoundError; +import com.skyflow.generated.auth.rest.errors.UnauthorizedError; +import com.skyflow.generated.auth.rest.types.V1GetAuthTokenResponse; +import com.skyflow.generated.auth.rest.core.ApiClientApiException; +import com.skyflow.generated.auth.rest.core.ApiClientException; +import com.skyflow.generated.auth.rest.core.ApiClientHttpResponse; +import com.skyflow.generated.auth.rest.core.ClientOptions; +import com.skyflow.generated.auth.rest.core.MediaTypes; +import com.skyflow.generated.auth.rest.core.ObjectMappers; +import com.skyflow.generated.auth.rest.core.RequestOptions; +import com.skyflow.generated.auth.rest.resources.authentication.requests.V1GetAuthTokenRequest; + import java.io.IOException; import java.util.Map; import okhttp3.Headers; diff --git a/common/src/main/java/com/skyflow/generated/rest/resources/authentication/requests/V1GetAuthTokenRequest.java b/common/src/main/java/com/skyflow/generated/auth/rest/resources/authentication/requests/V1GetAuthTokenRequest.java similarity index 98% rename from common/src/main/java/com/skyflow/generated/rest/resources/authentication/requests/V1GetAuthTokenRequest.java rename to common/src/main/java/com/skyflow/generated/auth/rest/resources/authentication/requests/V1GetAuthTokenRequest.java index 8c4961b1..cd1d22c1 100644 --- a/common/src/main/java/com/skyflow/generated/rest/resources/authentication/requests/V1GetAuthTokenRequest.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/resources/authentication/requests/V1GetAuthTokenRequest.java @@ -1,7 +1,7 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest.resources.authentication.requests; +package com.skyflow.generated.auth.rest.resources.authentication.requests; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; @@ -11,7 +11,8 @@ import com.fasterxml.jackson.annotation.JsonSetter; import com.fasterxml.jackson.annotation.Nulls; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.skyflow.generated.rest.core.ObjectMappers; +import com.skyflow.generated.auth.rest.core.ObjectMappers; + import java.util.HashMap; import java.util.Map; import java.util.Objects; diff --git a/common/src/main/java/com/skyflow/generated/rest/types/GooglerpcStatus.java b/common/src/main/java/com/skyflow/generated/auth/rest/types/GooglerpcStatus.java similarity index 97% rename from common/src/main/java/com/skyflow/generated/rest/types/GooglerpcStatus.java rename to common/src/main/java/com/skyflow/generated/auth/rest/types/GooglerpcStatus.java index d0290573..06a9373c 100644 --- a/common/src/main/java/com/skyflow/generated/rest/types/GooglerpcStatus.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/types/GooglerpcStatus.java @@ -1,7 +1,7 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest.types; +package com.skyflow.generated.auth.rest.types; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; @@ -11,7 +11,7 @@ import com.fasterxml.jackson.annotation.JsonSetter; import com.fasterxml.jackson.annotation.Nulls; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.skyflow.generated.rest.core.ObjectMappers; +import com.skyflow.generated.auth.rest.core.ObjectMappers; import java.util.HashMap; import java.util.List; import java.util.Map; diff --git a/common/src/main/java/com/skyflow/generated/rest/types/ProtobufAny.java b/common/src/main/java/com/skyflow/generated/auth/rest/types/ProtobufAny.java similarity index 96% rename from common/src/main/java/com/skyflow/generated/rest/types/ProtobufAny.java rename to common/src/main/java/com/skyflow/generated/auth/rest/types/ProtobufAny.java index 37555aae..6f5df772 100644 --- a/common/src/main/java/com/skyflow/generated/rest/types/ProtobufAny.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/types/ProtobufAny.java @@ -1,7 +1,7 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest.types; +package com.skyflow.generated.auth.rest.types; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; @@ -11,7 +11,7 @@ import com.fasterxml.jackson.annotation.JsonSetter; import com.fasterxml.jackson.annotation.Nulls; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.skyflow.generated.rest.core.ObjectMappers; +import com.skyflow.generated.auth.rest.core.ObjectMappers; import java.util.HashMap; import java.util.Map; import java.util.Objects; diff --git a/common/src/main/java/com/skyflow/generated/rest/types/V1GetAuthTokenResponse.java b/common/src/main/java/com/skyflow/generated/auth/rest/types/V1GetAuthTokenResponse.java similarity index 97% rename from common/src/main/java/com/skyflow/generated/rest/types/V1GetAuthTokenResponse.java rename to common/src/main/java/com/skyflow/generated/auth/rest/types/V1GetAuthTokenResponse.java index 9b6be70b..3c10fbd3 100644 --- a/common/src/main/java/com/skyflow/generated/rest/types/V1GetAuthTokenResponse.java +++ b/common/src/main/java/com/skyflow/generated/auth/rest/types/V1GetAuthTokenResponse.java @@ -1,7 +1,7 @@ /** * This file was auto-generated by Fern from our API Definition. */ -package com.skyflow.generated.rest.types; +package com.skyflow.generated.auth.rest.types; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; @@ -11,7 +11,7 @@ import com.fasterxml.jackson.annotation.JsonSetter; import com.fasterxml.jackson.annotation.Nulls; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.skyflow.generated.rest.core.ObjectMappers; +import com.skyflow.generated.auth.rest.core.ObjectMappers; import java.util.HashMap; import java.util.Map; import java.util.Objects; diff --git a/common/src/main/java/com/skyflow/logs/ErrorLogs.java b/common/src/main/java/com/skyflow/logs/ErrorLogs.java index 3415860c..8f1156fd 100644 --- a/common/src/main/java/com/skyflow/logs/ErrorLogs.java +++ b/common/src/main/java/com/skyflow/logs/ErrorLogs.java @@ -66,6 +66,15 @@ public enum ErrorLogs { EMPTY_OR_NULL_TOKEN_IN_DETOKENIZE_DATA("Invalid %s1 request. Token can not be null or empty in detokenize data at index %s2."), REDACTION_IS_REQUIRED("Invalid %s1 request. Redaction is required."), DETOKENIZE_REQUEST_REJECTED("Detokenize request resulted in failure."), + DETOKENIZE_REQUEST_NULL("Invalid %s1 request. Detokenize request can not be null."), + + NULL_TOKEN_REDACTION_GROUP_OBJECT("Invalid %s1 request. Token Redaction group object can not be null or empty."), + + NULL_REDACTION_IN_TOKEN_GROUP("Invalid %s1 request. Redaction can not be null in token redaction group"), + + NULL_TOKEN_GROUP_NAME_IN_TOKEN_GROUP("Invalid %s1 request. Token group name can not be null in token redaction group"), + + EMPTY_OR_NULL_REDACTION_IN_TOKEN_GROUP("Invalid %s1 request. Redaction can not be null or empty in token redaction group"), IDS_IS_REQUIRED("Invalid %s1 request. Ids are required."), EMPTY_IDS("Invalid %s1 request. Ids can not be empty."), EMPTY_OR_NULL_ID_IN_IDS("Invalid %s1 request. Id can not be null or empty in ids at index %s2."), @@ -126,7 +135,10 @@ public enum ErrorLogs { OUTPUT_DIRECTORY_NOT_FOUND("Invalid %s1 request. The output directory does not exist. Please specify a valid output directory."), INVALID_PERMISSIONS_FOR_OUTPUT_DIRECTORY("Invalid %s1 request. The output directory is not writable. Please check the permissions or specify a valid output directory."), EMPTY_FILE_AND_FILE_PATH_IN_DEIDENTIFY_FILE("Invalid %s1 request. The file and file path fields are both empty. Specify a valid file object or file path."), - ; + + UNEXPECTED_ERROR_DURING_BATCH_PROCESSING("Unexpected error occurred during batch processing. Error: %s1"), + + PROCESSING_ERROR_RESPONSE("Processing error response."); private final String log; diff --git a/common/src/main/java/com/skyflow/logs/InfoLogs.java b/common/src/main/java/com/skyflow/logs/InfoLogs.java index efd81a49..9727e811 100644 --- a/common/src/main/java/com/skyflow/logs/InfoLogs.java +++ b/common/src/main/java/com/skyflow/logs/InfoLogs.java @@ -20,7 +20,8 @@ public enum InfoLogs { GET_SIGNED_DATA_TOKENS_TRIGGERED("getSignedDataTokens method triggered."), GET_SIGNED_DATA_TOKEN_SUCCESS("Signed data tokens generated."), REUSE_BEARER_TOKEN("Reusing bearer token."), - REUSE_API_KEY("Reusing api key."), + USE_CLIENT_PROVIDED_BEARER_TOKEN("Using bearer token provided by client."), + USE_API_KEY("Using api key."), GENERATE_BEARER_TOKEN_FROM_CREDENTIALS_TRIGGERED("generateBearerTokenFromCredentials method triggered."), GENERATE_BEARER_TOKEN_FROM_CREDENTIALS_STRING_TRIGGERED("generateBearerTokenFromCredentialString method triggered."), GENERATE_SIGNED_TOKENS_FROM_CREDENTIALS_FILE_TRIGGERED("generateSignedTokensFromCredentialsFile method triggered."), @@ -90,6 +91,8 @@ public enum InfoLogs { GET_DETECT_RUN_TRIGGERED("Get detect run method triggered."), VALIDATE_GET_DETECT_RUN_REQUEST("Validating get detect run request."), REIDENTIFY_TEXT_SUCCESS("Text data re-identified."), + + PROCESSING_BATCHES("Processing batch"), ; diff --git a/common/src/main/java/com/skyflow/logs/WarningLogs.java b/common/src/main/java/com/skyflow/logs/WarningLogs.java index 8d49f056..5f80a728 100644 --- a/common/src/main/java/com/skyflow/logs/WarningLogs.java +++ b/common/src/main/java/com/skyflow/logs/WarningLogs.java @@ -1,7 +1,11 @@ package com.skyflow.logs; public enum WarningLogs { - OVERRIDING_EXISTING_VAULT_CONFIG("New vault config identified. Overriding existing vault config"); + INVALID_BATCH_SIZE_PROVIDED("Invalid value for batch size provided, switching to default value."), + INVALID_CONCURRENCY_LIMIT_PROVIDED("Invalid value for concurrency limit provided, switching to default value."), + BATCH_SIZE_EXCEEDS_MAX_LIMIT("Provided batch size exceeds the maximum limit, switching to max limit."), + CONCURRENCY_EXCEEDS_MAX_LIMIT("Provided concurrency limit exceeds the maximum limit, switching to max limit.") + ; private final String log; diff --git a/common/src/main/java/com/skyflow/serviceaccount/util/BearerToken.java b/common/src/main/java/com/skyflow/serviceaccount/util/BearerToken.java index f2c15a6f..9f0fc0e3 100644 --- a/common/src/main/java/com/skyflow/serviceaccount/util/BearerToken.java +++ b/common/src/main/java/com/skyflow/serviceaccount/util/BearerToken.java @@ -4,12 +4,12 @@ import com.skyflow.errors.ErrorCode; import com.skyflow.errors.ErrorMessage; import com.skyflow.errors.SkyflowException; -import com.skyflow.generated.rest.ApiClient; -import com.skyflow.generated.rest.ApiClientBuilder; -import com.skyflow.generated.rest.core.ApiClientApiException; -import com.skyflow.generated.rest.resources.authentication.AuthenticationClient; -import com.skyflow.generated.rest.resources.authentication.requests.V1GetAuthTokenRequest; -import com.skyflow.generated.rest.types.V1GetAuthTokenResponse; +import com.skyflow.generated.auth.rest.ApiClient; +import com.skyflow.generated.auth.rest.ApiClientBuilder; +import com.skyflow.generated.auth.rest.core.ApiClientApiException; +import com.skyflow.generated.auth.rest.resources.authentication.AuthenticationClient; +import com.skyflow.generated.auth.rest.resources.authentication.requests.V1GetAuthTokenRequest; +import com.skyflow.generated.auth.rest.types.V1GetAuthTokenResponse; import com.skyflow.logs.ErrorLogs; import com.skyflow.logs.InfoLogs; import com.skyflow.utils.BaseConstants; diff --git a/common/src/main/java/com/skyflow/utils/BaseConstants.java b/common/src/main/java/com/skyflow/utils/BaseConstants.java index f38be8e8..0880034f 100644 --- a/common/src/main/java/com/skyflow/utils/BaseConstants.java +++ b/common/src/main/java/com/skyflow/utils/BaseConstants.java @@ -7,10 +7,13 @@ public class BaseConstants { public static final String ORDER_ASCENDING = "ASCENDING"; public static final String ENV_CREDENTIALS_KEY_NAME = "SKYFLOW_CREDENTIALS"; public static final String SECURE_PROTOCOL = "https://"; - public static final String DEV_DOMAIN = ".vault.skyflowapis.dev"; - public static final String STAGE_DOMAIN = ".vault.skyflowapis.tech"; - public static final String SANDBOX_DOMAIN = ".vault.skyflowapis-preview.com"; - public static final String PROD_DOMAIN = ".vault.skyflowapis.com"; + + public static final String V2_VAULT_DOMAIN = ".vault."; + public static final String V3_VAULT_DOMAIN = ".skyvault."; + public static final String DEV_DOMAIN = "skyflowapis.dev"; + public static final String STAGE_DOMAIN = "skyflowapis.tech"; + public static final String SANDBOX_DOMAIN = "skyflowapis-preview.com"; + public static final String PROD_DOMAIN = "skyflowapis.com"; public static final String PKCS8_PRIVATE_HEADER = "-----BEGIN PRIVATE KEY-----"; public static final String PKCS8_PRIVATE_FOOTER = "-----END PRIVATE KEY-----"; public static final String GRANT_TYPE = "urn:ietf:params:oauth:grant-type:jwt-bearer"; diff --git a/common/src/main/java/com/skyflow/utils/BaseUtils.java b/common/src/main/java/com/skyflow/utils/BaseUtils.java index b51aaaf3..b7cf6bb0 100644 --- a/common/src/main/java/com/skyflow/utils/BaseUtils.java +++ b/common/src/main/java/com/skyflow/utils/BaseUtils.java @@ -9,6 +9,7 @@ import com.skyflow.logs.ErrorLogs; import com.skyflow.logs.InfoLogs; import com.skyflow.serviceaccount.util.BearerToken; +import com.skyflow.serviceaccount.util.Token; import com.skyflow.utils.logger.LogUtil; import org.apache.commons.codec.binary.Base64; @@ -22,9 +23,8 @@ import java.security.spec.PKCS8EncodedKeySpec; public class BaseUtils { - public static String getVaultURL(String clusterId, Env env) { - StringBuilder sb = new StringBuilder(BaseConstants.SECURE_PROTOCOL); - sb.append(clusterId); + public static String getVaultURL(String clusterId, Env env, String vaultDomain) { + StringBuilder sb = buildBaseUrl(clusterId, vaultDomain); switch (env) { case DEV: sb.append(BaseConstants.DEV_DOMAIN); @@ -44,23 +44,31 @@ public static String getVaultURL(String clusterId, Env env) { } public static String generateBearerToken(Credentials credentials) throws SkyflowException { + String bearerToken; if (credentials.getPath() != null) { - return BearerToken.builder() + bearerToken = BearerToken.builder() .setCredentials(new File(credentials.getPath())) .setRoles(credentials.getRoles()) .setCtx(credentials.getContext()) .build() .getBearerToken(); } else if (credentials.getCredentialsString() != null) { - return BearerToken.builder() + bearerToken = BearerToken.builder() .setCredentials(credentials.getCredentialsString()) .setRoles(credentials.getRoles()) .setCtx(credentials.getContext()) .build() .getBearerToken(); } else { - return credentials.getToken(); + LogUtil.printInfoLog(InfoLogs.USE_CLIENT_PROVIDED_BEARER_TOKEN.getLog()); + bearerToken = credentials.getToken(); + } + // check expiry for generated token + if (Token.isExpired(bearerToken)) { + LogUtil.printErrorLog(ErrorLogs.INVALID_BEARER_TOKEN.getLog()); + throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.BearerTokenExpired.getMessage()); } + return bearerToken; } public static PrivateKey getPrivateKeyFromPem(String pemKey) throws SkyflowException { @@ -160,4 +168,10 @@ private static PrivateKey parsePkcs8PrivateKey(byte[] pkcs8Bytes) throws Skyflow return privateKey; } + private static StringBuilder buildBaseUrl(String clusterId, String vaultDomain) { + StringBuilder sb = new StringBuilder(BaseConstants.SECURE_PROTOCOL); + sb.append(clusterId); + sb.append(vaultDomain); + return sb; + } } diff --git a/common/src/main/java/com/skyflow/vault/data/BaseGetRequest.java b/common/src/main/java/com/skyflow/vault/data/BaseGetRequest.java deleted file mode 100644 index c6d828cc..00000000 --- a/common/src/main/java/com/skyflow/vault/data/BaseGetRequest.java +++ /dev/null @@ -1,122 +0,0 @@ -package com.skyflow.vault.data; - -import com.skyflow.utils.BaseConstants; - -import java.util.ArrayList; - -class BaseGetRequest { - private final BaseGetRequestBuilder builder; - - protected BaseGetRequest(BaseGetRequestBuilder builder) { - this.builder = builder; - } - - public String getTable() { - return this.builder.table; - } - - public ArrayList getIds() { - return this.builder.ids; - } - - public Boolean getReturnTokens() { - return this.builder.returnTokens; - } - - public ArrayList getFields() { - return this.builder.fields; - } - - public String getOffset() { - return this.builder.offset; - } - - public String getLimit() { - return this.builder.limit; - } - - public Boolean getDownloadURL() { - return this.builder.downloadURL; - } - - public String getColumnName() { - return this.builder.columnName; - } - - public ArrayList getColumnValues() { - return this.builder.columnValues; - } - - public String getOrderBy() { - return this.builder.orderBy; - } - - static class BaseGetRequestBuilder { - protected String table; - protected ArrayList ids; - protected Boolean returnTokens; - protected ArrayList fields; - protected String offset; - protected String limit; - protected Boolean downloadURL; - protected String columnName; - protected ArrayList columnValues; - protected String orderBy; - - protected BaseGetRequestBuilder() { - this.downloadURL = true; - this.orderBy = BaseConstants.ORDER_ASCENDING; - } - - public BaseGetRequestBuilder table(String table) { - this.table = table; - return this; - } - - public BaseGetRequestBuilder ids(ArrayList ids) { - this.ids = ids; - return this; - } - - public BaseGetRequestBuilder returnTokens(Boolean returnTokens) { - this.returnTokens = returnTokens; - return this; - } - - public BaseGetRequestBuilder fields(ArrayList fields) { - this.fields = fields; - return this; - } - - public BaseGetRequestBuilder offset(String offset) { - this.offset = offset; - return this; - } - - public BaseGetRequestBuilder limit(String limit) { - this.limit = limit; - return this; - } - - public BaseGetRequestBuilder downloadURL(Boolean downloadURL) { - this.downloadURL = downloadURL == null || downloadURL; - return this; - } - - public BaseGetRequestBuilder columnName(String columnName) { - this.columnName = columnName; - return this; - } - - public BaseGetRequestBuilder columnValues(ArrayList columnValues) { - this.columnValues = columnValues; - return this; - } - - public BaseGetRequestBuilder orderBy(String orderBy) { - this.orderBy = orderBy == null ? BaseConstants.ORDER_ASCENDING : orderBy; - return this; - } - - } -} diff --git a/common/src/main/java/com/skyflow/vault/data/BaseGetResponse.java b/common/src/main/java/com/skyflow/vault/data/BaseGetResponse.java deleted file mode 100644 index 7a985fe6..00000000 --- a/common/src/main/java/com/skyflow/vault/data/BaseGetResponse.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.skyflow.vault.data; - -import com.google.gson.Gson; - -import java.util.ArrayList; -import java.util.HashMap; - -public class BaseGetResponse { - private final ArrayList> data; - private final ArrayList> errors; - - public BaseGetResponse(ArrayList> data, ArrayList> errors) { - this.data = data; - this.errors = errors; - } - - public ArrayList> getData() { - return data; - } - - public ArrayList> getErrors() { - return errors; - } - - @Override - public String toString() { - Gson gson = new Gson(); - return gson.toJson(this); - } -} diff --git a/common/src/main/java/com/skyflow/vault/data/BaseInsertRequest.java b/common/src/main/java/com/skyflow/vault/data/BaseInsertRequest.java index 64e61153..b856492d 100644 --- a/common/src/main/java/com/skyflow/vault/data/BaseInsertRequest.java +++ b/common/src/main/java/com/skyflow/vault/data/BaseInsertRequest.java @@ -18,27 +18,12 @@ public ArrayList> getValues() { return this.builder.values; } - public ArrayList> getTokens() { - return this.builder.tokens; - } - - public Boolean getReturnTokens() { - return this.builder.returnTokens; - } - - public String getUpsert() { - return this.builder.upsert; - } - static class BaseInsertRequestBuilder { protected String table; protected ArrayList> values; - protected ArrayList> tokens; - protected Boolean returnTokens; protected String upsert; protected BaseInsertRequestBuilder() { - this.returnTokens = false; } public BaseInsertRequestBuilder table(String table) { @@ -51,20 +36,6 @@ public BaseInsertRequestBuilder values(ArrayList> values return this; } - public BaseInsertRequestBuilder tokens(ArrayList> tokens) { - this.tokens = tokens; - return this; - } - - public BaseInsertRequestBuilder returnTokens(Boolean returnTokens) { - this.returnTokens = returnTokens != null && returnTokens; - return this; - } - - public BaseInsertRequestBuilder upsert(String upsert) { - this.upsert = upsert; - return this; - } } } diff --git a/common/src/main/java/com/skyflow/vault/data/BaseInsertResponse.java b/common/src/main/java/com/skyflow/vault/data/BaseInsertResponse.java deleted file mode 100644 index b3eead69..00000000 --- a/common/src/main/java/com/skyflow/vault/data/BaseInsertResponse.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.skyflow.vault.data; - -import com.google.gson.Gson; - -import java.util.ArrayList; -import java.util.HashMap; - -public class BaseInsertResponse { - private final ArrayList> insertedFields; - private final ArrayList> errors; - - public BaseInsertResponse(ArrayList> insertedFields, ArrayList> errors) { - this.insertedFields = insertedFields; - this.errors = errors; - } - - public ArrayList> getInsertedFields() { - return insertedFields; - } - - public ArrayList> getErrors() { - return errors; - } - - @Override - public String toString() { - Gson gson = new Gson(); - return gson.toJson(this); - } -} diff --git a/common/src/test/java/com/skyflow/config/CredentialsTests.java b/common/test/java/com/skyflow/config/CredentialsTests.java similarity index 100% rename from common/src/test/java/com/skyflow/config/CredentialsTests.java rename to common/test/java/com/skyflow/config/CredentialsTests.java diff --git a/common/src/test/java/com/skyflow/config/VaultConfigTests.java b/common/test/java/com/skyflow/config/VaultConfigTests.java similarity index 100% rename from common/src/test/java/com/skyflow/config/VaultConfigTests.java rename to common/test/java/com/skyflow/config/VaultConfigTests.java diff --git a/common/src/test/java/com/skyflow/errors/SkyflowExceptionTest.java b/common/test/java/com/skyflow/errors/SkyflowExceptionTest.java similarity index 100% rename from common/src/test/java/com/skyflow/errors/SkyflowExceptionTest.java rename to common/test/java/com/skyflow/errors/SkyflowExceptionTest.java diff --git a/common/src/test/java/com/skyflow/serviceaccount/util/BearerTokenTests.java b/common/test/java/com/skyflow/serviceaccount/util/BearerTokenTests.java similarity index 94% rename from common/src/test/java/com/skyflow/serviceaccount/util/BearerTokenTests.java rename to common/test/java/com/skyflow/serviceaccount/util/BearerTokenTests.java index 3e8a7696..cf5bbcd5 100644 --- a/common/src/test/java/com/skyflow/serviceaccount/util/BearerTokenTests.java +++ b/common/test/java/com/skyflow/serviceaccount/util/BearerTokenTests.java @@ -25,7 +25,7 @@ public class BearerTokenTests { @BeforeClass public static void setup() { credentialsFilePath = "./credentials.json"; - invalidJsonFilePath = "./src/test/resources/notJson.txt"; + invalidJsonFilePath = "./test/resources/notJson.txt"; invalidFilePath = "./src/test/credentials.json"; credentialsString = "{\"key\":\"value\"}"; context = "test_context"; @@ -128,7 +128,7 @@ public void testInvalidCredentialsString() { @Test public void testNoPrivateKeyInCredentialsForCredentials() { - String filePath = "./src/test/resources/noPrivateKeyCredentials.json"; + String filePath = "./test/resources/noPrivateKeyCredentials.json"; File file = new File(filePath); try { BearerToken bearerToken = BearerToken.builder().setCredentials(file).build(); @@ -142,7 +142,7 @@ public void testNoPrivateKeyInCredentialsForCredentials() { @Test public void testNoClientIDInCredentialsForCredentials() { - String filePath = "./src/test/resources/noClientIDCredentials.json"; + String filePath = "./test/resources/noClientIDCredentials.json"; File file = new File(filePath); try { BearerToken bearerToken = BearerToken.builder().setCredentials(file).build(); @@ -156,7 +156,7 @@ public void testNoClientIDInCredentialsForCredentials() { @Test public void testNoKeyIDInCredentialsForCredentials() { - String filePath = "./src/test/resources/noKeyIDCredentials.json"; + String filePath = "./test/resources/noKeyIDCredentials.json"; File file = new File(filePath); try { BearerToken bearerToken = BearerToken.builder().setCredentials(file).build(); @@ -170,7 +170,7 @@ public void testNoKeyIDInCredentialsForCredentials() { @Test public void testNoTokenURIInCredentialsForCredentials() { - String filePath = "./src/test/resources/noTokenURICredentials.json"; + String filePath = "./test/resources/noTokenURICredentials.json"; File file = new File(filePath); try { BearerToken bearerToken = BearerToken.builder().setCredentials(file).build(); @@ -184,7 +184,7 @@ public void testNoTokenURIInCredentialsForCredentials() { @Test public void testInvalidPrivateKeyInCredentialsForCredentials() { - String filePath = "./src/test/resources/invalidPrivateKeyCredentials.json"; + String filePath = "./test/resources/invalidPrivateKeyCredentials.json"; File file = new File(filePath); try { BearerToken bearerToken = BearerToken.builder().setCredentials(file).build(); @@ -211,7 +211,7 @@ public void testInvalidKeySpecInCredentialsForCredentials() { @Test public void testInvalidTokenURIInCredentialsForCredentials() throws SkyflowException { - String filePath = "./src/test/resources/invalidTokenURICredentials.json"; + String filePath = "./test/resources/invalidTokenURICredentials.json"; File file = new File(filePath); try { BearerToken bearerToken = BearerToken.builder().setCredentials(file).build(); diff --git a/common/src/test/java/com/skyflow/serviceaccount/util/SignedDataTokensTests.java b/common/test/java/com/skyflow/serviceaccount/util/SignedDataTokensTests.java similarity index 95% rename from common/src/test/java/com/skyflow/serviceaccount/util/SignedDataTokensTests.java rename to common/test/java/com/skyflow/serviceaccount/util/SignedDataTokensTests.java index bd46cc9f..dcda716e 100644 --- a/common/src/test/java/com/skyflow/serviceaccount/util/SignedDataTokensTests.java +++ b/common/test/java/com/skyflow/serviceaccount/util/SignedDataTokensTests.java @@ -26,7 +26,7 @@ public class SignedDataTokensTests { @BeforeClass public static void setup() { credentialsFilePath = "./credentials.json"; - invalidJsonFilePath = "./src/test/resources/notJson.txt"; + invalidJsonFilePath = "./test/resources/notJson.txt"; invalidFilePath = "./src/test/credentials.json"; credentialsString = "{\"key\":\"value\"}"; context = "test_context"; @@ -138,7 +138,7 @@ public void testInvalidCredentialsString() { @Test public void testNoPrivateKeyInCredentials() { - String filePath = "./src/test/resources/noPrivateKeyCredentials.json"; + String filePath = "./test/resources/noPrivateKeyCredentials.json"; File file = new File(filePath); try { SignedDataTokens signedTokens = SignedDataTokens.builder().setCredentials(file).build(); @@ -152,7 +152,7 @@ public void testNoPrivateKeyInCredentials() { @Test public void testNoClientIDInCredentials() { - String filePath = "./src/test/resources/noClientIDCredentials.json"; + String filePath = "./test/resources/noClientIDCredentials.json"; File file = new File(filePath); try { SignedDataTokens signedTokens = SignedDataTokens.builder().setCredentials(file).build(); @@ -166,7 +166,7 @@ public void testNoClientIDInCredentials() { @Test public void testNoKeyIDInCredentials() { - String filePath = "./src/test/resources/noKeyIDCredentials.json"; + String filePath = "./test/resources/noKeyIDCredentials.json"; File file = new File(filePath); try { SignedDataTokens signedTokens = SignedDataTokens.builder().setCredentials(file).build(); @@ -180,7 +180,7 @@ public void testNoKeyIDInCredentials() { @Test public void testInvalidPrivateKeyInCredentials() { - String filePath = "./src/test/resources/invalidPrivateKeyCredentials.json"; + String filePath = "./test/resources/invalidPrivateKeyCredentials.json"; File file = new File(filePath); try { SignedDataTokens signedTokens = SignedDataTokens.builder().setCredentials(file).build(); diff --git a/common/src/test/java/com/skyflow/serviceaccount/util/TokenTests.java b/common/test/java/com/skyflow/serviceaccount/util/TokenTests.java similarity index 100% rename from common/src/test/java/com/skyflow/serviceaccount/util/TokenTests.java rename to common/test/java/com/skyflow/serviceaccount/util/TokenTests.java diff --git a/common/src/test/java/com/skyflow/utils/BaseUtilsTests.java b/common/test/java/com/skyflow/utils/BaseUtilsTests.java similarity index 100% rename from common/src/test/java/com/skyflow/utils/BaseUtilsTests.java rename to common/test/java/com/skyflow/utils/BaseUtilsTests.java diff --git a/common/src/test/resources/invalidPrivateKeyCredentials.json b/common/test/resources/invalidPrivateKeyCredentials.json similarity index 100% rename from common/src/test/resources/invalidPrivateKeyCredentials.json rename to common/test/resources/invalidPrivateKeyCredentials.json diff --git a/common/src/test/resources/invalidTokenURICredentials.json b/common/test/resources/invalidTokenURICredentials.json similarity index 100% rename from common/src/test/resources/invalidTokenURICredentials.json rename to common/test/resources/invalidTokenURICredentials.json diff --git a/common/src/test/resources/noClientIDCredentials.json b/common/test/resources/noClientIDCredentials.json similarity index 100% rename from common/src/test/resources/noClientIDCredentials.json rename to common/test/resources/noClientIDCredentials.json diff --git a/common/src/test/resources/noKeyIDCredentials.json b/common/test/resources/noKeyIDCredentials.json similarity index 100% rename from common/src/test/resources/noKeyIDCredentials.json rename to common/test/resources/noKeyIDCredentials.json diff --git a/common/src/test/resources/noPrivateKeyCredentials.json b/common/test/resources/noPrivateKeyCredentials.json similarity index 100% rename from common/src/test/resources/noPrivateKeyCredentials.json rename to common/test/resources/noPrivateKeyCredentials.json diff --git a/common/src/test/resources/noTokenURICredentials.json b/common/test/resources/noTokenURICredentials.json similarity index 100% rename from common/src/test/resources/noTokenURICredentials.json rename to common/test/resources/noTokenURICredentials.json diff --git a/common/src/test/resources/notJson.txt b/common/test/resources/notJson.txt similarity index 100% rename from common/src/test/resources/notJson.txt rename to common/test/resources/notJson.txt diff --git a/pom.xml b/pom.xml index f36b6778..e94e5f2e 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.skyflow - skyflow-java + skyflow 1.0.0 pom @@ -37,6 +37,7 @@ + true 8 8 4.12.0 @@ -169,7 +170,8 @@ 3.2.0 - com.skyflow.generated.rest.* + com.skyflow.generated.rest.*: + com.skyflow.generated.auth.*: @@ -178,6 +180,7 @@ jar + @@ -256,50 +259,4 @@ https://repo.maven.apache.org/maven2/ - - - - maven-central - - - central - https://central.sonatype.com/api/v1/publisher/upload - - - central-snapshots - https://central.sonatype.com/api/v1/publisher/upload - - - - - - org.sonatype.central - central-publishing-maven-plugin - 0.4.0 - true - - central - true - true - - - - - - - jfrog - - - central - prekarilabs.jfrog.io-releases - https://prekarilabs.jfrog.io/artifactory/skyflow-java - - - snapshots - prekarilabs.jfrog.io-snapshots - https://prekarilabs.jfrog.io/artifactory/skyflow-java - - - - - + \ No newline at end of file diff --git a/samples/pom.xml b/samples/pom.xml index c48ba302..96f921ee 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -18,7 +18,7 @@ com.skyflow skyflow-java - 1.15.0 + 3.0.0-beta.3 diff --git a/samples/src/main/java/com/example/connection/InvokeConnectionExample.java b/samples/src/main/java/com/example/connection/InvokeConnectionExample.java deleted file mode 100644 index b2e80924..00000000 --- a/samples/src/main/java/com/example/connection/InvokeConnectionExample.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.example.connection; - -import com.skyflow.Skyflow; -import com.skyflow.config.ConnectionConfig; -import com.skyflow.config.Credentials; -import com.skyflow.enums.LogLevel; -import com.skyflow.enums.RequestMethod; -import com.skyflow.errors.SkyflowException; -import com.skyflow.vault.connection.InvokeConnectionRequest; -import com.skyflow.vault.connection.InvokeConnectionResponse; - -import java.util.HashMap; -import java.util.Map; - -/** - * This example demonstrates how to use the Skyflow SDK to invoke API connections. - * It includes: - * 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 API authentication - Credentials credentials = new Credentials(); - credentials.setApiKey(""); // Replace with the actual API key - - // 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 - 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.setCredentialsString(""); // Replace with the credentials string - - // Step 5: Create a Skyflow client with connection configurations - Skyflow skyflowClient = Skyflow.builder() - .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 request body and headers - Map requestBody = new HashMap<>(); - 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 actual header name and value - requestHeaders.put("", ""); // Replace with another header name and value - - // Build and send the POST request - InvokeConnectionRequest invokeConnectionRequest1 = InvokeConnectionRequest.builder() - .method(RequestMethod.POST) // HTTP method set to POST - .requestBody(requestBody) // Include request body - .requestHeaders(requestHeaders) // Include request headers - .build(); - - InvokeConnectionResponse invokeConnectionResponse1 = skyflowClient.connection().invoke(invokeConnectionRequest1); - System.out.println("Invoke Connection Response (POST): " + invokeConnectionResponse1); - } catch (SkyflowException e) { - System.out.println("Error while invoking connection (POST):" + e); - } - - // Example 2: Sending a GET request to the second connection - try { - // Set up path and query parameters - Map pathParams = new HashMap<>(); - pathParams.put("", ""); // Replace with actual path parameter - pathParams.put("", ""); // Replace with another path parameter - - Map queryParams = new HashMap<>(); - queryParams.put("", ""); // Replace with actual query parameter - queryParams.put("", ""); // Replace with another query parameter - - // Build and send the GET request - InvokeConnectionRequest invokeConnectionRequest2 = InvokeConnectionRequest.builder() - .method(RequestMethod.GET) // HTTP method set to GET - .pathParams(pathParams) // Include path parameters - .queryParams(queryParams) // Include query parameters - .build(); - - InvokeConnectionResponse invokeConnectionResponse2 = skyflowClient - .connection("").invoke(invokeConnectionRequest2); - System.out.println("Invoke Connection Response (GET): " + invokeConnectionResponse2); - } catch (SkyflowException e) { - System.out.println("Error while invoking connection (GET):" + e); - } - } -} diff --git a/samples/src/main/java/com/example/detect/DeidentifyFileExample.java b/samples/src/main/java/com/example/detect/DeidentifyFileExample.java deleted file mode 100644 index 7f573d33..00000000 --- a/samples/src/main/java/com/example/detect/DeidentifyFileExample.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.example.detect; - -import java.io.File; - -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.enums.MaskingMethod; -import com.skyflow.errors.SkyflowException; -import com.skyflow.vault.detect.DeidentifyFileRequest; -import com.skyflow.vault.detect.DeidentifyFileResponse; -import com.skyflow.vault.detect.FileInput; - -/** - * Skyflow Deidentify File Example - *

- * This example demonstrates how to use the Skyflow SDK to deidentify file - * It has all available options for deidentifying files. - * Supported file types: images (jpg, png, etc.), pdf, audio (mp3, wav), documents, spreadsheets, presentations, structured text. - * It includes: - * 1. Configure credentials - * 2. Set up vault configuration - * 3. Create a deidentify file request with all options - * 4. Call deidentifyFile to deidentify file. - * 5. Handle response and errors - */ -public class DeidentifyFileExample { - - 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 vault config - 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: Create a Skyflow client - Skyflow skyflowClient = Skyflow.builder() - .setLogLevel(LogLevel.DEBUG) // Enable debugging for detailed logs - .addVaultConfig(vaultConfig) // Add the vault configuration - .build(); - - try { - - // Step 4: Create a deidentify file request with all options - - // Create file object - File file = new File("") // Alternatively, you can use .filePath() - .build(); - - // Output configuration - String outputDirectory = ""; // Replace with the desired output directory to save the deidentified file - - // Entities to detect - // List detectEntities = new ArrayList<>(); - // detectEntities.add(DetectEntities.IP_ADDRESS); // Replace with the entities you want to detect - - // Image-specific options - // Boolean outputProcessedImage = true; // Include processed image in output - // Boolean outputOcrText = true; // Include OCR text in output - MaskingMethod maskingMethod = MaskingMethod.BLACKBOX; // Masking method for images - - // PDF-specific options - // Integer pixelDensity = 15; // Pixel density for PDF processing - // Integer maxResolution = 2000; // Max resolution for PDF - - // Audio-specific options - // Boolean outputProcessedAudio = true; // Include processed audio - // DetectOutputTranscriptions outputTanscription = DetectOutputTranscriptions.PLAINTEXT_TRANSCRIPTION; // Transcription type - - // Audio bleep configuration - // AudioBleep audioBleep = AudioBleep.builder() - // .frequency(5D) // Pitch in Hz - // .startPadding(7D) // Padding at start (seconds) - // .stopPadding(8D) // Padding at end (seconds) - // .build(); - - Integer waitTime = 20; // Max wait time for response (max 64 seconds) - - DeidentifyFileRequest deidentifyFileRequest = DeidentifyFileRequest.builder() - .file(fileInput) - .waitTime(waitTime) - // .entities(detectEntities) - .outputDirectory(outputDirectory) - .maskingMethod(maskingMethod) - // .outputProcessedImage(outputProcessedImage) - // .outputOcrText(outputOcrText) - // .pixelDensity(pixelDensity) - // .maxResolution(maxResolution) - // .outputProcessedAudio(outputProcessedAudio) - // .outputTranscription(outputTanscription) - // .bleep(audioBleep) - .build(); - - - DeidentifyFileResponse deidentifyFileResponse = skyflowClient.detect(vaultConfig.getVaultId()).deidentifyFile(deidentifyFileRequest); - System.out.println("Deidentify file response: " + deidentifyFileResponse.toString()); - } catch (SkyflowException e) { - System.err.println("Error occurred during deidentify file: "); - e.printStackTrace(); - } - } -} \ No newline at end of file diff --git a/samples/src/main/java/com/example/detect/DeidentifyTextExample.java b/samples/src/main/java/com/example/detect/DeidentifyTextExample.java deleted file mode 100644 index 837dde00..00000000 --- a/samples/src/main/java/com/example/detect/DeidentifyTextExample.java +++ /dev/null @@ -1,142 +0,0 @@ -package com.example.detect; - -import java.util.ArrayList; -import java.util.List; - -import com.skyflow.Skyflow; -import com.skyflow.config.Credentials; -import com.skyflow.config.VaultConfig; -import com.skyflow.enums.DetectEntities; -import com.skyflow.enums.Env; -import com.skyflow.enums.LogLevel; -import com.skyflow.errors.SkyflowException; -import com.skyflow.vault.detect.DeidentifyTextRequest; -import com.skyflow.vault.detect.DeidentifyTextResponse; -import com.skyflow.vault.detect.TokenFormat; - -/** - * Skyflow Deidentify Text Example - *

- * This example demonstrates how to use the Skyflow SDK to deidentify text data - * across multiple vaults. It includes: - * 1. Setting up credentials and vault configurations. - * 2. Creating a Skyflow client with multiple vaults. - * 3. Performing deidentify of text with various options. - * 4. Handling responses and errors. - */ - -public class DeidentifyTextExample { - 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(); - - // Step 6: Configuring the different options for deidentify - // Replace with the entity you want to detect - List detectEntitiesList = new ArrayList<>(); - detectEntitiesList.add(DetectEntities.SSN); - detectEntitiesList.add(DetectEntities.CREDIT_CARD); - - // Replace with the entity you want to detect with vault token - List vaultTokenList = new ArrayList<>(); - vaultTokenList.add(DetectEntities.SSN); - vaultTokenList.add(DetectEntities.CREDIT_CARD); - - // Replace with the entity you want to detect with entity only - // List entityOnlyList = new ArrayList<>(); - // entityOnlyList.add(DetectEntities.SSN); - - // Replace with the entity you want to detect with entity unique counter - // List entityUniqueCounterList = new ArrayList<>(); - // entityUniqueCounterList.add(DetectEntities.SSN); - - // Replace with the regex patterns you want to allow during deidentification - // List allowRegexList = new ArrayList<>(); - // allowRegexList.add(""); - - // Replace with the regex patterns you want to restrict during deidentification - // List restrictRegexList = new ArrayList<>(); - // restrictRegexList.add("YOUR_RESTRICT_REGEX_LIST"); - - // Configure Token Format - TokenFormat tokenFormat = TokenFormat.builder() - .vaultToken(vaultTokenList) - // .entityOnly(entityOnlyList) - // .entityUniqueCounter(entityUniqueCounterList) - .build(); - - // Configure Transformation for deidentified entities - // List detectEntitiesTransformationList = new ArrayList<>(); - // detectEntitiesTransformationList.add(DetectEntities.DOB); // Replace with the entity you want to transform - // detectEntitiesTransformationList.add(DetectEntities.DATE); - - // DateTransformation dateTransformation = new DateTransformation(20, 5, detectEntitiesTransformationList); - // Transformations transformations = new Transformations(dateTransformation); - - // Example 1: Deidentify text on the first vault - try { - // Create a deidentify text request for the first vault - DeidentifyTextRequest deidentifyTextRequest = DeidentifyTextRequest.builder() - .text("My SSN is 123-45-6789 and my card is 4111 1111 1111 1111.") // Replace with the text you want to deidentify - .entities(detectEntitiesList) - // .allowRegexList(allowRegexList) - // .restrictRegexList(restrictRegexList) - .tokenFormat(tokenFormat) - // .transformations(transformations) - .build(); - - - DeidentifyTextResponse deidentifyTextResponse = skyflowClient.detect(blitzConfig.getVaultId()).deidentifyText(deidentifyTextRequest); - - System.out.println("Deidentify text Response (Vault1): " + deidentifyTextResponse); - } catch (SkyflowException e) { - System.err.println("Error occurred during deidentify (Vault1): "); - e.printStackTrace(); - } - // Example 2: Deidentify text on the second vault - try { - // Create a deidentify text request for the second vault - DeidentifyTextRequest deidentifyTextRequest2 = DeidentifyTextRequest.builder() - .text("My SSN is 123-45-6789 and my card is 4111 1111 1111 1111.") // Replace with the text you want to deidentify - .entities(detectEntitiesList) - // .allowRegexList(allowRegexList) - // .restrictRegexList(restrictRegexList) - .tokenFormat(tokenFormat) - // .transformations(transformations) - .build(); - - DeidentifyTextResponse deidentifyTextResponse2 = skyflowClient.detect(stageConfig.getVaultId()).deidentifyText(deidentifyTextRequest2); - System.out.println("Deidentify text Response (Vault2): " + deidentifyTextResponse2); - - } catch (SkyflowException e) { - System.err.println("Error occurred during deidentify (Vault2): "); - e.printStackTrace(); - } - } -} \ No newline at end of file diff --git a/samples/src/main/java/com/example/detect/GetDetectRunExample.java b/samples/src/main/java/com/example/detect/GetDetectRunExample.java deleted file mode 100644 index 09fc2bc4..00000000 --- a/samples/src/main/java/com/example/detect/GetDetectRunExample.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.example.detect; - -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.detect.DeidentifyFileResponse; -import com.skyflow.vault.detect.GetDetectRunRequest; - -/** - * Skyflow Get Detect Run Example - *

- * This example demonstrates how to: - * 1. Configure credentials - * 2. Set up vault configuration - * 3. Create a get detect run request - * 4. Call getDetectRun to poll for file processing results - * 5. Handle response and errors - */ -public class GetDetectRunExample { - public static void main(String[] args) throws SkyflowException { - // Step 1: Configure credentials - Credentials credentials = new Credentials(); - credentials.setPath(""); // Replace with the path to the credentials file - - // Step 2: Configure the vault config - 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: Create a Skyflow client - Skyflow skyflowClient = Skyflow.builder() - .setLogLevel(LogLevel.DEBUG) // Enable debugging for detailed logs - .addVaultConfig(vaultConfig) // Add the vault configuration - .build(); - - try { - // Step 4: Create a get detect run request - GetDetectRunRequest getDetectRunRequest = GetDetectRunRequest.builder() - .runId("") // Replace with the runId from deidentifyFile call - .build(); - - // Step 5: Call getDetectRun to poll for file processing results - DeidentifyFileResponse deidentifyFileResponse = skyflowClient.detect(vaultConfig.getVaultId()).getDetectRun(getDetectRunRequest); - System.out.println("Get Detect Run Response: " + deidentifyFileResponse); - } catch (SkyflowException e) { - System.err.println("Error occurred during get detect run: "); - e.printStackTrace(); - } - } -} \ No newline at end of file diff --git a/samples/src/main/java/com/example/serviceaccount/BearerTokenExpiryExample.java b/samples/src/main/java/com/example/serviceaccount/BearerTokenExpiryExample.java deleted file mode 100644 index 1f56296d..00000000 --- a/samples/src/main/java/com/example/serviceaccount/BearerTokenExpiryExample.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.example.serviceaccount; - -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.enums.RedactionType; -import com.skyflow.errors.SkyflowException; -import com.skyflow.vault.tokens.DetokenizeRequest; -import com.skyflow.vault.tokens.DetokenizeResponse; -import io.github.cdimascio.dotenv.Dotenv; -import java.util.ArrayList; - -/** - * This example demonstrates how to configure and use the Skyflow SDK - * to detokenize sensitive data stored in a Skyflow vault. - * It includes setting up credentials, configuring the vault, and - * making a detokenization request. The code also implements a retry - * mechanism to handle unauthorized access errors (HTTP 401). - */ -public class BearerTokenExpiryExample { - public static void main(String[] args) { - try { - // Setting up credentials for accessing the Skyflow vault - Credentials vaultCredentials = new Credentials(); - vaultCredentials.setCredentialsString(""); - - // Configuring the Skyflow vault with necessary details - VaultConfig vaultConfig = new VaultConfig(); - vaultConfig.setVaultId(""); // Vault ID - vaultConfig.setClusterId(""); // Cluster ID - vaultConfig.setEnv(Env.PROD); // Environment (e.g., DEV, PROD) - vaultConfig.setCredentials(vaultCredentials); // Setting credentials - - // Creating a Skyflow client instance with the configured vault - Skyflow skyflowClient = Skyflow.builder() - .setLogLevel(LogLevel.ERROR) // Setting log level to ERROR - .addVaultConfig(vaultConfig) // Adding vault configuration - .build(); - - // Attempting to detokenize data using the Skyflow client - try { - detokenizeData(skyflowClient); - } catch (SkyflowException e) { - // Retry detokenization if the error is due to unauthorized access (HTTP 401) - if (e.getHttpCode() == 401) { - detokenizeData(skyflowClient); - } else { - // Rethrow the exception for other error codes - throw e; - } - } - } catch (SkyflowException e) { - // Handling any exceptions that occur during the process - System.out.println("An error occurred: " + e.getMessage()); - } - } - - /** - * Method to detokenize data using the Skyflow client. - * It sends a detokenization request with a list of tokens and prints the response. - * - * @param skyflowClient The Skyflow client instance used for detokenization. - * @throws SkyflowException If an error occurs during the detokenization process. - */ - public static void detokenizeData(Skyflow skyflowClient) throws SkyflowException { - // Creating a list of tokens to be detokenized - ArrayList tokenList = new ArrayList<>(); - tokenList.add(""); // First token - tokenList.add(""); // Second token - - // Building a detokenization request with the token list and configuration - DetokenizeRequest detokenizeRequest = DetokenizeRequest.builder() - .tokens(tokenList) // Adding tokens to the request - .continueOnError(false) // Stop on error - .redactionType(RedactionType.PLAIN_TEXT) // Redaction type (e.g., PLAIN_TEXT) - .build(); - - // Sending the detokenization request and receiving the response - DetokenizeResponse detokenizeResponse = skyflowClient.vault().detokenize(detokenizeRequest); - - // Printing the detokenized response - System.out.println(detokenizeResponse); - } -} diff --git a/samples/src/main/java/com/example/serviceaccount/BearerTokenGenerationExample.java b/samples/src/main/java/com/example/serviceaccount/BearerTokenGenerationExample.java deleted file mode 100644 index c4578545..00000000 --- a/samples/src/main/java/com/example/serviceaccount/BearerTokenGenerationExample.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.example.serviceaccount; - -import com.skyflow.errors.SkyflowException; -import com.skyflow.serviceaccount.util.BearerToken; -import com.skyflow.serviceaccount.util.Token; - -import java.io.File; - -/** - * Example program to generate a Bearer Token using Skyflow's BearerToken utility. - * The token can be generated in two ways: - * 1. Using the file path to a credentials.json file. - * 2. Using the JSON content of the credentials file as a string. - */ -public class BearerTokenGenerationExample { - public static void main(String[] args) { - // Variable to store the generated token - String token = null; - - // Example 1: Generate Bearer Token using a credentials.json file - try { - // Specify the full file path to the credentials.json file - String filePath = ""; - - // Check if the token is either not initialized or has expired - if (Token.isExpired(token)) { - // Create a BearerToken object using the credentials file - BearerToken bearerToken = BearerToken.builder() - .setCredentials(new File(filePath)) // Set credentials from the file path - .build(); - - // Generate a new Bearer Token - token = bearerToken.getBearerToken(); - } - - // Print the generated Bearer Token to the console - System.out.println("Generated Bearer Token (from file): " + token); - } catch (SkyflowException e) { - // Handle any exceptions encountered during the token generation process - e.printStackTrace(); - } - - // Example 2: Generate Bearer Token using the credentials JSON as a string - try { - // Provide the credentials JSON content as a string - String fileContents = ""; - - // Check if the token is either not initialized or has expired - if (Token.isExpired(token)) { - // Create a BearerToken object using the credentials string - BearerToken bearerToken = BearerToken.builder() - .setCredentials(fileContents) // Set credentials from the string - .build(); - - // Generate a new Bearer Token - token = bearerToken.getBearerToken(); - } - - // Print the generated Bearer Token to the console - System.out.println("Generated Bearer Token (from string): " + token); - } catch (SkyflowException e) { - // Handle any exceptions encountered during the token generation process - e.printStackTrace(); - } - } -} diff --git a/samples/src/main/java/com/example/serviceaccount/BearerTokenGenerationUsingThreadsExample.java b/samples/src/main/java/com/example/serviceaccount/BearerTokenGenerationUsingThreadsExample.java deleted file mode 100644 index 30d8f9ba..00000000 --- a/samples/src/main/java/com/example/serviceaccount/BearerTokenGenerationUsingThreadsExample.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.example.serviceaccount; - -import com.skyflow.errors.SkyflowException; -import com.skyflow.serviceaccount.util.BearerToken; - -import java.io.File; - -/** - * This example demonstrates how to generate Bearer tokens in two different ways: - * 1. Using a credentials file specified by its file path. - * 2. Using the credentials as a string. - *

- * The code also showcases multithreaded token generation with a shared context (`ctx`), - * where each thread generates and prints tokens repeatedly. - */ -public class BearerTokenGenerationUsingThreadsExample { - public static void main(String[] args) { - // Example 1: Generate Bearer token using a credentials file path - try { - // Step 1: Specify the path to the credentials file - String filePath = ""; // Replace with the actual file path - - // Step 2: Create a BearerToken object using the file path - final BearerToken bearerToken = BearerToken.builder() - .setCredentials(new File(filePath)) // Provide the credentials file - .setCtx("abc") // Specify a context string ("abc" in this case) - .build(); - - // Step 3: Create and start a thread to repeatedly generate and print tokens - Thread t = new Thread(() -> { - for (int i = 0; i < 5; i++) { // Loop to generate tokens 5 times - try { - System.out.println(bearerToken.getBearerToken()); // Print the Bearer token - } catch (SkyflowException e) { // Handle exceptions during token generation - Thread.currentThread().interrupt(); // Interrupt the thread on error - throw new RuntimeException(e); // Wrap and propagate the exception - } - } - }); - t.start(); // Start the thread - } catch (Exception e) { // Handle exceptions during BearerToken creation - e.printStackTrace(); - } - - // Example 2: Generate Bearer token using credentials as a string - try { - // Step 1: Specify the credentials as a string (file contents) - String fileContents = ""; // Replace with actual file contents - - // Step 2: Create a BearerToken object using the credentials string - final BearerToken bearerToken = BearerToken.builder() - .setCredentials(fileContents) // Provide the credentials as a string - .setCtx("abc") // Specify a context string ("abc" in this case) - .build(); - - // Step 3: Create and start a thread to repeatedly generate and print tokens - Thread t = new Thread(() -> { - for (int i = 0; i < 5; i++) { // Loop to generate tokens 5 times - try { - System.out.println(bearerToken.getBearerToken()); // Print the Bearer token - } catch (SkyflowException e) { // Handle exceptions during token generation - Thread.currentThread().interrupt(); // Interrupt the thread on error - throw new RuntimeException(e); // Wrap and propagate the exception - } - } - }); - t.start(); // Start the thread - } catch (Exception e) { // Handle exceptions during BearerToken creation - e.printStackTrace(); - } - } -} diff --git a/samples/src/main/java/com/example/serviceaccount/BearerTokenGenerationWithContextExample.java b/samples/src/main/java/com/example/serviceaccount/BearerTokenGenerationWithContextExample.java deleted file mode 100644 index 3ed9e267..00000000 --- a/samples/src/main/java/com/example/serviceaccount/BearerTokenGenerationWithContextExample.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.example.serviceaccount; - -import com.skyflow.errors.SkyflowException; -import com.skyflow.serviceaccount.util.BearerToken; - -import java.io.File; - -/** - * Example program to generate a Bearer Token using Skyflow's BearerToken utility. - * The token is generated using two approaches: - * 1. By providing the credentials.json file path. - * 2. By providing the contents of credentials.json as a string. - */ -public class BearerTokenGenerationWithContextExample { - public static void main(String[] args) { - // Variable to store the generated Bearer Token - String bearerToken = null; - - // Approach 1: Generate Bearer Token by specifying the path to the credentials.json file - try { - // Replace with the full path to your credentials.json file - String filePath = ""; - - // Create a BearerToken object using the file path - BearerToken token = BearerToken.builder() - .setCredentials(new File(filePath)) // Set credentials using a File object - .setCtx("abc") // Set context string (example: "abc") - .build(); // Build the BearerToken object - - // Retrieve the Bearer Token as a string - bearerToken = token.getBearerToken(); - - // Print the generated Bearer Token to the console - System.out.println(bearerToken); - } catch (SkyflowException e) { - // Handle exceptions specific to Skyflow operations - e.printStackTrace(); - } - - // Approach 2: Generate Bearer Token by specifying the contents of credentials.json as a string - try { - // Replace with the actual contents of your credentials.json file - String fileContents = ""; - - // Create a BearerToken object using the file contents as a string - BearerToken token = BearerToken.builder() - .setCredentials(fileContents) // Set credentials using a string representation of the file - .setCtx("abc") // Set context string (example: "abc") - .build(); // Build the BearerToken object - - // Retrieve the Bearer Token as a string - bearerToken = token.getBearerToken(); - - // Print the generated Bearer Token to the console - System.out.println(bearerToken); - } catch (SkyflowException e) { - // Handle exceptions specific to Skyflow operations - e.printStackTrace(); - } - } -} diff --git a/samples/src/main/java/com/example/serviceaccount/ScopedTokenGenerationExample.java b/samples/src/main/java/com/example/serviceaccount/ScopedTokenGenerationExample.java deleted file mode 100644 index 3cba8bd5..00000000 --- a/samples/src/main/java/com/example/serviceaccount/ScopedTokenGenerationExample.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.example.serviceaccount; - -import com.skyflow.errors.SkyflowException; -import com.skyflow.serviceaccount.util.BearerToken; - -import java.io.File; -import java.util.ArrayList; - -/** - * This example demonstrates how to generate a Scoped Bearer Token in two ways: - * 1. Using a credentials file specified by its file path. - * 2. Using the credentials as a string. - *

- * Scoped tokens are generated by assigning specific roles for access control. - */ -public class ScopedTokenGenerationExample { - public static void main(String[] args) { - String scopedToken = null; // Variable to store the generated Scoped Bearer Token - - // Example 1: Generate Scoped Token using a credentials file path - try { - // Step 1: Specify the roles required for the scoped token - ArrayList roles = new ArrayList<>(); - roles.add("YOUR_ROLE_ID"); // Replace with your actual role ID - - // Step 2: Specify the path to the credentials file - String filePath = ""; // Replace with the actual file path - - // Step 3: Create a BearerToken object using the file path and roles - BearerToken bearerToken = BearerToken.builder() - .setCredentials(new File(filePath)) // Provide the credentials file - .setRoles(roles) // Set the roles for the scoped token - .build(); - - // Step 4: Generate and print the Scoped Bearer Token - scopedToken = bearerToken.getBearerToken(); - System.out.println("Scoped Token (using file path): " + scopedToken); - } catch (SkyflowException e) { // Handle exceptions during token generation - System.out.println("Error occurred while generating Scoped Token using file path:"); - e.printStackTrace(); - } - - // Example 2: Generate Scoped Token using credentials as a string - try { - // Step 1: Specify the roles required for the scoped token - ArrayList roles = new ArrayList<>(); - roles.add("YOUR_ROLE_ID"); // Replace with your actual role ID - - // Step 2: Specify the credentials as a string (file contents) - String fileContents = ""; // Replace with actual file contents - - // Step 3: Create a BearerToken object using the credentials string and roles - BearerToken bearerToken = BearerToken.builder() - .setCredentials(fileContents) // Provide the credentials as a string - .setRoles(roles) // Set the roles for the scoped token - .build(); - - // Step 4: Generate and print the Scoped Bearer Token - scopedToken = bearerToken.getBearerToken(); - System.out.println("Scoped Token (using credentials string): " + scopedToken); - } catch (SkyflowException e) { // Handle exceptions during token generation - System.out.println("Error occurred while generating Scoped Token using credentials string:"); - e.printStackTrace(); - } - } -} diff --git a/samples/src/main/java/com/example/serviceaccount/SignedTokenGenerationExample.java b/samples/src/main/java/com/example/serviceaccount/SignedTokenGenerationExample.java deleted file mode 100644 index 98f552f3..00000000 --- a/samples/src/main/java/com/example/serviceaccount/SignedTokenGenerationExample.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.example.serviceaccount; - -import com.skyflow.errors.SkyflowException; -import com.skyflow.serviceaccount.util.SignedDataTokenResponse; -import com.skyflow.serviceaccount.util.SignedDataTokens; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -/** - * This example demonstrates how to generate Signed Data Tokens using two methods: - * 1. Specifying the path to a credentials JSON file. - * 2. Providing the credentials JSON as a string. - *

- * Signed data tokens are used to verify and securely transmit data with a specified context and TTL. - */ -public class SignedTokenGenerationExample { - public static void main(String[] args) { - List signedTokenValues; // List to store signed data token responses - - // Example 1: Generate Signed Data Token using a credentials file path - try { - // Step 1: Specify the path to the service account credentials JSON file - String filePath = ""; // Replace with the actual file path - - // Step 2: Set the context and create the list of data tokens to be signed - String context = "abc"; // Replace with your specific context (e.g., session identifier) - ArrayList dataTokens = new ArrayList<>(); - dataTokens.add("YOUR_DATA_TOKEN_1"); // Replace with your actual data token(s) - - // Step 3: Build the SignedDataTokens object - SignedDataTokens signedToken = SignedDataTokens.builder() - .setCredentials(new File(filePath)) // Provide the credentials file - .setCtx(context) // Set the context for the token - .setTimeToLive(30) // Set the TTL (in seconds) - .setDataTokens(dataTokens) // Set the data tokens to sign - .build(); - - // Step 4: Retrieve and print the signed data tokens - signedTokenValues = signedToken.getSignedDataTokens(); - System.out.println("Signed Tokens (using file path): " + signedTokenValues); - } catch (SkyflowException e) { - System.out.println("Error occurred while generating signed tokens using file path:"); - e.printStackTrace(); - } - - // Example 2: Generate Signed Data Token using credentials JSON as a string - try { - // Step 1: Provide the contents of the credentials JSON file as a string - String fileContents = ""; // Replace with actual JSON content - - // Step 2: Set the context and create the list of data tokens to be signed - String context = "abc"; // Replace with your specific context - ArrayList dataTokens = new ArrayList<>(); - dataTokens.add("YOUR_DATA_TOKEN_1"); // Replace with your actual data token(s) - - // Step 3: Build the SignedDataTokens object - SignedDataTokens signedToken = SignedDataTokens.builder() - .setCredentials(fileContents) // Provide the credentials as a string - .setCtx(context) // Set the context for the token - .setTimeToLive(30) // Set the TTL (in seconds) - .setDataTokens(dataTokens) // Set the data tokens to sign - .build(); - - // Step 4: Retrieve and print the signed data tokens - signedTokenValues = signedToken.getSignedDataTokens(); - System.out.println("Signed Tokens (using credentials string): " + signedTokenValues); - } catch (SkyflowException e) { - System.out.println("Error occurred while generating signed tokens using credentials string:"); - e.printStackTrace(); - } - } -} diff --git a/samples/src/main/java/com/example/vault/BulkDetokenizeAsync.java b/samples/src/main/java/com/example/vault/BulkDetokenizeAsync.java new file mode 100644 index 00000000..9673ab81 --- /dev/null +++ b/samples/src/main/java/com/example/vault/BulkDetokenizeAsync.java @@ -0,0 +1,81 @@ +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.DetokenizeRequest; +import com.skyflow.vault.data.DetokenizeResponse; +import com.skyflow.vault.data.TokenGroupRedactions; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; + +/** + * This sample demonstrates how to perform an asynchronous bulk detokenize operation using the Skyflow Java SDK. + * The process involves: + * 1. Setting up credentials and vault configuration + * 2. Creating a list of tokens to detokenize + * 3. Configuring token group redactions + * 4. Building and executing an async bulk detokenize request + * 5. Handling the detokenize response or errors using CompletableFuture + */ +public class BulkDetokenizeAsync { + + public static void main(String[] args) { + try { + // Step 1: Initialize credentials using credentials string + String credentialsString = ""; + Credentials credentials = new Credentials(); + credentials.setCredentialsString(credentialsString); + + // Step 2: Configure the vault with required parameters + VaultConfig vaultConfig = new VaultConfig(); + vaultConfig.setVaultId(""); + vaultConfig.setClusterId(""); + vaultConfig.setEnv(Env.PROD); + vaultConfig.setCredentials(credentials); + + // Step 3: Create Skyflow client instance with error logging + Skyflow skyflowClient = Skyflow.builder() + .setLogLevel(LogLevel.ERROR) + .addVaultConfig(vaultConfig) + .build(); + + // Step 4: Prepare list of tokens to detokenize + ArrayList tokens = new ArrayList<>(); + tokens.add(""); + tokens.add(""); + + // Step 5: Configure token group redactions + TokenGroupRedactions tokenGroupRedaction = TokenGroupRedactions.builder() + .tokenGroupName("") + .redaction("") + .build(); + List tokenGroupRedactions = new ArrayList<>(); + tokenGroupRedactions.add(tokenGroupRedaction); + + // Step 6: Build the detokenize request + DetokenizeRequest detokenizeRequest = DetokenizeRequest.builder() + .tokens(tokens) + .tokenGroupRedactions(tokenGroupRedactions) + .build(); + + // Step 7: Execute the async bulk detokenize operation and handle response using callbacks + CompletableFuture future = skyflowClient.vault().bulkDetokenizeAsync(detokenizeRequest); + future.thenAccept(response -> { + System.out.println("Async bulk detokenize resolved with response:\t" + response); + }).exceptionally(throwable -> { + System.err.println("Async bulk detokenize rejected with error:\t" + throwable.getMessage()); + throw new CompletionException(throwable); + }); + } catch (SkyflowException e) { + // Step 8: Handle any synchronous errors that occur during setup + System.err.println("Error in Skyflow operations: " + e.getMessage()); + } + } +} \ No newline at end of file diff --git a/samples/src/main/java/com/example/vault/BulkDetokenizeSync.java b/samples/src/main/java/com/example/vault/BulkDetokenizeSync.java new file mode 100644 index 00000000..dbd3dee4 --- /dev/null +++ b/samples/src/main/java/com/example/vault/BulkDetokenizeSync.java @@ -0,0 +1,74 @@ +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.DetokenizeRequest; +import com.skyflow.vault.data.DetokenizeResponse; +import com.skyflow.vault.data.TokenGroupRedactions; + +import java.util.ArrayList; +import java.util.List; + +/** + * This sample demonstrates how to perform a synchronous bulk detokenize operation using the Skyflow Java SDK. + * The process involves: + * 1. Setting up credentials and vault configuration + * 2. Creating a list of tokens to detokenize + * 3. Configuring token group redactions + * 4. Building and executing a bulk detokenize request + * 5. Handling the detokenize response or any potential errors + */ +public class BulkDetokenizeSync { + + public static void main(String[] args) { + try { + // Step 1: Initialize credentials using credentials string + String credentialsString = ""; + Credentials credentials = new Credentials(); + credentials.setCredentialsString(credentialsString); + + // Step 2: Configure the vault with required parameters + VaultConfig vaultConfig = new VaultConfig(); + vaultConfig.setVaultId(""); + vaultConfig.setClusterId(""); + vaultConfig.setEnv(Env.PROD); + vaultConfig.setCredentials(credentials); + + // Step 3: Create Skyflow client instance with error logging + Skyflow skyflowClient = Skyflow.builder() + .setLogLevel(LogLevel.ERROR) + .addVaultConfig(vaultConfig) + .build(); + + // Step 4: Prepare list of tokens to detokenize + ArrayList tokens = new ArrayList<>(); + tokens.add(""); + tokens.add(""); + + // Step 5: Configure token group redactions + TokenGroupRedactions tokenGroupRedaction = TokenGroupRedactions.builder() + .tokenGroupName("") + .redaction("") + .build(); + List tokenGroupRedactions = new ArrayList<>(); + tokenGroupRedactions.add(tokenGroupRedaction); + + // Step 6: Build the detokenize request + DetokenizeRequest detokenizeRequest = DetokenizeRequest.builder() + .tokens(tokens) + .tokenGroupRedactions(tokenGroupRedactions) + .build(); + + // Step 7: Execute the bulk detokenize operation and print the response + DetokenizeResponse detokenizeResponse = skyflowClient.vault().bulkDetokenize(detokenizeRequest); + System.out.println(detokenizeResponse); + } catch (SkyflowException e) { + // Step 8: Handle any errors that occur during the process + System.err.println("Error in Skyflow operations: " + e.getMessage()); + } + } +} \ No newline at end of file diff --git a/samples/src/main/java/com/example/vault/BulkInsertAsync.java b/samples/src/main/java/com/example/vault/BulkInsertAsync.java new file mode 100644 index 00000000..30e675c7 --- /dev/null +++ b/samples/src/main/java/com/example/vault/BulkInsertAsync.java @@ -0,0 +1,81 @@ +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.vault.data.InsertRequest; +import com.skyflow.vault.data.InsertResponse; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; + +/** + * This sample demonstrates how to perform an asynchronous bulk insert operation using the Skyflow Java SDK. + * The process involves: + * 1. Setting up credentials and vault configuration + * 2. Creating multiple records to be inserted + * 3. Building and executing an async bulk insert request + * 4. Handling the insert response or errors using CompletableFuture + */ +public class BulkInsertAsync { + + public static void main(String[] args) { + try { + // Step 1: Initialize credentials with the path to your service account key file + String filePath = ""; + Credentials credentials = new Credentials(); + credentials.setPath(filePath); + + // Step 2: Configure the vault with required parameters + VaultConfig vaultConfig = new VaultConfig(); + vaultConfig.setVaultId(""); + vaultConfig.setClusterId(""); + vaultConfig.setEnv(Env.PROD); + vaultConfig.setCredentials(credentials); + + // Step 3: Create Skyflow client instance with error logging + Skyflow skyflowClient = Skyflow.builder() + .setLogLevel(LogLevel.ERROR) + .addVaultConfig(vaultConfig) + .build(); + + // Step 4: Prepare first record for insertion + HashMap record1 = new HashMap<>(); + record1.put("", ""); + record1.put("", ""); + + // Step 5: Prepare second record for insertion + HashMap record2 = new HashMap<>(); + record2.put("", ""); + record2.put("", ""); + + // Step 6: Combine records into a single list + ArrayList> values = new ArrayList<>(); + values.add(record1); + values.add(record2); + + // Step 7: Build the insert request with table name and values + InsertRequest request = InsertRequest.builder() + .table("") + .values(values) + .build(); + + // Step 8: Execute the async bulk insert operation and handle response using callbacks + CompletableFuture future = skyflowClient.vault().bulkInsertAsync(request); + // Add success and error callbacks + future.thenAccept(response -> { + System.out.println("Async bulk insert resolved with response:\t" + response); + }).exceptionally(throwable -> { + System.err.println("Async bulk insert rejected with error:\t" + throwable.getMessage()); + throw new CompletionException(throwable); + }); + } catch (Exception e) { + // Step 9: Handle any synchronous errors that occur during setup + System.err.println("Error in Skyflow operations:\t" + e.getMessage()); + } + } +} \ No newline at end of file diff --git a/samples/src/main/java/com/example/vault/BulkInsertSync.java b/samples/src/main/java/com/example/vault/BulkInsertSync.java new file mode 100644 index 00000000..ab27e8c1 --- /dev/null +++ b/samples/src/main/java/com/example/vault/BulkInsertSync.java @@ -0,0 +1,74 @@ +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.InsertRequest; +import com.skyflow.vault.data.InsertResponse; + +import java.util.ArrayList; +import java.util.HashMap; + +/** + * This sample demonstrates how to perform a synchronous bulk insert operation using the Skyflow Java SDK. + * The process involves: + * 1. Setting up credentials and vault configuration + * 2. Creating multiple records to be inserted + * 3. Building and executing a bulk insert request + * 4. Handling the insert response or any potential errors + */ +public class BulkInsertSync { + + public static void main(String[] args) { + try { + // Step 1: Initialize credentials with the path to your service account key file + String filePath = ""; + Credentials credentials = new Credentials(); + credentials.setPath(filePath); + + // Step 2: Configure the vault with required parameters + VaultConfig vaultConfig = new VaultConfig(); + vaultConfig.setVaultId(""); + vaultConfig.setClusterId(""); + vaultConfig.setEnv(Env.PROD); + vaultConfig.setCredentials(credentials); + + // Step 3: Create Skyflow client instance with error logging + Skyflow skyflowClient = Skyflow.builder() + .setLogLevel(LogLevel.ERROR) + .addVaultConfig(vaultConfig) + .build(); + + // Step 4: Prepare first record for insertion + HashMap record1 = new HashMap<>(); + record1.put("", ""); + record1.put("", ""); + + // Step 5: Prepare second record for insertion + HashMap record2 = new HashMap<>(); + record2.put("", ""); + record2.put("", ""); + + // Step 6: Combine records into a single list + ArrayList> values = new ArrayList<>(); + values.add(record1); + values.add(record2); + + // Step 7: Build the insert request with table name and values + InsertRequest request = InsertRequest.builder() + .table("") + .values(values) + .build(); + + // Step 8: Execute the bulk insert operation and print the response + InsertResponse response = skyflowClient.vault().bulkInsert(request); + System.out.println(response); + } catch (SkyflowException e) { + // Step 9: Handle any errors that occur during the process + System.err.println("Error in Skyflow operations: " + e.getMessage()); + } + } +} \ No newline at end of file diff --git a/samples/src/main/java/com/example/vault/ClientOperations.java b/samples/src/main/java/com/example/vault/ClientOperations.java deleted file mode 100644 index 7931db34..00000000 --- a/samples/src/main/java/com/example/vault/ClientOperations.java +++ /dev/null @@ -1,95 +0,0 @@ -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 deleted file mode 100644 index 8a3ebc6a..00000000 --- a/samples/src/main/java/com/example/vault/CredentialsOptions.java +++ /dev/null @@ -1,84 +0,0 @@ -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 deleted file mode 100644 index 9fe41f61..00000000 --- a/samples/src/main/java/com/example/vault/DeleteExample.java +++ /dev/null @@ -1,64 +0,0 @@ -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 example demonstrates how to use the Skyflow SDK to delete records from one or more vaults - * by specifying the vault configurations, credentials, and record IDs to delete. - *

- * Steps include: - * 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 Skyflow credentials - Credentials credentials = new Credentials(); - credentials.setPath(""); // Replace with the actual path to the credentials file - - // 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: Set up credentials for the Skyflow client - Credentials skyflowCredentials = new Credentials(); - skyflowCredentials.setCredentialsString(""); // Replace with credentials string - - // Step 4: Create a Skyflow client and add vault configurations - Skyflow skyflowClient = Skyflow.builder() - .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(); - - // Step 5: Delete a record from the first vault - try { - 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 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: " + e); - } - } -} diff --git a/samples/src/main/java/com/example/vault/DetokenizeExample.java b/samples/src/main/java/com/example/vault/DetokenizeExample.java deleted file mode 100644 index b5d87d49..00000000 --- a/samples/src/main/java/com/example/vault/DetokenizeExample.java +++ /dev/null @@ -1,87 +0,0 @@ -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.tokens.DetokenizeData; -import com.skyflow.vault.tokens.DetokenizeRequest; -import com.skyflow.vault.tokens.DetokenizeResponse; - -import java.util.ArrayList; - -/** - * This example demonstrates how to use the Skyflow SDK to detokenize sensitive data. - * The steps include: - * 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 Skyflow credentials - Credentials credentials = new Credentials(); - credentials.setToken(""); // Replace with the actual bearer token - - // 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: Set up credentials for the Skyflow client - Credentials skyflowCredentials = new Credentials(); - skyflowCredentials.setCredentialsString(""); // Replace with credentials string - - // Step 4: Create a Skyflow client and add vault configurations - Skyflow skyflowClient = Skyflow.builder() - .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(); - - // Step 5: Detokenize tokens from the first vault - try { - ArrayList detokenizeData1 = new ArrayList<>(); - DetokenizeData detokenizeDataRecord1 = new DetokenizeData("", RedactionType.MASKED); // Replace with a token to detokenize with MASKED redaction - DetokenizeData detokenizeDataRecord2 = new DetokenizeData(""); // Replace with another token to detokenize with PLAIN_TEXT redaction - detokenizeData1.add(detokenizeDataRecord1); - detokenizeData1.add(detokenizeDataRecord2); - - DetokenizeRequest detokenizeRequest1 = DetokenizeRequest.builder() - .detokenizeData(detokenizeData1) // Specify the tokens to detokenize with specified redaction types - .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 detokenizeData2 = new ArrayList<>(); - DetokenizeData detokenizeDataRecord3 = new DetokenizeData("", RedactionType.DEFAULT); // Replace with a token to detokenize - DetokenizeData detokenizeDataRecord4 = new DetokenizeData(""); // Replace with another token to detokenize - detokenizeData2.add(detokenizeDataRecord3); - detokenizeData2.add(detokenizeDataRecord4); - - DetokenizeRequest detokenizeRequest2 = DetokenizeRequest.builder() - .detokenizeData(detokenizeData2) // Specify the tokens to detokenize with specified redaction types - .continueOnError(false) // Stop processing on the first error - .downloadURL(true) // Specify whether to return URLs for file data type - .build(); - - DetokenizeResponse detokenizeResponse2 = skyflowClient.vault("").detokenize(detokenizeRequest2); // Perform detokenization - System.out.println("Detokenize Response (Vault 2): " + detokenizeResponse2); - } catch (SkyflowException e) { - 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 deleted file mode 100644 index 6d300752..00000000 --- a/samples/src/main/java/com/example/vault/GetExample.java +++ /dev/null @@ -1,82 +0,0 @@ -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.enums.RedactionType; -import com.skyflow.errors.SkyflowException; -import com.skyflow.vault.data.GetRequest; -import com.skyflow.vault.data.GetResponse; - -import java.util.ArrayList; - -/** - * This example demonstrates how to use the Skyflow SDK to fetch sensitive data securely. - * The steps include: - * 1. Setting up vault configurations. - * 2. Creating a Skyflow client. - * 3. Retrieving records using Skyflow IDs and column values. - */ -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.setCredentialsString(""); // Replace with the actual credentials string - - // 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: Set up credentials for the Skyflow client - Credentials skyflowCredentials = new Credentials(); - skyflowCredentials.setCredentialsString(""); // Replace with another credentials string - - // Step 4: Create a Skyflow client and add vault configurations - Skyflow skyflowClient = Skyflow.builder() - .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(); - - // Example 1: Fetch records by Skyflow IDs from the first vault - try { - ArrayList ids = new ArrayList<>(); - ids.add(""); // Replace with the Skyflow ID to fetch the record - - GetRequest getByIdRequest = GetRequest.builder() - .ids(ids) // Specify the list of Skyflow IDs - .table("") // Replace with the table name - .build(); - - 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:"); - e.printStackTrace(); - } - - // Example 2: Fetch records by column values from the second vault - try { - ArrayList columnValues = new ArrayList<>(); - columnValues.add(""); // Replace with the column value to fetch the record - - GetRequest getByColumnRequest = GetRequest.builder() - .table("") // Replace with the table name - .columnName("") // Replace with the column name - .columnValues(columnValues) // Specify the list of column values - .redactionType(RedactionType.PLAIN_TEXT) // Fetch the data in plain text format - .build(); - - 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:"); - e.printStackTrace(); - } - } -} diff --git a/samples/src/main/java/com/example/vault/InsertExample.java b/samples/src/main/java/com/example/vault/InsertExample.java deleted file mode 100644 index 25610b2b..00000000 --- a/samples/src/main/java/com/example/vault/InsertExample.java +++ /dev/null @@ -1,99 +0,0 @@ -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.enums.TokenMode; -import com.skyflow.errors.SkyflowException; -import com.skyflow.vault.data.InsertRequest; -import com.skyflow.vault.data.InsertResponse; - -import java.util.ArrayList; -import java.util.HashMap; - -/** - * This example demonstrates how to use the Skyflow SDK to securely insert records into a vault. - * It includes: - * 1. Setting up vault configurations. - * 2. Creating a Skyflow client. - * 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.setApiKey(""); // Replace with the actual API key - - // 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 3: Set up credentials for the Skyflow client - Credentials skyflowCredentials = new Credentials(); - skyflowCredentials.setCredentialsString(""); // Replace with the actual credentials string - - // Step 4: Create a Skyflow client and add vault configurations - Skyflow skyflowClient = Skyflow.builder() - .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 TokenMode enabled - try { - ArrayList> values1 = new ArrayList<>(); - HashMap value1 = new HashMap<>(); - 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 actual token value for COLUMN_NAME_2 - tokens.add(token); - - InsertRequest insertRequest = InsertRequest.builder() - .table("") // Replace with the actual table name - .continueOnError(true) // Continue inserting even if some records fail - .tokenMode(TokenMode.ENABLE) // Enable TokenMode for token validation - .values(values1) // Data to insert - .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 (TokenMode Enabled): " + insertResponse); - } catch (SkyflowException e) { - System.out.println("Error during insertion with TokenMode enabled:" + e); - } - - // 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 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 actual table name - .continueOnError(false) // Stop inserting if any record fails - .tokenMode(TokenMode.DISABLE) // Disable TokenMode - .values(values2) // Data to insert - .returnTokens(false) // Do not return tokens - .upsert("") // Replace with the actual column name used for upsert logic - .build(); - - 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); - } - } -} \ 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 deleted file mode 100644 index bde5c697..00000000 --- a/samples/src/main/java/com/example/vault/QueryExample.java +++ /dev/null @@ -1,56 +0,0 @@ -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.QueryRequest; -import com.skyflow.vault.data.QueryResponse; - -/** - * 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 vault. - */ -public class QueryExample { - public static void main(String[] args) throws SkyflowException { - // Step 1: Set up credentials for the vault configuration - Credentials credentials = new Credentials(); - credentials.setApiKey(""); // Replace with the actual API key - - // 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: Set up credentials for the Skyflow client - Credentials skyflowCredentials = new Credentials(); - skyflowCredentials.setCredentialsString(""); // Replace with the actual credentials string - - // Step 4: Create a Skyflow client and add vault configuration - Skyflow skyflowClient = Skyflow.builder() - .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: Perform a query on the vault - try { - String query = ""; // Replace with a valid SQL query for the vault - QueryRequest queryRequest = QueryRequest.builder() - .query(query) // Build the query request - .build(); - - 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 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 deleted file mode 100644 index 2c390be8..00000000 --- a/samples/src/main/java/com/example/vault/TokenizeExample.java +++ /dev/null @@ -1,63 +0,0 @@ -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.tokens.ColumnValue; -import com.skyflow.vault.tokens.TokenizeRequest; -import com.skyflow.vault.tokens.TokenizeResponse; - -import java.util.ArrayList; - -/** - * This example demonstrates how to use the Skyflow SDK to tokenize data using a vault configuration. - * It includes: - * 1. Setting up a vault configuration. - * 2. Creating a Skyflow client. - * 3. Performing tokenization. - */ -public class TokenizeExample { - public static void main(String[] args) { - try { - // 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(); - - // 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()); - - // Step 5: Build and execute the tokenization request - TokenizeRequest tokenizeRequest = TokenizeRequest.builder().values(columnValues).build(); - - TokenizeResponse tokenizeResponse = skyflowClient.vault().tokenize(tokenizeRequest); - System.out.println("Tokenization Response: " + tokenizeResponse); - } catch (SkyflowException e) { - 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 deleted file mode 100644 index d5c5ed02..00000000 --- a/samples/src/main/java/com/example/vault/UpdateExample.java +++ /dev/null @@ -1,91 +0,0 @@ -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.enums.TokenMode; -import com.skyflow.errors.SkyflowException; -import com.skyflow.vault.data.UpdateRequest; -import com.skyflow.vault.data.UpdateResponse; - -import java.util.HashMap; - -/** - * This example demonstrates how to use the Skyflow SDK to securely update records in a vault. - * It includes: - * 1. Setting up vault configurations. - * 2. Creating a Skyflow client. - * 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.setApiKey(""); // Replace with the actual API key - - // 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: Set up credentials for the Skyflow client - Credentials skyflowCredentials = new Credentials(); - skyflowCredentials.setCredentialsString(""); // Replace with the actual credentials string - - // Step 4: Create a Skyflow client and add vault configurations - Skyflow skyflowClient = Skyflow.builder() - .setLogLevel(LogLevel.ERROR) // Enable debugging for detailed logs - .addVaultConfig(primaryVaultConfig) // Add the first vault configuration - .addSkyflowCredentials(skyflowCredentials) // Add general Skyflow credentials - .build(); - - // 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 - - HashMap tokens = new HashMap<>(); - tokens.put("", ""); // Replace with the token for COLUMN_NAME_2 - - UpdateRequest updateRequest1 = UpdateRequest.builder() - .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 (TokenMode Enabled): " + updateResponse1); - } catch (SkyflowException e) { - System.out.println("Error during update with TokenMode enabled:"); - e.printStackTrace(); - } - - // 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 - - UpdateRequest updateRequest2 = UpdateRequest.builder() - .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 (TokenMode Disabled): " + updateResponse2); - } catch (SkyflowException e) { - System.out.println("Error during update with TokenMode disabled:" + e); - } - } -} diff --git a/scripts/bump_version.sh b/scripts/bump_version.sh index d729ea63..45d67388 100755 --- a/scripts/bump_version.sh +++ b/scripts/bump_version.sh @@ -1,7 +1,8 @@ # Input Arguments Version=$1 CommitHash=$2 -PomFile="$GITHUB_WORKSPACE/pom.xml" +Module=$3 +PomFile="$GITHUB_WORKSPACE/v3/pom.xml" if [ -z "$Version" ]; then echo "Error: Version argument is required." @@ -14,27 +15,29 @@ if [ -z "$CommitHash" ]; then awk -v version="$Version" ' BEGIN { updated = 0 } + //,/<\/parent>/ { print; next } // && updated == 0 { sub(/.*<\/version>/, "" version "") updated = 1 } { print } - ' "$PomFile" > tempfile && cat tempfile > "$PomFile" && rm -f tempfile + ' "$PomFile" > tempfile && cat tempfile > "$PomFile" && rm -f tempfile echo "--------------------------" echo "Done. Main project version now at $Version" else echo "Bumping main project version to $Version-dev-$CommitHash" - awk -v version="$Version-dev.$CommitHash" ' - BEGIN { updated = 0 } - // && updated == 0 { - sub(/.*<\/version>/, "" version "") - updated = 1 - } - { print } - ' "$PomFile" > tempfile && cat tempfile > "$PomFile" && rm -f tempfile + awk -v version="$Version${CommitHash:+-dev.$CommitHash}" ' + BEGIN { updated = 0 } + //,/<\/parent>/ { print; next } + // && updated == 0 { + sub(/.*<\/version>/, "" version "") + updated = 1 + } + { print } + ' "$PomFile" > tempfile && cat tempfile > "$PomFile" && rm -f tempfile - echo "--------------------------" - echo "Done. Main project version now at $Version-dev.$CommitHash" +echo "--------------------------" +echo "Done. v3 module version now at $Version${CommitHash:+-dev.$CommitHash}" fi diff --git a/v2/pom.xml b/v2/pom.xml index 943b7c80..17e4ebe6 100644 --- a/v2/pom.xml +++ b/v2/pom.xml @@ -5,14 +5,14 @@ 4.0.0 com.skyflow - skyflow-java + skyflow 1.0.0 ../pom.xml skyflow-java - 2.0.0-beta.2 - jar + 2.0.0-beta.3 + com.skyflow 8 @@ -24,32 +24,8 @@ com.skyflow common - 1.0.0 + 1.0.1 - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.6.0 - - - package - - shade - - - - - com.skyflow:common - - - - - - - - + \ No newline at end of file diff --git a/v2/src/main/java/com/skyflow/ConnectionClient.java b/v2/src/main/java/com/skyflow/ConnectionClient.java index d3b20c3d..79541add 100644 --- a/v2/src/main/java/com/skyflow/ConnectionClient.java +++ b/v2/src/main/java/com/skyflow/ConnectionClient.java @@ -57,7 +57,7 @@ private void setApiKey() { if (apiKey == null) { apiKey = this.finalCredentials.getApiKey(); } else { - LogUtil.printInfoLog(InfoLogs.REUSE_API_KEY.getLog()); + LogUtil.printInfoLog(InfoLogs.USE_API_KEY.getLog()); } } diff --git a/v2/src/main/java/com/skyflow/VaultClient.java b/v2/src/main/java/com/skyflow/VaultClient.java index 7854a81b..e9981523 100644 --- a/v2/src/main/java/com/skyflow/VaultClient.java +++ b/v2/src/main/java/com/skyflow/VaultClient.java @@ -213,7 +213,7 @@ protected void setBearerToken() throws SkyflowException { prioritiseCredentials(); Validations.validateCredentials(this.finalCredentials); if (this.finalCredentials.getApiKey() != null) { - LogUtil.printInfoLog(InfoLogs.REUSE_API_KEY.getLog()); + LogUtil.printInfoLog(InfoLogs.USE_API_KEY.getLog()); token = this.finalCredentials.getApiKey(); } else if (Token.isExpired(token)) { LogUtil.printInfoLog(InfoLogs.BEARER_TOKEN_EXPIRED.getLog()); diff --git a/v2/src/main/java/com/skyflow/logs/ErrorLogs.java b/v2/src/main/java/com/skyflow/logs/ErrorLogs.java deleted file mode 100644 index 3415860c..00000000 --- a/v2/src/main/java/com/skyflow/logs/ErrorLogs.java +++ /dev/null @@ -1,140 +0,0 @@ -package com.skyflow.logs; - -public enum ErrorLogs { - // Client initialization - VAULT_CONFIG_EXISTS("Vault config with vault ID %s1 already exists."), - VAULT_CONFIG_DOES_NOT_EXIST("Vault config with vault ID %s1 doesn't exist."), - VAULT_ID_IS_REQUIRED("Invalid vault config. Vault ID is required."), - EMPTY_VAULT_ID("Invalid vault config. Vault ID can not be empty."), - CLUSTER_ID_IS_REQUIRED("Invalid vault config. Cluster ID is required."), - EMPTY_CLUSTER_ID("Invalid vault config. Cluster ID can not be empty."), - CONNECTION_CONFIG_EXISTS("Connection config with connection ID %s1 already exists."), - CONNECTION_CONFIG_DOES_NOT_EXIST("Connection config with connection ID %s1 doesn't exist."), - CONNECTION_ID_IS_REQUIRED("Invalid connection config. Connection ID is required."), - EMPTY_CONNECTION_ID("Invalid connection config. Connection ID can not be empty."), - CONNECTION_URL_IS_REQUIRED("Invalid connection config. Connection URL is required."), - EMPTY_CONNECTION_URL("Invalid connection config. Connection URL can not be empty."), - INVALID_CONNECTION_URL("Invalid connection config. Connection URL is not a valid URL."), - MULTIPLE_TOKEN_GENERATION_MEANS_PASSED("Invalid credentials. Only one of 'path', 'credentialsString', 'token' or 'apiKey' is allowed."), - NO_TOKEN_GENERATION_MEANS_PASSED("Invalid credentials. Any one of 'path', 'credentialsString', 'token' or 'apiKey' is required."), - EMPTY_CREDENTIALS_PATH("Invalid credentials. Credentials path can not be empty."), - EMPTY_CREDENTIALS_STRING("Invalid credentials. Credentials string can not be empty."), - EMPTY_TOKEN_VALUE("Invalid credentials. Token can not be empty."), - EMPTY_API_KEY_VALUE("Invalid credentials. Api key can not be empty."), - INVALID_API_KEY("Invalid credentials. Api key is invalid."), - EMPTY_ROLES("Invalid credentials. Roles can not be empty."), - EMPTY_OR_NULL_ROLE_IN_ROLES("Invalid credentials. Role can not be null or empty in roles at index %s1."), - EMPTY_OR_NULL_CONTEXT("Invalid credentials. Context can not be empty."), - - // Bearer token generation - INVALID_BEARER_TOKEN("Bearer token is invalid or expired."), - INVALID_CREDENTIALS_FILE("Credentials file is either null or an invalid file."), - INVALID_CREDENTIALS_STRING("Credentials string is either null or empty."), - INVALID_CREDENTIALS_FILE_FORMAT("Credentials file is not in a valid JSON format."), - CREDENTIALS_FILE_NOT_FOUND("Credentials file not found at specified path."), - INVALID_CREDENTIALS_STRING_FORMAT("Credentials string is not in a valid JSON string format."), - PRIVATE_KEY_IS_REQUIRED("Private key is required."), - CLIENT_ID_IS_REQUIRED("Client ID is required."), - KEY_ID_IS_REQUIRED("Key ID is required."), - TOKEN_URI_IS_REQUIRED("Token URI is required."), - INVALID_TOKEN_URI("Invalid value for token URI in credentials."), - JWT_INVALID_FORMAT("Private key is not in a valid format."), - INVALID_ALGORITHM("Algorithm for parsing private key is invalid or does not exist."), - INVALID_KEY_SPEC("Unable to parse RSA private key."), - BEARER_TOKEN_REJECTED("Bearer token request resulted in failure."), - SIGNED_DATA_TOKENS_REJECTED("Signed data tokens request resulted in failure."), - - // Vault api interfaces - TABLE_IS_REQUIRED("Invalid %s1 request. Table is required."), - EMPTY_TABLE_NAME("Invalid %s1 request. Table name can not be empty."), - VALUES_IS_REQUIRED("Invalid %s1 request. Values are required."), - EMPTY_VALUES("Invalid %s1 request. Values can not be empty."), - EMPTY_OR_NULL_VALUE_IN_VALUES("Invalid %s1 request. Value can not be null or empty in values for key \"%s2\"."), - EMPTY_OR_NULL_KEY_IN_VALUES("Invalid %s1 request. Key can not be null or empty in values"), - EMPTY_UPSERT("Invalid %s1 request. Upsert can not be empty."), - HOMOGENOUS_NOT_SUPPORTED_WITH_UPSERT("Invalid %s1 request. Homogenous is not supported when upsert is passed."), - TOKENS_NOT_ALLOWED_WITH_TOKEN_MODE_DISABLE("Invalid %s1 request. Tokens are not allowed when tokenMode is DISABLE."), - TOKENS_REQUIRED_WITH_TOKEN_MODE("Invalid %s1 request. Tokens are required when tokenMode is %s2."), - EMPTY_TOKENS("Invalid %s1 request. Tokens can not be empty."), - EMPTY_OR_NULL_VALUE_IN_TOKENS("Invalid %s1 request. Value can not be null or empty in tokens for key \"%s2\"."), - EMPTY_OR_NULL_KEY_IN_TOKENS("Invalid %s1 request. Key can not be null or empty in tokens."), - INSUFFICIENT_TOKENS_PASSED_FOR_TOKEN_MODE_ENABLE_STRICT("Invalid %s1 request. For tokenMode as ENABLE_STRICT, tokens should be passed for all fields."), - MISMATCH_OF_FIELDS_AND_TOKENS("Invalid %s1 request. Keys for values and tokens are not matching."), - INSERT_RECORDS_REJECTED("Insert request resulted in failure."), - DETOKENIZE_DATA_REQUIRED("Invalid %s1 request. Detokenize data is required."), - EMPTY_DETOKENIZE_DATA("Invalid %s1 request. Detokenize data can not be empty."), - EMPTY_OR_NULL_TOKEN_IN_DETOKENIZE_DATA("Invalid %s1 request. Token can not be null or empty in detokenize data at index %s2."), - REDACTION_IS_REQUIRED("Invalid %s1 request. Redaction is required."), - DETOKENIZE_REQUEST_REJECTED("Detokenize request resulted in failure."), - IDS_IS_REQUIRED("Invalid %s1 request. Ids are required."), - EMPTY_IDS("Invalid %s1 request. Ids can not be empty."), - EMPTY_OR_NULL_ID_IN_IDS("Invalid %s1 request. Id can not be null or empty in ids at index %s2."), - EMPTY_FIELDS("Invalid %s1 request. Fields can not be empty."), - EMPTY_OR_NULL_FIELD_IN_FIELDS("Invalid %s1 request. Field can not be null or empty in fields at index %s2."), - TOKENIZATION_NOT_SUPPORTED_WITH_REDACTION("Invalid %s1 request. Return tokens is not supported when redaction is applied."), - TOKENIZATION_SUPPORTED_ONLY_WITH_IDS("Invalid %s1 request. Return tokens is not supported when column name and values are passed."), - EMPTY_OFFSET("Invalid %s1 request. Offset can not be empty."), - EMPTY_LIMIT("Invalid %s1 request. Limit can not be empty."), - NEITHER_IDS_NOR_COLUMN_NAME_PASSED("Invalid %s1 request. Neither ids nor column name and values are passed."), - BOTH_IDS_AND_COLUMN_NAME_PASSED("Invalid %s1 request. Both ids and column name and values are passed."), - COLUMN_NAME_IS_REQUIRED("Invalid %s1 request. Column name is required when column values are passed."), - EMPTY_COLUMN_NAME("Invalid %s1 request. Column name can not be empty."), - COLUMN_VALUES_IS_REQUIRED_GET("Invalid %s1 request. Column values are required when column name is passed."), - EMPTY_COLUMN_VALUES("Invalid %s1 request. Column values can not be empty."), - EMPTY_OR_NULL_COLUMN_VALUE_IN_COLUMN_VALUES("Invalid %s1 request. Column value can not by null or empty in column values at index %s2."), - GET_REQUEST_REJECTED("Get request resulted in failure."), - DATA_IS_REQUIRED("Invalid %s1 request. Data is required."), - EMPTY_DATA("Invalid %s1 request. Data can not be empty."), - SKYFLOW_ID_IS_REQUIRED("Invalid %s1 request. Skyflow Id is required."), - INVALID_SKYFLOW_ID_TYPE("Invalid %s1 request. Skyflow Id should of type String."), - EMPTY_SKYFLOW_ID("Invalid %s1 request. Skyflow Id can not be empty."), - UPDATE_REQUEST_REJECTED("Update request resulted in failure."), - QUERY_IS_REQUIRED("Invalid %s1 request. Query is required."), - EMPTY_QUERY("Invalid %s1 request. Query can not be empty."), - QUERY_REQUEST_REJECTED("Query request resulted in failure."), - COLUMN_VALUES_IS_REQUIRED_TOKENIZE("Invalid %s1 request. ColumnValues are required."), - EMPTY_OR_NULL_COLUMN_GROUP_IN_COLUMN_VALUES("Invalid %s1 request. Column group can not be null or empty in column values at index %s2."), - TOKENIZE_REQUEST_REJECTED("Tokenize request resulted in failure."), - DELETE_REQUEST_REJECTED("Delete request resulted in failure."), - - // invoke connection interface - INVOKE_CONNECTION_INVALID_CONNECTION_URL("Invalid %s1 request. Connection URL is not a valid URL."), - EMPTY_REQUEST_HEADERS("Invalid %s1 request. Request headers can not be empty."), - INVALID_REQUEST_HEADERS("Invalid %s1 request. Request header can not be null or empty in request headers."), - EMPTY_PATH_PARAMS("Invalid %s1 request. Path params can not be empty."), - INVALID_PATH_PARAM("Invalid %s1 request. Path parameter can not be null or empty in path params."), - EMPTY_QUERY_PARAMS("Invalid %s1 request. Query params can not be empty."), - INVALID_QUERY_PARAM("Invalid %s1 request. Query parameter can not be null or empty in query params."), - EMPTY_REQUEST_BODY("Invalid %s1 request. Request body can not be empty."), - INVALID_REQUEST_BODY("Invalid %s1 request. Request body can not be empty."), - INVOKE_CONNECTION_REQUEST_REJECTED("Invoke connection request resulted in failure."), - - - // detect interface - INVALID_TEXT_IN_DEIDENTIFY("Invalid %s1 request. The text field is required and must be a non-empty string. Specify a valid text."), - DEIDENTIFY_TEXT_REQUEST_REJECTED("DeIdentify text request resulted in failure."), - INVALID_TEXT_IN_REIDENTIFY("Invalid %s1 request. The text field is required and must be a non-empty string. Specify a valid text."), - REIDENTIFY_TEXT_REQUEST_REJECTED("ReIdentify text request resulted in failure."), - DEIDENTIFY_FILE_REQUEST_REJECTED("DeIdentify file request resulted in failure."), - GET_DETECT_RUN_REQUEST_REJECTED("Get detect run request resulted in failure."), - INVALID_NULL_FILE_IN_DEIDENTIFY_FILE("Invalid %s1 request. The file field is required and must not be null. Specify a valid file."), - FILE_NOT_FOUND_TO_DEIDENTIFY("Invalid %s1 request. The file field is required and must not be empty. Specify a valid file."), - FILE_NOT_READABLE_TO_DEIDENTIFY("Invalid %s1 request. The file is not readable. Please check the file permissions or path."), - INVALID_PIXEL_DENSITY_TO_DEIDENTIFY_FILE("Invalid %s1 request. Pixel density must be a positive integer greater than 0. Specify a valid pixel density."), - INVALID_MAX_RESOLUTION("Invalid %s1 request. Max resolution must be a positive integer greater than 0. Specify a valid max resolution."), - INVALID_BLEEP_TO_DEIDENTIFY_AUDIO("Invalid %s1 request. Specify a valid bleep as AudioBleep"), - OUTPUT_DIRECTORY_NOT_FOUND("Invalid %s1 request. The output directory does not exist. Please specify a valid output directory."), - INVALID_PERMISSIONS_FOR_OUTPUT_DIRECTORY("Invalid %s1 request. The output directory is not writable. Please check the permissions or specify a valid output directory."), - EMPTY_FILE_AND_FILE_PATH_IN_DEIDENTIFY_FILE("Invalid %s1 request. The file and file path fields are both empty. Specify a valid file object or file path."), - ; - - private final String log; - - ErrorLogs(String log) { - this.log = log; - } - - public final String getLog() { - return log; - } -} diff --git a/v2/src/main/java/com/skyflow/logs/InfoLogs.java b/v2/src/main/java/com/skyflow/logs/InfoLogs.java deleted file mode 100644 index efd81a49..00000000 --- a/v2/src/main/java/com/skyflow/logs/InfoLogs.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.skyflow.logs; - -public enum InfoLogs { - // Client initialization - CLIENT_INITIALIZED("Initialized skyflow client."), - VALIDATING_VAULT_CONFIG("Validating vault config."), - VALIDATING_CONNECTION_CONFIG("Validating connection config."), - UNABLE_TO_GENERATE_SDK_METRIC("Unable to generate %s1 metric."), - VAULT_CONTROLLER_INITIALIZED("Initialized vault controller with vault ID %s1."), - DETECT_CONTROLLER_INITIALIZED("Initialized detect controller with vault ID %s1."), - CONNECTION_CONTROLLER_INITIALIZED("Initialized connection controller with connection ID %s1."), - LOGGER_SETUP_DONE("Set up logger."), - CURRENT_LOG_LEVEL("Current log level is %s1."), - - // Bearer token generation - EMPTY_BEARER_TOKEN("Bearer token is empty."), - BEARER_TOKEN_EXPIRED("Bearer token is expired."), - GET_BEARER_TOKEN_TRIGGERED("getBearerToken method triggered."), - GET_BEARER_TOKEN_SUCCESS("Bearer token generated."), - GET_SIGNED_DATA_TOKENS_TRIGGERED("getSignedDataTokens method triggered."), - GET_SIGNED_DATA_TOKEN_SUCCESS("Signed data tokens generated."), - REUSE_BEARER_TOKEN("Reusing bearer token."), - REUSE_API_KEY("Reusing api key."), - GENERATE_BEARER_TOKEN_FROM_CREDENTIALS_TRIGGERED("generateBearerTokenFromCredentials method triggered."), - GENERATE_BEARER_TOKEN_FROM_CREDENTIALS_STRING_TRIGGERED("generateBearerTokenFromCredentialString method triggered."), - GENERATE_SIGNED_TOKENS_FROM_CREDENTIALS_FILE_TRIGGERED("generateSignedTokensFromCredentialsFile method triggered."), - GENERATE_SIGNED_TOKENS_FROM_CREDENTIALS_STRING_TRIGGERED("generateSignedTokensFromCredentialsString method triggered."), - - // Insert interface - INSERT_TRIGGERED("Insert method triggered."), - VALIDATE_INSERT_REQUEST("Validating insert request."), - INSERT_REQUEST_RESOLVED("Insert request resolved."), - INSERT_SUCCESS("Data inserted."), - - // Detokenize interface - DETOKENIZE_TRIGGERED("Detokenize method triggered."), - VALIDATE_DETOKENIZE_REQUEST("Validating detokenize request."), - DETOKENIZE_REQUEST_RESOLVED("Detokenize request resolved."), - DETOKENIZE_PARTIAL_SUCCESS("Data detokenized partially."), - DETOKENIZE_SUCCESS("Data detokenized."), - - // Get interface - GET_TRIGGERED("Get method triggered."), - VALIDATE_GET_REQUEST("Validating get request."), - GET_REQUEST_RESOLVED("Get request resolved."), - GET_SUCCESS("Data revealed."), - - // Update interface - UPDATE_TRIGGERED("Update method triggered."), - VALIDATE_UPDATE_REQUEST("Validating update request."), - UPDATE_REQUEST_RESOLVED("Update request resolved."), - UPDATE_SUCCESS("Data updated."), - - // Delete interface - DELETE_TRIGGERED("Delete method triggered."), - VALIDATING_DELETE_REQUEST("Validating delete request."), - DELETE_REQUEST_RESOLVED("Delete request resolved."), - DELETE_SUCCESS("Data deleted."), - - // Query interface - QUERY_TRIGGERED("Query method triggered."), - VALIDATING_QUERY_REQUEST("Validating query request."), - QUERY_REQUEST_RESOLVED("Query request resolved."), - QUERY_SUCCESS("Query executed."), - - // Tokenize interface - TOKENIZE_TRIGGERED("Tokenize method triggered."), - VALIDATING_TOKENIZE_REQUEST("Validating tokenize request."), - TOKENIZE_REQUEST_RESOLVED("Tokenize request resolved."), - TOKENIZE_SUCCESS("Data tokenized."), - - - // Invoke connection interface - INVOKE_CONNECTION_TRIGGERED("Invoke connection method triggered."), - VALIDATING_INVOKE_CONNECTION_REQUEST("Validating invoke connection request."), - INVOKE_CONNECTION_REQUEST_RESOLVED("Invoke connection request resolved."), - - // detect - VALIDATE_DEIDENTIFY_TEXT_REQUEST("Validating deidentify text request."), - DEIDENTIFY_TEXT_SUCCESS("Text data de-identified."), - DEIDENTIFY_TEXT_TRIGGERED("DeIdentify text method triggered."), - DEIDENTIFY_TEXT_REQUEST_RESOLVED("DeIdentify text request resolved."), - VALIDATE_REIDENTIFY_TEXT_REQUEST("Validating reidentify text request."), - REIDENTIFY_TEXT_TRIGGERED("ReIdentify text method triggered."), - REIDENTIFY_TEXT_REQUEST_RESOLVED("ReIdentify text request resolved."), - DEIDENTIFY_FILE_TRIGGERED("DeIdentify file method triggered."), - VALIDATE_DEIDENTIFY_FILE_REQUEST("Validating deidentify file request."), - DEIDENTIFY_FILE_REQUEST_RESOLVED("DeIdentify file request resolved."), - DEIDENTIFY_FILE_SUCCESS("File deidentified successfully."), - GET_DETECT_RUN_TRIGGERED("Get detect run method triggered."), - VALIDATE_GET_DETECT_RUN_REQUEST("Validating get detect run request."), - REIDENTIFY_TEXT_SUCCESS("Text data re-identified."), - ; - - - private final String log; - - InfoLogs(String log) { - this.log = log; - } - - public final String getLog() { - return log; - } -} diff --git a/v2/src/main/java/com/skyflow/utils/Constants.java b/v2/src/main/java/com/skyflow/utils/Constants.java index c0f2a778..9b850bf0 100644 --- a/v2/src/main/java/com/skyflow/utils/Constants.java +++ b/v2/src/main/java/com/skyflow/utils/Constants.java @@ -4,6 +4,7 @@ public final class Constants extends BaseConstants { public static final String SDK_NAME = "Skyflow Java SDK "; public static final String SDK_VERSION = "2.0.0-beta.2"; public static final String SDK_PREFIX = SDK_NAME + SDK_VERSION; + public static final String VAULT_DOMAIN = ".vault."; public static final String PROCESSED_FILE_NAME_PREFIX = "processed-"; public static final String DEIDENTIFIED_FILE_PREFIX = "deidentified"; } diff --git a/v2/src/main/java/com/skyflow/utils/Utils.java b/v2/src/main/java/com/skyflow/utils/Utils.java index c1b34102..ff43c089 100644 --- a/v2/src/main/java/com/skyflow/utils/Utils.java +++ b/v2/src/main/java/com/skyflow/utils/Utils.java @@ -2,6 +2,7 @@ import com.google.gson.JsonObject; import com.skyflow.config.ConnectionConfig; +import com.skyflow.enums.Env; import com.skyflow.vault.connection.InvokeConnectionRequest; import java.util.HashMap; @@ -9,6 +10,10 @@ public final class Utils extends BaseUtils { + public static String getVaultURL(String clusterId, Env env) { + return getVaultURL(clusterId, env, Constants.VAULT_DOMAIN); + } + public static String constructConnectionURL(ConnectionConfig config, InvokeConnectionRequest invokeConnectionRequest) { StringBuilder filledURL = new StringBuilder(config.getConnectionUrl()); diff --git a/v2/src/main/java/com/skyflow/vault/data/GetRequest.java b/v2/src/main/java/com/skyflow/vault/data/GetRequest.java index ef4edea2..5fa59852 100644 --- a/v2/src/main/java/com/skyflow/vault/data/GetRequest.java +++ b/v2/src/main/java/com/skyflow/vault/data/GetRequest.java @@ -1,15 +1,15 @@ package com.skyflow.vault.data; import com.skyflow.enums.RedactionType; +import com.skyflow.utils.BaseConstants; import com.skyflow.utils.Constants; import java.util.ArrayList; -public class GetRequest extends BaseGetRequest { +public class GetRequest { private final GetRequestBuilder builder; private GetRequest(GetRequestBuilder builder) { - super(builder); this.builder = builder; } @@ -17,28 +17,75 @@ public static GetRequestBuilder builder() { return new GetRequestBuilder(); } + public String getTable() { + return this.builder.table; + } + + public ArrayList getIds() { + return this.builder.ids; + } + + public Boolean getReturnTokens() { + return this.builder.returnTokens; + } + + public ArrayList getFields() { + return this.builder.fields; + } + + public String getOffset() { + return this.builder.offset; + } + + public String getLimit() { + return this.builder.limit; + } + + public Boolean getDownloadURL() { + return this.builder.downloadURL; + } + + public String getColumnName() { + return this.builder.columnName; + } + + public ArrayList getColumnValues() { + return this.builder.columnValues; + } + + public String getOrderBy() { + return this.builder.orderBy; + } + public RedactionType getRedactionType() { return this.builder.redactionType; } - public static final class GetRequestBuilder extends BaseGetRequestBuilder { + public static final class GetRequestBuilder { + private String table; + private ArrayList ids; + private Boolean returnTokens; + private ArrayList fields; + private String offset; + private String limit; + private Boolean downloadURL; + private String columnName; + private ArrayList columnValues; + private String orderBy; private RedactionType redactionType; private GetRequestBuilder() { - super(); this.downloadURL = true; this.orderBy = Constants.ORDER_ASCENDING; } - @Override public GetRequestBuilder table(String table) { - super.table(table); + this.table = table; return this; } - @Override public GetRequestBuilder ids(ArrayList ids) { - super.ids(ids); + this.ids = ids; return this; } @@ -47,51 +94,43 @@ public GetRequestBuilder redactionType(RedactionType redactionType) { return this; } - @Override public GetRequestBuilder returnTokens(Boolean returnTokens) { - super.returnTokens(returnTokens); + this.returnTokens = returnTokens; return this; } - @Override public GetRequestBuilder fields(ArrayList fields) { - super.fields(fields); + this.fields = fields; return this; } - @Override public GetRequestBuilder offset(String offset) { - super.offset(offset); + this.offset = offset; return this; } - @Override public GetRequestBuilder limit(String limit) { - super.limit(limit); + this.limit = limit; return this; } - @Override public GetRequestBuilder downloadURL(Boolean downloadURL) { - super.downloadURL(downloadURL); + this.downloadURL = downloadURL == null || downloadURL; return this; } - @Override public GetRequestBuilder columnName(String columnName) { - super.columnName(columnName); + this.columnName = columnName; return this; } - @Override public GetRequestBuilder columnValues(ArrayList columnValues) { - super.columnValues(columnValues); + this.columnValues = columnValues; return this; } - @Override public GetRequestBuilder orderBy(String orderBy) { - super.orderBy(orderBy); + this.orderBy = orderBy == null ? BaseConstants.ORDER_ASCENDING : orderBy; return this; } diff --git a/v2/src/main/java/com/skyflow/vault/data/InsertRequest.java b/v2/src/main/java/com/skyflow/vault/data/InsertRequest.java index 01655f02..9758e98f 100644 --- a/v2/src/main/java/com/skyflow/vault/data/InsertRequest.java +++ b/v2/src/main/java/com/skyflow/vault/data/InsertRequest.java @@ -28,16 +28,30 @@ public Boolean getContinueOnError() { public TokenMode getTokenMode() { return this.builder.tokenMode; } + public String getUpsert() { + return this.builder.upsert; + } + public Boolean getReturnTokens() { + return this.builder.returnTokens; + } + + public ArrayList> getTokens() { + return this.builder.tokens; + } public static final class InsertRequestBuilder extends BaseInsertRequestBuilder { private Boolean homogeneous; private Boolean continueOnError; private TokenMode tokenMode; + private ArrayList> tokens; + private Boolean returnTokens; + private InsertRequestBuilder() { super(); this.continueOnError = false; this.tokenMode = TokenMode.DISABLE; + this.returnTokens = false; } @Override @@ -52,21 +66,18 @@ public InsertRequestBuilder values(ArrayList> values) { return this; } - @Override public InsertRequestBuilder tokens(ArrayList> tokens) { - super.tokens(tokens); + this.tokens = tokens ; return this; } - @Override public InsertRequestBuilder returnTokens(Boolean returnTokens) { - super.returnTokens(returnTokens); + this.returnTokens = returnTokens != null && returnTokens; return this; } - @Override public InsertRequestBuilder upsert(String upsert) { - super.upsert(upsert); + this.upsert = upsert; return this; } diff --git a/v2/test/java/com/skyflow/utils/UtilsTests.java b/v2/test/java/com/skyflow/utils/UtilsTests.java index 4f1bba41..00543567 100644 --- a/v2/test/java/com/skyflow/utils/UtilsTests.java +++ b/v2/test/java/com/skyflow/utils/UtilsTests.java @@ -122,9 +122,10 @@ public void testGenerateBearerTokenWithToken() { credentials.setContext(context); credentials.setRoles(roles); String bearerToken = Utils.generateBearerToken(credentials); - Assert.assertEquals(token, bearerToken); + Assert.fail(EXCEPTION_NOT_THROWN); } catch (SkyflowException e) { - Assert.fail(INVALID_EXCEPTION_THROWN); + Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode()); + Assert.assertEquals(ErrorMessage.BearerTokenExpired.getMessage(), e.getMessage()); } } diff --git a/v3/pom.xml b/v3/pom.xml index a2ba27a5..4655a067 100644 --- a/v3/pom.xml +++ b/v3/pom.xml @@ -5,51 +5,117 @@ 4.0.0 com.skyflow - skyflow-java + skyflow 1.0.0 ../pom.xml skyflow-java - 3.0.0-beta.0 + 3.0.0-beta.3 jar + ${project.groupId}:${project.artifactId} + Skyflow V3 SDK for the Java programming language + https://github.com/skyflowapi/skyflow-java/tree/main + + + + The MIT License (MIT) + https://github.com/skyflowapi/skyflow-java/blob/main/LICENSE + + + + + skyflow + skyflow + + 8 8 UTF-8 + false + + com.skyflow common - 1.0.0 + 1.0.1 - - - org.apache.maven.plugins - maven-shade-plugin - 3.6.0 - - - package - - shade - + + + org.apache.maven.plugins + maven-shade-plugin + 3.6.0 + + + package + + shade + + + + + com.skyflow:common + + + + + + + + + + + + jfrog + + + central + prekarilabs.jfrog.io-releases + https://prekarilabs.jfrog.io/artifactory/skyflow-java + + + snapshots + prekarilabs.jfrog.io-snapshots + https://prekarilabs.jfrog.io/artifactory/skyflow-java + + + + + maven-central + + + central + https://central.sonatype.com/api/v1/publisher/upload + + + central-snapshots + https://central.sonatype.com/api/v1/publisher/upload + + + + + + org.sonatype.central + central-publishing-maven-plugin + 0.4.0 + true - - - com.skyflow:common - - + central + true + true - - - - - - \ No newline at end of file + + + + + + + diff --git a/v3/src/main/java/com/skyflow/Skyflow.java b/v3/src/main/java/com/skyflow/Skyflow.java index 09b16a2c..7973c747 100644 --- a/v3/src/main/java/com/skyflow/Skyflow.java +++ b/v3/src/main/java/com/skyflow/Skyflow.java @@ -43,6 +43,7 @@ public VaultController vault() throws SkyflowException { LogUtil.printErrorLog(ErrorLogs.VAULT_CONFIG_DOES_NOT_EXIST.getLog()); throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.VaultIdNotInConfigList.getMessage()); } + return controller; } diff --git a/v3/src/main/java/com/skyflow/VaultClient.java b/v3/src/main/java/com/skyflow/VaultClient.java index cbeedb94..b43ccd60 100644 --- a/v3/src/main/java/com/skyflow/VaultClient.java +++ b/v3/src/main/java/com/skyflow/VaultClient.java @@ -2,20 +2,32 @@ import com.skyflow.config.Credentials; import com.skyflow.config.VaultConfig; +import com.skyflow.enums.UpdateType; import com.skyflow.errors.ErrorCode; import com.skyflow.errors.ErrorMessage; import com.skyflow.errors.SkyflowException; import com.skyflow.generated.rest.ApiClient; import com.skyflow.generated.rest.ApiClientBuilder; import com.skyflow.generated.rest.resources.recordservice.RecordserviceClient; +import com.skyflow.generated.rest.resources.recordservice.requests.InsertRequest; +import com.skyflow.generated.rest.types.EnumUpdateType; +import com.skyflow.generated.rest.types.InsertRecordData; +import com.skyflow.generated.rest.types.Upsert; import com.skyflow.logs.InfoLogs; import com.skyflow.serviceaccount.util.Token; import com.skyflow.utils.Constants; import com.skyflow.utils.Utils; import com.skyflow.utils.logger.LogUtil; import com.skyflow.utils.validations.Validations; +import com.skyflow.vault.data.DetokenizeRequest; import io.github.cdimascio.dotenv.Dotenv; import io.github.cdimascio.dotenv.DotenvException; +import okhttp3.OkHttpClient; +import okhttp3.Request; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; public class VaultClient { @@ -53,14 +65,17 @@ protected void setBearerToken() throws SkyflowException { prioritiseCredentials(); Validations.validateCredentials(this.finalCredentials); if (this.finalCredentials.getApiKey() != null) { - LogUtil.printInfoLog(InfoLogs.REUSE_API_KEY.getLog()); + LogUtil.printInfoLog(InfoLogs.USE_API_KEY.getLog()); token = this.finalCredentials.getApiKey(); + } else if (token == null || token.trim().isEmpty()) { + token = Utils.generateBearerToken(this.finalCredentials); } else if (Token.isExpired(token)) { LogUtil.printInfoLog(InfoLogs.BEARER_TOKEN_EXPIRED.getLog()); token = Utils.generateBearerToken(this.finalCredentials); } else { LogUtil.printInfoLog(InfoLogs.REUSE_BEARER_TOKEN.getLog()); } + updateExecutorInHTTP(); // update executor this.apiClient = this.apiClientBuilder.build(); } @@ -98,4 +113,68 @@ private void prioritiseCredentials() throws SkyflowException { throw new RuntimeException(e); } } + + protected void updateExecutorInHTTP() { + OkHttpClient httpClient = new OkHttpClient.Builder() + .addInterceptor(chain -> { + Request original = chain.request(); + Request requestWithAuth = original.newBuilder() + .header("Authorization", "Bearer " + this.token) + .build(); + return chain.proceed(requestWithAuth); + }) + .build(); + apiClientBuilder.httpClient(httpClient); + } + protected InsertRequest getBulkInsertRequestBody(com.skyflow.vault.data.InsertRequest request, VaultConfig config) throws SkyflowException { + List> values = request.getValues(); + List insertRecordDataList = new ArrayList<>(); + for (HashMap value : values) { + InsertRecordData data = InsertRecordData.builder().data(value).build(); + insertRecordDataList.add(data); + } + InsertRequest.Builder builder = InsertRequest.builder() + .vaultId(config.getVaultId()) + .records(insertRecordDataList) + .tableName(request.getTable()); + if(request.getUpsert() != null && !request.getUpsert().isEmpty()){ + if (request.getUpsertType() != null) { + EnumUpdateType updateType = null; + if(request.getUpsertType() == UpdateType.REPLACE){ + updateType = EnumUpdateType.REPLACE; + } else if (request.getUpsertType() == UpdateType.REPLACE) { + updateType = EnumUpdateType.UPDATE; + } + Upsert upsert = Upsert.builder().uniqueColumns(request.getUpsert()).updateType(updateType).build(); + builder.upsert(upsert); + } else { + Upsert upsert = Upsert.builder().uniqueColumns(request.getUpsert()).build(); + builder.upsert(upsert); + } + } + return builder.build(); + + } + + protected com.skyflow.generated.rest.resources.recordservice.requests.DetokenizeRequest getDetokenizeRequestBody(DetokenizeRequest request) { + List tokens = request.getTokens(); + com.skyflow.generated.rest.resources.recordservice.requests.DetokenizeRequest.Builder builder = + com.skyflow.generated.rest.resources.recordservice.requests.DetokenizeRequest.builder() + .vaultId(this.vaultConfig.getVaultId()) + .tokens(tokens); + if (request.getTokenGroupRedactions() != null){ + List tokenGroupRedactionsList = new ArrayList<>(); + for (com.skyflow.vault.data.TokenGroupRedactions tokenGroupRedactions : request.getTokenGroupRedactions()) { + com.skyflow.generated.rest.types.TokenGroupRedactions redactions = + com.skyflow.generated.rest.types.TokenGroupRedactions.builder() + .tokenGroupName(tokenGroupRedactions.getTokenGroupName()) + .redaction(tokenGroupRedactions.getRedaction()) + .build(); + tokenGroupRedactionsList.add(redactions); + } + + builder.tokenGroupRedactions(tokenGroupRedactionsList); + } + return builder.build(); + } } diff --git a/v3/src/main/java/com/skyflow/enums/UpdateType.java b/v3/src/main/java/com/skyflow/enums/UpdateType.java new file mode 100644 index 00000000..7fcb6f65 --- /dev/null +++ b/v3/src/main/java/com/skyflow/enums/UpdateType.java @@ -0,0 +1,20 @@ +package com.skyflow.enums; + +import com.fasterxml.jackson.annotation.JsonValue; + +public enum UpdateType { + UPDATE("UPDATE"), + + REPLACE("REPLACE"); + + private final String value; + + UpdateType(String value) { + this.value = value; + } + + @Override + public String toString() { + return this.value; + } +} diff --git a/v3/src/main/java/com/skyflow/utils/Constants.java b/v3/src/main/java/com/skyflow/utils/Constants.java index a8fd82ab..e3c56ad3 100644 --- a/v3/src/main/java/com/skyflow/utils/Constants.java +++ b/v3/src/main/java/com/skyflow/utils/Constants.java @@ -1,7 +1,18 @@ package com.skyflow.utils; -public class Constants extends BaseConstants { +public final class Constants extends BaseConstants { public static final String SDK_NAME = "Skyflow Java SDK "; - public static final String SDK_VERSION = "3.0.0-beta.0"; + public static final String SDK_VERSION = "3.0.0-beta.3"; + public static final String VAULT_DOMAIN = ".skyvault."; public static final String SDK_PREFIX = SDK_NAME + SDK_VERSION; + public static final Integer INSERT_BATCH_SIZE = 50; + public static final Integer MAX_INSERT_BATCH_SIZE = 1000; + public static final Integer INSERT_CONCURRENCY_LIMIT = 10; + public static final Integer MAX_INSERT_CONCURRENCY_LIMIT = 10; + + public static final Integer DETOKENIZE_BATCH_SIZE = 50; + public static final Integer DETOKENIZE_CONCURRENCY_LIMIT = 10; + public static final Integer MAX_DETOKENIZE_BATCH_SIZE = 1000; + public static final Integer MAX_DETOKENIZE_CONCURRENCY_LIMIT = 10; + } diff --git a/v3/src/main/java/com/skyflow/utils/Utils.java b/v3/src/main/java/com/skyflow/utils/Utils.java index 915c7e55..f2142bd6 100644 --- a/v3/src/main/java/com/skyflow/utils/Utils.java +++ b/v3/src/main/java/com/skyflow/utils/Utils.java @@ -1,13 +1,242 @@ package com.skyflow.utils; import com.google.gson.JsonObject; +import com.skyflow.enums.Env; +import com.skyflow.generated.rest.core.ApiClientApiException; +import com.skyflow.generated.rest.resources.recordservice.requests.DetokenizeRequest; +import com.skyflow.generated.rest.types.InsertRecordData; +import com.skyflow.generated.rest.types.InsertResponse; +import com.skyflow.generated.rest.types.RecordResponseObject; +import com.skyflow.generated.rest.types.TokenGroupRedactions; +import com.skyflow.vault.data.DetokenizeResponse; +import com.skyflow.vault.data.ErrorRecord; +import com.skyflow.vault.data.Success; +import com.skyflow.vault.data.Token; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; public final class Utils extends BaseUtils { + public static String getVaultURL(String clusterId, Env env) { + return getVaultURL(clusterId, env, Constants.VAULT_DOMAIN); + } + public static JsonObject getMetrics() { JsonObject details = getCommonMetrics(); String sdkVersion = Constants.SDK_VERSION; details.addProperty(Constants.SDK_METRIC_NAME_VERSION, Constants.SDK_METRIC_NAME_VERSION_PREFIX + sdkVersion); return details; } + + public static List> createBatches(List records, int batchSize) { + List> batches = new ArrayList<>(); + for (int i = 0; i < records.size(); i += batchSize) { + batches.add(records.subList(i, Math.min(i + batchSize, records.size()))); + } + return batches; + } + + public static List createDetokenizeBatches(DetokenizeRequest request, int batchSize) { + List detokenizeRequests = new ArrayList<>(); + List tokens = request.getTokens().get(); + + for (int i = 0; i < tokens.size(); i += batchSize) { + // Create a sublist for the current batch + List batchTokens = tokens.subList(i, Math.min(i + batchSize, tokens.size())); + List tokenGroupRedactions = null; + if (request.getTokenGroupRedactions().isPresent() && !request.getTokenGroupRedactions().get().isEmpty() && i < request.getTokenGroupRedactions().get().size()) { + tokenGroupRedactions = request.getTokenGroupRedactions().get(); + } + // Build a new DetokenizeRequest for the current batch + DetokenizeRequest batchRequest = DetokenizeRequest.builder() + .vaultId(request.getVaultId()) + .tokens(new ArrayList<>(batchTokens)) + .tokenGroupRedactions(tokenGroupRedactions) + .build(); + + detokenizeRequests.add(batchRequest); + } + + return detokenizeRequests; + } + + public static ErrorRecord createErrorRecord(Map recordMap, int indexNumber) { + ErrorRecord err = null; + if (recordMap != null) { + int code = 500; + if (recordMap.containsKey("http_code")) { + code = (Integer) recordMap.get("http_code"); + } else if (recordMap.containsKey("httpCode")) { + code = (Integer) recordMap.get("httpCode"); + + } else{ + if (recordMap.containsKey("statusCode")) { + code = (Integer) recordMap.get("statusCode"); + } + } + String message = recordMap.containsKey("error") ? (String) recordMap.get("error") : + recordMap.containsKey("message") ? (String) recordMap.get("message") : "Unknown error"; + err = new ErrorRecord(indexNumber, message, code); + } + return err; + } + + public static List handleBatchException( + Throwable ex, List batch, int batchNumber + ) { + List errorRecords = new ArrayList<>(); + Throwable cause = ex.getCause(); + if (cause instanceof ApiClientApiException) { + ApiClientApiException apiException = (ApiClientApiException) cause; + Map responseBody = (Map) apiException.body(); + int indexNumber = batchNumber > 0 ? batchNumber * batch.size() : 0; + if (responseBody != null) { + if (responseBody.containsKey("records")) { + Object recordss = responseBody.get("records"); + if (recordss instanceof List) { + List recordsList = (List) recordss; + for (Object record : recordsList) { + if (record instanceof Map) { + Map recordMap = (Map) record; + ErrorRecord err = Utils.createErrorRecord(recordMap, indexNumber); + errorRecords.add(err); + indexNumber++; + } + } + } + } else if (responseBody.containsKey("error")) { + Map recordMap = (Map) responseBody.get("error"); + for (int j = 0; j < batch.size(); j++) { + ErrorRecord err = Utils.createErrorRecord(recordMap, indexNumber); + errorRecords.add(err); + indexNumber++; + } + } + } + } else { + int indexNumber = batchNumber > 0 ? batchNumber * batch.size() : 0; + for (int j = 0; j < batch.size(); j++) { + ErrorRecord err = new ErrorRecord(indexNumber, ex.getMessage(), 500); + errorRecords.add(err); + indexNumber++; + } + } + return errorRecords; + } + + public static List handleDetokenizeBatchException( + Throwable ex, DetokenizeRequest batch, int batchNumber, int batchSize + ) { + List errorRecords = new ArrayList<>(); + Throwable cause = ex.getCause(); + if (cause instanceof ApiClientApiException) { + ApiClientApiException apiException = (ApiClientApiException) cause; + Map responseBody = (Map) apiException.body(); + int indexNumber = batchNumber * batchSize; + if (responseBody != null) { + if (responseBody.containsKey("response")) { + Object recordss = responseBody.get("response"); + if (recordss instanceof List) { + List recordsList = (List) recordss; + for (Object record : recordsList) { + if (record instanceof Map) { + Map recordMap = (Map) record; + ErrorRecord err = Utils.createErrorRecord(recordMap, indexNumber); + errorRecords.add(err); + indexNumber++; + } + } + } + } else if (responseBody.containsKey("error")) { + Map recordMap = (Map) responseBody.get("error"); + for (int j = 0; j < batch.getTokens().get().size(); j++) { + ErrorRecord err = Utils.createErrorRecord(recordMap, indexNumber); + errorRecords.add(err); + indexNumber++; + } + } + } + } else { + int indexNumber = batchNumber * batchSize; + for (int j = 0; j < batch.getTokens().get().size(); j++) { + ErrorRecord err = new ErrorRecord(indexNumber, ex.getMessage(), 500); + errorRecords.add(err); + indexNumber++; + } + } + return errorRecords; + } + + public static DetokenizeResponse formatDetokenizeResponse(com.skyflow.generated.rest.types.DetokenizeResponse response, int batch, int batchSize) { + if (response != null) { + List record = response.getResponse().get(); + List errorRecords = new ArrayList<>(); + List successRecords = new ArrayList<>(); + int indexNumber = batch * batchSize; + int recordsSize = response.getResponse().get().size(); + for (int index = 0; index < recordsSize; index++) { + if (record.get(index).getError().isPresent()) { + ErrorRecord errorRecord = new ErrorRecord(indexNumber, record.get(index).getError().get(), record.get(index).getHttpCode().get()); + errorRecords.add(errorRecord); + } else { + com.skyflow.vault.data.DetokenizeResponseObject success = new com.skyflow.vault.data.DetokenizeResponseObject(indexNumber, record.get(index).getToken().orElse(null), record.get(index).getValue().orElse(null), record.get(index).getTokenGroupName().orElse(null), record.get(index).getError().orElse(null), record.get(index).getMetadata().orElse(null)); + successRecords.add(success); + } + indexNumber++; + } + DetokenizeResponse formattedResponse = new DetokenizeResponse(successRecords, errorRecords); + return formattedResponse; + } + return null; + } + + public static com.skyflow.vault.data.InsertResponse formatResponse(InsertResponse response, int batch, int batchSize) { + com.skyflow.vault.data.InsertResponse formattedResponse = null; + List successRecords = new ArrayList<>(); + List errorRecords = new ArrayList<>(); + if (response != null) { + List record = response.getRecords().get(); + int indexNumber = batch * batchSize; + int recordsSize = response.getRecords().get().size(); + for (int index = 0; index < recordsSize; index++) { + if (record.get(index).getError().isPresent()) { + ErrorRecord errorRecord = new ErrorRecord(indexNumber, record.get(index).getError().get(), record.get(index).getHttpCode().get()); + errorRecords.add(errorRecord); + } else { + Map> tokensMap = null; + + if (record.get(index).getTokens().isPresent()) { + tokensMap = new HashMap<>(); + Map tok = record.get(index).getTokens().get(); + for (Map.Entry entry : tok.entrySet()) { + String key = entry.getKey(); + Object value = entry.getValue(); + List tokenList = new ArrayList<>(); + if (value instanceof List) { + List valueList = (List) value; + for (Object item : valueList) { + if(item instanceof Map) { + Map tokenMap = (Map) item; + Token token = new Token((String) tokenMap.get("token"), (String) tokenMap.get("tokenGroupName")); + tokenList.add(token); + } + } + } + tokensMap.put(key, tokenList); + } + } + Success success = new Success(indexNumber, record.get(index).getSkyflowId().get(), tokensMap, record.get(index).getData().isPresent() ? record.get(index).getData().get() : null); + successRecords.add(success); + } + indexNumber++; + } + + formattedResponse = new com.skyflow.vault.data.InsertResponse(successRecords, errorRecords); + } + return formattedResponse; + } + } diff --git a/v3/src/main/java/com/skyflow/utils/validations/Validations.java b/v3/src/main/java/com/skyflow/utils/validations/Validations.java index 374e84d4..b7ea4bbd 100644 --- a/v3/src/main/java/com/skyflow/utils/validations/Validations.java +++ b/v3/src/main/java/com/skyflow/utils/validations/Validations.java @@ -1,9 +1,121 @@ package com.skyflow.utils.validations; +import com.skyflow.enums.InterfaceName; +import com.skyflow.errors.ErrorCode; +import com.skyflow.errors.ErrorMessage; +import com.skyflow.errors.SkyflowException; +import com.skyflow.logs.ErrorLogs; +import com.skyflow.utils.Utils; +import com.skyflow.utils.logger.LogUtil; +import com.skyflow.vault.data.DetokenizeRequest; +import com.skyflow.vault.data.InsertRequest; +import com.skyflow.vault.data.TokenGroupRedactions; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + public class Validations extends BaseValidations { private Validations() { super(); } // add validations specific to v3 SDK + public static void validateInsertRequest(InsertRequest insertRequest) throws SkyflowException { + String table = insertRequest.getTable(); + ArrayList> values = insertRequest.getValues(); + List upsert = insertRequest.getUpsert(); + + if (table == null) { + LogUtil.printErrorLog(Utils.parameterizedString( + ErrorLogs.TABLE_IS_REQUIRED.getLog(), InterfaceName.INSERT.getName() + )); + throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.TableKeyError.getMessage()); + } else if (table.trim().isEmpty()) { + LogUtil.printErrorLog(Utils.parameterizedString( + ErrorLogs.EMPTY_TABLE_NAME.getLog(), InterfaceName.INSERT.getName() + )); + throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyTable.getMessage()); + } else if (values == null) { + LogUtil.printErrorLog(Utils.parameterizedString( + ErrorLogs.VALUES_IS_REQUIRED.getLog(), InterfaceName.INSERT.getName() + )); + throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.ValuesKeyError.getMessage()); + } else if (values.isEmpty()) { + LogUtil.printErrorLog(Utils.parameterizedString( + ErrorLogs.EMPTY_VALUES.getLog(), InterfaceName.INSERT.getName() + )); + throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyValues.getMessage()); + } else if (upsert != null && upsert.isEmpty()){ + LogUtil.printErrorLog(Utils.parameterizedString( + ErrorLogs.EMPTY_UPSERT.getLog(), InterfaceName.INSERT.getName() + )); + } + // upsert + + for (HashMap valuesMap : values) { + for (String key : valuesMap.keySet()) { + if (key == null || key.trim().isEmpty()) { + LogUtil.printErrorLog(Utils.parameterizedString( + ErrorLogs.EMPTY_OR_NULL_KEY_IN_VALUES.getLog(), InterfaceName.INSERT.getName() + )); + throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyKeyInValues.getMessage()); + } else { + Object value = valuesMap.get(key); + if (value == null || value.toString().trim().isEmpty()) { + LogUtil.printErrorLog(Utils.parameterizedString( + ErrorLogs.EMPTY_OR_NULL_VALUE_IN_VALUES.getLog(), + InterfaceName.INSERT.getName(), key + )); + throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyValueInValues.getMessage()); + } + } + } + } + } + + public static void validateDetokenizeRequest(DetokenizeRequest request) throws SkyflowException { + if (request == null) { + LogUtil.printErrorLog(Utils.parameterizedString( + ErrorLogs.DETOKENIZE_REQUEST_NULL.getLog(), InterfaceName.DETOKENIZE.getName() + )); + throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.DetokenizeRequestNull.getMessage()); + } + List tokens = request.getTokens(); + if (tokens == null || tokens.isEmpty()) { + LogUtil.printErrorLog(Utils.parameterizedString( + ErrorLogs.EMPTY_DETOKENIZE_DATA.getLog(), InterfaceName.DETOKENIZE.getName() + )); + throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyDetokenizeData.getMessage()); + } + for (String token : tokens) { + if (token == null || token.trim().isEmpty()) { + LogUtil.printErrorLog(Utils.parameterizedString( + ErrorLogs.EMPTY_OR_NULL_TOKEN_IN_DETOKENIZE_DATA.getLog(), InterfaceName.DETOKENIZE.getName() + )); + throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyTokenInDetokenizeData.getMessage()); + } + } + List groupRedactions = request.getTokenGroupRedactions(); + if (groupRedactions != null && !groupRedactions.isEmpty()) { + for (TokenGroupRedactions group : groupRedactions) { + if (group == null) { + LogUtil.printErrorLog(Utils.parameterizedString(ErrorLogs.NULL_TOKEN_REDACTION_GROUP_OBJECT.getLog(), InterfaceName.DETOKENIZE.getName())); + throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.NullTokenGroupRedactions.getMessage()); + } + String groupName = group.getTokenGroupName(); + String redaction = group.getRedaction(); + if (groupName == null || groupName.trim().isEmpty()) { + LogUtil.printErrorLog(Utils.parameterizedString(ErrorLogs.NULL_TOKEN_GROUP_NAME_IN_TOKEN_GROUP.getLog(), InterfaceName.DETOKENIZE.getName())); + throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.NullTokenGroupNameInTokenGroup.getMessage()); + } + if (redaction == null || redaction.trim().isEmpty()) { + LogUtil.printErrorLog(Utils.parameterizedString(ErrorLogs.EMPTY_OR_NULL_REDACTION_IN_TOKEN_GROUP.getLog(), InterfaceName.DETOKENIZE.getName())); + throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.NullRedactionInTokenGroup.getMessage()); + } + } + } + + } + } diff --git a/v3/src/main/java/com/skyflow/vault/controller/VaultController.java b/v3/src/main/java/com/skyflow/vault/controller/VaultController.java index b5181f07..0ac80f4a 100644 --- a/v3/src/main/java/com/skyflow/vault/controller/VaultController.java +++ b/v3/src/main/java/com/skyflow/vault/controller/VaultController.java @@ -5,30 +5,410 @@ import com.skyflow.VaultClient; import com.skyflow.config.Credentials; import com.skyflow.config.VaultConfig; +import com.skyflow.errors.SkyflowException; +import com.skyflow.generated.rest.core.ApiClientApiException; +import com.skyflow.generated.rest.types.InsertRecordData; import com.skyflow.generated.rest.types.InsertResponse; +import com.skyflow.logs.ErrorLogs; import com.skyflow.logs.InfoLogs; +import com.skyflow.logs.WarningLogs; +import com.skyflow.utils.Constants; +import com.skyflow.utils.Utils; import com.skyflow.utils.logger.LogUtil; -import com.skyflow.vault.RequestOptions; -import com.skyflow.vault.data.BaseInsertRequest; +import com.skyflow.utils.validations.Validations; +import com.skyflow.vault.data.*; +import io.github.cdimascio.dotenv.Dotenv; -import java.util.concurrent.CompletableFuture; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.concurrent.*; + +import static com.skyflow.utils.Utils.*; public final class VaultController extends VaultClient { private static final Gson gson = new GsonBuilder().serializeNulls().create(); + private int insertBatchSize; + private int insertConcurrencyLimit; + private int detokenizeBatchSize; + private int detokenizeConcurrencyLimit; public VaultController(VaultConfig vaultConfig, Credentials credentials) { super(vaultConfig, credentials); + this.insertBatchSize = Constants.INSERT_BATCH_SIZE; + this.insertConcurrencyLimit = Constants.INSERT_CONCURRENCY_LIMIT; + this.detokenizeBatchSize = Constants.DETOKENIZE_BATCH_SIZE; + this.detokenizeConcurrencyLimit = Constants.DETOKENIZE_CONCURRENCY_LIMIT; + } + + public com.skyflow.vault.data.InsertResponse bulkInsert(InsertRequest insertRequest) throws SkyflowException { + com.skyflow.vault.data.InsertResponse response; + LogUtil.printInfoLog(InfoLogs.INSERT_TRIGGERED.getLog()); + try { + LogUtil.printInfoLog(InfoLogs.VALIDATE_INSERT_REQUEST.getLog()); + Validations.validateInsertRequest(insertRequest); + configureInsertConcurrencyAndBatchSize(insertRequest.getValues().size()); + + setBearerToken(); + com.skyflow.generated.rest.resources.recordservice.requests.InsertRequest request = super.getBulkInsertRequestBody(insertRequest, super.getVaultConfig()); + + response = this.processSync(request, insertRequest.getValues()); + return response; + } catch (ApiClientApiException e) { + String bodyString = gson.toJson(e.body()); + LogUtil.printErrorLog(ErrorLogs.INSERT_RECORDS_REJECTED.getLog()); + throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString); + } catch (ExecutionException | InterruptedException e) { + LogUtil.printErrorLog(ErrorLogs.INSERT_RECORDS_REJECTED.getLog()); + throw new SkyflowException(e.getMessage()); + } } - // add methods for v3 SDK - public InsertResponse bulkInsert(BaseInsertRequest insertRequest, RequestOptions requestOptions) { - InsertResponse response = null; + public CompletableFuture bulkInsertAsync(InsertRequest insertRequest) throws SkyflowException { LogUtil.printInfoLog(InfoLogs.INSERT_TRIGGERED.getLog()); + try { + LogUtil.printInfoLog(InfoLogs.VALIDATE_INSERT_REQUEST.getLog()); + Validations.validateInsertRequest(insertRequest); + configureInsertConcurrencyAndBatchSize(insertRequest.getValues().size()); + + setBearerToken(); + com.skyflow.generated.rest.resources.recordservice.requests.InsertRequest request = super.getBulkInsertRequestBody(insertRequest, super.getVaultConfig()); + List errorRecords = Collections.synchronizedList(new ArrayList<>()); + List> futures = this.insertBatchFutures(request, errorRecords); + + return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])) + .thenApply(v -> { + List successRecords = new ArrayList<>(); +// List errorRecords = new ArrayList<>(); + + for (CompletableFuture future : futures) { + com.skyflow.vault.data.InsertResponse futureResponse = future.join(); + if (futureResponse != null) { + if (futureResponse.getSuccess() != null) { + successRecords.addAll(futureResponse.getSuccess()); + } + if (futureResponse.getErrors() != null) { + errorRecords.addAll(futureResponse.getErrors()); + } + } + } + + return new com.skyflow.vault.data.InsertResponse(successRecords, errorRecords, insertRequest.getValues()); + }); + } catch (ApiClientApiException e) { + String bodyString = gson.toJson(e.body()); + LogUtil.printErrorLog(ErrorLogs.INSERT_RECORDS_REJECTED.getLog()); + throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString); + } + } + + public DetokenizeResponse bulkDetokenize(DetokenizeRequest detokenizeRequest) throws SkyflowException { + LogUtil.printInfoLog(InfoLogs.DETOKENIZE_TRIGGERED.getLog()); + try { + DetokenizeResponse response; + configureDetokenizeConcurrencyAndBatchSize(detokenizeRequest.getTokens().size()); + LogUtil.printInfoLog(InfoLogs.VALIDATE_DETOKENIZE_REQUEST.getLog()); + Validations.validateDetokenizeRequest(detokenizeRequest); + setBearerToken(); + com.skyflow.generated.rest.resources.recordservice.requests.DetokenizeRequest request = super.getDetokenizeRequestBody(detokenizeRequest); + + response = this.processDetokenizeSync(request, detokenizeRequest.getTokens()); + return response; + } catch (ApiClientApiException e) { + String bodyString = gson.toJson(e.body()); + LogUtil.printErrorLog(ErrorLogs.DETOKENIZE_REQUEST_REJECTED.getLog()); + throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString); + } catch (ExecutionException | InterruptedException e) { + LogUtil.printErrorLog(ErrorLogs.DETOKENIZE_REQUEST_REJECTED.getLog()); + throw new SkyflowException(e.getMessage()); + } + } + + public CompletableFuture bulkDetokenizeAsync(DetokenizeRequest detokenizeRequest) throws SkyflowException{ + LogUtil.printInfoLog(InfoLogs.DETOKENIZE_TRIGGERED.getLog()); + ExecutorService executor = Executors.newFixedThreadPool(detokenizeConcurrencyLimit); + try { + configureDetokenizeConcurrencyAndBatchSize(detokenizeRequest.getTokens().size()); + LogUtil.printInfoLog(InfoLogs.VALIDATE_DETOKENIZE_REQUEST.getLog()); + Validations.validateDetokenizeRequest(detokenizeRequest); + setBearerToken(); + com.skyflow.generated.rest.resources.recordservice.requests.DetokenizeRequest request = super.getDetokenizeRequestBody(detokenizeRequest); + + LogUtil.printInfoLog(InfoLogs.PROCESSING_BATCHES.getLog()); + + List errorTokens = Collections.synchronizedList(new ArrayList<>()); + List successRecords = new ArrayList<>(); + + // Create batches + List batches = Utils.createDetokenizeBatches(request, detokenizeBatchSize); + + List> futures = this.detokenizeBatchFutures(executor, batches, errorTokens); + return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])) + .thenApply(v -> { + for (CompletableFuture future : futures) { + DetokenizeResponse futureResponse = future.join(); + if (futureResponse != null) { + if (futureResponse.getSuccess() != null) { + successRecords.addAll(futureResponse.getSuccess()); + } + if (futureResponse.getErrors() != null) { + errorTokens.addAll(futureResponse.getErrors()); + } + } + } + LogUtil.printInfoLog(InfoLogs.DETOKENIZE_REQUEST_RESOLVED.getLog()); + executor.shutdown(); + return new DetokenizeResponse(successRecords, errorTokens, detokenizeRequest.getTokens()); + }); + } catch (Exception e){ + LogUtil.printErrorLog(ErrorLogs.DETOKENIZE_REQUEST_REJECTED.getLog()); + throw new SkyflowException(e.getMessage()); + } finally { + executor.shutdown(); + } + } + private com.skyflow.vault.data.InsertResponse processSync( + com.skyflow.generated.rest.resources.recordservice.requests.InsertRequest insertRequest, + ArrayList> originalPayload + ) throws ExecutionException, InterruptedException { + LogUtil.printInfoLog(InfoLogs.PROCESSING_BATCHES.getLog()); + List successRecords = new ArrayList<>(); + List errorRecords = Collections.synchronizedList(new ArrayList<>()); + List> futures = this.insertBatchFutures(insertRequest, errorRecords); + + CompletableFuture allFutures = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])); + allFutures.join(); + + for (CompletableFuture future : futures) { + com.skyflow.vault.data.InsertResponse futureResponse = future.get(); + if (futureResponse != null) { + if (futureResponse.getSuccess() != null) { + successRecords.addAll(futureResponse.getSuccess()); + } + if (futureResponse.getErrors() != null) { + errorRecords.addAll(futureResponse.getErrors()); + } + } + } + com.skyflow.vault.data.InsertResponse response = new com.skyflow.vault.data.InsertResponse(successRecords, errorRecords, originalPayload); + LogUtil.printInfoLog(InfoLogs.INSERT_REQUEST_RESOLVED.getLog()); return response; } - public CompletableFuture bulkInsertAsync(BaseInsertRequest insertRequest, RequestOptions requestOptions){ - CompletableFuture future = null; - return future; + private DetokenizeResponse processDetokenizeSync( + com.skyflow.generated.rest.resources.recordservice.requests.DetokenizeRequest detokenizeRequest, + List originalTokens + ) throws ExecutionException, InterruptedException, SkyflowException { + LogUtil.printInfoLog(InfoLogs.PROCESSING_BATCHES.getLog()); + List errorTokens = Collections.synchronizedList(new ArrayList<>()); + List successTokens = new ArrayList<>(); + ExecutorService executor = Executors.newFixedThreadPool(detokenizeConcurrencyLimit); + List batches = Utils.createDetokenizeBatches(detokenizeRequest, detokenizeBatchSize); + try { + List> futures = this.detokenizeBatchFutures(executor, batches, errorTokens); + try{ + + CompletableFuture allFutures = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])); + allFutures.join(); + } catch (Exception e){ + } + for (CompletableFuture future : futures) { + DetokenizeResponse futureResponse = future.get(); + if (futureResponse != null) { + if (futureResponse.getSuccess() != null) { + successTokens.addAll(futureResponse.getSuccess()); + } + if (futureResponse.getErrors() != null) { + errorTokens.addAll(futureResponse.getErrors()); + } + } + } + } catch (Exception e){ + LogUtil.printErrorLog(ErrorLogs.DETOKENIZE_REQUEST_REJECTED.getLog()); + throw new SkyflowException(e.getMessage()); + } finally { + executor.shutdown(); + } + DetokenizeResponse response = new DetokenizeResponse(successTokens, errorTokens, originalTokens); + LogUtil.printInfoLog(InfoLogs.DETOKENIZE_REQUEST_RESOLVED.getLog()); + return response; } -} + + private List> detokenizeBatchFutures(ExecutorService executor, List batches, List errorTokens) { + List> futures = new ArrayList<>(); + try { + + for (int batchIndex = 0; batchIndex < batches.size(); batchIndex++) { + com.skyflow.generated.rest.resources.recordservice.requests.DetokenizeRequest batch = batches.get(batchIndex); + int batchNumber = batchIndex; + CompletableFuture future = CompletableFuture + .supplyAsync(() -> processDetokenizeBatch(batch), executor) + .thenApply(response -> formatDetokenizeResponse(response, batchNumber, detokenizeBatchSize)) + .exceptionally(ex -> { + errorTokens.addAll(handleDetokenizeBatchException(ex, batch, batchNumber, detokenizeBatchSize)); + return null; + }); + futures.add(future); + } + } catch (Exception e){ + ErrorRecord errorRecord = new ErrorRecord(0, e.getMessage(), 500); + errorTokens.add(errorRecord); + } + return futures; + } + private com.skyflow.generated.rest.types.DetokenizeResponse processDetokenizeBatch(com.skyflow.generated.rest.resources.recordservice.requests.DetokenizeRequest batch) { + return this.getRecordsApi().detokenize(batch); + } + + private List> + insertBatchFutures( + com.skyflow.generated.rest.resources.recordservice.requests.InsertRequest insertRequest, + List errorRecords) { + List records = insertRequest.getRecords().get(); + + ExecutorService executor = Executors.newFixedThreadPool(insertConcurrencyLimit); + List> batches = Utils.createBatches(records, insertBatchSize); + List> futures = new ArrayList<>(); + + try { + for (int batchIndex = 0; batchIndex < batches.size(); batchIndex++) { + List batch = batches.get(batchIndex); + int batchNumber = batchIndex; + CompletableFuture future = CompletableFuture + .supplyAsync(() -> insertBatch(batch, insertRequest.getTableName().get()), executor) + .thenApply(response -> formatResponse(response, batchNumber, insertBatchSize)) + .exceptionally(ex -> { + errorRecords.addAll(handleBatchException(ex, batch, batchNumber)); + return null; + }); + futures.add(future); + } + } finally { + executor.shutdown(); + } + return futures; + } + + private InsertResponse insertBatch(List batch, String tableName) { + com.skyflow.generated.rest.resources.recordservice.requests.InsertRequest req = com.skyflow.generated.rest.resources.recordservice.requests.InsertRequest.builder() + .vaultId(this.getVaultConfig().getVaultId()) + .tableName(tableName) + .records(batch) + .build(); + return this.getRecordsApi().insert(req); + } + + private void configureInsertConcurrencyAndBatchSize(int totalRequests) { + try { + Dotenv dotenv = Dotenv.load(); + String userProvidedBatchSize = dotenv.get("INSERT_BATCH_SIZE"); + String userProvidedConcurrencyLimit = dotenv.get("INSERT_CONCURRENCY_LIMIT"); + + if (userProvidedBatchSize != null) { + try { + int batchSize = Integer.parseInt(userProvidedBatchSize); + if (batchSize > Constants.MAX_INSERT_BATCH_SIZE) { + LogUtil.printWarningLog(WarningLogs.BATCH_SIZE_EXCEEDS_MAX_LIMIT.getLog()); + } + int maxBatchSize = Math.min(batchSize, Constants.MAX_INSERT_BATCH_SIZE); + if (maxBatchSize > 0) { + this.insertBatchSize = maxBatchSize; + } else { + LogUtil.printWarningLog(WarningLogs.INVALID_BATCH_SIZE_PROVIDED.getLog()); + this.insertBatchSize = Constants.INSERT_BATCH_SIZE; + } + } catch (NumberFormatException e) { + LogUtil.printWarningLog(WarningLogs.INVALID_BATCH_SIZE_PROVIDED.getLog()); + this.insertBatchSize = Constants.INSERT_BATCH_SIZE; + } + } + + // Max no of threads required to run all batches concurrently at once + int maxConcurrencyNeeded = (totalRequests + this.insertBatchSize - 1) / this.insertBatchSize; + + if (userProvidedConcurrencyLimit != null) { + try { + int concurrencyLimit = Integer.parseInt(userProvidedConcurrencyLimit); + int maxConcurrencyLimit = Math.min(concurrencyLimit, Constants.MAX_INSERT_CONCURRENCY_LIMIT); + if (concurrencyLimit > Constants.MAX_INSERT_CONCURRENCY_LIMIT) { + LogUtil.printWarningLog(WarningLogs.CONCURRENCY_EXCEEDS_MAX_LIMIT.getLog()); + } + if (maxConcurrencyLimit > 0) { + this.insertConcurrencyLimit = Math.min(maxConcurrencyLimit, maxConcurrencyNeeded); + } else { + LogUtil.printWarningLog(WarningLogs.INVALID_CONCURRENCY_LIMIT_PROVIDED.getLog()); + this.insertConcurrencyLimit = Math.min(Constants.INSERT_CONCURRENCY_LIMIT, maxConcurrencyNeeded); + } + } catch (NumberFormatException e) { + LogUtil.printWarningLog(WarningLogs.INVALID_CONCURRENCY_LIMIT_PROVIDED.getLog()); + this.insertConcurrencyLimit = Math.min(Constants.INSERT_CONCURRENCY_LIMIT, maxConcurrencyNeeded); + } + } else { + this.insertConcurrencyLimit = Math.min(Constants.INSERT_CONCURRENCY_LIMIT, maxConcurrencyNeeded); + } + } catch (Exception e) { + this.insertBatchSize = Constants.INSERT_BATCH_SIZE; + int maxConcurrencyNeeded = (totalRequests + this.insertBatchSize - 1) / this.insertBatchSize; + this.insertConcurrencyLimit = Math.min(Constants.INSERT_CONCURRENCY_LIMIT, maxConcurrencyNeeded); + } + } + + + private void configureDetokenizeConcurrencyAndBatchSize(int totalRequests) { + try { + Dotenv dotenv = Dotenv.load(); + String userProvidedBatchSize = dotenv.get("DETOKENIZE_BATCH_SIZE"); + String userProvidedConcurrencyLimit = dotenv.get("DETOKENIZE_CONCURRENCY_LIMIT"); + + if (userProvidedBatchSize != null) { + try { + int batchSize = Integer.parseInt(userProvidedBatchSize); + if (batchSize > Constants.MAX_DETOKENIZE_BATCH_SIZE) { + LogUtil.printWarningLog(WarningLogs.BATCH_SIZE_EXCEEDS_MAX_LIMIT.getLog()); + } + int maxBatchSize = Math.min(batchSize, Constants.MAX_DETOKENIZE_BATCH_SIZE); + if (maxBatchSize > 0) { + this.detokenizeBatchSize = maxBatchSize; + } else { + LogUtil.printWarningLog(WarningLogs.INVALID_BATCH_SIZE_PROVIDED.getLog()); + this.detokenizeBatchSize = Constants.DETOKENIZE_BATCH_SIZE; + } + } catch (NumberFormatException e) { + LogUtil.printWarningLog(WarningLogs.INVALID_BATCH_SIZE_PROVIDED.getLog()); + this.detokenizeBatchSize = Constants.DETOKENIZE_BATCH_SIZE; + } + } + + // Max no of threads required to run all batches concurrently at once + int maxConcurrencyNeeded = (totalRequests + this.detokenizeBatchSize - 1) / this.detokenizeBatchSize; + + if (userProvidedConcurrencyLimit != null) { + try { + int concurrencyLimit = Integer.parseInt(userProvidedConcurrencyLimit); + if (concurrencyLimit > Constants.MAX_DETOKENIZE_CONCURRENCY_LIMIT) { + LogUtil.printWarningLog(WarningLogs.CONCURRENCY_EXCEEDS_MAX_LIMIT.getLog()); + } + int maxConcurrencyLimit = Math.min(concurrencyLimit, Constants.MAX_DETOKENIZE_CONCURRENCY_LIMIT); + + if (maxConcurrencyLimit > 0) { + this.detokenizeConcurrencyLimit = Math.min(maxConcurrencyLimit, maxConcurrencyNeeded); + } else { + LogUtil.printWarningLog(WarningLogs.INVALID_CONCURRENCY_LIMIT_PROVIDED.getLog()); + this.detokenizeConcurrencyLimit = Math.min(Constants.DETOKENIZE_CONCURRENCY_LIMIT, maxConcurrencyNeeded); + } + } catch (NumberFormatException e) { + LogUtil.printWarningLog(WarningLogs.INVALID_CONCURRENCY_LIMIT_PROVIDED.getLog()); + this.detokenizeConcurrencyLimit = Math.min(Constants.DETOKENIZE_CONCURRENCY_LIMIT, maxConcurrencyNeeded); + } + } else { + this.detokenizeConcurrencyLimit = Math.min(Constants.DETOKENIZE_CONCURRENCY_LIMIT, maxConcurrencyNeeded); + } + } catch (Exception e) { + this.detokenizeBatchSize = Constants.DETOKENIZE_BATCH_SIZE; + int maxConcurrencyNeeded = (totalRequests + this.detokenizeBatchSize - 1) / this.detokenizeBatchSize; + this.detokenizeConcurrencyLimit = Math.min(Constants.DETOKENIZE_CONCURRENCY_LIMIT, maxConcurrencyNeeded); + } + } + +} \ No newline at end of file diff --git a/v3/src/main/java/com/skyflow/vault/data/DetokenizeRequest.java b/v3/src/main/java/com/skyflow/vault/data/DetokenizeRequest.java new file mode 100644 index 00000000..93ba8b9b --- /dev/null +++ b/v3/src/main/java/com/skyflow/vault/data/DetokenizeRequest.java @@ -0,0 +1,42 @@ +package com.skyflow.vault.data; + +import java.util.ArrayList; +import java.util.List; + +public class DetokenizeRequest { + private final DetokenizeRequestBuilder builder; + private DetokenizeRequest(DetokenizeRequestBuilder builder){ + this.builder = builder; + } + + public static DetokenizeRequestBuilder builder(){ + return new DetokenizeRequestBuilder(); + } + public List getTokens(){ + return this.builder.tokens; + } + public List getTokenGroupRedactions(){ + return this.builder.tokenGroupRedactions; + } + + public static final class DetokenizeRequestBuilder{ + private List tokens; + + private List tokenGroupRedactions; + + public DetokenizeRequestBuilder tokens(List tokens){ + this.tokens = tokens; + return this; + } + public DetokenizeRequestBuilder tokenGroupRedactions(List tokenGroupRedactions){ + this.tokenGroupRedactions = tokenGroupRedactions; + return this; + } + public DetokenizeRequest build(){ + return new DetokenizeRequest(this); + } + + + } + +} diff --git a/v3/src/main/java/com/skyflow/vault/data/DetokenizeResponse.java b/v3/src/main/java/com/skyflow/vault/data/DetokenizeResponse.java new file mode 100644 index 00000000..b00817db --- /dev/null +++ b/v3/src/main/java/com/skyflow/vault/data/DetokenizeResponse.java @@ -0,0 +1,63 @@ +package com.skyflow.vault.data; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.annotations.Expose; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +public class DetokenizeResponse { + @Expose(serialize = true) + private List success; + @Expose(serialize = true) + private DetokenizeSummary summary; + + @Expose(serialize = true) + private List errors; + + private List originalPayload; + private List tokensToRetry; + + public DetokenizeResponse(List success, List errors) { + this.success = success; + this.summary = summary; + this.errors = errors; + } + + public DetokenizeResponse(List success, List errors, List originalPayload) { + this.success = success; + this.errors = errors; + this.originalPayload = originalPayload; + this.summary = new DetokenizeSummary(this.originalPayload.size(), this.success.size(), this.errors.size()); + } + + public List getTokensToRetry() { + if (tokensToRetry == null) { + tokensToRetry = new ArrayList<>(); + tokensToRetry = errors.stream() + .filter(error -> (error.getCode() >= 500 && error.getCode() <= 599) && error.getCode() != 529) + .map(errorRecord -> originalPayload.get(errorRecord.getIndex())) + .collect(Collectors.toList()); + } + return tokensToRetry; + } + + public List getSuccess() { + return success; + } + public DetokenizeSummary getSummary() { + return this.summary; + } + + public List getErrors() { + return this.errors; + } + @Override + public String toString() { + Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); + return gson.toJson(this); + } + +} diff --git a/v3/src/main/java/com/skyflow/vault/data/DetokenizeResponseObject.java b/v3/src/main/java/com/skyflow/vault/data/DetokenizeResponseObject.java new file mode 100644 index 00000000..f45e2724 --- /dev/null +++ b/v3/src/main/java/com/skyflow/vault/data/DetokenizeResponseObject.java @@ -0,0 +1,63 @@ +package com.skyflow.vault.data; + +import com.google.gson.Gson; +import com.google.gson.annotations.Expose; + +import java.util.Map; + +public class DetokenizeResponseObject { + @Expose(serialize = true) + private String token; + @Expose(serialize = true) + private Object value; + @Expose(serialize = true) + private String tokenGroupName; + @Expose(serialize = true) + private String error; + + @Expose(serialize = true) + private int index; + + @Expose(serialize = true) + private Map metadata; + + public DetokenizeResponseObject(int index, String token, Object value, String tokenGroupName, String error, Map metadata) { + this.token = token; + this.value = value; + this.tokenGroupName = tokenGroupName; + this.error = error; + this.metadata = metadata; + this.index = index; + } + + public String getToken() { + return token; + } + + public Object getValue() { + return value; + } + + public String getTokenGroupName() { + return tokenGroupName; + } + + public String getError() { + return error; + } + + public int getIndex() { + return index; + } + + public Map getMetadata() { + return metadata; + } + + @Override + public String toString() { + Gson gson = new Gson(); + return gson.toJson(this); + } + +} diff --git a/v3/src/main/java/com/skyflow/vault/data/DetokenizeSummary.java b/v3/src/main/java/com/skyflow/vault/data/DetokenizeSummary.java new file mode 100644 index 00000000..c86c1854 --- /dev/null +++ b/v3/src/main/java/com/skyflow/vault/data/DetokenizeSummary.java @@ -0,0 +1,40 @@ +package com.skyflow.vault.data; + +import com.google.gson.Gson; +import com.google.gson.annotations.Expose; + +public class DetokenizeSummary { + @Expose(serialize = true) + private int totalTokens; + @Expose(serialize = true) + private int totalDetokenized; + @Expose(serialize = true) + private int totalFailed; + + public DetokenizeSummary() { + } + + public DetokenizeSummary(int totalTokens, int totalDetokenized, int totalFailed) { + this.totalTokens = totalTokens; + this.totalDetokenized = totalDetokenized; + this.totalFailed = totalFailed; + } + + public int getTotalTokens() { + return totalTokens; + } + + public int getTotalDetokenized() { + return totalDetokenized; + } + + public int getTotalFailed() { + return totalFailed; + } + + @Override + public String toString() { + Gson gson = new Gson(); + return gson.toJson(this); + } +} diff --git a/v3/src/main/java/com/skyflow/vault/data/ErrorRecord.java b/v3/src/main/java/com/skyflow/vault/data/ErrorRecord.java new file mode 100644 index 00000000..9044f189 --- /dev/null +++ b/v3/src/main/java/com/skyflow/vault/data/ErrorRecord.java @@ -0,0 +1,39 @@ +package com.skyflow.vault.data; + +import com.google.gson.Gson; +import com.google.gson.annotations.Expose; + +public class ErrorRecord { + @Expose(serialize = true) + private int index; + @Expose(serialize = true) + private String error; + @Expose(serialize = true) + private int code; +// public ErrorRecord() { +// } + + public ErrorRecord(int index, String error, int code) { + this.index = index; + this.error = error; + this.code = code; + } + public String getError() { + return error; + } + + public int getCode() { + return code; + } + + public int getIndex() { + return index; + } + + + @Override + public String toString() { + Gson gson = new Gson(); + return gson.toJson(this); + } +} \ No newline at end of file diff --git a/v3/src/main/java/com/skyflow/vault/data/InsertRequest.java b/v3/src/main/java/com/skyflow/vault/data/InsertRequest.java new file mode 100644 index 00000000..732df960 --- /dev/null +++ b/v3/src/main/java/com/skyflow/vault/data/InsertRequest.java @@ -0,0 +1,64 @@ +package com.skyflow.vault.data; + +import com.skyflow.enums.UpdateType; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class InsertRequest extends BaseInsertRequest { + private final InsertRequestBuilder builder; + + private InsertRequest(InsertRequestBuilder builder) { + super(builder); + this.builder = builder; + } + + public static InsertRequestBuilder builder() { + return new InsertRequestBuilder(); + } + + public List getUpsert() { + return this.builder.upsert; + } + + public UpdateType getUpsertType() { + return this.builder.upsertType; + } + + public static final class InsertRequestBuilder extends BaseInsertRequestBuilder { + private List upsert; + + private UpdateType upsertType; + + private InsertRequestBuilder() { + super(); + } + + @Override + public InsertRequestBuilder table(String table) { + super.table(table); + return this; + } + + @Override + public InsertRequestBuilder values(ArrayList> values) { + super.values(values); + return this; + } + + public InsertRequestBuilder upsert(List upsert) { + this.upsert = upsert; + return this; + } + + public InsertRequestBuilder upsertType(UpdateType upsertType) { + this.upsertType = upsertType; + return this; + } + + public InsertRequest build() { + return new InsertRequest(this); + } + } +} diff --git a/v3/src/main/java/com/skyflow/vault/data/InsertResponse.java b/v3/src/main/java/com/skyflow/vault/data/InsertResponse.java new file mode 100644 index 00000000..a84e121c --- /dev/null +++ b/v3/src/main/java/com/skyflow/vault/data/InsertResponse.java @@ -0,0 +1,69 @@ +package com.skyflow.vault.data; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.annotations.Expose; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.stream.Collectors; + +public class InsertResponse { + // These members will be included in the toString() output + @Expose(serialize = true) + private Summary summary; + @Expose(serialize = true) + private List success; + @Expose(serialize = true) + private List errors; + + // Internal fields. Should not be included in toString() output + private ArrayList> originalPayload; + private ArrayList> recordsToRetry; + + public InsertResponse(List successRecords, List errorRecords) { + this.success = successRecords; + this.errors = errorRecords; + } + + public InsertResponse( + List successRecords, + List errorRecords, + ArrayList> originalPayload + ) { + this.success = successRecords; + this.errors = errorRecords; + this.originalPayload = originalPayload; + this.summary = new Summary(this.originalPayload.size(), this.success.size(), this.errors.size()); + } + + public Summary getSummary() { + return this.summary; + } + + public List getSuccess() { + return this.success; + } + + public List getErrors() { + return this.errors; + } + + public ArrayList> getRecordsToRetry() { + if (recordsToRetry == null) { + recordsToRetry = new ArrayList<>(); + recordsToRetry = errors.stream() + .filter(error -> (error.getCode() >= 500 && error.getCode() <= 599) && error.getCode() != 529) + .map(errorRecord -> originalPayload.get(errorRecord.getIndex())) + .collect(Collectors.toCollection(ArrayList::new)); + } + return recordsToRetry; + } + + @Override + public String toString() { + Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); + return gson.toJson(this); + } +} \ No newline at end of file diff --git a/v3/src/main/java/com/skyflow/vault/data/Success.java b/v3/src/main/java/com/skyflow/vault/data/Success.java new file mode 100644 index 00000000..db302e6c --- /dev/null +++ b/v3/src/main/java/com/skyflow/vault/data/Success.java @@ -0,0 +1,46 @@ +package com.skyflow.vault.data; +import com.google.gson.Gson; +import com.google.gson.annotations.Expose; + +import java.util.List; +import java.util.Map; + +public class Success { + @Expose(serialize = true) + private int index; + @Expose(serialize = true) + private String skyflow_id; + @Expose(serialize = true) + private Map> tokens; + @Expose(serialize = true) + private Map data; + + public int getIndex() { + return index; + } + + public Success(int index, String skyflow_id, Map> tokens, Map data) { + this.index = index; + this.skyflow_id = skyflow_id; + this.tokens = tokens; + this.data = data; + } + + public String getSkyflowId() { + return skyflow_id; + } + + public Map> getTokens() { + return tokens; + } + + public Map getData() { + return data; + } + + @Override + public String toString() { + Gson gson = new Gson(); + return gson.toJson(this); + } +} \ No newline at end of file diff --git a/v3/src/main/java/com/skyflow/vault/data/Summary.java b/v3/src/main/java/com/skyflow/vault/data/Summary.java new file mode 100644 index 00000000..c15db6cb --- /dev/null +++ b/v3/src/main/java/com/skyflow/vault/data/Summary.java @@ -0,0 +1,42 @@ +package com.skyflow.vault.data; + +import com.google.gson.Gson; +import com.google.gson.annotations.Expose; + +public class Summary { + @Expose(serialize = true) + private int totalRecords; + @Expose(serialize = true) + private int totalInserted; + @Expose(serialize = true) + private int totalFailed; + + public Summary() { + } + + public Summary(int totalRecords, int totalInserted, int totalFailed) { + this.totalRecords = totalRecords; + this.totalInserted = totalInserted; + this.totalFailed = totalFailed; + } + + public int getTotalRecords() { + return totalRecords; + } + + + public int getTotalInserted() { + return totalInserted; + } + + public int getTotalFailed() { + return totalFailed; + } + + + @Override + public String toString() { + Gson gson = new Gson(); + return gson.toJson(this); + } +} \ No newline at end of file diff --git a/v3/src/main/java/com/skyflow/vault/data/Token.java b/v3/src/main/java/com/skyflow/vault/data/Token.java new file mode 100644 index 00000000..642d62c4 --- /dev/null +++ b/v3/src/main/java/com/skyflow/vault/data/Token.java @@ -0,0 +1,23 @@ +package com.skyflow.vault.data; + +import com.google.gson.annotations.Expose; + +public class Token { + @Expose(serialize = true) + private String token; + @Expose(serialize = true) + private String tokenGroupName; + + public String getToken() { + return token; + } + + public String getTokenGroupName() { + return tokenGroupName; + } + + public Token(String token, String tokenGroupName) { + this.token = token; + this.tokenGroupName = tokenGroupName; + } +} \ No newline at end of file diff --git a/v3/src/main/java/com/skyflow/vault/data/TokenGroupRedactions.java b/v3/src/main/java/com/skyflow/vault/data/TokenGroupRedactions.java new file mode 100644 index 00000000..3f89014c --- /dev/null +++ b/v3/src/main/java/com/skyflow/vault/data/TokenGroupRedactions.java @@ -0,0 +1,39 @@ +package com.skyflow.vault.data; + +public class TokenGroupRedactions { + private final TokenGroupRedactionsBuilder builder; + + private TokenGroupRedactions(TokenGroupRedactionsBuilder builder) { + this.builder = builder; + } + public String getTokenGroupName() { + return this.builder.tokenGroupName; + } + + public String getRedaction() { + return this.builder.redaction; + } + + public static TokenGroupRedactionsBuilder builder() { + return new TokenGroupRedactionsBuilder(); + } + + public static final class TokenGroupRedactionsBuilder { + private String tokenGroupName; + private String redaction; + + public TokenGroupRedactionsBuilder tokenGroupName(String tokenGroupName) { + this.tokenGroupName = tokenGroupName; + return this; + } + + public TokenGroupRedactionsBuilder redaction(String redaction) { + this.redaction = redaction; + return this; + } + + public TokenGroupRedactions build() { + return new TokenGroupRedactions(this); + } + } +} \ No newline at end of file diff --git a/v3/test/java/com/skyflow/utils/UtilsTests.java b/v3/test/java/com/skyflow/utils/UtilsTests.java index 096a4ec6..d3780e83 100644 --- a/v3/test/java/com/skyflow/utils/UtilsTests.java +++ b/v3/test/java/com/skyflow/utils/UtilsTests.java @@ -1,20 +1,129 @@ package com.skyflow.utils; import com.google.gson.JsonObject; +import com.skyflow.config.Credentials; +import com.skyflow.enums.Env; +import com.skyflow.errors.ErrorCode; +import com.skyflow.errors.ErrorMessage; +import com.skyflow.errors.SkyflowException; +import com.skyflow.generated.auth.rest.core.ApiClientApiException; +import com.skyflow.generated.rest.types.InsertRecordData; +import com.skyflow.generated.rest.types.InsertResponse; +import com.skyflow.generated.rest.types.RecordResponseObject; +import com.skyflow.utils.validations.Validations; +import com.skyflow.vault.data.*; import org.junit.Assert; +import org.junit.BeforeClass; import org.junit.Test; +import java.util.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + public class UtilsTests { private static final String INVALID_EXCEPTION_THROWN = "Should not have thrown any exception"; - private static final String EXCEPTION_NOT_THROWN = "Should have thrown an exception"; + private static final String EXCEPTIONNOTTHROWN = "Should have thrown an exception"; + private static String filePath = null; + private static String credentialsString = null; + private static String token = null; + private static String context = null; + private static ArrayList roles = null; + + @BeforeClass + public static void setup() { + filePath = "invalid/file/path/credentials.json"; + credentialsString = "invalid credentials string"; + token = "invalid-token"; + context = "testcontext"; + roles = new ArrayList<>(); + String role = "testrole"; + roles.add(role); + SdkVersion.setSdkPrefix(Constants.SDK_PREFIX); + } + + @Test + public void testGetVaultURL() { + // Test with production environment + String prodUrl = Utils.getVaultURL("abc123", Env.PROD); + Assert.assertEquals( + "https://abc123.skyvault.skyflowapis.com", + prodUrl + ); + + // Test with development environment + String devUrl = Utils.getVaultURL("xyz789", Env.DEV); + Assert.assertEquals( + "https://xyz789.skyvault.skyflowapis.dev", + devUrl + ); + } + @Test(expected = NullPointerException.class) + public void testGetVaultURLWithNullEnv() { + Utils.getVaultURL("abc123", null); + } + + @Test + public void testGetVaultURLWithEmptyClusterId() { + String url = Utils.getVaultURL("", Env.PROD); + Assert.assertEquals( + "https://.skyvault.skyflowapis.com", + url + ); + } + + @Test + public void testGenerateBearerTokenWithCredentialsFile() { + try { + Credentials credentials = new Credentials(); + credentials.setPath(filePath); + credentials.setContext(context); + credentials.setRoles(roles); + Utils.generateBearerToken(credentials); + Assert.fail(EXCEPTIONNOTTHROWN); + } catch (SkyflowException e) { + Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode()); + Assert.assertEquals( + Utils.parameterizedString(ErrorMessage.FileNotFound.getMessage(), filePath), + e.getMessage() + ); + } + } + + @Test + public void testGenerateBearerTokenWithCredentialsString() { + try { + Credentials credentials = new Credentials(); + credentials.setCredentialsString(credentialsString); + credentials.setContext(context); + credentials.setRoles(roles); + Utils.generateBearerToken(credentials); + Assert.fail(EXCEPTIONNOTTHROWN); + } catch (SkyflowException e) { + Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode()); + Assert.assertEquals(ErrorMessage.CredentialsStringInvalidJson.getMessage(), e.getMessage()); + } + } + + @Test + public void testGenerateBearerTokenWithToken() { + try { + Credentials credentials = new Credentials(); + credentials.setToken(token); + credentials.setContext(context); + credentials.setRoles(roles); + String bearerToken = Utils.generateBearerToken(credentials); + Assert.assertEquals(token, bearerToken); + } catch (SkyflowException e) { + Assert.assertEquals(e.getMessage(), ErrorMessage.BearerTokenExpired.getMessage()); + } + } @Test public void testGetMetrics() { try { JsonObject metrics = Utils.getMetrics(); - String sdkVersion = Constants.SDK_VERSION; Assert.assertNotNull(metrics.get(Constants.SDK_METRIC_NAME_VERSION)); - Assert.assertEquals("skyflow-java@" + sdkVersion, metrics.get(Constants.SDK_METRIC_NAME_VERSION).getAsString()); Assert.assertNotNull(metrics.get(Constants.SDK_METRIC_CLIENT_DEVICE_MODEL)); Assert.assertNotNull(metrics.get(Constants.SDK_METRIC_CLIENT_OS_DETAILS)); Assert.assertNotNull(metrics.get(Constants.SDK_METRIC_RUNTIME_DETAILS)); @@ -22,4 +131,698 @@ public void testGetMetrics() { Assert.fail(INVALID_EXCEPTION_THROWN); } } -} + + @Test + public void testGetMetricsWithException() { + try { + System.clearProperty("os.name"); + System.clearProperty("os.version"); + System.clearProperty("java.version"); + + String sdkVersion = Constants.SDK_VERSION; + JsonObject metrics = Utils.getMetrics(); + Assert.assertEquals("skyflow-java@" + sdkVersion, metrics.get(Constants.SDK_METRIC_NAME_VERSION).getAsString()); + Assert.assertEquals("Java@", metrics.get(Constants.SDK_METRIC_RUNTIME_DETAILS).getAsString()); + Assert.assertTrue(metrics.get(Constants.SDK_METRIC_CLIENT_DEVICE_MODEL).getAsString().isEmpty()); + Assert.assertTrue(metrics.get(Constants.SDK_METRIC_CLIENT_OS_DETAILS).getAsString().isEmpty()); + } catch (Exception e) { + Assert.fail(INVALID_EXCEPTION_THROWN); + } + } + + @Test + public void testCreateBatchesMultipleBatches() { + List records = new ArrayList<>(); + for (int i = 0; i < 125; i++) { + records.add(InsertRecordData.builder().build()); + } + List> batches = Utils.createBatches(records, 50); + + Assert.assertEquals(3, batches.size()); + Assert.assertEquals(50, batches.get(0).size()); + Assert.assertEquals(50, batches.get(1).size()); + Assert.assertEquals(25, batches.get(2).size()); + } + + @Test + public void testCreateBatchesWithEmptyList() { + List records = new ArrayList<>(); + List> batches = Utils.createBatches(records, 50); + Assert.assertTrue("Batches should be empty for empty input", batches.isEmpty()); + } + + @Test + public void testCreateBatchesWithSmallerSizeThanBatch() { + List records = new ArrayList<>(); + for (int i = 0; i < 25; i++) { + records.add(InsertRecordData.builder().build()); + } + List> batches = Utils.createBatches(records, 50); + + Assert.assertEquals("Should create single batch", 1, batches.size()); + Assert.assertEquals("Batch should contain all records", 25, batches.get(0).size()); + } + + @Test + public void testCreateBatchesWithExactBatchSize() { + List records = new ArrayList<>(); + for (int i = 0; i < 50; i++) { + records.add(InsertRecordData.builder().build()); + } + List> batches = Utils.createBatches(records, 50); + + Assert.assertEquals("Should create single batch", 1, batches.size()); + Assert.assertEquals("Batch should have exact size", 50, batches.get(0).size()); + } + + @Test + public void testCreateBatchesPreservesOrder() { + List records = new ArrayList<>(); + for (int i = 0; i < 75; i++) { + InsertRecordData record = InsertRecordData.builder() + .data(Optional.of(Collections.singletonMap("id", String.valueOf(i)))) + .build(); + records.add(record); + } + + List> batches = Utils.createBatches(records, 50); + + Assert.assertEquals("Should create two batches", 2, batches.size()); + Assert.assertEquals("First record in first batch should be 0", + "0", batches.get(0).get(0).getData().get().get("id")); + Assert.assertEquals("First record in second batch should be 50", + "50", batches.get(1).get(0).getData().get().get("id")); + } + + @Test(expected = NullPointerException.class) + public void testCreateBatchesWithNullList() { + Utils.createBatches(null, 50); + } + + @Test + public void testCreateErrorRecord() { + Map recordMap = new HashMap<>(); + recordMap.put("error", "Test error"); + recordMap.put("message", "Test message"); + recordMap.put("http_code", 400); + + ErrorRecord error = Utils.createErrorRecord(recordMap, 1); + + Assert.assertEquals(1, error.getIndex()); + Assert.assertEquals("Test error", error.getError()); + Assert.assertEquals(400, error.getCode()); + } + + @Test + public void testHandleBatchExceptionApiClientExceptionWithSingleError() { + List batch = Arrays.asList(InsertRecordData.builder().build(), InsertRecordData.builder().build()); + List> batches = Collections.singletonList(batch); + + Map errorMap = new HashMap<>(); + errorMap.put("error", "Common error"); + errorMap.put("http_code", 403); + + Map responseBody = new HashMap<>(); + responseBody.put("error", errorMap); + + ApiClientApiException apiException = new ApiClientApiException("Forbidden", 403, responseBody); + Exception exception = new Exception("Test exception", apiException); + + List errors = Utils.handleBatchException(exception, batch, 0); + + Assert.assertEquals("Should have errors for all records", 2, errors.size()); + Assert.assertEquals("Error message should be same", "Test exception", errors.get(0).getError()); + Assert.assertEquals("Error code should be same", 500, errors.get(0).getCode()); + Assert.assertEquals("First error index", 0, errors.get(0).getIndex()); + Assert.assertEquals("Second error index", 1, errors.get(1).getIndex()); + } + + @Test + public void testHandleBatchExceptionWithNonApiClientException() { + List batch = Arrays.asList(InsertRecordData.builder().build(), InsertRecordData.builder().build()); + List> batches = Collections.singletonList(batch); + + RuntimeException exception = new RuntimeException("Unexpected error"); + + List errors = Utils.handleBatchException(exception, batch, 0); + + Assert.assertEquals("Should have errors for all records", 2, errors.size()); + Assert.assertEquals("Error message should match", "Unexpected error", errors.get(0).getError()); + Assert.assertEquals("Error code should be 500", 500, errors.get(0).getCode()); + Assert.assertEquals("First error index", 0, errors.get(0).getIndex()); + Assert.assertEquals("Second error index", 1, errors.get(1).getIndex()); + } + + @Test + public void testHandleBatchExceptionWithNonZeroBatchNumber() { + List batch = Arrays.asList(InsertRecordData.builder().build(), InsertRecordData.builder().build()); + List> batches = Arrays.asList(new ArrayList<>(), batch); + + RuntimeException exception = new RuntimeException("Batch error"); + + List errors = Utils.handleBatchException(exception, batch, 1); + + Assert.assertEquals("Should have errors for all records", 2, errors.size()); + Assert.assertEquals("First error index should be offset", 2, errors.get(0).getIndex()); + Assert.assertEquals("Second error index should be offset", 3, errors.get(1).getIndex()); + } + + @Test + public void testHandleBatchExceptionWithNullResponseBody() { + List batch = Arrays.asList(InsertRecordData.builder().build(), InsertRecordData.builder().build()); + List> batches = Collections.singletonList(batch); + + ApiClientApiException apiException = new ApiClientApiException("Bad Request", 400, null); + Exception exception = new Exception("Test exception", apiException); + + List errors = Utils.handleBatchException(exception, batch, 0); + Assert.assertEquals("Should return empty list for null response body", 2, errors.size()); + } + + @Test + public void testFormatResponseWithSuccessAndErrorRecords() { + RecordResponseObject successRecord = RecordResponseObject.builder() + .skyflowId(Optional.of("testId1")) + .error(Optional.empty()) + .build(); + RecordResponseObject errorRecord = RecordResponseObject.builder() + .error(Optional.of("Test error")) + .httpCode(Optional.of(400)) + .build(); + + InsertResponse response = InsertResponse.builder() + .records(Optional.of(Arrays.asList(successRecord, errorRecord))) + .build(); + + com.skyflow.vault.data.InsertResponse result = Utils.formatResponse(response, 0, 50); + + Assert.assertNotNull(result.getSuccess()); + Assert.assertEquals(1, result.getSuccess().size()); + Assert.assertEquals("testId1", result.getSuccess().get(0).getSkyflowId()); + + Assert.assertNotNull(result.getErrors()); + Assert.assertEquals(1, result.getErrors().size()); + Assert.assertEquals("Test error", result.getErrors().get(0).getError()); + Assert.assertEquals(400, result.getErrors().get(0).getCode()); + } + + @Test + public void testFormatResponseWithNullResponse() { + com.skyflow.vault.data.InsertResponse result = Utils.formatResponse(null, 0, 50); + Assert.assertNull(result); + } + + @Test + public void testFormatResponseWithSuccessRecordsOnly() { + RecordResponseObject successRecord1 = RecordResponseObject.builder() + .skyflowId(Optional.of("id1")) + .error(Optional.empty()) + .build(); + RecordResponseObject successRecord2 = RecordResponseObject.builder() + .skyflowId(Optional.of("id2")) + .error(Optional.empty()) + .build(); + + InsertResponse response = InsertResponse.builder() + .records(Optional.of(Arrays.asList(successRecord1, successRecord2))) + .build(); + + com.skyflow.vault.data.InsertResponse result = Utils.formatResponse(response, 0, 50); + + Assert.assertNotNull("Response should not be null", result); + Assert.assertEquals("Should have two success records", 2, result.getSuccess().size()); + Assert.assertEquals("First skyflow ID should match", "id1", result.getSuccess().get(0).getSkyflowId()); + Assert.assertEquals("Second skyflow ID should match", "id2", result.getSuccess().get(1).getSkyflowId()); + Assert.assertTrue("Error list should be empty", result.getErrors().isEmpty()); + } + + @Test + public void testFormatResponseWithErrorRecordsOnly() { + RecordResponseObject errorRecord1 = RecordResponseObject.builder() + .error(Optional.of("Error 1")) + .httpCode(Optional.of(400)) + .build(); + RecordResponseObject errorRecord2 = RecordResponseObject.builder() + .error(Optional.of("Error 2")) + .httpCode(Optional.of(500)) + .build(); + + InsertResponse response = InsertResponse.builder() + .records(Optional.of(Arrays.asList(errorRecord1, errorRecord2))) + .build(); + + com.skyflow.vault.data.InsertResponse result = Utils.formatResponse(response, 0, 50); + + Assert.assertNotNull("Response should not be null", result); + Assert.assertEquals("Should have two error records", 2, result.getErrors().size()); + Assert.assertEquals("First error message should match", "Error 1", result.getErrors().get(0).getError()); + Assert.assertEquals("First error code should match", 400, result.getErrors().get(0).getCode()); + Assert.assertEquals("Second error message should match", "Error 2", result.getErrors().get(1).getError()); + Assert.assertEquals("Second error code should match", 500, result.getErrors().get(1).getCode()); + Assert.assertTrue("Success list should be empty", result.getSuccess().isEmpty()); + } + + @Test + public void testFormatResponseWithBatchOffset() { + RecordResponseObject successRecord = RecordResponseObject.builder() + .skyflowId(Optional.of("id1")) + .error(Optional.empty()) + .build(); + RecordResponseObject errorRecord = RecordResponseObject.builder() + .error(Optional.of("Error")) + .httpCode(Optional.of(400)) + .build(); + + InsertResponse response = InsertResponse.builder() + .records(Optional.of(Arrays.asList(successRecord, errorRecord))) + .build(); + + com.skyflow.vault.data.InsertResponse result = Utils.formatResponse(response, 1, 50); + + Assert.assertNotNull("Response should not be null", result); + Assert.assertEquals("Should have correct index for error record", 51, result.getErrors().get(0).getIndex()); + } + + @Test + public void testFormatResponseWithEmptyRecords() { + InsertResponse response = InsertResponse.builder() + .records(Optional.of(new ArrayList<>())) + .build(); + + com.skyflow.vault.data.InsertResponse result = Utils.formatResponse(response, 0, 50); + + Assert.assertNotNull("Response should not be null", result); + Assert.assertTrue("Success list should be empty", result.getSuccess().isEmpty()); + Assert.assertTrue("Error list should be empty", result.getErrors().isEmpty()); + } + + @Test + public void testFormatResponseWithTokens() { + Map tokens = new HashMap<>(); + tokens.put("field1", "token1"); + tokens.put("field2", "token2"); + + RecordResponseObject successRecord = RecordResponseObject.builder() + .skyflowId(Optional.of("id1")) + .tokens(Optional.of(tokens)) + .error(Optional.empty()) + .build(); + + InsertResponse response = InsertResponse.builder() + .records(Optional.of(Collections.singletonList(successRecord))) + .build(); + + com.skyflow.vault.data.InsertResponse result = Utils.formatResponse(response, 0, 50); + + Assert.assertNotNull("Response should not be null", result); + Assert.assertEquals("Should have one success record", 1, result.getSuccess().size()); + Assert.assertEquals("Skyflow ID should match", "id1", result.getSuccess().get(0).getSkyflowId()); + } + @Test + public void testFormatResponseWithTokenListMapping() { + // Prepare test data + Map tokenData = new HashMap<>(); + List> tokenList = new ArrayList<>(); + Map tokenMap = new HashMap<>(); + tokenMap.put("token", "token123"); + tokenMap.put("tokenGroupName", "group1"); + tokenList.add(tokenMap); + tokenData.put("field1", tokenList); + + // Create success record with tokens + RecordResponseObject successRecord = RecordResponseObject.builder() + .skyflowId(Optional.of("id1")) + .tokens(Optional.of(tokenData)) + .error(Optional.empty()) + .build(); + + // Create response object + InsertResponse response = InsertResponse.builder() + .records(Optional.of(Collections.singletonList(successRecord))) + .build(); + + // Format response + com.skyflow.vault.data.InsertResponse result = Utils.formatResponse(response, 0, 50); + + // Assertions + Assert.assertNotNull("Response should not be null", result); + Assert.assertEquals("Should have one success record", 1, result.getSuccess().size()); + + Success successResult = result.getSuccess().get(0); + Assert.assertEquals("Skyflow ID should match", "id1", successResult.getSkyflowId()); + + Map> tokens = successResult.getTokens(); + Assert.assertNotNull("Tokens map should not be null", tokens); + Assert.assertTrue("Should contain field1", tokens.containsKey("field1")); + + List tokensList = tokens.get("field1"); + Assert.assertEquals("Should have one token", 1, tokensList.size()); + Assert.assertEquals("Token value should match", "token123", tokensList.get(0).getToken()); + Assert.assertEquals("Token group name should match", "group1", tokensList.get(0).getTokenGroupName()); + } + @Test + public void testHandleBatchExceptionWithRecordsInResponseBody() { + // Prepare test data + List batch = Arrays.asList( + InsertRecordData.builder().build(), + InsertRecordData.builder().build() + ); + List> batches = Collections.singletonList(batch); + + // Create nested records with errors + List> recordsList = new ArrayList<>(); + Map record1 = new HashMap<>(); + record1.put("error", "Error 1"); + record1.put("http_code", 400); + Map record2 = new HashMap<>(); + record2.put("error", "Error 2"); + record2.put("http_code", 401); + recordsList.add(record1); + recordsList.add(record2); + + // Create response body + Map responseBody = new HashMap<>(); + responseBody.put("records", recordsList); + + // Create API exception + ApiClientApiException apiException = new ApiClientApiException("Bad Request", 400, responseBody); + Exception exception = new Exception("Test exception", apiException); + + // Test the method + List errors = Utils.handleBatchException(exception, batch, 0); + + // Assertions + Assert.assertNotNull("Errors list should not be null", errors); + Assert.assertEquals("Should have two error records", 2, errors.size()); + + // Verify first error + Assert.assertEquals("First error message should match", "Test exception", errors.get(0).getError()); + Assert.assertEquals("First error code should match", 500, errors.get(0).getCode()); + Assert.assertEquals("First error index should be 0", 0, errors.get(0).getIndex()); + + // Verify second error + Assert.assertEquals("Second error message should match", "Test exception", errors.get(1).getError()); + Assert.assertEquals("Second error code should match", 500, errors.get(1).getCode()); + Assert.assertEquals("Second error index should be 1", 1, errors.get(1).getIndex()); + } + + @Test + public void testValidateDetokenizeRequestValidInput() throws SkyflowException { + ArrayList tokens = new ArrayList<>(); + tokens.add("token1"); + tokens.add("token2"); + + ArrayList groupRedactions = new ArrayList<>(); + groupRedactions.add(TokenGroupRedactions.builder() + .tokenGroupName("group1") + .redaction("MASK") + .build()); + + DetokenizeRequest request = DetokenizeRequest.builder() + .tokens(tokens) + .tokenGroupRedactions(groupRedactions) + .build(); + + Validations.validateDetokenizeRequest(request); // Should not throw an exception + } + + @Test + public void testValidateDetokenizeRequestNullRequest() { + try{ + Validations.validateDetokenizeRequest(null); + Assert.fail(EXCEPTIONNOTTHROWN); + } catch (SkyflowException e){ + assertEquals(e.getMessage(), ErrorMessage.DetokenizeRequestNull.getMessage()); + } + + } + + @Test + public void testValidateDetokenizeRequestEmptyTokens() { + try { + DetokenizeRequest request = DetokenizeRequest.builder() + .tokens(new ArrayList<>()) + .tokenGroupRedactions(new ArrayList<>()) + .build(); + + Validations.validateDetokenizeRequest(request); + + } catch (SkyflowException e){ + assertEquals(e.getMessage(), ErrorMessage.EmptyDetokenizeData.getMessage()); + } + } + + @Test + public void testValidateDetokenizeRequestNullTokenInList() { + ArrayList tokens = new ArrayList<>(); + tokens.add(null); + + DetokenizeRequest request = DetokenizeRequest.builder() + .tokens(tokens) + .tokenGroupRedactions(new ArrayList<>()) + .build(); + } + + @Test + public void testValidateDetokenizeRequestNullGroupRedactions() { + ArrayList tokens = new ArrayList<>(); + tokens.add("token1"); + + DetokenizeRequest request = DetokenizeRequest.builder() + .tokens(tokens) + .tokenGroupRedactions(null) + .build(); + try{ + Validations.validateDetokenizeRequest(request); + } catch (SkyflowException e){ + Assert.fail(INVALID_EXCEPTION_THROWN); + } + } + + @Test + public void testValidateDetokenizeRequestNullTokenGroupRedaction() { + ArrayList tokens = new ArrayList<>(); + tokens.add("token1"); + + ArrayList groupRedactions = new ArrayList<>(); + groupRedactions.add(null); + + DetokenizeRequest request = DetokenizeRequest.builder() + .tokens(tokens) + .tokenGroupRedactions(groupRedactions) + .build(); + try{ + Validations.validateDetokenizeRequest(request); + } catch (SkyflowException e){ + Assert.assertEquals(ErrorMessage.NullTokenGroupRedactions.getMessage(), e.getMessage());// + } + } + + @Test + public void testValidateDetokenizeRequestEmptyTokenGroupName() { + ArrayList tokens = new ArrayList<>(); + tokens.add("token1"); + + ArrayList groupRedactions = new ArrayList<>(); + groupRedactions.add(TokenGroupRedactions.builder() + .tokenGroupName("") + .redaction("MASK") + .build()); + + DetokenizeRequest request = DetokenizeRequest.builder() + .tokens(tokens) + .tokenGroupRedactions(groupRedactions) + .build(); + + try{ + Validations.validateDetokenizeRequest(request); + } catch (SkyflowException e){ + assertEquals(ErrorMessage.NullTokenGroupNameInTokenGroup.getMessage(), e.getMessage()); + } + } + + @Test + public void testValidateDetokenizeRequestEmptyRedaction() { + ArrayList tokens = new ArrayList<>(); + tokens.add("token1"); + + ArrayList groupRedactions = new ArrayList<>(); + groupRedactions.add(TokenGroupRedactions.builder() + .tokenGroupName("group1") + .redaction("") + .build()); + + DetokenizeRequest request = DetokenizeRequest.builder() + .tokens(tokens) + .tokenGroupRedactions(groupRedactions) + .build(); + + try { + Validations.validateDetokenizeRequest(request); + } catch (SkyflowException e){ + assertEquals(ErrorMessage.NullRedactionInTokenGroup.getMessage(), e.getMessage()); + } + } + + @Test + public void testValidateInsertRequestNullTable() { + ArrayList> values = new ArrayList<>(); + HashMap valueMap = new HashMap<>(); + valueMap.put("key1", "value1"); + values.add(valueMap); + + InsertRequest request = InsertRequest.builder() + .table(null) + .values(values) + .build(); + + try { + Validations.validateInsertRequest(request); + } catch (SkyflowException e) { + assertEquals(ErrorMessage.TableKeyError.getMessage(), e.getMessage()); // Replace with the actual error message + } + } + + @Test + public void testValidateInsertRequestEmptyTable() { + ArrayList> values = new ArrayList<>(); + HashMap valueMap = new HashMap<>(); + valueMap.put("key1", "value1"); + values.add(valueMap); + + InsertRequest request = InsertRequest.builder() + .table("") + .values(values) + .build(); + + try { + Validations.validateInsertRequest(request); + } catch (SkyflowException e) { + assertEquals(ErrorMessage.EmptyTable.getMessage(), e.getMessage()); // Replace with the actual error message + } + } + + @Test + public void testValidateInsertRequestNullValues() { + InsertRequest request = InsertRequest.builder() + .table("testTable") + .values(null) + .build(); + + try { + Validations.validateInsertRequest(request); + } catch (SkyflowException e) { + assertEquals(ErrorMessage.ValuesKeyError.getMessage(), e.getMessage()); // Replace with the actual error message + } + } + + @Test + public void testValidateInsertRequestEmptyValues() { + InsertRequest request = InsertRequest.builder() + .table("testTable") + .values(new ArrayList<>()) + .build(); + + try { + Validations.validateInsertRequest(request); + } catch (SkyflowException e) { + assertEquals(ErrorMessage.EmptyValues.getMessage(), e.getMessage()); // Replace with the actual error message + } + } + + + @Test + public void testFormatDetokenizeResponseValidResponse() { + // Arrange + List responseObjectsGen = new ArrayList<>(); + Map tokens = new HashMap<>(); + tokens.put("token1", "value1"); + tokens.put("token2", "value2"); + com.skyflow.generated.rest.types.DetokenizeResponseObject object = com.skyflow.generated.rest.types.DetokenizeResponseObject.builder().token("token1").value("value1").tokenGroupName("demo").build(); + responseObjectsGen.add(object); + responseObjectsGen.add(object); + + com.skyflow.generated.rest.types.DetokenizeResponse response = com.skyflow.generated.rest.types.DetokenizeResponse.builder().response(Optional.of(responseObjectsGen)).build(); + + int batch = 0; + int batchSize = 2; + + // Act + DetokenizeResponse result = Utils.formatDetokenizeResponse(response, batch, batchSize); + + // Assert + Assert.assertNotNull(result); + Assert.assertEquals(2, result.getSuccess().size()); + Assert.assertEquals(0, result.getErrors().size()); + } + + @Test + public void testFormatDetokenizeResponseResponseWithErrors() { + + + List responseObjectsGen = new ArrayList<>(); + com.skyflow.generated.rest.types.DetokenizeResponseObject object = com.skyflow.generated.rest.types.DetokenizeResponseObject.builder().error("Error occurred").httpCode(400).build(); + com.skyflow.generated.rest.types.DetokenizeResponseObject object2 = com.skyflow.generated.rest.types.DetokenizeResponseObject.builder().token("token1").tokenGroupName("demo").value("hello").build(); + + responseObjectsGen.add(object); + responseObjectsGen.add(object2); + + com.skyflow.generated.rest.types.DetokenizeResponse response = com.skyflow.generated.rest.types.DetokenizeResponse.builder().response(Optional.of(responseObjectsGen)).build(); + + int batch = 1; + int batchSize = 2; + + // Act + DetokenizeResponse result = Utils.formatDetokenizeResponse(response, batch, batchSize); + + // Assert + assertEquals(1, result.getSuccess().size()); + assertEquals(1, result.getErrors().size()); + assertEquals("Error occurred", result.getErrors().get(0).getError()); + } + + @Test + public void testFormatDetokenizeResponse_NullResponse() { + // Act + DetokenizeResponse result = Utils.formatDetokenizeResponse(null, 0, 2); + + // Assert + Assert.assertNull(result); + } + + public static List createDetokenizeBatches(com.skyflow.generated.rest.resources.recordservice.requests.DetokenizeRequest request, int batchSize) { + List detokenizeRequests = new ArrayList<>(); + List tokens = request.getTokens().get(); + + for (int i = 0; i < tokens.size(); i += batchSize) { + // Create a sublist for the current batch + List batchTokens = tokens.subList(i, Math.min(i + batchSize, tokens.size())); + List tokenGroupRedactions = null; + if (request.getTokenGroupRedactions().isPresent() && !request.getTokenGroupRedactions().get().isEmpty() && i < request.getTokenGroupRedactions().get().size()) { + tokenGroupRedactions = request.getTokenGroupRedactions().get().subList(i, Math.min(i + batchSize, request.getTokenGroupRedactions().get().size())); } + // Build a new DetokenizeRequest for the current batch + com.skyflow.generated.rest.resources.recordservice.requests.DetokenizeRequest batchRequest = com.skyflow.generated.rest.resources.recordservice.requests.DetokenizeRequest.builder() + .vaultId(request.getVaultId()) + .tokens(new ArrayList<>(batchTokens)) + .tokenGroupRedactions(tokenGroupRedactions) + .build(); + + detokenizeRequests.add(batchRequest); + } + + return detokenizeRequests; + } + + + private DetokenizeResponseObject createResponseObject(String token, String value, String groupName, String error, Integer httpCode) { + DetokenizeResponseObject responseObject = new DetokenizeResponseObject( + 0, + String.valueOf(Optional.ofNullable(token)), + Optional.ofNullable(value), + String.valueOf(Optional.ofNullable(groupName)), + String.valueOf(Optional.ofNullable(error)), + null + );return responseObject; + } + +} \ No newline at end of file diff --git a/v3/test/java/com/skyflow/vault/controller/VaultControllerTests.java b/v3/test/java/com/skyflow/vault/controller/VaultControllerTests.java new file mode 100644 index 00000000..7ffa1d3a --- /dev/null +++ b/v3/test/java/com/skyflow/vault/controller/VaultControllerTests.java @@ -0,0 +1,373 @@ +package com.skyflow.vault.controller; + +import com.skyflow.config.Credentials; +import com.skyflow.config.VaultConfig; +import com.skyflow.errors.SkyflowException; +import com.skyflow.utils.Constants; +import com.skyflow.utils.validations.Validations; +import com.skyflow.vault.data.InsertRequest; +import org.junit.*; +import java.io.FileWriter; +import java.io.IOException; +import java.lang.reflect.Method; +import java.lang.reflect.Field; +import java.util.*; +import static org.junit.Assert.*; + + +public class VaultControllerTests { + private static final String ENV_PATH = "/home/saib/skyflow3/skyflow-java/v3/.env"; + + private VaultConfig vaultConfig; + private Credentials credentials; + + @Before + public void setUp() { + vaultConfig = new VaultConfig(); + vaultConfig.setVaultId("vault123"); + vaultConfig.setClusterId("cluster123"); + vaultConfig.setEnv(com.skyflow.enums.Env.DEV); + + credentials = new Credentials(); + credentials.setToken("valid-token"); + vaultConfig.setCredentials(credentials); + + writeEnv("INSERT_BATCH_SIZE=50\nINSERT_CONCURRENCY_LIMIT=10"); + } + + @After + public void tearDown() { + // Optionally clean up .env file + writeEnv(""); // or restore to default + } + + private void writeEnv(String content) { + try (FileWriter writer = new FileWriter(ENV_PATH)) { + writer.write(content); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private VaultController createController() { + return new VaultController(vaultConfig, credentials); + } + + // Helper to set private fields via reflection + private void setPrivateField(Object obj, String field, Object value) throws Exception { + Field f = obj.getClass().getDeclaredField(field); + f.setAccessible(true); + f.set(obj, value); + } + + private void invokeConfigureInsertConcurrencyAndBatchSize(VaultController controller, int totalRequests) throws Exception { + Method method = VaultController.class.getDeclaredMethod("configureInsertConcurrencyAndBatchSize", int.class); + method.setAccessible(true); + method.invoke(controller, totalRequests); + } + + private ArrayList> generateValues(int noOfRecords){ + ArrayList> values = new ArrayList<>(); + for (int i = 0; i < noOfRecords; i++) { + values.add(new HashMap<>()); + } + + return values; + } + + @Test + public void testValidation_tableIsNull() { + InsertRequest req = InsertRequest.builder().table(null).values(generateValues(1)).build(); + try { + Validations.validateInsertRequest(req); + fail("Expected SkyflowException for null table"); + } catch (SkyflowException e) { + assertTrue(!e.getMessage().isEmpty()); + } + } + + @Test + public void testValidation_tableIsEmpty() { + InsertRequest req = InsertRequest.builder().table(" ").values(generateValues(1)).build(); + try { + Validations.validateInsertRequest(req); + fail("Expected SkyflowException for empty table"); + } catch (SkyflowException e) { + assertTrue(!e.getMessage().isEmpty()); + } + } + + @Test + public void testValidation_valuesIsNull() { + InsertRequest req = InsertRequest.builder().table("table1").values(null).build(); + try { + Validations.validateInsertRequest(req); + fail("Expected SkyflowException for null values"); + } catch (SkyflowException e) { + assertTrue(!e.getMessage().isEmpty()); + } + } + + @Test + public void testValidation_valuesIsEmpty() { + InsertRequest req = InsertRequest.builder().table("table1").values(new ArrayList<>()).build(); + try { + Validations.validateInsertRequest(req); + fail("Expected SkyflowException for empty values"); + } catch (SkyflowException e) { + assertFalse(e.getMessage().isEmpty()); + } + } + + @Test + public void testValidation_upsertIsEmpty() throws SkyflowException { + InsertRequest req = InsertRequest.builder().table("table1").values(generateValues(1)).upsert(new ArrayList<>()).build(); + // Should not throw, just logs a warning + Validations.validateInsertRequest(req); + } + + + @Test + public void testValidation_keyIsNullOrEmpty() { + ArrayList> values = new ArrayList<>(); + HashMap map = new HashMap<>(); + map.put(null, "value"); + values.add(map); + InsertRequest req = InsertRequest.builder().table("table1").values(values).build(); + try { + Validations.validateInsertRequest(req); + fail("Expected SkyflowException for null key in values"); + } catch (SkyflowException e) { + assertFalse(e.getMessage().isEmpty()); + } + + // Test empty key + values.clear(); + map = new HashMap<>(); + map.put(" ", "value"); + values.add(map); + req = InsertRequest.builder().table("table1").values(values).build(); + try { + Validations.validateInsertRequest(req); + fail("Expected SkyflowException for empty key in values"); + } catch (SkyflowException e) { + assertFalse(e.getMessage().isEmpty()); + } + } + + @Test + public void testValidation_valueIsNullOrEmpty() { + ArrayList> values = new ArrayList<>(); + HashMap map = new HashMap<>(); + map.put("field1", null); + values.add(map); + InsertRequest req = InsertRequest.builder().table("table1").values(values).build(); + try { + Validations.validateInsertRequest(req); + fail("Expected SkyflowException for null value in values"); + } catch (SkyflowException e) { + assertFalse(e.getMessage().isEmpty()); + } + + // Test empty value + values.clear(); + map = new HashMap<>(); + map.put("field1", " "); + values.add(map); + req = InsertRequest.builder().table("table1").values(values).build(); + try { + Validations.validateInsertRequest(req); + fail("Expected SkyflowException for empty value in values"); + } catch (SkyflowException e) { + assertFalse(e.getMessage().isEmpty()); + } + } + + @Test + public void testDefaultValues() throws Exception { + VaultController controller = createController(); + setPrivateField(controller, "insertBatchSize", Constants.INSERT_BATCH_SIZE); + setPrivateField(controller, "insertConcurrencyLimit", Constants.INSERT_CONCURRENCY_LIMIT); + + invokeConfigureInsertConcurrencyAndBatchSize(controller, 10); + assertEquals(Constants.INSERT_BATCH_SIZE.intValue(), getPrivateInt(controller, "insertBatchSize")); + assertEquals(Math.min(Constants.INSERT_CONCURRENCY_LIMIT, (10 + Constants.INSERT_BATCH_SIZE - 1) / Constants.INSERT_BATCH_SIZE), + getPrivateInt(controller, "insertConcurrencyLimit")); + } + + @Test + public void testCustomValidBatchAndConcurrency() throws Exception { + writeEnv("INSERT_BATCH_SIZE=5\nINSERT_CONCURRENCY_LIMIT=3"); + VaultController controller = createController(); + + InsertRequest insertRequest = InsertRequest.builder().table("table1").values(generateValues(20)).build(); + + try { + controller.bulkInsert(insertRequest); + } catch (Exception ignored) { + // Ignore, Testing concurrency/batch config + } + + assertEquals(5, getPrivateInt(controller, "insertBatchSize")); + assertEquals(3, getPrivateInt(controller, "insertConcurrencyLimit")); + } + + @Test + public void testBatchSizeExceedsMax() throws Exception { + writeEnv("INSERT_BATCH_SIZE=1100\nINSERT_CONCURRENCY_LIMIT=3"); + VaultController controller = createController(); + + InsertRequest insertRequest = InsertRequest.builder().table("table1").values(generateValues(50)).build(); + + try { + controller.bulkInsert(insertRequest); + } catch (Exception ignored) { + // Ignore, Testing concurrency/batch config + } + + assertEquals(1000, getPrivateInt(controller, "insertBatchSize")); + } + + @Test + public void testConcurrencyExceedsMax() throws Exception { + writeEnv("INSERT_CONCURRENCY_LIMIT=110"); + VaultController controller = createController(); + InsertRequest insertRequest = InsertRequest.builder().table("table1").values(generateValues(50)).build(); + + + try { + controller.bulkInsert(insertRequest); + } catch (Exception ignored) { + // Ignore, Testing concurrency/batch config + } + + assertEquals(1, getPrivateInt(controller, "insertConcurrencyLimit")); + } + + @Test + public void testBatchSizeZeroOrNegative() throws Exception { + writeEnv("INSERT_BATCH_SIZE=0"); + VaultController controller = createController(); + InsertRequest insertRequest = InsertRequest.builder().table("table1").values(generateValues(10)).build(); + + try { + controller.bulkInsert(insertRequest); + } catch (Exception ignored) { + // Ignore, Testing concurrency/batch config + } + + assertEquals(50, getPrivateInt(controller, "insertBatchSize")); + + writeEnv("INSERT_BATCH_SIZE=-5"); + + try { + controller.bulkInsert(insertRequest); + } catch (Exception ignored) { + // Ignore, Testing concurrency/batch config + } + + assertEquals(50, getPrivateInt(controller, "insertBatchSize")); + } + + @Test + public void testConcurrencyZeroOrNegative() throws Exception { + writeEnv("INSERT_CONCURRENCY_LIMIT=0"); + VaultController controller = createController(); + InsertRequest insertRequest = InsertRequest.builder().table("table1").values(generateValues(10)).build(); + + try { + controller.bulkInsert(insertRequest); + } catch (Exception ignored) { + // Ignore, Testing concurrency/batch config + } + + int min = Math.min(Constants.INSERT_CONCURRENCY_LIMIT, (10 + Constants.INSERT_BATCH_SIZE - 1) / Constants.INSERT_BATCH_SIZE); + assertEquals(min, getPrivateInt(controller, "insertConcurrencyLimit")); + + + + + writeEnv("INSERT_CONCURRENCY_LIMIT=-5"); + + try { + controller.bulkInsert(insertRequest); + } catch (Exception ignored) { + // Ignore, Testing concurrency/batch config + } + + min = Math.min(Constants.INSERT_CONCURRENCY_LIMIT, (10 + Constants.INSERT_BATCH_SIZE - 1) / Constants.INSERT_BATCH_SIZE); + assertEquals(min, getPrivateInt(controller, "insertConcurrencyLimit")); + } + + + @Test + public void testTotalRequestsLessThanBatchSize() throws Exception { + writeEnv("INSERT_BATCH_SIZE=100\nINSERT_CONCURRENCY_LIMIT=10"); + VaultController controller = createController(); + InsertRequest insertRequest = InsertRequest.builder().table("table1").values(generateValues(10)).build(); + + + try { + controller.bulkInsert(insertRequest); + } catch (Exception ignored) { + // Ignore, Testing concurrency/batch config + } + + assertEquals(100, getPrivateInt(controller, "insertBatchSize")); + assertEquals(1, getPrivateInt(controller, "insertConcurrencyLimit")); + } + + @Test + public void testTotalRequestsZero() throws Exception { + VaultController controller = createController(); + InsertRequest insertRequest = InsertRequest.builder().table("table1").values(generateValues(0)).build(); + + boolean exceptionThrown = false; + + try { + + controller.bulkInsert(insertRequest); + } catch (Exception e) { + exceptionThrown = true; + } + assertTrue("Exception should be thrown for zero records", exceptionThrown); + } + + + @Test + public void testHighConcurrencyForLowRecords() throws Exception { + writeEnv("INSERT_BATCH_SIZE=1000\nINSERT_CONCURRENCY_LIMIT=100"); + VaultController controller = createController(); + InsertRequest insertRequest = InsertRequest.builder().table("table1").values(generateValues(10000)).build(); + + try { + controller.bulkInsert(insertRequest); + } catch (Exception ignored) {} + + // Only 10 batches needed, so concurrency should be clamped to 10 + assertEquals(1000, getPrivateInt(controller, "insertBatchSize")); + assertEquals(10, getPrivateInt(controller, "insertConcurrencyLimit")); + } + + + @Test + public void testFractionalLastBatch() throws Exception { + writeEnv("INSERT_BATCH_SIZE=100"); + VaultController controller = createController(); + InsertRequest insertRequest = InsertRequest.builder().table("table1").values(generateValues(10050)).build(); + + try { + controller.bulkInsert(insertRequest); + } catch (Exception ignored) {} + + // Last batch should have 50 records, concurrency should be 101 + assertEquals(100, getPrivateInt(controller, "insertBatchSize")); + assertEquals(10, getPrivateInt(controller, "insertConcurrencyLimit")); + } + + private int getPrivateInt(Object obj, String field) throws Exception { + Field f = obj.getClass().getDeclaredField(field); + f.setAccessible(true); + return f.getInt(obj); + } +} \ No newline at end of file diff --git a/v3/test/java/com/skyflow/vault/data/InsertTests.java b/v3/test/java/com/skyflow/vault/data/InsertTests.java new file mode 100644 index 00000000..7ea17d89 --- /dev/null +++ b/v3/test/java/com/skyflow/vault/data/InsertTests.java @@ -0,0 +1,267 @@ +package com.skyflow.vault.data; + +import com.skyflow.Skyflow; +import com.skyflow.config.Credentials; +import com.skyflow.config.VaultConfig; +import com.skyflow.enums.Env; +import com.skyflow.errors.ErrorCode; +import com.skyflow.errors.ErrorMessage; +import com.skyflow.errors.SkyflowException; +import com.skyflow.utils.Constants; +import com.skyflow.utils.SdkVersion; +import com.skyflow.utils.Utils; +import com.skyflow.utils.validations.Validations; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class InsertTests { + private static final String INVALID_EXCEPTION_THROWN = "Should not have thrown any exception"; + private static final String EXCEPTION_NOT_THROWN = "Should have thrown an exception"; + private static final String requestId = "95be08fc-4d13-4335-8b8d-24e85d53ed1d"; + private static String vaultID = null; + private static String clusterID = null; + private static String table = null; + private static ArrayList> values = null; + private static ArrayList> tokens = null; + private static HashMap valueMap = null; + private static HashMap tokenMap = null; + private static List upsert = new ArrayList<>(); + private static Skyflow skyflowClient = null; + + @BeforeClass + public static void setup() { + + vaultID = "vault123"; + clusterID = "cluster123"; + + Credentials credentials = new Credentials(); + credentials.setToken("valid-token"); + + VaultConfig vaultConfig = new VaultConfig(); + vaultConfig.setVaultId(vaultID); + vaultConfig.setClusterId(clusterID); + vaultConfig.setEnv(Env.DEV); + vaultConfig.setCredentials(credentials); + + table = "test_table"; + values = new ArrayList<>(); + tokens = new ArrayList<>(); + valueMap = new HashMap<>(); + tokenMap = new HashMap<>(); + upsert.add("upsert_column"); + SdkVersion.setSdkPrefix(Constants.SDK_PREFIX); + } + + @Before + public void setupTest() { + values.clear(); + tokens.clear(); + valueMap.clear(); + valueMap.put("test_column_1", "test_value_1"); + valueMap.put("test_column_2", "test_value_2"); + tokenMap.clear(); + tokenMap.put("test_column_1", "test_token_1"); + } + + @Test + public void testValidInputInInsertRequestValidations() { + try { + values.add(valueMap); + tokens.add(tokenMap); + + InsertRequest request = InsertRequest.builder() + .table(table) + .upsert(upsert) + .values(values) + .build(); + Validations.validateInsertRequest(request); + + Assert.assertEquals(table, request.getTable()); + Assert.assertEquals(upsert, request.getUpsert()); + Assert.assertEquals(1, request.getValues().size()); + } catch (SkyflowException e) { + Assert.fail(INVALID_EXCEPTION_THROWN); + } + } + + @Test + public void testValidInputInInsertRequestValidationsWithTokenModeDisable() { + try { + values.add(valueMap); + tokens.add(tokenMap); + InsertRequest request = InsertRequest.builder() + .table(table) + .upsert(upsert) + .values(values) + .build(); + Validations.validateInsertRequest(request); + + Assert.assertEquals(table, request.getTable()); + Assert.assertEquals(upsert, request.getUpsert()); + Assert.assertEquals(1, request.getValues().size()); + } catch (SkyflowException e) { + Assert.fail(INVALID_EXCEPTION_THROWN); + } + } + + @Test + public void testNoTableInInsertRequestValidations() { + InsertRequest request = InsertRequest.builder().build(); + try { + Validations.validateInsertRequest(request); + Assert.fail(EXCEPTION_NOT_THROWN); + } catch (SkyflowException e) { + Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode()); + Assert.assertEquals( + Utils.parameterizedString(ErrorMessage.TableKeyError.getMessage(), Constants.SDK_PREFIX), + e.getMessage() + ); + } + } + + @Test + public void testEmptyTableInInsertRequestValidations() { + InsertRequest request = InsertRequest.builder().table("").build(); + try { + Validations.validateInsertRequest(request); + Assert.fail(EXCEPTION_NOT_THROWN); + } catch (SkyflowException e) { + Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode()); + Assert.assertEquals( + Utils.parameterizedString(ErrorMessage.EmptyTable.getMessage(), Constants.SDK_PREFIX), + e.getMessage() + ); + } + } + + @Test + public void testNoValuesInInsertRequestValidations() { + InsertRequest request = InsertRequest.builder().table(table).build(); + try { + Validations.validateInsertRequest(request); + Assert.fail(EXCEPTION_NOT_THROWN); + } catch (SkyflowException e) { + Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode()); + Assert.assertEquals( + Utils.parameterizedString(ErrorMessage.ValuesKeyError.getMessage(), Constants.SDK_PREFIX), + e.getMessage() + ); + } + } + + @Test + public void testEmptyValuesInInsertRequestValidations() { + InsertRequest request = InsertRequest.builder().table(table).values(values).build(); + try { + Validations.validateInsertRequest(request); + Assert.fail(EXCEPTION_NOT_THROWN); + } catch (SkyflowException e) { + Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode()); + Assert.assertEquals( + Utils.parameterizedString(ErrorMessage.EmptyValues.getMessage(), Constants.SDK_PREFIX), + e.getMessage() + ); + } + } + + @Test + public void testEmptyKeyInValuesInInsertRequestValidations() { + valueMap.put("", "test_value_3"); + values.add(valueMap); + InsertRequest request = InsertRequest.builder().table(table).values(values).build(); + try { + Validations.validateInsertRequest(request); + Assert.fail(EXCEPTION_NOT_THROWN); + } catch (SkyflowException e) { + Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode()); + Assert.assertEquals( + Utils.parameterizedString(ErrorMessage.EmptyKeyInValues.getMessage(), Constants.SDK_PREFIX), + e.getMessage() + ); + } + } + + @Test + public void testEmptyValueInValuesInInsertRequestValidations() { + valueMap.put("test_column_3", ""); + values.add(valueMap); + InsertRequest request = InsertRequest.builder().table(table).values(values).build(); + try { + Validations.validateInsertRequest(request); + Assert.fail(EXCEPTION_NOT_THROWN); + } catch (SkyflowException e) { + Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode()); + Assert.assertEquals( + Utils.parameterizedString(ErrorMessage.EmptyValueInValues.getMessage(), Constants.SDK_PREFIX), + e.getMessage() + ); + } + } + + @Test + public void testEmptyUpsertInInsertRequestValidations() { + values.add(valueMap); + InsertRequest request = InsertRequest.builder().table(table).values(values).upsert(new ArrayList<>()).build(); + try { + Validations.validateInsertRequest(request); +// Assert.fail(EXCEPTION_NOT_THROWN); + } catch (SkyflowException e) { + Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode()); + Assert.assertEquals( + Utils.parameterizedString(ErrorMessage.EmptyUpsert.getMessage(), Constants.SDK_PREFIX), + e.getMessage() + ); + } + } + + @Test + public void testInsertResponse() { + try { + Map value = new HashMap<>(); + value.put("test_column_1", "test_value_1"); + Success success = new Success(0, "id", null, null); + + List successList = new ArrayList<>(); + successList.add(success); + InsertResponse response = new InsertResponse(successList, null); + String responseString = "{\"success\":[{\"index\":0,\"skyflow_id\":\"id\"}]}"; + Assert.assertEquals(1, response.getSuccess().size()); + Assert.assertNull(response.getErrors()); + Assert.assertEquals(responseString, response.toString()); + } catch (Exception e) { + Assert.fail(INVALID_EXCEPTION_THROWN); + } + } + + @Test + public void testInsertErrorResponse() { + try { + HashMap value = new HashMap<>(); + value.put("test_column_1", "test_value_1"); + Success success = new Success(0, "id", null, value); + + List successList = new ArrayList<>(); + successList.add(success); + + List errorList = new ArrayList<>(); + ErrorRecord error = new ErrorRecord(1, "Bad Request", 400); + errorList.add(error); + + InsertResponse response1 = new InsertResponse(successList, errorList); + String responseString = "{\"success\":[{\"index\":0,\"skyflow_id\":\"id\",\"data\":{\"test_column_1\":\"test_value_1\"}}],\"errors\":[{\"index\":1,\"error\":\"Bad Request\",\"code\":400}]}"; + Assert.assertEquals(1, response1.getSuccess().size()); + Assert.assertEquals(1, response1.getErrors().size()); + Assert.assertEquals(responseString, response1.toString()); + } catch (Exception e) { + Assert.fail(INVALID_EXCEPTION_THROWN); + } + } + +}