Repository navigation
Expand file tree
/
Copy pathcredentials-options.ts
More file actions
130 lines (110 loc) · 4.73 KB
/
Copy pathcredentials-options.ts
File metadata and controls
130 lines (110 loc) · 4.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import {
Credentials,
DeleteRequest,
Env,
LogLevel,
Skyflow,
VaultConfig,
SkyflowConfig,
SkyflowError,
DeleteResponse,
StringCredentials
} from 'skyflow-node';
/**
* Skyflow Secure Data Deletion Example
*
* This example demonstrates how to:
* 1. Configure Skyflow client credentials
* 2. Set up vault configurations
* 3. Create and perform delete requests
* 4. Handle response and errors
*/
async function performSecureDataDeletion() {
try {
// Step 1: Configure Skyflow client Credentials
const cred: Record<string, string> = {
clientID: '<your-client-id>', // Client identifier
clientName: '<your-client-name>', // Client name
keyID: '<your-key-id>', // Key identifier
tokenURI: '<your-token-uri>', // Token URI
privateKey: '<your-pem-private-key>' // Private key for authentication
};
const stringCredentials: StringCredentials = {
credentialsString: JSON.stringify(cred), // Credentials string
}
const skyflowCredentials: Credentials = stringCredentials;
const credentials: Credentials = {
token: '<your_bearer_token>', // Bearer token
// apiKey: '<your_api_key>', // Uncomment to use API key
// path: 'path_to_credentials_json', // Path to credentials file
// credentialsString: 'your_credentials_string', // Credentials as string
};
// Step 2: Configure Vaults
const primaryVaultConfig: VaultConfig = {
vaultId: '<your_vault_id>', // Primary vault
clusterId: '<your_cluster_id>', // Cluster ID from your vault URL
env: Env.PROD, // Deployment environment (PROD by default)
};
const secondaryVaultConfig: VaultConfig = {
vaultId: '<your_secondary_vault_id>', // Secondary vault
clusterId: '<your_secondary_cluster_id>', // Cluster ID from your vault URL
env: Env.PROD, // Deployment environment
credentials: credentials, // Use credentials if specified
};
// Step 3: Configure Skyflow Client
const skyflowConfig: SkyflowConfig = {
vaultConfigs: [primaryVaultConfig, secondaryVaultConfig], // Vault configurations
skyflowCredentials: skyflowCredentials, // Used if no individual credentials are passed
logLevel: LogLevel.ERROR, // Set log level (ERROR in this case)
};
// Initialize Skyflow Client
const skyflowClient: Skyflow = new Skyflow(skyflowConfig);
// Step 4: Prepare Delete Request for Primary Vault
const primaryDeleteIds: Array<string> = [
'skyflow_id1',
'skyflow_id2',
'skyflow_id3',
];
const primaryTableName: string = '<primary_table_name>'; // Replace with actual table name
const primaryDeleteRequest: DeleteRequest = new DeleteRequest(
primaryTableName,
primaryDeleteIds,
);
// Perform Delete Operation for Primary Vault
const primaryDeleteResponse: DeleteResponse = await skyflowClient
.vault('<your_vault_id>') // Specify the primary vault ID
.delete(primaryDeleteRequest);
// Handle Successful Response
console.log('Primary Vault Deletion Successful:', primaryDeleteResponse);
// Step 5: Prepare Delete Request for Secondary Vault
const secondaryDeleteIds: Array<string> = [
'skyflow_id4',
'skyflow_id5',
'skyflow_id6',
];
const secondaryTableName: string = '<secondary_table_name>'; // Replace with actual table name
const secondaryDeleteRequest: DeleteRequest = new DeleteRequest(
secondaryTableName,
secondaryDeleteIds,
);
// Perform Delete Operation for Secondary Vault
const secondaryDeleteResponse: DeleteResponse = await skyflowClient
.vault('<your_secondary_vault_id>') // Specify the secondary vault ID
.delete(secondaryDeleteRequest);
// Handle Successful Response
console.log('Secondary Vault Deletion Successful:', secondaryDeleteResponse);
} catch (error) {
// Comprehensive Error Handling
if (error instanceof SkyflowError) {
console.error('Skyflow Specific Error:', {
code: error.error?.http_code,
message: error.message,
details: error.error?.details
});
} else {
console.error('Unexpected Error:', error);
}
}
}
// Invoke the secure data deletion function
performSecureDataDeletion();