diff --git a/CHANGELOG.md b/CHANGELOG.md index dee863b..a1491e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. +## [1.8.0] - 2023-01-10 +### Added +- update and get methods. + ## [1.7.0] - 2022-12-07 ### Added - `upsert` support for insert method. diff --git a/README.md b/README.md index 07be2fc..fc6906b 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,9 @@ This Python SDK is designed to help developers easily implement Skyflow into the - [Vault APIs](#vault-apis) - [Insert](#insert-data-into-the-vault) - [Detokenize](#detokenize) + - [Get](#get) - [Get By Id](#get-by-id) + - [Update](#update-data) - [Invoke Connection](#invoke-connection) - [Logging](#logging) - [Reporting a Vulnerability](#reporting-a-vulnerability) @@ -304,6 +306,104 @@ Sample response: } ``` +### Get + +To retrieve data using Skyflow IDs or unique column values, use the `get(records: dict)` method. The `records` parameter takes a Dictionary that contains either an array of Skyflow IDs or a unique column name and values. + +Note: You can use either Skyflow IDs or `unique` values to retrieve records. You can't use both at the same time. + +```python +{ + 'records': [ + { + 'columnName': str, # Name of the unique column. + 'columnValues': [str], # List of unique column values. + 'table': str, # Name of table holding the data. + 'redaction': Skyflow.RedactionType, # Redaction applied to retrieved data. + } + ] +} + or +{ + 'records': [ + { + 'ids': [str], # List of Skyflow IDs. + 'table': str, # Name of table holding the data. + 'redaction': Skyflow.RedactionType, # Redaction applied to retrieved data. + } + ] +} + +``` +Sample usage + +The following snippet shows how to use the `get()` method. For details, see [get_sample.py].(https://github.com/skyflowapi/skyflow-python/blob/main/samples/get_sample.py), + +```python +from skyflow.vault import RedactionType + +skyflowIDs = ['f8d8a622-b557-4c6b-a12c-c5ebe0b0bfd9'] +record = {'ids': skyflowIDs, 'table': 'cards', 'redaction':RedactionType.PLAIN_TEXT} +recordsWithUniqueColumn = + { + 'table': 'test_table', + 'columnName': 'card_number', + 'columnValues': ['123456'], + 'redaction': RedactionType.PLAIN_TEXT + } + +invalidID = ['invalid skyflow ID'] +badRecord = {'ids': invalidID, 'table': 'cards', 'redaction': RedactionType.PLAIN_TEXT} + +records = {'records': [record, badRecord]} + +try: + client.get(records) +except SkyflowError as e: + if e.data: + print(e.data) + else: + print(e) +``` + +Sample response: + +```python +{ + 'records': [ + { + 'fields': { + 'card_number': '4111111111111111', + 'cvv': '127', + 'expiry_date': '11/35', + 'fullname': 'monica', + 'skyflow_id': 'f8d8a622-b557-4c6b-a12c-c5ebe0b0bfd9' + }, + 'table': 'cards' + }, + { + 'fields': { + 'card_number': '123456', + 'cvv': '317', + 'expiry_date': '10/23', + 'fullname': 'sam', + 'skyflow_id': 'da26de53-95d5-4bdb-99db-8d8c66a35ff9' + }, + 'table': 'cards' + } + ], + 'errors': [ + { + 'error': { + 'code': '404', + 'description': 'No Records Found' + }, + 'skyflow_ids': ['invalid skyflow id'] + } + ] +} +``` + ### Get By Id For retrieving using SkyflowID's, use the get_by_id(records: dict) method. The records parameter takes a Dictionary that contains records to be fetched as shown below: @@ -392,6 +492,104 @@ Sample response: `Note:` While using detokenize and get_by_id methods, there is a possibility that some or all of the tokens might be invalid. In such cases, the data from response consists of both errors and detokenized records. In the SDK, this will raise a SkyflowError Exception and you can retrieve the data from this Exception object as shown above. +### Update + +To update data in your vault, use the `update(records: dict, options: UpdateOptions)` method. The `records` parameter takes a Dictionary that contains records to fetch. If `UpdateTokens` is `True`, Skyflow returns tokens for the record you just updated. If `, ids if `UpdateOptions` is `False`, Skyflow returns IDs for the record you updated. + +```python +# Optional, indicates whether to return all fields for updated data. Defaults to 'true'. +options: UpdateOptions +``` + +```python +{ + 'records': [ + { + 'id': str, # Skyflow ID of the record to be updated. + 'table': str, # Name of table holding the skyflowID. + 'fields': { + str: str # Name of the column and value to update. + } + } + ] +} +``` +Sample usage + +The following snippet shows how to use the `update()` method. For details, see [update_sample.py](https://github.com/skyflowapi/skyflow-python/blob/main/samples/update_sample.py), + +```python +records = { + 'records': [ + { + 'id': '56513264-fc45-41fa-9cb0-d1ad3602bc49', + 'table': 'cards', + 'fields': { + 'card_number': '45678910234' + } + } + ] + } +try: + client.update(records, UpdateOptions(True)) +except SkyflowError as e: + if e.data: + print(e.data) + else: + print(e) +``` + +Sample response + +`UpdateOptions` set to `True` + +```python +{ + 'records':[ + { + 'id':'56513264-fc45-41fa-9cb0-d1ad3602bc49', + 'fields':{ + 'card_number':'0051-6502-5704-9879' + } + } + ], + 'errors':[] +} +``` + +`UpdateOptions` set to `False` + +```python +{ + 'records':[ + { + 'id':'56513264-fc45-41fa-9cb0-d1ad3602bc49' + } + ], + 'errors':[] +} +``` + +Sample Error + +```python +{ + 'records':[ + { + 'id':'56513264-fc45-41fa-9cb0-d1ad3602bc49' + } + ], + 'errors':[ + { + 'error':{ + 'code':404, + 'description':'Token for skyflowID doesn"t exist in vault - Request ID: a8def196-9569-9cb7-9974-f899f9e4bd0a' + } + } + ] +} +``` + ### Invoke Connection Using Skyflow Connection, end-user applications can integrate checkout/card issuance flow with their apps/systems. To invoke connection, use the invoke_connection(config: Skyflow.ConnectionConfig) method of the Skyflow client. @@ -504,4 +702,200 @@ Current the following 5 log levels are supported: ## Reporting a Vulnerability -If you discover a potential security issue in this project, please reach out to us at security@skyflow.com. Please do not create public GitHub issues or Pull Requests, as malicious actors could potentially view them. \ No newline at end of file +If you discover a potential security issue in this project, please reach out to us at security@skyflow.com. Please do not create public GitHub issues or Pull Requests, as malicious actors could potentially view them. + +### Get + +To retrieve data using Skyflow IDs or unique column values, use the `get(records: dict)` method. The `records` parameter takes a Dictionary that contains either an array of Skyflow IDs or a unique column name and values. + +Note: You can use either Skyflow IDs or `unique` values to retrieve records. You can't use both at the same time. + +```python +{ + 'records': [ + { + 'columnName': str, # Name of the unique column. + 'columnValues': [str], # List of unique column values. + 'table': str, # Name of table holding the data. + 'redaction': Skyflow.RedactionType, # Redaction applied to retrieved data. + } + ] +} + or +{ + 'records': [ + { + 'ids': [str], # List of Skyflow IDs. + 'table': str, # Name of table holding the data. + 'redaction': Skyflow.RedactionType, # Redaction applied to retrieved data. + } + ] +} + +``` +Sample usage + +The following snippet shows how to use the `get()` method. For details, see [get_sample.py].(https://github.com/skyflowapi/skyflow-python/blob/main/samples/get_sample.py), + +```python +from skyflow.vault import RedactionType + +skyflowIDs = ['f8d8a622-b557-4c6b-a12c-c5ebe0b0bfd9'] +record = {'ids': skyflowIDs, 'table': 'cards', 'redaction':RedactionType.PLAIN_TEXT} +recordsWithUniqueColumn = + { + 'table': 'test_table', + 'columnName': 'card_number', + 'columnValues': ['123456'], + 'redaction': RedactionType.PLAIN_TEXT + } + +invalidID = ['invalid skyflow ID'] +badRecord = {'ids': invalidID, 'table': 'cards', 'redaction': RedactionType.PLAIN_TEXT} + +records = {'records': [record, badRecord]} + +try: + client.get(records) +except SkyflowError as e: + if e.data: + print(e.data) + else: + print(e) +``` + +Sample response: + +```python +{ + 'records': [ + { + 'fields': { + 'card_number': '4111111111111111', + 'cvv': '127', + 'expiry_date': '11/35', + 'fullname': 'monica', + 'skyflow_id': 'f8d8a622-b557-4c6b-a12c-c5ebe0b0bfd9' + }, + 'table': 'cards' + }, + { + 'fields': { + 'card_number': '123456', + 'cvv': '317', + 'expiry_date': '10/23', + 'fullname': 'sam', + 'skyflow_id': 'da26de53-95d5-4bdb-99db-8d8c66a35ff9' + }, + 'table': 'cards' + } + ], + 'errors': [ + { + 'error': { + 'code': '404', + 'description': 'No Records Found' + }, + 'skyflow_ids': ['invalid skyflow id'] + } + ] +} +``` + +### Update + +To update data in your vault, use the `update(records: dict, options: UpdateOptions)` method. The `records` parameter takes a Dictionary that contains records to fetch. If `UpdateTokens` is `True`, Skyflow returns tokens for the record you just updated. If `, ids if `UpdateOptions` is `False`, Skyflow returns IDs for the record you updated. + +```python +# Optional, indicates whether to return all fields for updated data. Defaults to 'true'. +options: UpdateOptions +``` + +```python +{ + 'records': [ + { + 'id': str, # Skyflow ID of the record to be updated. + 'table': str, # Name of table holding the skyflowID. + 'fields': { + str: str # Name of the column and value to update. + } + } + ] +} +``` +Sample usage + +The following snippet shows how to use the `update()` method. For details, see [update_sample.py](https://github.com/skyflowapi/skyflow-python/blob/main/samples/update_sample.py), + +```python +records = { + 'records': [ + { + 'id': '56513264-fc45-41fa-9cb0-d1ad3602bc49', + 'table': 'cards', + 'fields': { + 'card_number': '45678910234' + } + } + ] + } +try: + client.update(records, UpdateOptions(True)) +except SkyflowError as e: + if e.data: + print(e.data) + else: + print(e) +``` + +Sample response + +`UpdateOptions` set to `True` + +```python +{ + 'records':[ + { + 'id':'56513264-fc45-41fa-9cb0-d1ad3602bc49', + 'fields':{ + 'card_number':'0051-6502-5704-9879' + } + } + ], + 'errors':[] +} +``` + +`UpdateOptions` set to `False` + +```python +{ + 'records':[ + { + 'id':'56513264-fc45-41fa-9cb0-d1ad3602bc49' + } + ], + 'errors':[] +} +``` + +Sample Error + +```python +{ + 'records':[ + { + 'id':'56513264-fc45-41fa-9cb0-d1ad3602bc49' + } + ], + 'errors':[ + { + 'error':{ + 'code':404, + 'description':'Token for skyflowID doesn"t exist in vault - Request ID: a8def196-9569-9cb7-9974-f899f9e4bd0a' + } + } + ] +} +``` \ No newline at end of file diff --git a/samples/README.md b/samples/README.md index 597e19e..64863db 100644 --- a/samples/README.md +++ b/samples/README.md @@ -33,8 +33,32 @@ pip install skyflow this file secure, as You'll need it for each of the samples. ## The samples +### [Get data](./get_sample.py) -### [Get data by ID](./getByIDSample.py) +To retrieve data using Skyflow IDs or unique column values, use the `get(records: dict)` method. The `records` parameter takes a Dictionary that contains either an array of Skyflow IDs or a unique column name and values. + +Note: You can use either Skyflow IDs or `unique` values to retrieve records. You can't use both at the same time. +#### Configure + +Replace the following values in the sample file: + +| Value | Description | +| ------------------------------ | ------------------------------------------------------- | +| `` | ID of your vault. | +| `` | URL of your vault. | +| `` | relative path to your service account credentials file. | +| `` | Name of the table to insert data into. | +| `` | One of the four Redaction Types. | +| `` | Skyflow Id of the record to be fetched. | +| `` | Unique column name to fetch the data. | +| `` | Column value of the corresponding column. | + +#### Run the sample + +```bash +python3 get_sample.py +``` +### [Get data by ID](./get_by_ids_sample.py) Get data using Skyflow IDs for the desired records. @@ -55,10 +79,35 @@ Replace the following values in the sample file: #### Run the sample ```bash -python3 getByIDSample.py +python3 get_by_ids_sample.py +``` + + +### [Update data](./update_sample.py) + +Update data in the vault. + +#### Configure + +Replace the following values in the sample file: + +| Value | Description | +| ------------------------------ | ------------------------------------------------------- | +| `` | ID of your vault. | +| `` | URL of your vault. | +| `` | relative path to your service account credentials file. | +| `` | Name of the table to insert data into. | +| `` | Skyflow Id of the record to be updated. | +| `` | Name of the column to update data. | +| `` | Valid value to update into the corresponding column. | + +#### Run the sample + +```bash +python3 update_sample.py ``` -### [Insert data](./InsertSample.py) +### [Insert data](./insert_sample.py) Insert data in the vault. @@ -78,10 +127,10 @@ Replace the following values in the sample file: #### Run the sample ```bash -python3 InsertSample.py +python3 insert_sample.py ``` -### [Detokenize data](./detokenizeSample.py) +### [Detokenize data](./detokenize_sample.py) Detokenize a data token from the vault. Make sure the specified token is for data that exists in the vault. If you need a valid token, use @@ -103,10 +152,10 @@ Replace the following values in the sample file: #### Run the sample ```bash -python3 detokenizeSample.py +python3 detokenize_sample.py ``` -### [Invoke a connection](./invokeConnectionSample.py) +### [Invoke a connection](./invoke_connection_sample.py) Skyflow Connections is a gateway service that uses Skyflow's underlying tokenization capabilities to securely connect to first-party and third-party @@ -130,10 +179,10 @@ Replace the following values in the sample file: #### Run the sample ```bash -python3 invokeConnectionSample.py +python3 invoke_connection_sample.py ``` -### [Service account token generation](./SATokenSample.py) +### [Service account token generation](./sa_token_sample.py) Generates SA Token using path of credentials file. @@ -144,10 +193,10 @@ Replace `` with the relative path to your service ac #### Run the sample ```bash -python3 SATokenSample.py +python3 sa_token_sample.py ``` -### [Generate Bearer Token](./generateBearerTokenFromCredsSample.py) +### [Generate Bearer Token](./generate_bearer_token_from_creds_sample.py) Generates SA Token using json content of credentials file. @@ -158,5 +207,5 @@ Replace `credentials` with the content of service account credentials file. #### Run the sample ```bash -python3 generateBearerTokenFromCredsSample.py +python3 generate_bearer_token_from_creds_sample.py ```