Skip to content

Commit 06b9b38

Browse files
SK-2838: add deprecated samples
1 parent 5345434 commit 06b9b38

3 files changed

Lines changed: 254 additions & 0 deletions

File tree

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import json
2+
from skyflow.error import SkyflowError
3+
from skyflow import Env
4+
from skyflow import Skyflow, LogLevel
5+
from skyflow.utils.enums import RedactionType
6+
from skyflow.vault.tokens import DetokenizeRequest
7+
8+
"""
9+
* [DEPRECATED] Skyflow Detokenize with 'redaction' Key Example
10+
*
11+
* The 'redaction' key in detokenize data is deprecated.
12+
* Use 'redaction_type' instead.
13+
*
14+
* This example demonstrates how to:
15+
* 1. Configure Skyflow client credentials
16+
* 2. Set up vault configuration
17+
* 3. Detokenize using the deprecated 'redaction' key
18+
* 4. Handle response and errors
19+
*
20+
* Migration:
21+
* Before: {'token': '<TOKEN>', 'redaction': RedactionType.PLAIN_TEXT}
22+
* After: {'token': '<TOKEN>', 'redaction_type': RedactionType.PLAIN_TEXT}
23+
"""
24+
25+
def perform_detokenization_deprecated():
26+
try:
27+
# Step 1: Configure Credentials
28+
cred = {
29+
'clientID': '<YOUR_CLIENT_ID>',
30+
'clientName': '<YOUR_CLIENT_NAME>',
31+
'tokenURI': '<YOUR_TOKEN_URI>',
32+
'keyID': '<YOUR_KEY_ID>',
33+
'privateKey': '<YOUR_PRIVATE_KEY>',
34+
}
35+
36+
skyflow_credentials = {
37+
'credentials_string': json.dumps(cred)
38+
}
39+
40+
credentials = {
41+
'token': '<YOUR_TOKEN>'
42+
}
43+
44+
# Step 2: Configure Vault
45+
primary_vault_config = {
46+
'vault_id': '<YOUR_VAULT_ID>',
47+
'cluster_id': '<YOUR_CLUSTER_ID>',
48+
'env': Env.PROD,
49+
'credentials': credentials
50+
}
51+
52+
# Step 3: Configure & Initialize Skyflow Client
53+
skyflow_client = (
54+
Skyflow.builder()
55+
.add_vault_config(primary_vault_config)
56+
.add_skyflow_credentials(skyflow_credentials)
57+
.set_log_level(LogLevel.ERROR)
58+
.build()
59+
)
60+
61+
# Step 4: Prepare Detokenization Data using deprecated 'redaction' key
62+
# DEPRECATED: 'redaction' key will be removed in a future release.
63+
# Use 'redaction_type' instead (see migration above).
64+
detokenize_data = [
65+
{
66+
'token': '<TOKEN1>',
67+
'redaction': RedactionType.REDACTED
68+
},
69+
{
70+
'token': '<TOKEN2>',
71+
'redaction': RedactionType.MASKED
72+
}
73+
]
74+
75+
detokenize_request = DetokenizeRequest(
76+
data=detokenize_data,
77+
continue_on_error=True
78+
)
79+
80+
# Step 5: Perform Detokenization
81+
response = skyflow_client.vault(primary_vault_config.get('vault_id')).detokenize(detokenize_request)
82+
print('Detokenization successful: ', response)
83+
84+
except SkyflowError as error:
85+
print('Skyflow Specific Error: ', {
86+
'code': error.http_code,
87+
'message': error.message,
88+
'details': error.details
89+
})
90+
except Exception as error:
91+
print('Unexpected Error:', error)
92+
93+
# Invoke the function
94+
perform_detokenization_deprecated()
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import json
2+
from skyflow.error import SkyflowError
3+
from skyflow import Env
4+
from skyflow import Skyflow, LogLevel
5+
from skyflow.vault.data import FileUploadRequest
6+
7+
"""
8+
* [DEPRECATED] Skyflow FileUploadRequest Positional Arguments Example
9+
*
10+
* Passing positional arguments after 'table' in FileUploadRequest is deprecated.
11+
* Use keyword arguments instead.
12+
*
13+
* This example demonstrates how to:
14+
* 1. Configure Skyflow client credentials
15+
* 2. Set up vault configuration
16+
* 3. Upload a file using the deprecated positional argument order
17+
* 4. Handle response and errors
18+
*
19+
* Migration:
20+
* Before: FileUploadRequest(table, skyflow_id, column_name, file_object=file_obj)
21+
* After: FileUploadRequest(table, column_name=column_name, skyflow_id=skyflow_id, file_object=file_obj)
22+
"""
23+
24+
def perform_file_upload_deprecated():
25+
try:
26+
# Step 1: Configure Credentials
27+
cred = {
28+
'clientID': '<YOUR_CLIENT_ID>',
29+
'clientName': '<YOUR_CLIENT_NAME>',
30+
'tokenURI': '<YOUR_TOKEN_URI>',
31+
'keyID': '<YOUR_KEY_ID>',
32+
'privateKey': '<YOUR_PRIVATE_KEY>',
33+
}
34+
35+
skyflow_credentials = {
36+
'credentials_string': json.dumps(cred)
37+
}
38+
39+
credentials = {
40+
'token': '<YOUR_TOKEN>'
41+
}
42+
43+
# Step 2: Configure Vault
44+
primary_vault_config = {
45+
'vault_id': '<YOUR_VAULT_ID>',
46+
'cluster_id': '<YOUR_CLUSTER_ID>',
47+
'env': Env.PROD,
48+
'credentials': credentials
49+
}
50+
51+
# Step 3: Configure & Initialize Skyflow Client
52+
skyflow_client = (
53+
Skyflow.builder()
54+
.add_vault_config(primary_vault_config)
55+
.add_skyflow_credentials(skyflow_credentials)
56+
.set_log_level(LogLevel.ERROR)
57+
.build()
58+
)
59+
60+
# Step 4: Perform File Upload using deprecated positional argument order
61+
with open('<PATH_TO_FILE>', 'rb') as file_obj:
62+
# DEPRECATED: positional args after 'table' are deprecated.
63+
# Old order: (table, skyflow_id, column_name)
64+
# Use keyword arguments instead (see migration above).
65+
upload_request = FileUploadRequest(
66+
'<TABLE_NAME>',
67+
'<SKYFLOW_ID>',
68+
'<COLUMN_NAME>',
69+
file_object=file_obj
70+
)
71+
72+
response = skyflow_client.vault('<YOUR_VAULT_ID>').upload_file(upload_request)
73+
print('File upload successful: ', response)
74+
75+
except SkyflowError as error:
76+
print('Skyflow Specific Error: ', {
77+
'code': error.http_code,
78+
'message': error.message,
79+
'details': error.details
80+
})
81+
except Exception as error:
82+
print('Unexpected Error:', error)
83+
84+
# Invoke the function
85+
perform_file_upload_deprecated()
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import json
2+
from skyflow.error import SkyflowError
3+
from skyflow import Env
4+
from skyflow import Skyflow, LogLevel
5+
6+
"""
7+
* [DEPRECATED] Skyflow update_log_level Example
8+
*
9+
* update_log_level() is deprecated. Use set_log_level() instead.
10+
*
11+
* This example demonstrates how to:
12+
* 1. Configure Skyflow client credentials
13+
* 2. Set up vault configuration
14+
* 3. Change the log level at runtime using the deprecated update_log_level()
15+
* 4. Handle response and errors
16+
*
17+
* Migration:
18+
* Before: skyflow_client.update_log_level(LogLevel.INFO)
19+
* After: skyflow_client.set_log_level(LogLevel.INFO)
20+
"""
21+
22+
def perform_update_log_level():
23+
try:
24+
# Step 1: Configure Credentials
25+
cred = {
26+
'clientID': '<YOUR_CLIENT_ID>',
27+
'clientName': '<YOUR_CLIENT_NAME>',
28+
'tokenURI': '<YOUR_TOKEN_URI>',
29+
'keyID': '<YOUR_KEY_ID>',
30+
'privateKey': '<YOUR_PRIVATE_KEY>',
31+
}
32+
33+
skyflow_credentials = {
34+
'credentials_string': json.dumps(cred)
35+
}
36+
37+
credentials = {
38+
'token': '<YOUR_TOKEN>'
39+
}
40+
41+
# Step 2: Configure Vault
42+
primary_vault_config = {
43+
'vault_id': '<YOUR_VAULT_ID>',
44+
'cluster_id': '<YOUR_CLUSTER_ID>',
45+
'env': Env.PROD,
46+
'credentials': credentials
47+
}
48+
49+
# Step 3: Configure & Initialize Skyflow Client
50+
skyflow_client = (
51+
Skyflow.builder()
52+
.add_vault_config(primary_vault_config)
53+
.add_skyflow_credentials(skyflow_credentials)
54+
.set_log_level(LogLevel.ERROR)
55+
.build()
56+
)
57+
58+
# Step 4: Change log level at runtime using deprecated method
59+
# DEPRECATED: update_log_level() will be removed in a future release.
60+
# Use set_log_level() instead.
61+
skyflow_client.update_log_level(LogLevel.INFO)
62+
63+
print('Log level updated successfully (deprecated). Use set_log_level() instead.')
64+
65+
except SkyflowError as error:
66+
print('Skyflow Specific Error: ', {
67+
'code': error.http_code,
68+
'message': error.message,
69+
'details': error.details
70+
})
71+
except Exception as error:
72+
print('Unexpected Error:', error)
73+
74+
# Invoke the function
75+
perform_update_log_level()

0 commit comments

Comments
 (0)