Skip to content

Commit

Permalink
SK-1621: refactor samples
Browse files Browse the repository at this point in the history
  • Loading branch information
“amith-skyflow” committed Oct 25, 2024
1 parent dd18289 commit 3f00f71
Show file tree
Hide file tree
Showing 16 changed files with 753 additions and 698 deletions.
114 changes: 59 additions & 55 deletions samples/vault-api/client-operations.ts
Original file line number Diff line number Diff line change
@@ -1,68 +1,72 @@
import { DeleteRequest, Env, LogLevel, Skyflow } from "skyflow-node";

// To generate Bearer Token from credentials string.
const cred = {
clientID: '<YOUR_CLIENT_ID>',
clientName: '<YOUR_CLIENT_NAME>',
keyID: '<YOUR_KEY_ID>',
tokenURI: '<YOUR_TOKEN_URI>',
privateKey: '<YOUR_PEM_PRIVATE_KEY>',
};
try {
// To generate Bearer Token from credentials string.
const cred = {
clientID: '<YOUR_CLIENT_ID>',
clientName: '<YOUR_CLIENT_NAME>',
keyID: '<YOUR_KEY_ID>',
tokenURI: '<YOUR_TOKEN_URI>',
privateKey: '<YOUR_PEM_PRIVATE_KEY>',
};

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

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

// please pass one of apiKey, token, credentialsString & path
const credentials = {
token: "BEARER_TOKEN", // bearer token
}
const skyflow_client = new Skyflow({
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 deault it is set to PROD
credentials: credentials // indiviudal credentails
}
],
skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual creds are passed
logLevel: LogLevel.ERROR // set loglevel by deault it is set to PROD
});

const skyflow_client = new Skyflow({
vaultConfigs: [
//add vault config on the go
skyflow_client.addVaultConfig(
{
vaultId: "VAULT_ID1", // primary vault
clusterId: "CLUSTER_ID1", // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com
vaultId: "VAULT_ID2", // secondary vault
clusterId: "CLUSTER_ID2", // ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com
env: Env.PROD, // Env by deault it is set to PROD
credentials: credentials // indiviudal credentails
// if you dont specify individual creds, skyflow creds will be used
}
],
skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual creds are passed
logLevel:LogLevel.ERROR // set loglevel by deault it is set to PROD
});

//add vault config on the go
skyflow_client.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 deault it is set to PROD
// if you dont specify individual creds, skyflow creds will be used
}
);
);

//add vault config on the go
skyflow_client.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
}
);
//add vault config on the go
skyflow_client.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
}
);

//perform operations
const deleteIds = [
"SKYLFOW_ID1",
"SKYLFOW_ID1"
]
//perform operations
const deleteIds = [
"SKYLFOW_ID1",
"SKYLFOW_ID1"
]

const deleteRequest = new DeleteRequest(
"TABLE_NAME",
deleteIds
);
const deleteRequest = new DeleteRequest(
"TABLE_NAME",
deleteIds
);

//perform delete call if you dont specify valut() it will return the first valid vault
skyflow_client.vault("VALUT_ID2").delete(deleteRequest);
//perform delete call if you dont specify valut() it will return the first valid vault
skyflow_client.vault("VALUT_ID2").delete(deleteRequest);

skyflow_client.removeVaultConfig("VAULT_ID");
skyflow_client.removeVaultConfig("VAULT_ID");
} catch (err) {
console.log(JSON.stringify(err));
}
143 changes: 73 additions & 70 deletions samples/vault-api/credentials-options.ts
Original file line number Diff line number Diff line change
@@ -1,81 +1,84 @@
import { DeleteRequest, Env, LogLevel, Skyflow } 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 = {
clientID: '<YOUR_CLIENT_ID>',
clientName: '<YOUR_CLIENT_NAME>',
keyID: '<YOUR_KEY_ID>',
tokenURI: '<YOUR_TOKEN_URI>',
privateKey: '<YOUR_PEM_PRIVATE_KEY>',
};

//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 = {
clientID: '<YOUR_CLIENT_ID>',
clientName: '<YOUR_CLIENT_NAME>',
keyID: '<YOUR_KEY_ID>',
tokenURI: '<YOUR_TOKEN_URI>',
privateKey: '<YOUR_PEM_PRIVATE_KEY>',
};
// please pass one of apiKey, token, credentialsString & path
const skyflowCredentials = {
credentialsString: JSON.stringify(cred)
}

// please pass one of apiKey, token, credentialsString & path
const skyflowCredentials = {
credentialsString: JSON.stringify(cred)
}
const credentials = {
token: "BEARER_TOKEN", // bearer token
// apiKey: "API_KEY", //API_KEY
// path: "PATH", //PATH to credentials json
// credentialsString: "CREDENTIAL_STRING", // credentials as string
}

const credentials = {
token: "BEARER_TOKEN", // bearer token
// apiKey: "API_KEY", //API_KEY
// path: "PATH", //PATH to credentials json
// credentialsString: "CREDENTIAL_STRING", // credentials as string
}
const skyflow_client = new Skyflow({
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 deault 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 deault it is set to PROD
credentials: credentials,
}
],
skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual creds are passed
logLevel: LogLevel.ERROR // set loglevel by deault it is set to PROD
});

const skyflow_client = new Skyflow({
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 deault 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 deault it is set to PROD
credentials: credentials,
}
],
skyflowCredentials: skyflowCredentials, // skyflow credentials will be used if no individual creds are passed
logLevel:LogLevel.ERROR // set loglevel by deault it is set to PROD
});
const primaryDeleteIds = [
'SKYFLOW_ID1',
'SKYFLOW_ID2',
'SKYFLOW_ID3',
]

const primaryDeleteIds = [
'SKYFLOW_ID1',
'SKYFLOW_ID2',
'SKYFLOW_ID3',
]
const primaryDeleteRequest = new DeleteRequest(
"TABLE_NAME1", // TABLE_NAME
primaryDeleteIds
);

const primaryDeleteRequest = new DeleteRequest(
"TABLE_NAME1", // TABLE_NAME
primaryDeleteIds
);
// VAULT_ID1 will use skyflowCredentials if you don't specify individual credentials at config level
skyflow_client.vault("VAULT_ID1").delete(
primaryDeleteRequest
).then(resp => {
console.log(resp);
}).catch(err => {
console.log(JSON.stringify(err));
});

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

const secondaryDeleteIds = [
'SKYFLOW_ID4',
'SKYFLOW_ID5',
'SKYFLOW_ID6',
]
const secondaryDeleteIds = [
'SKYFLOW_ID4',
'SKYFLOW_ID5',
'SKYFLOW_ID6',
]

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

// VAULT_ID1 will use individual credentials at config level
skyflow_client.vault("VAULT_ID2").delete(
secondaryDeleteRequest
).then(resp=>{
console.log(resp);
}).catch(err=>{
// VAULT_ID1 will use individual credentials at config level
skyflow_client.vault("VAULT_ID2").delete(
secondaryDeleteRequest
).then(resp => {
console.log(resp);
}).catch(err => {
console.log(JSON.stringify(err));
});
} catch (err) {
console.log(JSON.stringify(err));
});
}
Loading

0 comments on commit 3f00f71

Please sign in to comment.