Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions samples/deprecated/detokenize_redaction_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
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

"""
* [DEPRECATED] Skyflow Detokenize with 'redaction' Key Example
*
* The 'redaction' key in detokenize data is deprecated.
* Use 'redaction_type' instead.
*
* This example demonstrates how to:
* 1. Configure Skyflow client credentials
* 2. Set up vault configuration
* 3. Detokenize using the deprecated 'redaction' key
* 4. Handle response and errors
*
* Migration:
* Before: {'token': '<TOKEN>', 'redaction': RedactionType.PLAIN_TEXT}
* After: {'token': '<TOKEN>', 'redaction_type': RedactionType.PLAIN_TEXT}
"""

def perform_detokenization_deprecated():
try:
# Step 1: Configure Credentials
cred = {
'clientID': '<YOUR_CLIENT_ID>',
'clientName': '<YOUR_CLIENT_NAME>',
'tokenURI': '<YOUR_TOKEN_URI>',
'keyID': '<YOUR_KEY_ID>',
'privateKey': '<YOUR_PRIVATE_KEY>',
}

skyflow_credentials = {
'credentials_string': json.dumps(cred)
}

credentials = {
'token': '<YOUR_TOKEN>'
}

# Step 2: Configure Vault
primary_vault_config = {
'vault_id': '<YOUR_VAULT_ID>',
'cluster_id': '<YOUR_CLUSTER_ID>',
'env': Env.PROD,
'credentials': credentials
}

# Step 3: Configure & Initialize Skyflow Client
skyflow_client = (
Skyflow.builder()
.add_vault_config(primary_vault_config)
.add_skyflow_credentials(skyflow_credentials)
.set_log_level(LogLevel.ERROR)
.build()
)

# Step 4: Prepare Detokenization Data using deprecated 'redaction' key
# DEPRECATED: 'redaction' key will be removed in a future release.
# Use 'redaction_type' instead (see migration above).
detokenize_data = [
{
'token': '<TOKEN1>',
'redaction': RedactionType.REDACTED
},
{
'token': '<TOKEN2>',
'redaction': RedactionType.MASKED
}
]

detokenize_request = DetokenizeRequest(
data=detokenize_data,
continue_on_error=True
)

# Step 5: Perform Detokenization
response = skyflow_client.vault(primary_vault_config.get('vault_id')).detokenize(detokenize_request)
print('Detokenization successful: ', response)

except SkyflowError as error:
print('Skyflow Specific Error: ', {
'code': error.http_code,
'message': error.message,
'details': error.details
})
except Exception as error:
print('Unexpected Error:', error)

# Invoke the function
perform_detokenization_deprecated()
85 changes: 85 additions & 0 deletions samples/deprecated/file_upload_positional_args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import json
from skyflow.error import SkyflowError
from skyflow import Env
from skyflow import Skyflow, LogLevel
from skyflow.vault.data import FileUploadRequest

"""
* [DEPRECATED] Skyflow FileUploadRequest Positional Arguments Example
*
* Passing positional arguments after 'table' in FileUploadRequest is deprecated.
* Use keyword arguments instead.
*
* This example demonstrates how to:
* 1. Configure Skyflow client credentials
* 2. Set up vault configuration
* 3. Upload a file using the deprecated positional argument order
* 4. Handle response and errors
*
* Migration:
* Before: FileUploadRequest(table, skyflow_id, column_name, file_object=file_obj)
* After: FileUploadRequest(table, column_name=column_name, skyflow_id=skyflow_id, file_object=file_obj)
"""

def perform_file_upload_deprecated():
try:
# Step 1: Configure Credentials
cred = {
'clientID': '<YOUR_CLIENT_ID>',
'clientName': '<YOUR_CLIENT_NAME>',
'tokenURI': '<YOUR_TOKEN_URI>',
'keyID': '<YOUR_KEY_ID>',
'privateKey': '<YOUR_PRIVATE_KEY>',
}

skyflow_credentials = {
'credentials_string': json.dumps(cred)
}

credentials = {
'token': '<YOUR_TOKEN>'
}

# Step 2: Configure Vault
primary_vault_config = {
'vault_id': '<YOUR_VAULT_ID>',
'cluster_id': '<YOUR_CLUSTER_ID>',
'env': Env.PROD,
'credentials': credentials
}

# Step 3: Configure & Initialize Skyflow Client
skyflow_client = (
Skyflow.builder()
.add_vault_config(primary_vault_config)
.add_skyflow_credentials(skyflow_credentials)
.set_log_level(LogLevel.ERROR)
.build()
)

# Step 4: Perform File Upload using deprecated positional argument order
with open('<PATH_TO_FILE>', 'rb') as file_obj:
# DEPRECATED: positional args after 'table' are deprecated.
# Old order: (table, skyflow_id, column_name)
# Use keyword arguments instead (see migration above).
upload_request = FileUploadRequest(
'<TABLE_NAME>',
'<SKYFLOW_ID>',
'<COLUMN_NAME>',
file_object=file_obj
)

response = skyflow_client.vault('<YOUR_VAULT_ID>').upload_file(upload_request)
print('File upload successful: ', response)

except SkyflowError as error:
print('Skyflow Specific Error: ', {
'code': error.http_code,
'message': error.message,
'details': error.details
})
except Exception as error:
print('Unexpected Error:', error)

# Invoke the function
perform_file_upload_deprecated()
75 changes: 75 additions & 0 deletions samples/deprecated/update_log_level.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import json
from skyflow.error import SkyflowError
from skyflow import Env
from skyflow import Skyflow, LogLevel

"""
* [DEPRECATED] Skyflow update_log_level Example
*
* update_log_level() is deprecated. Use set_log_level() instead.
*
* This example demonstrates how to:
* 1. Configure Skyflow client credentials
* 2. Set up vault configuration
* 3. Change the log level at runtime using the deprecated update_log_level()
* 4. Handle response and errors
*
* Migration:
* Before: skyflow_client.update_log_level(LogLevel.INFO)
* After: skyflow_client.set_log_level(LogLevel.INFO)
"""

def perform_update_log_level():
try:
# Step 1: Configure Credentials
cred = {
'clientID': '<YOUR_CLIENT_ID>',
'clientName': '<YOUR_CLIENT_NAME>',
'tokenURI': '<YOUR_TOKEN_URI>',
'keyID': '<YOUR_KEY_ID>',
'privateKey': '<YOUR_PRIVATE_KEY>',
}

skyflow_credentials = {
'credentials_string': json.dumps(cred)
}

credentials = {
'token': '<YOUR_TOKEN>'
}

# Step 2: Configure Vault
primary_vault_config = {
'vault_id': '<YOUR_VAULT_ID>',
'cluster_id': '<YOUR_CLUSTER_ID>',
'env': Env.PROD,
'credentials': credentials
}

# Step 3: Configure & Initialize Skyflow Client
skyflow_client = (
Skyflow.builder()
.add_vault_config(primary_vault_config)
.add_skyflow_credentials(skyflow_credentials)
.set_log_level(LogLevel.ERROR)
.build()
)

# Step 4: Change log level at runtime using deprecated method
# DEPRECATED: update_log_level() will be removed in a future release.
# Use set_log_level() instead.
skyflow_client.update_log_level(LogLevel.INFO)

print('Log level updated successfully (deprecated). Use set_log_level() instead.')

except SkyflowError as error:
print('Skyflow Specific Error: ', {
'code': error.http_code,
'message': error.message,
'details': error.details
})
except Exception as error:
print('Unexpected Error:', error)

# Invoke the function
perform_update_log_level()
Loading