Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,92 +13,89 @@
import java.util.Map;

/**
* This example demonstrates how to use the Skyflow SDK to invoke connections for different endpoints with different configurations.
* This example demonstrates how to use the Skyflow SDK to invoke API connections.
* It includes:
* 1. Setting up connection configurations.
* 2. Creating a Skyflow client.
* 3. Sending POST and GET requests to connections.
* 1. Setting up credentials and connection configurations.
* 2. Creating a Skyflow client with multiple connections.
* 3. Sending a POST request with request body and headers.
* 4. Sending a GET request with path and query parameters.
*/
public class InvokeConnectionExample {
public static void main(String[] args) throws SkyflowException {
// Step 1: Set up credentials for the first connection configuration
// Step 1: Set up credentials for API authentication
Credentials credentials = new Credentials();
credentials.setPath("<YOUR_CREDENTIALS_FILE_PATH_1>"); // Replace with the path to the credentials file
credentials.setApiKey("<YOUR_API_KEY>"); // Replace with the actual API key

// Step 2: Configure the first connection (Connection 1)
ConnectionConfig connectionConfig1 = new ConnectionConfig();
connectionConfig1.setConnectionId("<YOUR_CONNECTION_ID_1>"); // Replace with the ID of the first connection
connectionConfig1.setConnectionUrl("<YOUR_CONNECTION_URL_1>"); // Replace with the URL of the first connection
connectionConfig1.setCredentials(credentials); // Associate credentials for the first connection
// Step 2: Configure the first connection
ConnectionConfig primaryConnectionConfig = new ConnectionConfig();
primaryConnectionConfig.setConnectionId("<YOUR_CONNECTION_ID_1>"); // Replace with first connection ID
primaryConnectionConfig.setConnectionUrl("<YOUR_CONNECTION_URL_1>"); // Replace with first connection URL
primaryConnectionConfig.setCredentials(credentials); // Assign credentials

// Step 3: Configure the second connection (Connection 2)
ConnectionConfig connectionConfig2 = new ConnectionConfig();
connectionConfig2.setConnectionId("<YOUR_CONNECTION_ID_2>"); // Replace with the ID of the second connection
connectionConfig2.setConnectionUrl("<YOUR_CONNECTION_URL_2>"); // Replace with the URL of the second connection
// Step 3: Configure the second connection
ConnectionConfig secondaryConnectionConfig = new ConnectionConfig();
secondaryConnectionConfig.setConnectionId("<YOUR_CONNECTION_ID_2>"); // Replace with second connection ID
secondaryConnectionConfig.setConnectionUrl("<YOUR_CONNECTION_URL_2>"); // Replace with second connection URL

// Step 4: Set up credentials for the Skyflow client
Credentials skyflowCredentials = new Credentials();
skyflowCredentials.setPath("<YOUR_CREDENTIALS_FILE_PATH_2>"); // Replace with the path to another credentials file
skyflowCredentials.setCredentialsString("<YOUR_CREDENTIALS_STRING>"); // Replace with the credentials string

// Step 5: Create a Skyflow client and add connection configurations
// Step 5: Create a Skyflow client with connection configurations
Skyflow skyflowClient = Skyflow.builder()
.setLogLevel(LogLevel.DEBUG) // Enable debugging for detailed logs
.addConnectionConfig(connectionConfig1) // Add the first connection configuration
.addConnectionConfig(connectionConfig2) // Add the second connection configuration
.addSkyflowCredentials(skyflowCredentials) // Add general Skyflow credentials
.setLogLevel(LogLevel.ERROR) // Set log level to ERROR
.addConnectionConfig(primaryConnectionConfig) // Add the first connection
.addConnectionConfig(secondaryConnectionConfig) // Add the second connection
.addSkyflowCredentials(skyflowCredentials) // Provide Skyflow credentials
.build();

// Example 1: Sending a POST request to the first connection
try {
// Set up the request body and headers for the POST request
// Set up request body and headers
Map<String, String> requestBody = new HashMap<>();
requestBody.put("<COLUMN_NAME_1>", "<COLUMN_VALUE_1>"); // Replace with the actual column name and value
requestBody.put("<COLUMN_NAME_1>", "<COLUMN_VALUE_1>"); // Replace with actual column name and value
requestBody.put("<COLUMN_NAME_2>", "<COLUMN_VALUE_2>"); // Replace with another column name and value

Map<String, String> requestHeaders = new HashMap<>();
requestHeaders.put("<HEADER_NAME_1>", "<HEADER_VALUE_1>"); // Replace with header name and value
requestHeaders.put("<HEADER_NAME_1>", "<HEADER_VALUE_1>"); // Replace with actual header name and value
requestHeaders.put("<HEADER_NAME_2>", "<HEADER_VALUE_2>"); // Replace with another header name and value

// Build the POST request to invoke the connection
// Build and send the POST request
InvokeConnectionRequest invokeConnectionRequest1 = InvokeConnectionRequest.builder()
.method(RequestMethod.POST) // Set the HTTP method to POST
.requestBody(requestBody) // Set the request body
.requestHeaders(requestHeaders) // Set the request headers
.method(RequestMethod.POST) // HTTP method set to POST
.requestBody(requestBody) // Include request body
.requestHeaders(requestHeaders) // Include request headers
.build();

// Execute the POST request to the first connection
InvokeConnectionResponse invokeConnectionResponse1 = skyflowClient.connection().invoke(invokeConnectionRequest1);
System.out.println("Invoke Connection Response (POST): " + invokeConnectionResponse1); // Print the response
System.out.println("Invoke Connection Response (POST): " + invokeConnectionResponse1);
} catch (SkyflowException e) {
System.out.println("Error while invoking connection (POST):");
e.printStackTrace();
System.out.println("Error while invoking connection (POST):" + e);
}

// Example 2: Sending a GET request to the second connection
try {
// Set up path parameters and query parameters for the GET request
// Set up path and query parameters
Map<String, String> pathParams = new HashMap<>();
pathParams.put("<YOUR_PATH_PARAM_KEY_1>", "<YOUR_PATH_PARAM_VALUE_1>"); // Replace with path parameters
pathParams.put("<YOUR_PATH_PARAM_KEY_1>", "<YOUR_PATH_PARAM_VALUE_1>"); // Replace with actual path parameter
pathParams.put("<YOUR_PATH_PARAM_KEY_2>", "<YOUR_PATH_PARAM_VALUE_2>"); // Replace with another path parameter

Map<String, String> queryParams = new HashMap<>();
queryParams.put("<YOUR_QUERY_PARAM_KEY_1>", "<YOUR_QUERY_PARAM_VALUE_1>"); // Replace with query parameters
queryParams.put("<YOUR_QUERY_PARAM_KEY_1>", "<YOUR_QUERY_PARAM_VALUE_1>"); // Replace with actual query parameter
queryParams.put("<YOUR_QUERY_PARAM_KEY_2>", "<YOUR_QUERY_PARAM_VALUE_2>"); // Replace with another query parameter

// Build the GET request to invoke the connection
// Build and send the GET request
InvokeConnectionRequest invokeConnectionRequest2 = InvokeConnectionRequest.builder()
.method(RequestMethod.GET) // Set the HTTP method to GET
.pathParams(pathParams) // Set the path parameters
.queryParams(queryParams) // Set the query parameters
.method(RequestMethod.GET) // HTTP method set to GET
.pathParams(pathParams) // Include path parameters
.queryParams(queryParams) // Include query parameters
.build();

// Execute the GET request to the second connection
InvokeConnectionResponse invokeConnectionResponse2 = skyflowClient
.connection("<YOUR_CONNECTION_ID_2>").invoke(invokeConnectionRequest2); // Invoke connection with ID 2
System.out.println("Invoke Connection Response (GET): " + invokeConnectionResponse2); // Print the response
.connection("<YOUR_CONNECTION_ID_2>").invoke(invokeConnectionRequest2);
System.out.println("Invoke Connection Response (GET): " + invokeConnectionResponse2);
} catch (SkyflowException e) {
System.out.println("Error while invoking connection (GET):");
e.printStackTrace();
System.out.println("Error while invoking connection (GET):" + e);
}
}
}
95 changes: 95 additions & 0 deletions samples/src/main/java/com/example/vault/ClientOperations.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.example.vault;

