diff --git a/samples/service_account/scoped_token_generation_example.py b/samples/service_account/scoped_token_generation_example.py index e94f6433..08c30a75 100644 --- a/samples/service_account/scoped_token_generation_example.py +++ b/samples/service_account/scoped_token_generation_example.py @@ -8,6 +8,7 @@ file_path = '' bearer_token = '' +# To generate Bearer Token from credentials string. skyflow_credentials = { 'clientID': '', 'clientName': '', @@ -16,21 +17,40 @@ 'privateKey': '', } credentials_string = json.dumps(skyflow_credentials) -# Generate bearer token from credentials file path options = {'role_ids': ['ROLE_ID1', 'ROLE_ID2']} -if is_expired(bearer_token): - bearer_token, token_type = generate_bearer_token( - '', options - ) - print(bearer_token, token_type) +def get_scoped_bearer_token_from_file_path(): + # Generate scoped bearer token from credentials file path. + global bearer_token + try: + if not is_expired(bearer_token): + return bearer_token + else: + token, _ = generate_bearer_token(file_path, options) + bearer_token = token + return bearer_token -# Generate bearer token from credentials string -if is_expired(bearer_token): - bearer_token, token_type = generate_bearer_token_from_creds( - credentials_string, options - ) + except Exception as e: + print(f'Error generating token from file path: {str(e)}') - print(bearer_token, token_type) + + +def get_scoped_bearer_token_from_credentials_string(): + # Generate scoped bearer token from credentials string. + global bearer_token + try: + if not is_expired(bearer_token): + return bearer_token + else: + token, _ = generate_bearer_token_from_creds(credentials_string, options) + bearer_token = token + return bearer_token + except Exception as e: + print(f"Error generating token from credentials string: {str(e)}") + + +print(get_scoped_bearer_token_from_file_path()) + +print(get_scoped_bearer_token_from_credentials_string()) \ No newline at end of file diff --git a/samples/service_account/signed_token_generation_example.py b/samples/service_account/signed_token_generation_example.py index 130cb6e8..1c97a1fb 100644 --- a/samples/service_account/signed_token_generation_example.py +++ b/samples/service_account/signed_token_generation_example.py @@ -24,15 +24,36 @@ 'time_to_live': 90, # in seconds } -# Generate bearer token from credentials file path -if is_expired(bearer_token): - actual_token, signed_token = generate_signed_data_tokens( - '', options - ) - - -# Generate bearer token from credentials string -if is_expired(bearer_token): - actual_token, signed_token = generate_signed_data_tokens_from_creds( - credentials_string, options - ) +def get_signed_bearer_token_from_file_path(): + # Generate signed bearer token from credentials file path. + global bearer_token + + try: + if not is_expired(bearer_token): + return bearer_token + else: + data_token, signed_data_token = generate_signed_data_tokens(file_path, options) + return data_token, signed_data_token + + except Exception as e: + print(f'Error generating token from file path: {str(e)}') + + +def get_signed_bearer_token_from_credentials_string(): + # Generate signed bearer token from credentials string. + global bearer_token + + try: + if not is_expired(bearer_token): + return bearer_token + else: + data_token, signed_data_token = generate_signed_data_tokens_from_creds(credentials_string, options) + return data_token, signed_data_token + + except Exception as e: + print(f'Error generating token from credentials string: {str(e)}') + + +print(get_signed_bearer_token_from_file_path()) + +print(get_signed_bearer_token_from_credentials_string()) diff --git a/samples/service_account/token_generation_example.py b/samples/service_account/token_generation_example.py index 1c44c0a5..34db4c37 100644 --- a/samples/service_account/token_generation_example.py +++ b/samples/service_account/token_generation_example.py @@ -8,6 +8,7 @@ file_path = 'CREDENTIALS_FILE_PATH' bearer_token = '' +# To generate Bearer Token from credentials string. skyflow_credentials = { 'clientID': '', 'clientName': '', @@ -18,15 +19,37 @@ credentials_string = json.dumps(skyflow_credentials) -# Generate bearer token from credentials file path -if is_expired(bearer_token): - bearer_token, token_type = generate_bearer_token('') +def get_bearer_token_from_file_path(): + # Generate bearer token from credentials file path. + global bearer_token - print(bearer_token, token_type) + try: + if not is_expired(bearer_token): + return bearer_token + else: + token, _ = generate_bearer_token(file_path) + bearer_token = token + return bearer_token + except Exception as e: + print(f'Error generating token from file path: {str(e)}') -# Generate bearer token from credentials string -if is_expired(bearer_token): - bearer_token, token_type = generate_bearer_token_from_creds(credentials_string) - print(bearer_token, token_type) +def get_bearer_token_from_credentials_string(): + # Generate bearer token from credentials string. + global bearer_token + try: + if not is_expired(bearer_token): + return bearer_token + else: + token, _ = generate_bearer_token_from_creds(credentials_string) + bearer_token = token + return bearer_token + except Exception as e: + print(f"Error generating token from credentials string: {str(e)}") + + + +print(get_bearer_token_from_file_path()) + +print(get_bearer_token_from_credentials_string()) \ No newline at end of file diff --git a/samples/service_account/token_generation_with_context_example.py b/samples/service_account/token_generation_with_context_example.py index b2deb714..a43a072a 100644 --- a/samples/service_account/token_generation_with_context_example.py +++ b/samples/service_account/token_generation_with_context_example.py @@ -8,6 +8,7 @@ file_path = 'CREDENTIALS_FILE_PATH' bearer_token = '' +# To generate Bearer Token from credentials string. skyflow_credentials = { 'clientID': '', 'clientName': '', @@ -17,21 +18,38 @@ } credentials_string = json.dumps(skyflow_credentials) -# Generate bearer token from credentials file path options = {'ctx': ''} -if is_expired(bearer_token): - bearer_token, token_type = generate_bearer_token( - '', options - ) +def get_bearer_token_with_context_from_file_path(): + # Generate bearer token with context from credentials file path. + global bearer_token - print(bearer_token, token_type) + try: + if not is_expired(bearer_token): + return bearer_token + else: + token, _ = generate_bearer_token(file_path, options) + bearer_token = token + return bearer_token + except Exception as e: + print(f'Error generating token from file path: {str(e)}') -# Generate bearer token from credentials string -if is_expired(bearer_token): - bearer_token, token_type = generate_bearer_token_from_creds( - credentials_string, options - ) - print(bearer_token, token_type) +def get_bearer_token_with_context_from_credentials_string(): + # Generate bearer token with context from credentials string. + global bearer_token + try: + if not is_expired(bearer_token): + return bearer_token + else: + token, _ = generate_bearer_token_from_creds(credentials_string, options) + bearer_token = token + return bearer_token + except Exception as e: + print(f"Error generating token from credentials string: {str(e)}") + + +print(get_bearer_token_with_context_from_file_path()) + +print(get_bearer_token_with_context_from_credentials_string()) \ No newline at end of file diff --git a/samples/vault_api/client_operations.py b/samples/vault_api/client_operations.py index ad98d309..80a8ca3a 100644 --- a/samples/vault_api/client_operations.py +++ b/samples/vault_api/client_operations.py @@ -1,70 +1,92 @@ -import json +from skyflow.error import SkyflowError from skyflow import Skyflow, LogLevel from skyflow import Env from skyflow.vault.data import DeleteRequest -# To generate Bearer Token from credentials string. -skyflow_credentials = { - 'clientID': '', - 'clientName': '', - 'tokenURI': '', - 'keyID': '', - 'privateKey': '', -} -credentials_string = json.dumps(skyflow_credentials) - -# please pass one of api_key, token, credentials_string & path as credentials -credentials = { - 'token': '', - #'credentials_string': credentials_string -} - - -skyflow_client = ( - Skyflow.builder() - .add_vault_config( - { - 'vault_id': '', # primary vault - 'cluster_id': '', # ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - 'env': Env.PROD, # Env by default it is set to PROD - 'credentials': credentials, # individual credentials +""" +Skyflow Secure Data Deletion Example + +This example demonstrates how to: + 1. Configure Skyflow client credentials + 2. Set up vault configuration + 3. Create a delete request + 4. Handle response and errors +""" + +def perform_secure_data_deletion(): + try: + # Step 1: Configure Bearer Token Credentials + credentials = { + 'token': '', # Bearer token + } + + # Step 2: Configure vault + primary_vault_config = { + 'vault_id': '', # primary vault + 'cluster_id': '', # Cluster ID from your vault URL + 'env': Env.PROD, # Deployment environment (PROD by default) + 'credentials': credentials, # Authentication method + } + + # Initialize Skyflow Client + skyflow_client = ( + Skyflow.builder() + .add_vault_config( + primary_vault_config + ) + .set_log_level(LogLevel.ERROR) # Logging verbosity + .build() + ) + + # Step 4: Add Secondary Vault Configuration + + secondary_vault_config = { + 'vault_id': 'YOUR_VAULT_ID2', # Secondary vault + 'cluster_id': 'YOUR_CLUSTER_ID2', # Cluster ID from your vault URL + 'env': Env.PROD, # Deployment environment + # If credentials aren't specified, Skyflow credentials will be used } - ) - .set_log_level(LogLevel.ERROR) # set log level by default it is set to ERROR - .build() -) + # Add secondary vault config on the fly + skyflow_client.add_vault_config(secondary_vault_config) + + # Step 5: Update Vault Configuration + updated_vault_config = { + 'vault_id': 'YOUR_VAULT_ID2', # Vault ID and cluster ID are unique + 'cluster_id': 'YOUR_CLUSTER_ID2', # Cluster ID from your vault URL + 'credentials': credentials, # Update credentials + } -# add vault config on the fly + # Update vault config on the fly + skyflow_client.update_vault_config(updated_vault_config) -skyflow_client.add_vault_config( - { - 'vault_id': 'VAULT_ID2', # secondary vault - 'cluster_id': 'CLUSTER_ID2', # ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - 'env': Env.PROD, # Env by default it is set to PROD - # if you don't specify individual credentials, skyflow credentials will be used - } -) + # Step 6: Prepare Delete Request + delete_ids = ['', ''] + table_name = '' # Replace with actual table name -skyflow_client.update_vault_config( - { - 'vault_id': 'VAULT_ID2', - 'cluster_id': 'CLUSTER_ID2', - 'credentials': credentials, # update credentials - } -) + delete_request = DeleteRequest( + table=table_name, + ids=delete_ids + ) + # Step 7: Perform Secure Deletion on Secondary Vault + response = skyflow_client.vault('YOUR_VAULT_ID2').delete(delete_request) -# perform operations + # Handle Successful Response + print('Delete successful: ', response) -delete_request = DeleteRequest( - table = '', - ids = ['', ''] -) + # Step 8: Remove Secondary Vault Configuration + skyflow_client.remove_vault_config(secondary_vault_config.get('vault_id')) # Remove vault configuration -# perform delete call if you don't specify vault() it will return the first valid vault -response = skyflow_client.vault('VAULT_ID2').delete(delete_request) + 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) -# remove vault on the fly -skyflow_client.remove_vault_config('VAULT_ID') +# Invoke the secure data deletion function +perform_secure_data_deletion() \ No newline at end of file diff --git a/samples/vault_api/credentials_options.py b/samples/vault_api/credentials_options.py index 09e02061..db792042 100644 --- a/samples/vault_api/credentials_options.py +++ b/samples/vault_api/credentials_options.py @@ -1,69 +1,94 @@ -import json +from skyflow.error import SkyflowError from skyflow import Skyflow, LogLevel from skyflow import Env from skyflow.vault.data import DeleteRequest -skyflow_credentials = { - 'clientID': '', - 'clientName': '', - 'tokenURI': '', - 'keyID': '', - 'privateKey': '', -} -credentials_string = json.dumps(skyflow_credentials) - -credentials = { - 'token': 'BEARER_TOKEN', # bearer token - # api_key: 'API_KEY', # API_KEY - # path: 'PATH', # path to credentials file - # credentials_string: credentials_string, # credentials as string -} - -skyflow_client = ( - Skyflow.builder() - .add_vault_config( - { - 'vault_id': '', # primary vault - 'cluster_id': '', # ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - 'env': Env.PROD, # Env by default it is set to PROD +""" +Skyflow Secure Data Deletion Example + +This example demonstrates how to: + 1. Configure Skyflow client credentials + 2. Set up vault configuration + 3. Create and perform delete requests + 4. Handle response and errors +""" + +def perform_secure_data_deletion(): + try: + # Step 1: Configure Bearer Token Credentials + credentials = { + 'token': '', # bearer token + # api_key: 'API_KEY', # API_KEY + # path: 'PATH', # path to credentials file + # credentials_string: 'your_credentials_string', # Credentials as string + } + + # Step 2: Configure Vaults + primary_vault_config = { + 'vault_id': '', # primary vault + 'cluster_id': '', # Cluster ID from your vault URL + 'env': Env.PROD, # Deployment environment (PROD by default) } - ) - .add_vault_config( - { - 'vault_id': '', - 'cluster_id': '', # ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - 'env': Env.PROD, # Env by default it is set to PROD - 'credentials': credentials, + + secondary_vault_config = { + 'vault_id': 'YOUR_SECONDARY_VAULT_ID', # Secondary vault + 'cluster_id': 'YOUR_SECONDARY_CLUSTER_ID', # Cluster ID from your vault URL + 'env': Env.PROD, # Deployment environment + 'credentials': credentials } - ) - .add_skyflow_credentials( - credentials - ) # skyflow credentials will be used if no individual credentials are passed - .set_log_level(LogLevel.ERROR) # set log level by default it is set to ERROR - .build() -) -primary_delete_ids = [ - 'SKYFLOW_ID1', - 'SKYFLOW_ID2', - 'SKYFLOW_ID3', -] + # Step 3: Configure & Initialize Skyflow Client + skyflow_client = ( + Skyflow.builder() + .add_vault_config(primary_vault_config) + .add_vault_config(secondary_vault_config) + .set_log_level(LogLevel.ERROR) # Logging verbosity + .build() + ) + + # Step 4: Prepare Delete Request for Primary Vault + primary_delete_ids = ['', ''] + + primary_table_name = '' # Replace with actual table name + + primary_delete_request = DeleteRequest( + table=primary_table_name, + ids=primary_delete_ids + ) + + # Perform Delete Operation for Primary Vault + primary_delete_response = skyflow_client.vault('').delete(primary_delete_request) + + # Handle Successful Response + print('Primary Vault Deletion Successful:', primary_delete_response) + + # Step 5: Prepare Delete Request for Secondary Vault + secondary_delete_ids = ['', ''] + + secondary_table_name = '' # Replace with actual table name -# perform operations + secondary_delete_request = DeleteRequest( + table=secondary_table_name, + ids=secondary_delete_ids + ) -primary_delete_request = DeleteRequest(table='', ids=primary_delete_ids) + # Perform Delete Operation for Secondary Vault + secondary_delete_response = skyflow_client.vault('').delete(secondary_delete_request) -# VAULT_ID1 will use credentials if you don't specify individual credentials at config level -response = skyflow_client.vault('VAULT_ID2').delete(primary_delete_request) + # Handle Successful Response + print('Secondary Vault Deletion Successful:', secondary_delete_response) -secondary_delete_ids = [ - 'SKYFLOW_ID1', - 'SKYFLOW_ID2', - 'SKYFLOW_ID3', -] + 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) -secondary_delete_request = DeleteRequest(table='TABLE_NAME', ids=secondary_delete_ids) -# VAULT_ID2 will use individual credentials at config level -response = skyflow_client.vault('VAULT_ID2').delete(primary_delete_request) +# Invoke the secure data deletion function +perform_secure_data_deletion() \ No newline at end of file diff --git a/samples/vault_api/delete_records.py b/samples/vault_api/delete_records.py index d0960629..bc497072 100644 --- a/samples/vault_api/delete_records.py +++ b/samples/vault_api/delete_records.py @@ -1,53 +1,80 @@ import json +from skyflow.error import SkyflowError from skyflow import Skyflow from skyflow import LogLevel from skyflow import Env from skyflow.vault.data import DeleteRequest +""" +* Skyflow Delete Records Example + * + * This example demonstrates how to: + * 1. Configure Skyflow client credentials + * 2. Set up vault configuration + * 3. Create a delete request + * 4. Handle response and errors +""" -# To generate Bearer Token from credentials string. -skyflow_credentials = { - 'clientID': '', - 'clientName': '', - 'tokenURI': '', - 'keyID': '', - 'privateKey': '', -} -credentials_string = json.dumps(skyflow_credentials) - -# please pass one of api_key, token, credentials_string & path as credentials -credentials = { - 'token': 'BEARER_TOKEN', # bearer token - # api_key: 'API_KEY', # API_KEY - # path: 'PATH', # path to credentials file - # credentials_string: credentials_string, # credentials as string -} - -client = ( - Skyflow.builder() - .add_vault_config( - { - 'vault_id': 'VAULT_ID', # primary vault - 'cluster_id': 'CLUSTER_ID', # ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - 'env': Env.PROD, # Env by default it is set to PROD - 'credentials': credentials, # individual credentials +def perform_delete(): + try: + # Step 1: Configure Credentials + cred = { + 'clientID': '', # Client identifier + 'clientName': '', # Client name + 'tokenURI': '', # Token URI + 'keyID': '', # Key identifier + 'privateKey': '', # Private key for authentication } - ) - .add_skyflow_credentials( - credentials - ) # skyflow credentials will be used if no individual credentials are passed - .set_log_level(LogLevel.INFO) # set log level by default it is set to ERROR - .build() -) + skyflow_credentials = { + 'credentials_string': json.dumps(cred) # Token credentials + } + + credentials = { + 'api_key': '' # API key for authentication + } + + # Step 2: Configure Vault + primary_vault_config = { + 'vault_id': '', # primary vault + 'cluster_id': '', # 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 Delete Data + delete_ids = ['SKYFLOW_ID1', 'SKYFLOW_ID2', 'SKYFLOW_ID3'] # Record IDs to delete + table_name = '' + + # Create Delete Request + delete_request = DeleteRequest( + table=table_name, + ids=delete_ids + ) -primary_delete_ids = [ - 'SKYFLOW_ID1', - 'SKYFLOW_ID2', - 'SKYFLOW_ID3', -] + # Step 5: Perform Deletion + response = skyflow_client.vault(primary_vault_config.get('vault_id')).delete(delete_request) -delete_request = DeleteRequest(table='', ids=primary_delete_ids) + # Handle Successful Response + print('Deletion successful: ', response) -response = client.vault('').delete(delete_request) + 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) -print(response) +# Invoke the deletion function +perform_delete() \ No newline at end of file diff --git a/samples/vault_api/detokenize_records.py b/samples/vault_api/detokenize_records.py index 192c7e75..b76aa89e 100644 --- a/samples/vault_api/detokenize_records.py +++ b/samples/vault_api/detokenize_records.py @@ -1,52 +1,82 @@ 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 -# To generate Bearer Token from credentials string. -skyflow_credentials = { - 'clientID': '', - 'clientName': '', - 'tokenURI': '', - 'keyID': '', - 'privateKey': '', -} -credentials_string = json.dumps(skyflow_credentials) - -# please pass one of api_key, token, credentials_string & path as credentials -credentials = { - 'token': 'BEARER_TOKEN', # bearer token - # api_key: 'API_KEY', #API_KEY - # path: 'PATH', #path to credentials file - # credentials_string: credentials_string, #credentials as string -} - -client = ( - Skyflow.builder() - .add_vault_config( - { - 'vault_id': 'VAULT_ID', # primary vault - 'cluster_id': 'CLUSTER_ID', # ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - 'env': Env.PROD, # Env by default it is set to PROD - 'credentials': credentials, # individual credentials +""" + * 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': '', # Client identifier + 'clientName': '', # Client name + 'tokenURI': '', # Token URI + 'keyID': '', # Key identifier + 'privateKey': '', # Private key for authentication + } + + skyflow_credentials = { + 'credentials_string': json.dumps(cred) # Token credentials + } + + credentials = { + 'token': '' # Bearer token for authentication } - ) - .add_skyflow_credentials( - credentials - ) # skyflow credentials will be used if no individual credentials are passed - .set_log_level(LogLevel.INFO) # set log level by default it is set to ERROR - .build() -) + # Step 2: Configure Vault + primary_vault_config = { + 'vault_id': '', # primary vault + 'cluster_id': '', # 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 = ['token1', 'token2', 'token3'] # Tokens to be detokenized + redaction_type = RedactionType.REDACTED + + # Create Detokenize Request + detokenize_request = DetokenizeRequest( + tokens=detokenize_data, + redaction_type=redaction_type, + continue_on_error=True # Continue processing on errors + ) -detokenize_data = ['TOKEN1', 'TOKEN2', 'TOKEN3'] + # Step 5: Perform Detokenization + response = skyflow_client.vault(primary_vault_config.get('vault_id')).detokenize(detokenize_request) -detokenize_request = DetokenizeRequest( - tokens=detokenize_data, - redaction_type = RedactionType.PLAIN_TEXT -) + # Handle Successful Response + print('Detokenization successful: ', response) -response = client.vault('VAULT_ID').detokenize(detokenize_request) + 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) -print(response) +# Invoke the detokenization function +perform_detokenization() \ No newline at end of file diff --git a/samples/vault_api/get_column_values.py b/samples/vault_api/get_column_values.py index 29272614..4b794c0d 100644 --- a/samples/vault_api/get_column_values.py +++ b/samples/vault_api/get_column_values.py @@ -1,55 +1,86 @@ import json +from skyflow.error import SkyflowError from skyflow import Env from skyflow import Skyflow, LogLevel from skyflow.vault.data import GetRequest -# To generate Bearer Token from credentials string. -skyflow_credentials = { - 'clientID': '', - 'clientName': '', - 'tokenURI': '', - 'keyID': '', - 'privateKey': '', -} -credentials_string = json.dumps(skyflow_credentials) - -# please pass one of api_key, token, credentials_string & path as credentials -credentials = { - 'token': 'BEARER_TOKEN', # bearer token - # api_key: 'API_KEY', # API_KEY - # path: 'PATH', # path to credentials file - # credentials_string: credentials_string, # credentials as string -} - -client = ( - Skyflow.builder() - .add_vault_config( - { - 'vault_id': 'VAULT_ID', # primary vault - 'cluster_id': 'CLUSTER_ID', # ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - 'env': Env.PROD, # Env by default it is set to PROD - 'credentials': credentials, # individual credentials +""" + * Skyflow Secure Column-Based Retrieval Example + * + * This example demonstrates how to: + * 1. Configure Skyflow client credentials + * 2. Set up vault configuration + * 3. Create a column-based get request + * 4. Handle response and errors +""" + +def perform_secure_column_retrieval(): + try: + # Step 1: Configure Credentials + cred = { + 'clientID': '', # Client identifier + 'clientName': '', # Client name + 'tokenURI': '', # Token URI + 'keyID': '', # Key identifier + 'privateKey': '', # Private key for authentication + } + + skyflow_credentials = { + 'credentials_string': json.dumps(cred) # Token credentials + } + + credentials = { + 'path': '' # Path to credentials file + } + + # Step 2: Configure Vault + primary_vault_config = { + 'vault_id': '', # primary vault + 'cluster_id': '', # Cluster ID from your vault URL + 'env': Env.PROD, # Deployment environment (PROD by default) + 'credentials': credentials # Authentication method } - ) - .add_skyflow_credentials( - credentials - ) # skyflow credentials will be used if no individual credentials are passed - .set_log_level(LogLevel.INFO) # set log level by default it is set to ERROR - .build() -) -column_values = [ - 'VALUE1', - 'VALUE2', -] + # 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 Column-Based Retrieval Data + column_values = [ + '', # Example Unique Column value 1 + '' # Example Unique Column value 2 + ] + table_name = '' # Replace with your actual table name + column_name = '' # Column name configured as unique in the schema -get_ids = ['SKYFLOW_ID1', 'SKYFLOW_ID2'] + # Step 5: Create Get Column Request + get_request = GetRequest( + table=table_name, + column_name=column_name, + column_values=column_values, # Column values of the records to return + return_tokens=True # Optional: Get tokens for retrieved data + ) + # Step 6: Perform Secure Retrieval + response = skyflow_client.vault(primary_vault_config.get('vault_id')).get(get_request) -get_request = GetRequest( - table='TABLE_NAME', column_name='COLUMN_NAME', column_values=column_values -) + # Handle Successful Response + print('Column-based retrieval successful: ', response) -response = client.vault('VAULT_ID').get(get_request) + 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) -print(response) +# Invoke the secure column retrieval function +perform_secure_column_retrieval() diff --git a/samples/vault_api/get_records.py b/samples/vault_api/get_records.py index 718bdd1a..b2fd445f 100644 --- a/samples/vault_api/get_records.py +++ b/samples/vault_api/get_records.py @@ -1,49 +1,71 @@ import json +from skyflow.error import SkyflowError from skyflow import Env from skyflow import Skyflow, LogLevel from skyflow.vault.data import GetRequest -# To generate Bearer Token from credentials string. -skyflow_credentials = { - 'clientID': '', - 'clientName': '', - 'tokenURI': '', - 'keyID': '', - 'privateKey': '', -} -credentials_string = json.dumps(skyflow_credentials) - -# please pass one of api_key, token, credentials_string & path as credentials -credentials = { - 'token': 'BEARER_TOKEN', # bearer token - # api_key: 'API_KEY', # API_KEY - # path: 'PATH', # path to credentials file - # credentials_string: credentials_string, # credentials as string -} - -client = ( - Skyflow.builder() - .add_vault_config( - { - 'vault_id': 'VAULT_ID', # primary vault - 'cluster_id': 'CLUSTER_ID', # ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - 'env': Env.PROD, # Env by default it is set to PROD - 'credentials': credentials, # individual credentials +def perform_secure_data_retrieval(): + try: + # Step 1: Configure Credentials + cred = { + 'clientID': '', # Client identifier + 'clientName': '', # Client name + 'tokenURI': '', # Token URI + 'keyID': '', # Key identifier + 'privateKey': '', # Private key for authentication } - ) - .add_skyflow_credentials( - credentials - ) # skyflow credentials will be used if no individual credentials are passed - .set_log_level(LogLevel.INFO) # set log level by default it is set to ERROR - .build() -) + skyflow_credentials = { + 'credentials_string': json.dumps(cred) # Token credentials + } + + credentials = { + 'path': '' # Path to credentials file + } + + # Step 2: Configure Vault + primary_vault_config = { + 'vault_id': '', # primary vault + 'cluster_id': '', # 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 Retrieval Data + + get_ids = ['', 'SKYFLOW_ID2'] + + get_request = GetRequest( + table='', # Replace with your actual table name + ids=get_ids, + ) + + # Step 6: Configure Get Options + response = skyflow_client.vault(primary_vault_config.get('vault_id')).get(get_request) -get_ids = ['SKYFLOW_ID1', 'SKYFLOW_ID2'] + # Handle Successful Response + print('Data retrieval 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) -get_request = GetRequest(table='TABLE_NAME', ids=get_ids, return_tokens=True) -response = client.vault('VAULT_ID').get(get_request) +# Invoke the secure data retrieval function -print(response) +perform_secure_data_retrieval() \ No newline at end of file diff --git a/samples/vault_api/insert_byot.py b/samples/vault_api/insert_byot.py index f2ec4773..ae4c1eae 100644 --- a/samples/vault_api/insert_byot.py +++ b/samples/vault_api/insert_byot.py @@ -2,59 +2,98 @@ from skyflow import Env from skyflow import Skyflow, LogLevel from skyflow.error import SkyflowError -from skyflow.utils.enums import TokenStrict +from skyflow.utils.enums import TokenMode from skyflow.vault.data import InsertRequest -# To generate Bearer Token from credentials string. -skyflow_credentials = { - 'clientID': '', - 'clientName': '', - 'tokenURI': '', - 'keyID': '', - 'privateKey': '', -} -credentials_string = json.dumps(skyflow_credentials) - -# please pass one of api_key, token, credentials_string & path as credentials -credentials = { - 'token': 'BEARER_TOKEN', # bearer token - # api_key: 'API_KEY', # API_KEY - # path: 'PATH', # path to credentials file - # credentials_string: credentials_string, # credentials as string -} - -skyflow_client = ( - Skyflow.builder() - .add_vault_config( - { - 'vault_id': 'VAULT_ID', # primary vault - 'cluster_id': 'CLUSTER_ID', # ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - 'env': Env.PROD, # Env by default it is set to PROD - 'credentials': credentials, # individual credentials +""" + * Skyflow Insert with BYOT Example + * + * This example demonstrates: + * 1. Configuring Skyflow client credentials + * 2. Setting up vault configuration + * 3. Utilizing Bring Your Own Token (BYOT) during insertion + * 4. Handling responses and errors +""" + +def perform_secure_data_insertion_with_byot(): + try: + # Step 1: Configure Credentials + cred = { + 'clientID': '', # Client identifier + 'clientName': '', # Client name + 'tokenURI': '', # Token URI + 'keyID': '', # Key identifier + 'privateKey': '', # Private key for authentication + } + + skyflow_credentials = { + 'credentials_string': json.dumps(cred) # Token credentials + } + + credentials = { + 'token': '' # Bearer token for authentication } - ) - .add_skyflow_credentials( - credentials - ) # skyflow credentials will be used if no individual credentials are passed - .set_log_level(LogLevel.INFO) # set log level by default it is set to ERROR - .build() -) - -# Initialize Client - -try: - insert_data = [{'': ''}, {'': ''}] - - token_data = [{'': ''}, {'': ''}] - - insert_request = InsertRequest( - table_name='', - values=insert_data, - token_strict=TokenStrict.ENABLE, # token strict is enabled, - tokens=token_data, - ) - - response = skyflow_client.vault('VAULT_ID').insert(insert_request) - print('Response:', response) -except SkyflowError as e: - print('Error Occurred:', e) + + # Step 2: Configure Vault + primary_vault_config = { + 'vault_id': '', # primary vault + 'cluster_id': '', # 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 Insertion Data + insert_data = [ + { + 'card_number': '', + 'cvv': '', + }, + ] + + table_name = '' + + # Step 5: BYOT Configuration + tokens = [ + { + 'card_number': '', + 'cvv': '', + }, + ] + + insert_request = InsertRequest( + table_name=table_name, + values=insert_data, + token_mode=TokenMode.ENABLE, # Enable Bring Your Own Token (BYOT) + tokens=tokens, # Specify tokens to use for BYOT + return_tokens=True, # Optionally get tokens for inserted data + continue_on_error=True # Optionally continue on partial errors + ) + + # Step 6: Perform Secure Insertion + response = skyflow_client.vault(primary_vault_config.get('vault_id')).insert(insert_request) + + # Handle Successful Response + print('Insertion 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 secure data insertion function +perform_secure_data_insertion_with_byot() \ No newline at end of file diff --git a/samples/vault_api/insert_records.py b/samples/vault_api/insert_records.py index 5e87f1d6..32ec1fae 100644 --- a/samples/vault_api/insert_records.py +++ b/samples/vault_api/insert_records.py @@ -1,54 +1,73 @@ -import json +from skyflow.error import SkyflowError from skyflow import Env from skyflow import Skyflow, LogLevel from skyflow.vault.data import InsertRequest -# To generate Bearer Token from credentials string. -skyflow_credentials = { - 'clientID': '', - 'clientName': '', - 'tokenURI': '', - 'keyID': '', - 'privateKey': '', -} -credentials_string = json.dumps(skyflow_credentials) -# please pass one of api_key, token, credentials_string & path as credentials -credentials = { - 'token': 'BEARER_TOKEN', # bearer token - # api_key: 'API_KEY', # API_KEY - # path: 'PATH', # path to credentials file - # credentials_string: credentials_string, # credentials as string -} - -skyflow_client = ( - Skyflow.builder() - .add_vault_config( - { - 'vault_id': 'VAULT_ID', # primary vault - 'cluster_id': 'CLUSTER_ID', # ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - 'env': Env.PROD, # Env by default it is set to PROD - 'credentials': credentials, # individual credentials +""" + * Skyflow Secure Data Insertion Example + * + * This example demonstrates how to: + * 1. Configure Skyflow client credentials + * 2. Set up vault configuration + * 3. Create an insert request + * 4. Handle response and errors +""" +def perform_secure_data_insertion(): + try: + # Step 1: Configure Credentials + credentials = { + 'api_key': '' # Using API Key authentication } - ) - .add_skyflow_credentials( - credentials - ) # skyflow credentials will be used if no individual credentials are passed - .set_log_level(LogLevel.INFO) # set log level by default it is set to ERROR - .build() -) - -# sample data -insert_data = [ - {'': '', '': ''}, -] - -insert_request = InsertRequest( - table_name='TABLE_NAME', - values=insert_data, - continue_on_error=False, # if continue on error is set true we will return request_index for errors - return_tokens=True, -) - -response = skyflow_client.vault('VAULT_ID').insert(insert_request) - -print(response) + + # Step 2: Configure Vault + primary_vault_config = { + 'vault_id': '', # primary vault + 'cluster_id': '', # 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) + .set_log_level(LogLevel.ERROR) # Logging verbosity + .build() + ) + + # Step 4: Prepare Insertion Data + insert_data = [ + { + 'card_number': '', + 'cvv': '', + }, + ] + + table_name = '' # Replace with your actual table name + + # Step 5: Create Insert Request + insert_request = InsertRequest( + table_name=table_name, + values=insert_data, + return_tokens=True, # Optional: Get tokens for inserted data + continue_on_error=True # Optional: Continue on partial errors + ) + + # Step 6: Perform Secure Insertion + response = skyflow_client.vault(primary_vault_config.get('vault_id')).insert(insert_request) + + # Handle Successful Response + print('Insertion 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 secure data insertion function +perform_secure_data_insertion() \ No newline at end of file diff --git a/samples/vault_api/invoke_connection.py b/samples/vault_api/invoke_connection.py index f1d7f503..54f36106 100644 --- a/samples/vault_api/invoke_connection.py +++ b/samples/vault_api/invoke_connection.py @@ -1,65 +1,85 @@ -import json +from skyflow.error import SkyflowError from skyflow import Env from skyflow import Skyflow, LogLevel -from skyflow.utils.enums import Method +from skyflow.utils.enums import RequestMethod from skyflow.vault.connection import InvokeConnectionRequest -# To generate Bearer Token from credentials string. -skyflow_credentials = { - 'clientID': '', - 'clientName': '', - 'tokenURI': '', - 'keyID': '', - 'privateKey': '', -} -credentials_string = json.dumps(skyflow_credentials) -# please pass one of api_key, token, credentials_string & path as credentials +""" + * Skyflow Connection Invocation Example + * + * This example demonstrates how to: + * 1. Configure Skyflow client credentials + * 2. Set up vault and connection configurations + * 3. Invoke a connection + * 4. Handle response and errors +""" -credentials = { - 'token': 'BEARER_TOKEN', # bearer token - # api_key: 'API_KEY', # API_KEY - # path: 'PATH', # path to credentials file - # credentials_string: credentials_string, # credentials as string -} +def invoke_skyflow_connection(): + try: + # Step 1: Configure Credentials + credentials = { + 'api_key': '' # Using API Key authentication + } + + # Step 2: Configure Vault + primary_vault_config = { + 'vault_id': '', # primary vault + 'cluster_id': '', # Cluster ID from your vault URL + 'env': Env.PROD, # Deployment environment (PROD by default) + 'credentials': credentials # Authentication method + } + + # Step 3: Configure Connection + primary_connection_config = { + 'connection_id': '', # Unique connection identifier + 'connection_url': '', # Connection url + 'credentials': credentials # Connection-specific credentials + } -skyflow_client = ( - Skyflow.builder() - .add_vault_config( - { - 'vault_id': 'VAULT_ID', # primary vault - 'cluster_id': 'CLUSTER_ID', # ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - 'env': Env.PROD, # Env by default it is set to PROD - 'credentials': credentials, # individual credentials + # Step 4: Configure & Initialize Skyflow Client + skyflow_client = ( + Skyflow.builder() + .add_vault_config(primary_vault_config) + .add_connection_config(primary_connection_config) + .set_log_level(LogLevel.ERROR) # Logging verbosity + .build() + ) + + # Step 5: Prepare Connection Request + request_body = { + '': '', # Replace with actual key-value pairs + '': '' } - ) - .add_connection_config( - { - 'connection_id': 'CONNECTION_ID', - 'connection_url': 'CONNECTION_URL', - 'credentials': credentials, + + request_headers = { + 'Content-Type': 'application/json' } - ) - .add_skyflow_credentials( - credentials - ) # skyflow credentials will be used if no individual credentials are passed - .set_log_level(LogLevel.INFO) # set log level by default it is set to ERROR - .build() -) + request_method = RequestMethod.POST + + # Step 6: Create Invoke Connection Request + invoke_connection_request = InvokeConnectionRequest( + method=request_method, + body=request_body, + headers=request_headers + ) + + # Step 7: Invoke Connection + response = skyflow_client.connection().invoke(invoke_connection_request) + + # Handle Successful Response + print('Connection invocation successful: ', response) -body = {'KEY1': 'VALUE1', 'KEY2': 'VALUE2'} -headers = {'KEY1': 'VALUE1'} -path_params = {'KEY1': 'VALUE1'} -query_params = {'KEY1': 'VALUE1'} + 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_connection_request = InvokeConnectionRequest( - method=Method.POST, - body=body, - headers=headers, # optional - path_params=path_params, # optional - query_params=query_params, # optional -) -# will return the first connection -response = skyflow_client.connection().invoke(invoke_connection_request) -print(response) +# Invoke the connection function +invoke_skyflow_connection() \ No newline at end of file diff --git a/samples/vault_api/query_records.py b/samples/vault_api/query_records.py index fa6ff6b7..0af332fd 100644 --- a/samples/vault_api/query_records.py +++ b/samples/vault_api/query_records.py @@ -1,56 +1,76 @@ import json +from skyflow.error import SkyflowError from skyflow import Env from skyflow import Skyflow, LogLevel from skyflow.vault.data import QueryRequest -# To generate Bearer Token from credentials string. -skyflow_credentials = { - 'clientID': '', - 'clientName': '', - 'tokenURI': '', - 'keyID': '', - 'privateKey': '', -} -credentials_string = json.dumps(skyflow_credentials) -# please pass one of api_key, token, credentials_string & path as credentials - -credentials = { - 'token': 'BEARER_TOKEN', # bearer token - # api_key: 'API_KEY', # API_KEY - # path: 'PATH', # path to credentials file - # credentials_string: credentials_string, # credentials as string -} - -skyflow_client = ( - Skyflow.builder() - .add_vault_config( - { - 'vault_id': 'VAULT_ID', # primary vault - 'cluster_id': 'CLUSTER_ID', # ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - 'env': Env.PROD, # Env by default it is set to PROD - 'credentials': credentials, # individual credentials +""" + * Skyflow Query Example + * + * This example demonstrates how to: + * 1. Configure Skyflow client credentials + * 2. Set up vault configuration + * 3. Execute a query on the vault + * 4. Handle response and errors +""" +def execute_query(): + try: + # Step 1: Configure Credentials + cred = { + 'clientID': '', # Client identifier + 'clientName': '', # Client name + 'tokenURI': '', # Token URI + 'keyID': '', # Key identifier + 'privateKey': '', # Private key for authentication } - ) - .add_connection_config( - { - 'connection_id': 'CONNECTION_ID', - 'connection_url': 'CONNECTION_URL', - 'credentials': credentials, + + skyflow_credentials = { + 'credentials_string': json.dumps(cred) + } + + credentials = { + 'api_key': '' # Using API Key authentication } - ) - .add_skyflow_credentials( - credentials - ) # skyflow credentials will be used if no individual credentials are passed - .set_log_level(LogLevel.INFO) # set log level by default it is set to ERROR - .build() -) -# sample query -query = '' + # Step 2: Configure Vault + primary_vault_config = { + 'vault_id': '', # primary vault + 'cluster_id': '', # 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 Query + query = 'select * from table_name limit 1' # Example query + + query_request = QueryRequest( + query=query + ) + # Step 5: Execute Query + response = skyflow_client.vault(primary_vault_config.get('vault_id')).query(query_request) -query_request = QueryRequest(query=query) + # Handle Successful Response + print('Query Result: ', response) -response = skyflow_client.vault('VAULT_ID').query(query_request) + 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) -print(response) +# Invoke the query function +execute_query() \ No newline at end of file diff --git a/samples/vault_api/tokenize_records.py b/samples/vault_api/tokenize_records.py index 3cf3f65c..b709a965 100644 --- a/samples/vault_api/tokenize_records.py +++ b/samples/vault_api/tokenize_records.py @@ -1,56 +1,80 @@ import json +from skyflow.error import SkyflowError from skyflow import Env from skyflow import Skyflow, LogLevel from skyflow.vault.tokens import TokenizeRequest -# To generate Bearer Token from credentials string. -skyflow_credentials = { - "clientID": "", - "clientName": "", - "tokenURI": "", - "keyID": "", - "privateKey": "", -} -credentials_string = json.dumps(skyflow_credentials) -# please pass one of api_key, token, credentials_string & path as credentials - -credentials = { - "token": "BEARER_TOKEN", # bearer token - # api_key: 'API_KEY', # API_KEY - # path: 'PATH', # path to credentials file - # credentials_string: credentials_string, # credentials as string -} - -skyflow_client = ( - Skyflow.builder() - .add_vault_config( - { - "vault_id": "VAULT_ID", # primary vault - "cluster_id": "CLUSTER_ID", # ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - "env": Env.PROD, # Env by default it is set to PROD - "credentials": credentials, # individual credentials +""" + * Skyflow Tokenization Example + * + * This example demonstrates how to: + * 1. Configure Skyflow client credentials + * 2. Set up vault configuration + * 3. Tokenize sensitive data + * 4. Handle response and errors +""" + +def execute_tokenization(): + try: + # Step 1: Configure Credentials + cred = { + 'clientID': '', # Client identifier + 'clientName': '', # Client name + 'tokenURI': '', # Token URI + 'keyID': '', # Key identifier + 'privateKey': '', # Private key for authentication } - ) - .add_connection_config( - { - "connection_id": "CONNECTION_ID", - "connection_url": "CONNECTION_URL", - "credentials": credentials, + + skyflow_credentials = { + 'credentials_string': json.dumps(cred) } - ) - .add_skyflow_credentials( - credentials - ) # skyflow credentials will be used if no individual credentials are passed - .set_log_level(LogLevel.INFO) # set log level by default it is set to ERROR - .build() -) -# tokenize only supports value and column_group -# sample data -tokenize_values = [{"": "", "": ""}] + credentials = { + 'api_key': '' # Using API Key authentication + } + + # Step 2: Configure Vault + primary_vault_config = { + 'vault_id': '', # primary vault + 'cluster_id': '', # 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 Tokenization Data + tokenize_values = [ + {'value': '', 'column_group': ''}, + {'value': '', 'column_group': ''}, + ] + + tokenize_request = TokenizeRequest( + values=tokenize_values + ) + + # Step 5: Execute Tokenization + response = skyflow_client.vault(primary_vault_config.get('vault_id')).tokenize(tokenize_request) -tokenize_request = TokenizeRequest(values=tokenize_values) + # Handle Successful Response + print('Tokenization successful:', response) -response = skyflow_client.vault("VAULT_ID").tokenize(tokenize_request) + 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) -print(response) +# Invoke the tokenization function +execute_tokenization() \ No newline at end of file diff --git a/samples/vault_api/update_record.py b/samples/vault_api/update_record.py index ad61718d..d7f0969f 100644 --- a/samples/vault_api/update_record.py +++ b/samples/vault_api/update_record.py @@ -1,55 +1,68 @@ -import json +from skyflow.error import SkyflowError from skyflow import Env from skyflow import Skyflow, LogLevel from skyflow.vault.data import UpdateRequest -# To generate Bearer Token from credentials string. -skyflow_credentials = { - 'clientID': '', - 'clientName': '', - 'tokenURI': '', - 'keyID': '', - 'privateKey': '', -} -credentials_string = json.dumps(skyflow_credentials) -# please pass one of api_key, token, credentials_string & path as credentials - -credentials = { - 'token': 'BEARER_TOKEN', # bearer token - # api_key: 'API_KEY', # API_KEY - # path: 'PATH', # path to credentials file - # credentials_string: credentials_string, # credentials as string -} - -skyflow_client = ( - Skyflow.builder() - .add_vault_config( - { - 'vault_id': 'VAULT_ID', # primary vault - 'cluster_id': 'CLUSTER_ID', # ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - 'env': Env.PROD, # Env by default it is set to PROD - 'credentials': credentials, # individual credentials +""" + * Skyflow Secure Data Update Example + * + * This example demonstrates how to: + * 1. Configure Skyflow client credentials + * 2. Set up vault configuration + * 3. Create an update request + * 4. Handle response and errors +""" + +def perform_secure_data_update(): + try: + credentials = { + 'api_key': '' # Using API Key authentication + } + + # Step 2: Configure Vault + primary_vault_config = { + 'vault_id': '', # primary vault + 'cluster_id': '', # Cluster ID from your vault URL + 'env': Env.PROD, # Deployment environment (PROD by default) + 'credentials': credentials # Authentication method } - ) - .add_connection_config( - { - 'connection_id': 'CONNECTION_ID', - 'connection_url': 'CONNECTION_URL', - 'credentials': credentials, + + # Step 3: Configure & Initialize Skyflow Client + skyflow_client = ( + Skyflow.builder() + .add_vault_config(primary_vault_config) + .set_log_level(LogLevel.ERROR) # Logging verbosity + .build() + ) + + # Step 4: Prepare Update Data + update_data = { + 'skyflow_id': '', # Skyflow ID of the record to update + 'card_number': '' # Updated sensitive data } - ) - .add_skyflow_credentials( - credentials - ) # skyflow credentials will be used if no individual credentials are passed - .set_log_level(LogLevel.INFO) # set log level by default it is set to ERROR - .build() -) -# sample data -update_data = {'skyflow_id': '', '': ''} + # Step 5: Create Update Request + update_request = UpdateRequest( + table='', + data=update_data, + return_tokens=True # Optional: Get tokens for updated data + ) + + # Step 7: Perform Secure Update + response = skyflow_client.vault(primary_vault_config.get('vault_id')).update(update_request) -update_request = UpdateRequest(table='TABLE_NAME', data=update_data) + # Handle Successful Response + print('Update successful: ', response) -response = skyflow_client.vault('VAULT_ID').update(update_request) + 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) -print(response) +# Invoke the secure data update function +perform_secure_data_update() \ No newline at end of file diff --git a/skyflow/error/_skyflow_error.py b/skyflow/error/_skyflow_error.py index b379fd03..68c97fb0 100644 --- a/skyflow/error/_skyflow_error.py +++ b/skyflow/error/_skyflow_error.py @@ -9,5 +9,10 @@ def __init__(self, http_status = None, details = None): self.message = message + self.http_code = http_code + self.grpc_code = grpc_code + self.http_status = http_status + self.details = details + self.request_id = request_id log_error(message, http_code, request_id, grpc_code, http_status, details) super().__init__() \ No newline at end of file