diff --git a/samples/deprecated/detokenize_redaction_key.py b/samples/deprecated/detokenize_redaction_key.py new file mode 100644 index 0000000..63da46b --- /dev/null +++ b/samples/deprecated/detokenize_redaction_key.py @@ -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': '', 'redaction': RedactionType.PLAIN_TEXT} + * After: {'token': '', 'redaction_type': RedactionType.PLAIN_TEXT} +""" + +def perform_detokenization_deprecated(): + try: + # Step 1: Configure Credentials + cred = { + 'clientID': '', + 'clientName': '', + 'tokenURI': '', + 'keyID': '', + 'privateKey': '', + } + + skyflow_credentials = { + 'credentials_string': json.dumps(cred) + } + + credentials = { + 'token': '' + } + + # Step 2: Configure Vault + primary_vault_config = { + 'vault_id': '', + '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': '', + 'redaction': RedactionType.REDACTED + }, + { + 'token': '', + '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() diff --git a/samples/deprecated/file_upload_positional_args.py b/samples/deprecated/file_upload_positional_args.py new file mode 100644 index 0000000..e5edf50 --- /dev/null +++ b/samples/deprecated/file_upload_positional_args.py @@ -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': '', + 'clientName': '', + 'tokenURI': '', + 'keyID': '', + 'privateKey': '', + } + + skyflow_credentials = { + 'credentials_string': json.dumps(cred) + } + + credentials = { + 'token': '' + } + + # Step 2: Configure Vault + primary_vault_config = { + 'vault_id': '', + '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('', '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( + '', + '', + '', + file_object=file_obj + ) + + response = skyflow_client.vault('').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() diff --git a/samples/deprecated/update_log_level.py b/samples/deprecated/update_log_level.py new file mode 100644 index 0000000..54f28a8 --- /dev/null +++ b/samples/deprecated/update_log_level.py @@ -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': '', + 'clientName': '', + 'tokenURI': '', + 'keyID': '', + 'privateKey': '', + } + + skyflow_credentials = { + 'credentials_string': json.dumps(cred) + } + + credentials = { + 'token': '' + } + + # Step 2: Configure Vault + primary_vault_config = { + 'vault_id': '', + '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()