import com.skyflow.Skyflow;
import com.skyflow.config.Credentials;
import com.skyflow.config.VaultConfig;
import com.skyflow.enums.Env;
import com.skyflow.enums.LogLevel;
import com.skyflow.errors.SkyflowException;
import com.skyflow.vault.data.DeleteRequest;
import com.skyflow.vault.data.DeleteResponse;

import java.util.ArrayList;

/**
* This class demonstrates how to configure and interact with Skyflow vaults using the Skyflow Java SDK.
* <p>
* 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.
* <p>
* 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("<YOUR_BEARER_TOKEN>"); // 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("<YOUR_VAULT_ID_1>"); // Set first vault ID
primaryVaultConfig.setClusterId("<YOUR_CLUSTER_ID_1>"); // 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("<YOUR_VAULT_ID_2>"); // Set second vault ID
secondaryVaultConfig.setClusterId("<YOUR_CLUSTER_ID_2>"); // 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("<YOUR_VAULT_ID_2>"); // Ensure update applies to the correct vault
updatedVaultConfig.setClusterId("<YOUR_CLUSTER_ID_2>"); // 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("<YOUR_API_KEY>"); // 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<String> ids = new ArrayList<>();
ids.add("<YOUR_SKYFLOW_ID_VALUE>"); // Replace with the actual ID of the record to delete

DeleteRequest deleteRequest = DeleteRequest.builder()
.ids(ids) // Specify record IDs targeted for deletion
.table("<TABLE_NAME>") // 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("<YOUR_VAULT_ID_2>").delete(deleteRequest);
System.out.println("Delete Response (Vault 2): " + deleteResponse);

// Step 9: Remove the secondary vault configuration after the operation is completed
skyflowClient.removeVaultConfig("<YOUR_VAULT_ID_2>");

} catch (SkyflowException e) {
// Handle any errors that occur during the delete operation
System.out.println("Error during delete operation in vault 2: " + e);
}
}
}
84 changes: 84 additions & 0 deletions samples/src/main/java/com/example/vault/CredentialsOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.example.vault;

import com.skyflow.Skyflow;
import com.skyflow.config.Credentials;
import com.skyflow.config.VaultConfig;
import com.skyflow.enums.Env;
import com.skyflow.enums.LogLevel;
import com.skyflow.errors.SkyflowException;
import com.skyflow.vault.data.DeleteRequest;
import com.skyflow.vault.data.DeleteResponse;

import java.util.ArrayList;

/**
* This class demonstrates multiple authentication methods and deletion operations across different Skyflow vaults.
* <p>
* 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("<YOUR_API_KEY>"); // Replace with your actual API key

// Alternative authentication methods (uncomment if needed)
// credentials.setToken("<YOUR_BEARER_TOKEN>");
// credentials.setPath("<YOUR_CREDENTIALS_FILE_PATH>");
// credentials.setCredentialsString("<YOUR_CREDENTIALS_STRING>");

// Step 2: Configure the primary vault
VaultConfig primaryVaultConfig = new VaultConfig();
primaryVaultConfig.setVaultId("<YOUR_VAULT_ID_1>"); // Set first vault ID
primaryVaultConfig.setClusterId("<YOUR_CLUSTER_ID_1>"); // 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("<YOUR_VAULT_ID_2>"); // Set second vault ID
secondaryVaultConfig.setClusterId("<YOUR_CLUSTER_ID_2>"); // 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<String> ids1 = new ArrayList<>();
ids1.add("<YOUR_SKYFLOW_ID_VALUE>"); // Replace with the actual ID to delete
DeleteRequest deleteRequest1 = DeleteRequest.builder()
.ids(ids1) // Specify record IDs targeted for deletion
.table("<TABLE_NAME>") // Set the table name from which records should be deleted
.build();

DeleteResponse deleteResponse1 = skyflowClient.vault("<YOUR_VAULT_ID_1>").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<String> ids2 = new ArrayList<>();
ids2.add("<YOUR_SKYFLOW_ID_VALUE>"); // Replace with the actual ID to delete
DeleteRequest deleteRequest2 = DeleteRequest.builder()
.ids(ids2) // Specify record IDs targeted for deletion
.table("<TABLE_NAME>") // Set the table name from which records should be deleted
.build();

DeleteResponse deleteResponse2 = skyflowClient.vault("<YOUR_VAULT_ID_2>").delete(deleteRequest2);
System.out.println("Delete Response (Vault 2): " + deleteResponse2);
} catch (SkyflowException e) {
System.out.println("Error during delete operation in Vault 2: " + e);
}
}
}
Loading
Loading