-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdetokenize_records.py
More file actions
89 lines (77 loc) · 2.96 KB
/
detokenize_records.py
File metadata and controls
89 lines (77 loc) · 2.96 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
import json
from skyflow.error import SkyflowError
from skyflow import Env
from skyflow import Skyflow, LogLevel
from skyflow.utils.enums import RedactionType
from skyflow.vault.tokens import DetokenizeRequest
"""
* Skyflow Detokenization Example
*
* This example demonstrates how to:
* 1. Configure Skyflow client credentials
* 2. Set up vault configuration
* 3. Create a detokenization request
* 4. Handle response and errors
"""
def perform_detokenization():
try:
# Step 1: Configure Credentials
cred = {
'clientID': '<YOUR_CLIENT_ID>', # Client identifier
'clientName': '<YOUR_CLIENT_NAME>', # Client name
'tokenURI': '<YOUR_TOKEN_URI>', # Token URI
'keyID': '<YOUR_KEY_ID>', # Key identifier
'privateKey': '<YOUR_PRIVATE_KEY>', # Private key for authentication
}
skyflow_credentials = {
'credentials_string': json.dumps(cred) # Token credentials
}
credentials = {
'token': '<YOUR_TOKEN>' # Bearer token for authentication
}
# Step 2: Configure Vault
primary_vault_config = {
'vault_id': '<YOUR_VAULT_ID1>', # primary vault
'cluster_id': '<YOUR_CLUSTER_ID1>', # Cluster ID from your vault URL
'env': Env.PROD, # Deployment environment (PROD by default)
'credentials': credentials # Authentication method
}
# Step 3: Configure & Initialize Skyflow Client
skyflow_client = (
Skyflow.builder()
.add_vault_config(primary_vault_config)
.add_skyflow_credentials(skyflow_credentials) # Used if no individual credentials are passed
.set_log_level(LogLevel.ERROR) # Logging verbosity
.build()
)
# Step 4: Prepare Detokenization Data
detokenize_data = [
{
'token': '<TOKEN1>', # Token to be detokenized
'redaction': RedactionType.REDACTED
},
{
'token': '<TOKEN2>', # Token to be detokenized
'redaction': RedactionType.MASKED
}
]
# Create Detokenize Request
detokenize_request = DetokenizeRequest(
data=detokenize_data,
continue_on_error=True # Continue processing on errors
)
# Step 5: Perform Detokenization
response = skyflow_client.vault(primary_vault_config.get('vault_id')).detokenize(detokenize_request)
# Handle Successful Response
print('Detokenization successful: ', response)
except SkyflowError as error:
# Comprehensive Error Handling
print('Skyflow Specific Error: ', {
'code': error.http_code,
'message': error.message,
'details': error.details
})
except Exception as error:
print('Unexpected Error:', error)
# Invoke the detokenization function
perform_detokenization()