Skip to content

Commit

Permalink
SK-1621: add readme and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
“amith-skyflow” committed Nov 21, 2024
1 parent f4f3017 commit 8f9068a
Show file tree
Hide file tree
Showing 32 changed files with 1,084 additions and 1,011 deletions.
939 changes: 450 additions & 489 deletions README.md

Large diffs are not rendered by default.

86 changes: 47 additions & 39 deletions samples/vault-api/client-operations.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { DeleteRequest, Env, LogLevel, Skyflow } from "skyflow-node";
import { Credentials, DeleteRequest, Env, LogLevel, Skyflow, VaultConfig, SkyflowConfig } from 'skyflow-node';

try {
// To generate Bearer Token from credentials string.
const cred = {
const cred: Object = {
clientID: '<YOUR_CLIENT_ID>',
clientName: '<YOUR_CLIENT_NAME>',
keyID: '<YOUR_KEY_ID>',
Expand All @@ -11,63 +11,71 @@ try {
};

// please pass one of apiKey, token, credentialsString & path as credentials
const skyflowCredentials = {
const skyflowCredentials: Credentials = {
credentialsString: JSON.stringify(cred),
}
};

// please pass one of apiKey, token, credentialsString & path as credentials
const credentials = {
token: "BEARER_TOKEN", // bearer token
}
const credentials: Credentials = {
token: 'BEARER_TOKEN', // bearer token
};

const primaryVaultConfig: VaultConfig = {
vaultId: 'VAULT_ID1', // primary vault
clusterId: 'CLUSTER_ID1', // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com
env: Env.PROD, // Env by default it is set to PROD
credentials: credentials, // individual credentials
};

const skyflowClient = new Skyflow({
// skyflow config
const skyflowConfig: SkyflowConfig = {
// pass array vault configs
vaultConfigs: [
{
vaultId: "VAULT_ID1", // primary vault
clusterId: "CLUSTER_ID1", // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com
env: Env.PROD, // Env by default it is set to PROD
credentials: credentials // individual credentials
}
primaryVaultConfig,
],
skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual credentials are passed
logLevel: LogLevel.ERROR // set log level by default it is set to PROD
});
logLevel: LogLevel.ERROR, // set log level by default it is set to PROD
};

// initialize skyflow client
const skyflowClient: Skyflow = new Skyflow(skyflowConfig);

const vaultConfig: VaultConfig = {
vaultId: 'VAULT_ID2', // secondary vault
clusterId: 'CLUSTER_ID2', // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com
env: Env.PROD, // Env by default it is set to PROD
// if you don't specify individual credentials, skyflow credentials will be used
};

//add vault config on the fly
skyflowClient.addVaultConfig(
{
vaultId: "VAULT_ID2", // secondary vault
clusterId: "CLUSTER_ID2", // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com
env: Env.PROD, // Env by default it is set to PROD
// if you don't specify individual credentials, skyflow credentials will be used
}
);
skyflowClient.addVaultConfig(vaultConfig);

const updatedVaultConfig: VaultConfig = {
vaultId: 'VAULT_ID2', // vault Id and cluster Id is unique
clusterId: 'CLUSTER_ID2', // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com
credentials: credentials, //update credentials
};
//update vault config on the fly
skyflowClient.updateVaultConfig(
{
vaultId: "VAULT_ID2", // vault Id and cluster Id is unique
clusterId: "CLUSTER_ID2", // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com
credentials: credentials, //update credentials
}
);
skyflowClient.updateVaultConfig(updatedVaultConfig);

//perform operations
const deleteIds = [
"SKYLFOW_ID1",
"SKYLFOW_ID2"
const deleteIds: Array<string> = [
'SKYLFOW_ID1',
'SKYLFOW_ID2',
]

const deleteRequest = new DeleteRequest(
"TABLE_NAME",
deleteIds
const tableName: string = 'TABLE_NAME';

const deleteRequest: DeleteRequest = new DeleteRequest(
tableName,
deleteIds,
);

//perform delete call if you don't specify vault() it will return the first valid vault
skyflowClient.vault("VAULT_ID2").delete(deleteRequest);
skyflowClient.vault('VAULT_ID2').delete(deleteRequest);

//remove vault on the fly
skyflowClient.removeVaultConfig("VAULT_ID");
skyflowClient.removeVaultConfig('VAULT_ID');
} catch (err) {
console.log(JSON.stringify(err));
}
95 changes: 53 additions & 42 deletions samples/vault-api/credentials-options.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { DeleteRequest, Env, LogLevel, Skyflow } from "skyflow-node";
import { Credentials, DeleteRequest, Env, LogLevel, Skyflow, VaultConfig, SkyflowConfig, DeleteResponse, SkyflowError } from 'skyflow-node';

try {
//NOTE : If you don't specify credentials at config level credentials or skyflow credentials, SDK will check SKYFLOW_CREDENTIALS key in your env
// To generate Bearer Token from credentials string.
const cred = {
const cred: Object = {
clientID: '<YOUR_CLIENT_ID>',
clientName: '<YOUR_CLIENT_NAME>',
keyID: '<YOUR_KEY_ID>',
Expand All @@ -11,72 +12,82 @@ try {
};

// please pass one of apiKey, token, credentialsString & path as credentials
const skyflowCredentials = {
credentialsString: JSON.stringify(cred)
}
const skyflowCredentials: Credentials = {
credentialsString: JSON.stringify(cred),
};

const credentials: Credentials = {
token: 'BEARER_TOKEN', // bearer token
// apiKey: 'API_KEY', //API_KEY
// path: 'PATH', //path to credentials file
// credentialsString: 'CREDENTIAL_STRING', // credentials as string
};

const primaryVaultConfig: VaultConfig = {
vaultId: 'VAULT_ID1', // primary vault
clusterId: 'CLUSTER_ID1', // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com
env: Env.PROD, // Env by default it is set to PROD
};

const credentials = {
token: "BEARER_TOKEN", // bearer token
// apiKey: "API_KEY", //API_KEY
// path: "PATH", //path to credentials file
// credentialsString: "CREDENTIAL_STRING", // credentials as string
}
const secondaryVaultConfig: VaultConfig = {
vaultId: 'VAULT_ID2', // secondary vault
clusterId: 'CLUSTER_ID2', // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com
env: Env.PROD, // Env by default it is set to PROD
credentials: credentials,
};

const skyflowClient = new Skyflow({
const skyflowConfig: SkyflowConfig = {
vaultConfigs: [
{
vaultId: "VAULT_ID1", // primary vault
clusterId: "CLUSTER_ID1", // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com
env: Env.PROD, // Env by default it is set to PROD
},
{
vaultId: "VAULT_ID2", // primary vault
clusterId: "CLUSTER_ID2", // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com
env: Env.PROD, // Env by default it is set to PROD
credentials: credentials,
}
primaryVaultConfig,
secondaryVaultConfig,
],
skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual credentials are passed
logLevel: LogLevel.ERROR // set log level by default it is set to PROD
});
logLevel: LogLevel.ERROR, // set log level by default it is set to PROD
};

const primaryDeleteIds = [
const skyflowClient: Skyflow = new Skyflow(skyflowConfig);

const primaryDeleteIds: Array<string> = [
'SKYFLOW_ID1',
'SKYFLOW_ID2',
'SKYFLOW_ID3',
]
];

const primaryTableName: string = 'TABLE_NAME1'; // TABLE_NAME

const primaryDeleteRequest = new DeleteRequest(
"TABLE_NAME1", // TABLE_NAME
primaryDeleteIds
const primaryDeleteRequest: DeleteRequest = new DeleteRequest(
primaryTableName,
primaryDeleteIds,
);

// VAULT_ID1 will use skyflowCredentials if you don't specify individual credentials at config level
skyflowClient.vault("VAULT_ID1").delete(
primaryDeleteRequest
).then(resp => {
skyflowClient.vault('VAULT_ID1').delete(
primaryDeleteRequest,
).then((resp: DeleteResponse) => {
console.log(resp);
}).catch(err => {
}).catch((err: SkyflowError) => {
console.log(JSON.stringify(err));
});

const secondaryDeleteIds = [
const secondaryDeleteIds: Array<string> = [
'SKYFLOW_ID4',
'SKYFLOW_ID5',
'SKYFLOW_ID6',
]
];

const secondaryTableName: string = 'TABLE_NAME2'; // TABLE_NAME

const secondaryDeleteRequest = new DeleteRequest(
"TABLE_NAME2", // TABLE_NAME
secondaryDeleteIds
const secondaryDeleteRequest: DeleteRequest = new DeleteRequest(
secondaryTableName,
secondaryDeleteIds,
);

// VAULT_ID1 will use individual credentials at config level
skyflowClient.vault("VAULT_ID2").delete(
skyflowClient.vault('VAULT_ID2').delete(
secondaryDeleteRequest
).then(resp => {
).then((resp: DeleteResponse) => {
console.log(resp);
}).catch(err => {
}).catch((err: SkyflowError) => {
console.log(JSON.stringify(err));
});
} catch (err) {
Expand Down
90 changes: 49 additions & 41 deletions samples/vault-api/data-residency.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Env, GetRequest, GetResponse, InsertRequest, LogLevel, Skyflow } from "skyflow-node";
import { Credentials, Env, GetRequest, GetResponse, InsertRequest, LogLevel, Skyflow, VaultConfig, SkyflowConfig, InsertResponse, SkyflowError } from 'skyflow-node';

try {
// To generate Bearer Token from credentials string.
const cred = {
const cred: Object = {
clientID: '<YOUR_CLIENT_ID>',
clientName: '<YOUR_CLIENT_NAME>',
keyID: '<YOUR_KEY_ID>',
Expand All @@ -11,71 +11,79 @@ try {
};

// please pass one of apiKey, token, credentialsString & path as credentials
const skyflowCredentials = {
const skyflowCredentials: Credentials = {
credentialsString: JSON.stringify(cred),
}
};

// please pass one of apiKey, token, credentialsString & path as credentials
const credentials = {
token: "BEARER_TOKEN", // bearer token
}
const credentials: Credentials = {
token: 'BEARER_TOKEN', // bearer token
};

const primaryVaultConfig: VaultConfig = {
vaultId: 'VAULT_ID1', // primary vault
clusterId: 'CLUSTER_ID1', // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com
env: Env.PROD, // Env by default it is set to PROD
credentials: credentials, // individual credentials
};

const skyflowClient = new Skyflow({
const skyflowConfig: SkyflowConfig = {
vaultConfigs: [
{
vaultId: "VAULT_ID1", // primary vault
clusterId: "CLUSTER_ID1", // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com
env: Env.PROD, // Env by default it is set to PROD
credentials: credentials // individual credentials
}
primaryVaultConfig,
],
skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual credentials are passed
logLevel: LogLevel.ERROR // set log level by default it is set to PROD
});
logLevel: LogLevel.ERROR, // set log level by default it is set to PROD
};

const skyflowClient: Skyflow = new Skyflow(skyflowConfig);

const secondaryVaultConfig: VaultConfig = {
vaultId: 'VAULT_ID2', // secondary vault
clusterId: 'CLUSTER_ID2', // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com
env: Env.PROD, // Env by default it is set to PROD
// if you dont specify individual credentials, skyflow credentials will be used
};

//add vault config from prod env
skyflowClient.addVaultConfig(
{
vaultId: "VAULT_ID2", // secondary vault
clusterId: "CLUSTER_ID2", // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com
env: Env.PROD, // Env by default it is set to PROD
// if you dont specify individual credentials, skyflow credentials will be used
}
);
skyflowClient.addVaultConfig(secondaryVaultConfig);

//perform operations
const getIds = [
"SKYLFOW_ID1",
"SKYLFOW_ID2"
]
const getIds: Array<string> = [
'SKYLFOW_ID1',
'SKYLFOW_ID2',
];

const getRequest = new GetRequest(
"TABLE_NAME",
getIds
const tableName: string = 'TABLE_NAME';

const getRequest: GetRequest = new GetRequest(
tableName,
getIds,
);

//perform delete call if you dont specify vault() it will return the first valid vault
skyflowClient.vault("VAULT_ID1").get(getRequest)
skyflowClient.vault('VAULT_ID1').get(getRequest)
.then(response => {
//
// get response
const getResponse: GetResponse = response as GetResponse;
console.log(getResponse.data);
const insertData = getResponse.data;
const insertData: Array<Object> = getResponse.data!;

const tableName: string = 'TABLE_NAME';
//parse insertData to remove skyflow_id
//get data from one vault and insert data to another vault
const insertRequest = new InsertRequest(
"TABLE_NAME",
insertData!,
const insertRequest: InsertRequest = new InsertRequest(
tableName,
insertData,
);
skyflowClient.vault("VAULT_ID2").insert(
skyflowClient.vault('VAULT_ID2').insert(
insertRequest
).then(resp => {
).then((resp: InsertResponse) => {
console.log(resp);
}).catch(err => {
}).catch((err: SkyflowError) => {
console.log(JSON.stringify(err));
});
})
.catch(err => {
.catch((err: SkyflowError) => {
console.log(JSON.stringify(err));
});
} catch (err) {
Expand Down
Loading

0 comments on commit 8f9068a

Please sign in to comment.