Skip to content
Open
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
35 changes: 31 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,10 @@ In V2, the log level is tied to each individual client instance.

During client initialization, you can pass the following parameters:

- `VaultID` and `VaultURL`: These values are derived from the vault ID & vault URL.
- `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.
- `BaseVaultURL`: URL of the vault that the client should connect to.

#### V1 (Old):
```go
Expand Down Expand Up @@ -440,15 +441,40 @@ func main() {
Env: common.SANDBOX, // Set the environment for this vault.
Credentials: tertiaryCredentials, // Attach the secondary credentials to this configuration.
}
// Step 9: Build and initialize the Skyflow client.
// Skyflow client is configured with multiple vaults and credentials.

// Step 9: Another vault config with Base Vault URL
credentials := common.Credentials {
ApiKey: "<API_KEY>",
} // Replace with your API Key for authentication.

// A vault configuration can be used for operations involving multiple vaults.
ConfigWithVaultURL := common.VaultConfig {
VaultId: "<SECONDARY_VAULT_ID>", // Replace with your secondary vault's ID.
BaseVaultURL: "<VAULT_URL>", // URL of the vault that the client should connect to.
Env: common.SANDBOX, // Set the environment for this vault.
Credentials: credentials, // Attach the secondary credentials to this configuration.
}

// Step 10: Build and initialize the Skyflow client.
var arr[] common.VaultConfig
arr = append(arr, primaryConfig, secondaryConfig, tertiaryConfig)
arr = append(arr, primaryConfig, secondaryConfig, tertiaryConfig, ConfigWithVaultURL)

// Skyflow client is configured with multiple vaults and credentials.
skyflowClient, err: = client.NewSkyflow(
client.WithVaults(arr...),
client.WithCredentials(skyflowCredentials), // Add JSON-formatted credentials if applicable.
client.WithLogLevel(logger.DEBUG), // Set log level for debugging or monitoring purposes.
)

// OR Build and initialize the Skyflow client with custom headers.
var customHeaders = make(map[string]string) // Create a map for custom headers
customHeaders["x-custom-header"] = "custom-header-value"

skyflowClient, err: = client.NewSkyflow(
client.WithVaults(arr...),
client.WithCredentials(skyflowCredentials), // Add JSON-formatted credentials if applicable.
client.WithLogLevel(logger.DEBUG), // Set log level for debugging or monitoring purposes.
client.WithCustomHeaders(customHeaders), // Added custom headers
)
// The Skyflow client is now fully initialized.
// Use the `skyflowClient` object to perform secure operations such as:
Expand All @@ -463,6 +489,7 @@ func main() {
- If both Skyflow common credentials and individual credentials at the configuration level are specified, the individual credentials at the configuration level will take precedence.
- 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.
- If `BaseVaultURL` is specified in the vault configuration, it will be used for all API calls for that vault.

### Insert data into the vault
To insert data into your vault, use the `Insert` method. The `InsertRequest` struct 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]() section.
Expand Down
72 changes: 72 additions & 0 deletions samples/v2/vaultapi/baseVaultURLAndCustomHeaders.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
Copyright (c) 2022 Skyflow, Inc.
*/
package main

import (
"context"
"fmt"

"github.com/skyflowapi/skyflow-go/v2/client"
"github.com/skyflowapi/skyflow-go/v2/utils/common"
"github.com/skyflowapi/skyflow-go/v2/utils/logger"
)

func main() {
// Step 1: Set up Skyflow vault credentials
vaultConfig1 := common.VaultConfig{
VaultId: "<VAULT_ID>",
BaseVaultURL: "<VAULT_URL>", // Custom base vault URL
Env: common.SANDBOX,
Credentials: common.Credentials{
Token: "<TOKEN>",
},
}
var arr []common.VaultConfig
arr = append(arr, vaultConfig1)

var customHeaders = make(map[string]string) // Create a map for custom headers
customHeaders["x-custom-header"] = "custom-header-value"
customHeaders["X-Gateway-Route-ID"] = "UNIQUE_VAULT_ROUTING_ID"
customHeaders["X-Application-Source"] = "sample-application"

// Step 2: Configure the skyflow client
skyflowInstance, err := client.NewSkyflow(
client.WithVaults(arr...),
client.WithLogLevel(logger.INFO),
client.WithCustomHeaders(customHeaders), // Added custom headers
)
if err != nil {
fmt.Println(*err)
} else {
// Step 3: Configure the vault
service, serviceError := skyflowInstance.Vault("<VAULT_ID>") // Replace with your vault ID from the vault config
if serviceError != nil {
fmt.Println(*serviceError)
} else {
ctx := context.TODO()
values := make([]map[string]interface{}, 0)
values = append(values, map[string]interface{}{
"<FIELD_1>": "<VALUE_1>",
})
values = append(values, map[string]interface{}{
"<FIELD_2>": "<VALUE_2>",
"<FIELD_3>": "<VALUE_3>",
})

// Step 4: Insert records with proper data and receive tokens
insert, insertErr := service.Insert(ctx, common.InsertRequest{
Table: "<TABLE>", // Replace with actual table
Values: values,
}, common.InsertOptions{ContinueOnError: false, ReturnTokens: true})

// Step 5: Handle the response and errors
if insertErr != nil {
fmt.Println("ERROR: ", *insertErr)
} else {
fmt.Println("RESPONSE: ", insert)
}
}
}

}
Loading