diff --git a/.github/workflows/internal-release.yml b/.github/workflows/internal-release.yml index 629fba1c..d4ad9400 100644 --- a/.github/workflows/internal-release.yml +++ b/.github/workflows/internal-release.yml @@ -9,7 +9,7 @@ on: - "*.yml" - "*.md" - "skyflow/utils/_version.py" - - "samples/*" + - "samples/**" branches: - release/* @@ -20,4 +20,4 @@ jobs: ref: ${{ github.ref_name }} is-internal: true secrets: inherit - + \ No newline at end of file diff --git a/samples/service_account/scoped_token_generation_example.py b/samples/service_account/scoped_token_generation_example.py index 1b7e9ed6..e94f6433 100644 --- a/samples/service_account/scoped_token_generation_example.py +++ b/samples/service_account/scoped_token_generation_example.py @@ -1,19 +1,27 @@ -from skyflow.service_account import generate_bearer_token, generate_bearer_token_from_creds, is_expired - -file_path = 'CREDENTIALS_FILE_PATH' +import json +from skyflow.service_account import ( + generate_bearer_token, + generate_bearer_token_from_creds, + is_expired, +) + +file_path = '' bearer_token = '' -skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' - - -# Generate bearer token from credentials file path -options = { - "ctx": "" +skyflow_credentials = { + 'clientID': '', + 'clientName': '', + 'tokenURI': '', + 'keyID': '', + '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 + '', options ) print(bearer_token, token_type) @@ -21,7 +29,8 @@ # Generate bearer token from credentials string if is_expired(bearer_token): - bearer_token, token_type = generate_bearer_token_from_creds(skyflow_credentials_string, options) + bearer_token, token_type = generate_bearer_token_from_creds( + credentials_string, options + ) print(bearer_token, token_type) - diff --git a/samples/service_account/signed_token_generation_example.py b/samples/service_account/signed_token_generation_example.py index 5488215d..130cb6e8 100644 --- a/samples/service_account/signed_token_generation_example.py +++ b/samples/service_account/signed_token_generation_example.py @@ -1,27 +1,38 @@ -from skyflow.service_account import is_expired, generate_signed_data_tokens, generate_signed_data_tokens_from_creds +import json +from skyflow.service_account import ( + is_expired, + generate_signed_data_tokens, + generate_signed_data_tokens_from_creds, +) file_path = 'CREDENTIALS_FILE_PATH' bearer_token = '' -skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' - +skyflow_credentials = { + 'clientID': '', + 'clientName': '', + 'tokenURI': '', + 'keyID': '', + 'privateKey': '', +} +credentials_string = json.dumps(skyflow_credentials) options = { - "ctx": "CONTEX_ID", - "data_tokens": ["DATA_TOKEN1", "DATA_TOKEN2"], - "time_to_live": 90 # in seconds + 'ctx': 'CONTEX_ID', + 'data_tokens': ['DATA_TOKEN1', 'DATA_TOKEN2'], + '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 + '', options ) # Generate bearer token from credentials string if is_expired(bearer_token): actual_token, signed_token = generate_signed_data_tokens_from_creds( - "", options - ) \ No newline at end of file + credentials_string, options + ) diff --git a/samples/service_account/token_generation_example.py b/samples/service_account/token_generation_example.py index fb201cae..1c44c0a5 100644 --- a/samples/service_account/token_generation_example.py +++ b/samples/service_account/token_generation_example.py @@ -1,23 +1,32 @@ -from skyflow.service_account import generate_bearer_token, generate_bearer_token_from_creds, is_expired +import json +from skyflow.service_account import ( + generate_bearer_token, + generate_bearer_token_from_creds, + is_expired, +) file_path = 'CREDENTIALS_FILE_PATH' bearer_token = '' -skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' +skyflow_credentials = { + 'clientID': '', + 'clientName': '', + 'tokenURI': '', + 'keyID': '', + 'privateKey': '', +} +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( - "" - ) + bearer_token, token_type = generate_bearer_token('') print(bearer_token, token_type) # Generate bearer token from credentials string if is_expired(bearer_token): - bearer_token, token_type = generate_bearer_token_from_creds(skyflow_credentials_string) + bearer_token, token_type = generate_bearer_token_from_creds(credentials_string) print(bearer_token, token_type) - diff --git a/samples/service_account/token_generation_with_context_example.py b/samples/service_account/token_generation_with_context_example.py index ea087c59..b2deb714 100644 --- a/samples/service_account/token_generation_with_context_example.py +++ b/samples/service_account/token_generation_with_context_example.py @@ -1,18 +1,28 @@ -from skyflow.service_account import generate_bearer_token, generate_bearer_token_from_creds, is_expired +import json +from skyflow.service_account import ( + generate_bearer_token, + generate_bearer_token_from_creds, + is_expired, +) file_path = 'CREDENTIALS_FILE_PATH' bearer_token = '' -skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' - +skyflow_credentials = { + 'clientID': '', + 'clientName': '', + 'tokenURI': '', + 'keyID': '', + 'privateKey': '', +} +credentials_string = json.dumps(skyflow_credentials) # Generate bearer token from credentials file path -options = { - "role_ids": ["ROLE_ID1", "ROLE_ID2"] -} +options = {'ctx': ''} + if is_expired(bearer_token): bearer_token, token_type = generate_bearer_token( - "", options + '', options ) print(bearer_token, token_type) @@ -20,7 +30,8 @@ # Generate bearer token from credentials string if is_expired(bearer_token): - bearer_token, token_type = generate_bearer_token_from_creds(skyflow_credentials_string, options) + bearer_token, token_type = generate_bearer_token_from_creds( + credentials_string, options + ) print(bearer_token, token_type) - diff --git a/samples/vault_api/client_operations.py b/samples/vault_api/client_operations.py index a9d59c5d..ad98d309 100644 --- a/samples/vault_api/client_operations.py +++ b/samples/vault_api/client_operations.py @@ -1,25 +1,36 @@ +import json from skyflow import Skyflow, LogLevel from skyflow import Env from skyflow.vault.data import DeleteRequest # To generate Bearer Token from credentials string. -skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' +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": "" + '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 - }) - .set_log_level(LogLevel.ERROR) # set log level by default it is set to ERROR + .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 + } + ) + .set_log_level(LogLevel.ERROR) # set log level by default it is set to ERROR .build() ) @@ -28,32 +39,32 @@ 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 + '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 } ) -skyflow_client.update_vault_config({ - "vault_id": "VAULT_ID2", - "cluster_id": "CLUSTER_ID2", - "credentials": credentials, # update credentials -}) +skyflow_client.update_vault_config( + { + 'vault_id': 'VAULT_ID2', + 'cluster_id': 'CLUSTER_ID2', + 'credentials': credentials, # update credentials + } +) # perform operations delete_request = DeleteRequest( - table='', - ids = ["77e093f8-3ace-4295-8683-bb6745d6178e", "bf5989cc-79e8-4b2f-ad71-cb20b0a76091"] + table = '', + ids = ['', ''] ) # 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) # remove vault on the fly -skyflow_client.remove_vault_config("VAULT_ID") - - +skyflow_client.remove_vault_config('VAULT_ID') diff --git a/samples/vault_api/credentials_options.py b/samples/vault_api/credentials_options.py index 06108b8d..09e02061 100644 --- a/samples/vault_api/credentials_options.py +++ b/samples/vault_api/credentials_options.py @@ -1,31 +1,45 @@ +import json from skyflow import Skyflow, LogLevel from skyflow import Env from skyflow.vault.data import DeleteRequest -skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' +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: "CREDENTIAL_STRING", // credentials as string + '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 - }) - .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, - }) - .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 + .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 + } + ) + .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, + } + ) + .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() ) @@ -37,10 +51,7 @@ # perform operations -primary_delete_request = DeleteRequest( - table='', - ids = primary_delete_ids -) +primary_delete_request = DeleteRequest(table='', ids=primary_delete_ids) # 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) @@ -52,10 +63,7 @@ 'SKYFLOW_ID3', ] -secondary_delete_request = DeleteRequest( - table = 'TABLE_NAME', - ids = secondary_delete_ids -) +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) \ No newline at end of file +response = skyflow_client.vault('VAULT_ID2').delete(primary_delete_request) diff --git a/samples/vault_api/delete_records.py b/samples/vault_api/delete_records.py index 449ff916..d0960629 100644 --- a/samples/vault_api/delete_records.py +++ b/samples/vault_api/delete_records.py @@ -1,3 +1,4 @@ +import json from skyflow import Skyflow from skyflow import LogLevel from skyflow import Env @@ -5,26 +6,37 @@ # To generate Bearer Token from credentials string. -skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' +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: "CREDENTIAL_STRING", // credentials as string + '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 - }) - .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 + .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 + } + ) + .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() ) @@ -34,15 +46,8 @@ 'SKYFLOW_ID3', ] -delete_request = DeleteRequest( - table='TABLE_NAME', - ids = primary_delete_ids -) +delete_request = DeleteRequest(table='', ids=primary_delete_ids) -# will return first Vault ID -response = client.vault().delete(delete_request) +response = client.vault('').delete(delete_request) print(response) - - - diff --git a/samples/vault_api/detokenize_records.py b/samples/vault_api/detokenize_records.py index f20d43c1..2c931c2a 100644 --- a/samples/vault_api/detokenize_records.py +++ b/samples/vault_api/detokenize_records.py @@ -1,38 +1,50 @@ +import json from skyflow import Env from skyflow import Skyflow, LogLevel from skyflow.vault.tokens import DetokenizeRequest # To generate Bearer Token from credentials string. -skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' +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: skyflow_credentials_string, // credentials as string + '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 - }) - .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 + .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 + } + ) + .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() ) -detokenize_data = ["TOKEN1", "TOKEN2", "TOKEN3"] +detokenize_data = ['TOKEN1', 'TOKEN2', 'TOKEN3'] detokenize_request = DetokenizeRequest( - tokens = detokenize_data, + tokens=detokenize_data, ) response = client.vault('VAULT_ID').detokenize(detokenize_request) -print(response) \ No newline at end of file +print(response) diff --git a/samples/vault_api/get_column_values.py b/samples/vault_api/get_column_values.py index 2b0577a9..29272614 100644 --- a/samples/vault_api/get_column_values.py +++ b/samples/vault_api/get_column_values.py @@ -1,29 +1,40 @@ +import json from skyflow import Env from skyflow import Skyflow, LogLevel from skyflow.vault.data import GetRequest -from skyflow.vault.tokens import DetokenizeRequest # To generate Bearer Token from credentials string. -skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' +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: skyflow_credentials_string, // credentials as string + '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 - }) - .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 + .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 + } + ) + .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() ) @@ -36,11 +47,9 @@ get_request = GetRequest( - table = 'TABLE_NAME', - column_name = "COLUMN_NAME", - column_values = column_values + table='TABLE_NAME', column_name='COLUMN_NAME', column_values=column_values ) response = client.vault('VAULT_ID').get(get_request) -print(response) \ No newline at end of file +print(response) diff --git a/samples/vault_api/get_records.py b/samples/vault_api/get_records.py index 0429a7fa..718bdd1a 100644 --- a/samples/vault_api/get_records.py +++ b/samples/vault_api/get_records.py @@ -1,29 +1,40 @@ +import json from skyflow import Env from skyflow import Skyflow, LogLevel from skyflow.vault.data import GetRequest -from skyflow.vault.tokens import DetokenizeRequest # To generate Bearer Token from credentials string. -skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' +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: skyflow_credentials_string, // credentials as string + '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 - }) - .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 + .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 + } + ) + .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() ) @@ -31,12 +42,8 @@ get_ids = ['SKYFLOW_ID1', 'SKYFLOW_ID2'] -get_request = GetRequest( - table = 'TABLE_NAME', - ids = get_ids, - return_tokens = True -) +get_request = GetRequest(table='TABLE_NAME', ids=get_ids, return_tokens=True) response = client.vault('VAULT_ID').get(get_request) -print(response) \ No newline at end of file +print(response) diff --git a/samples/vault_api/insert_byot.py b/samples/vault_api/insert_byot.py index 36135d7c..f2ec4773 100644 --- a/samples/vault_api/insert_byot.py +++ b/samples/vault_api/insert_byot.py @@ -1,50 +1,60 @@ +import json from skyflow import Env from skyflow import Skyflow, LogLevel +from skyflow.error import SkyflowError from skyflow.utils.enums import TokenStrict -from skyflow.vault.data import GetRequest, InsertRequest -from skyflow.vault.tokens import DetokenizeRequest +from skyflow.vault.data import InsertRequest # To generate Bearer Token from credentials string. -skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' +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: skyflow_credentials_string, // credentials as string + '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 - }) - .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 + .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 + } + ) + .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 = [ - { "card_number": 'CARD_NUMBER1', "card_cvv": 'CVV1' }, - { "card_number": 'CARD_NUMBER2', "card_cvv": 'CVV2' }, -] - -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 - token_strict=TokenStrict.ENABLE, # token strict / byot is enabled, - tokens = [ - { "card_number": 'CARD_NUMBER1', "card_cvv": 'CVV1' }, - { "card_number": 'CARD_NUMBER2', "card_cvv": 'CVV2' }, - ], -) +# Initialize Client + +try: + insert_data = [{'': ''}, {'': ''}] + + token_data = [{'': ''}, {'': ''}] -response = skyflow_client.vault('VAULT_ID').insert(insert_request) + insert_request = InsertRequest( + table_name='', + values=insert_data, + token_strict=TokenStrict.ENABLE, # token strict is enabled, + tokens=token_data, + ) -print(response) + response = skyflow_client.vault('VAULT_ID').insert(insert_request) + print('Response:', response) +except SkyflowError as e: + print('Error Occurred:', e) diff --git a/samples/vault_api/insert_records.py b/samples/vault_api/insert_records.py index ee89c248..5e87f1d6 100644 --- a/samples/vault_api/insert_records.py +++ b/samples/vault_api/insert_records.py @@ -1,43 +1,52 @@ +import json from skyflow import Env from skyflow import Skyflow, LogLevel -from skyflow.vault.data import GetRequest, InsertRequest -from skyflow.vault.tokens import DetokenizeRequest +from skyflow.vault.data import InsertRequest # To generate Bearer Token from credentials string. -skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' - +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: skyflow_credentials_string, // credentials as string + '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 - }) - .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 + .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 + } + ) + .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 = [ - { "card_number": 'CARD_NUMBER1', "card_cvv": 'CVV1' }, - { "card_number": 'CARD_NUMBER2', "card_cvv": 'CVV2' }, + {'': '', '': ''}, ] 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 + 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) diff --git a/samples/vault_api/invoke_connection.py b/samples/vault_api/invoke_connection.py index 1daca5a4..a2243fa2 100644 --- a/samples/vault_api/invoke_connection.py +++ b/samples/vault_api/invoke_connection.py @@ -1,52 +1,63 @@ +import json from skyflow import Env from skyflow import Skyflow, LogLevel from skyflow.utils.enums import Method from skyflow.vault.connection import InvokeConnectionRequest -from skyflow.vault.data import GetRequest, InsertRequest -from skyflow.vault.tokens import DetokenizeRequest # To generate Bearer Token from credentials string. -skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' - +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: skyflow_credentials_string, // credentials as string + '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 - }) - .add_connection_config({ - "connection_id": "CONNECTION_ID", - "connection_url": "CONNECTION_URL", - "credentials": credentials - }) - .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 + .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 + } + ) + .add_connection_config( + { + 'connection_id': 'CONNECTION_ID', + 'connection_url': 'CONNECTION_URL', + 'credentials': credentials, + } + ) + .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() ) -body = { - "KEY1": "VALUE1", - "KEY2": "VALUE2" -} -headers = { -'Content-Type': 'application/json' -} +body = {'KEY1': 'VALUE1', 'KEY2': 'VALUE2'} +headers = {'KEY1': 'VALUE1'} +path_params = {'KEY1': 'VALUE1'} +query_params = {'KEY1': 'VALUE1'} invoke_connection_request = InvokeConnectionRequest( method=Method.POST, body=body, - request_headers = headers + request_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) diff --git a/samples/vault_api/query_records.py b/samples/vault_api/query_records.py index f1449efc..fa6ff6b7 100644 --- a/samples/vault_api/query_records.py +++ b/samples/vault_api/query_records.py @@ -1,47 +1,56 @@ +import json from skyflow import Env from skyflow import Skyflow, LogLevel -from skyflow.utils.enums import Method -from skyflow.vault.connection import InvokeConnectionRequest -from skyflow.vault.data import GetRequest, InsertRequest, QueryRequest -from skyflow.vault.tokens import DetokenizeRequest +from skyflow.vault.data import QueryRequest # To generate Bearer Token from credentials string. -skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' - +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: skyflow_credentials_string, // credentials as string + '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 - }) - .add_connection_config({ - "connection_id": "CONNECTION_ID", - "connection_url": "CONNECTION_URL", - "credentials": credentials - }) - .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 + .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 + } + ) + .add_connection_config( + { + 'connection_id': 'CONNECTION_ID', + 'connection_url': 'CONNECTION_URL', + 'credentials': credentials, + } + ) + .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 = "select * from TABLE_NAME limit 1" +query = '' -query_request = QueryRequest( - query= query -) +query_request = QueryRequest(query=query) -response = skyflow_client.vault("VAULT_ID").query(query_request) +response = skyflow_client.vault('VAULT_ID').query(query_request) print(response) diff --git a/samples/vault_api/tokenize_records.py b/samples/vault_api/tokenize_records.py index 66287164..0ca8e975 100644 --- a/samples/vault_api/tokenize_records.py +++ b/samples/vault_api/tokenize_records.py @@ -1,50 +1,56 @@ +import json from skyflow import Env from skyflow import Skyflow, LogLevel -from skyflow.utils.enums import Method -from skyflow.vault.connection import InvokeConnectionRequest -from skyflow.vault.data import GetRequest, InsertRequest, QueryRequest -from skyflow.vault.tokens import DetokenizeRequest, TokenizeRequest +from skyflow.vault.tokens import TokenizeRequest # To generate Bearer Token from credentials string. -skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' - +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: skyflow_credentials_string, // credentials as string + "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 - }) - .add_connection_config({ - "connection_id": "CONNECTION_ID", - "connection_url": "CONNECTION_URL", - "credentials": credentials - }) - .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 + .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 + } + ) + .add_connection_config( + { + "connection_id": "CONNECTION_ID", + "connection_url": "CONNECTION_URL", + "credentials": credentials, + } + ) + .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 = [{ - "value": '4111111111111111', - "column_group": "card_number_cg" -}] +tokenize_values = [{"": "", "": ""}] -tokenize_request = TokenizeRequest( - tokenize_parameters=tokenize_values -) +tokenize_request = TokenizeRequest(tokenize_parameters=tokenize_values) -response = skyflow_client.vault('VAULT_ID').tokenize(tokenize_request) +response = skyflow_client.vault("VAULT_ID").tokenize(tokenize_request) -print(response) \ No newline at end of file +print(response) diff --git a/samples/vault_api/update_record.py b/samples/vault_api/update_record.py index 2179abfb..367e4ac7 100644 --- a/samples/vault_api/update_record.py +++ b/samples/vault_api/update_record.py @@ -1,50 +1,55 @@ +import json from skyflow import Env from skyflow import Skyflow, LogLevel -from skyflow.utils.enums import Method -from skyflow.vault.connection import InvokeConnectionRequest -from skyflow.vault.data import GetRequest, InsertRequest, QueryRequest, UpdateRequest -from skyflow.vault.tokens import DetokenizeRequest, TokenizeRequest +from skyflow.vault.data import UpdateRequest # To generate Bearer Token from credentials string. -skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' - +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: skyflow_credentials_string, // credentials as string + '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 - }) - .add_connection_config({ - "connection_id": "CONNECTION_ID", - "connection_url": "CONNECTION_URL", - "credentials": credentials - }) - .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 + .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 + } + ) + .add_connection_config( + { + 'connection_id': 'CONNECTION_ID', + 'connection_url': 'CONNECTION_URL', + 'credentials': credentials, + } + ) + .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 = { - 'id': '', - 'card_number': '9999999999999999' -} +update_data = {'id': '', '': ''} -update_request = UpdateRequest( - table='TABLE_NAME', - data = update_data -) +update_request = UpdateRequest(table='TABLE_NAME', data=update_data) response = skyflow_client.vault('VAULT_ID').update(update_request) -print(response) \ No newline at end of file +print(response) diff --git a/skyflow/generated/rest/api/tokens_api.py b/skyflow/generated/rest/api/tokens_api.py index d6bd55e6..e21e7935 100644 --- a/skyflow/generated/rest/api/tokens_api.py +++ b/skyflow/generated/rest/api/tokens_api.py @@ -101,6 +101,7 @@ def record_service_detokenize( _response_types_map: Dict[str, Optional[str]] = { '200': "V1DetokenizeResponse", + '207': "V1DetokenizeResponse", '404': "object", } response_data = self.api_client.call_api( diff --git a/skyflow/vault/controller/_vault.py b/skyflow/vault/controller/_vault.py index a7c8eade..2361f063 100644 --- a/skyflow/vault/controller/_vault.py +++ b/skyflow/vault/controller/_vault.py @@ -30,7 +30,7 @@ def __build_bulk_field_records(self, values, tokens=None): def __build_batch_field_records(self, values, tokens, table_name, return_tokens, upsert): batch_record_list = [] for i, value in enumerate(values): - token = tokens[i] if tokens is not None else None + token = tokens[i] if tokens is not None and i < len(tokens) else None batch_record = V1BatchRecord( fields=value, table_name=table_name, @@ -83,6 +83,7 @@ def insert(self, request: InsertRequest): if request.continue_on_error: api_response = records_api.record_service_batch_operation(self.__vault_client.get_vault_id(), insert_body) + print("respomse: ", api_response) else: api_response = records_api.record_service_insert_record(self.__vault_client.get_vault_id(), diff --git a/skyflow/vault/data/_get_request.py b/skyflow/vault/data/_get_request.py index e40f9047..f7238deb 100644 --- a/skyflow/vault/data/_get_request.py +++ b/skyflow/vault/data/_get_request.py @@ -5,7 +5,7 @@ class GetRequest: def __init__(self, table, ids = None, - redaction_type = "plain-text", + redaction_type = None, return_tokens = False, fields = None, offset = None, @@ -22,4 +22,4 @@ def __init__(self, self.limit = limit self.download_url = download_url self.column_name = column_name - self.column_values = column_values + self.column_values = column_values \ No newline at end of file