From 7d844fbd62c5a4aee7f48779b7eec1817b025d29 Mon Sep 17 00:00:00 2001 From: skyflow-vivek Date: Mon, 11 Sep 2023 13:35:10 +0530 Subject: [PATCH] SK-1038 BYOT Strict Mode in Insert - Updated README, CHANGELOG and Samples --- CHANGELOG.md | 4 ++ README.md | 81 +++++++++++++++++++++++++++++++++-- samples/insert_byot_sample.py | 41 ++++++++++++++++++ tests/vault/test_insert.py | 8 ++++ 4 files changed, 130 insertions(+), 4 deletions(-) create mode 100644 samples/insert_byot_sample.py diff --git a/CHANGELOG.md b/CHANGELOG.md index fb88bed..f3d9626 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. +## [1.14.0] - 2023-09-11 +## Added +- Support for different BYOT modes in Insert method. + ## [1.13.0] - 2023-09-04 ### Added - Added new Query method. diff --git a/README.md b/README.md index 03bad84..bb5e332 100644 --- a/README.md +++ b/README.md @@ -149,8 +149,9 @@ All Vault APIs must be invoked using a client instance. ### Insert data into the vault -To insert data into your vault use the `insert(records: dict, options: InsertOptions)` method. The `records` parameter is a dictionary that requires a `records` key and takes an array of records to insert into the vault. The `options` parameter takes a dictionary of optional parameters for the insertion. This includes an option to return tokenized data, upsert records and continue on error. +To insert data into your vault use the `insert(records: dict, options: InsertOptions)` method. The `records` parameter is a dictionary that requires a `records` key and takes an array of records to insert into the vault. The `options` parameter takes a dictionary of optional parameters for the insertion. The optional parameter includes: +Insert Options ```python # Optional, indicates whether you return tokens for inserted data. Defaults to 'true'. tokens: bool @@ -158,8 +159,14 @@ tokens: bool upsert: [UpsertOption] # Optional, decides whether to continue if error encountered or not continueOnError: bool +# Optional, decides the byot mode +byot: Skyflow.BYOT ``` +Notes: +- For supported `byot` types, see [Skyflow.BYOT](#byot) +- `byot` defaults to `BYOT.DISABLE` + Insert call schema ```python from skyflow.vault import InsertOptions, UpsertOption @@ -216,13 +223,14 @@ Skyflow returns tokens for the record you just inserted. "fields": { "cardNumber": "f3907186-e7e2-466f-91e5-48e12c2bcbc1", "cvv": "1989cb56-63da-4482-a2df-1f74cd0dd1a5", + "skyflow_id": "d863633c-8c75-44fc-b2ed-2b58162d1117" }, } ] } ``` -**Insert call [example](https://github.com/skyflowapi/skyflow-python/blob/main/samples/insert_with_continue_on_error_sample.py) with continueOnError option** +**Insert call [example](https://github.com/skyflowapi/skyflow-python/blob/main/samples/insert_with_continue_on_error_sample.py) with `continueOnError` option** ```python client.insert( @@ -256,7 +264,8 @@ Sample Response "table": "cards", "fields": { "card_number": "f37186-e7e2-466f-91e5-48e2bcbc1", - "full_name": "1989cb56-63a-4482-adf-1f74cd1a5" + "full_name": "1989cb56-63a-4482-adf-1f74cd1a5", + "skyflow_id": "3daf1a7f-bc7f-4fc9-8c56-a6e4e93231e6" } } ], @@ -264,7 +273,7 @@ Sample Response { "error": { "code": 404, - "description": "Object Name pii_field was not found for Vault - requestId : id1234" + "description": "Object Name pii_field was not found for Vault - requestId : af4aad11-f276-474d-b626-c75c8b35d49e" } } ] @@ -272,6 +281,62 @@ Sample Response ``` +**Insert call [example](https://github.com/skyflowapi/skyflow-python/blob/main/samples/insert_byot_sample.py) with `byot` option** + +```python +client.insert( + { + "records": [ + { + "table": "cards", + "fields": { + "card_number": "4111111111111111", + "full_name": "john doe" + }, + "tokens": { + "card_number": "8486-6981-3757-9998" + } + }, + { + "table": "cards", + "fields": { + "card_number": "4242424242424200" + "full_name": "jane doe" + }, + "tokens": { + "card_number": "9426-6911-3750-7998" + } + } + ] + }, InsertOptions(tokens=True, byot=BYOT.ENABLE) +) +``` + +Sample Response: + +```json +{ + "records": [ + { + "table": "cards", + "fields": { + "card_number": "8486-6981-3757-9998", + "full_name": "1989cb56-63a-4482-adf-1f74cd1a5", + "skyflow_id": "3daf1a7f-bc7f-4fc9-8c56-a6e4e93231e6" + } + }, + { + "table": "cards", + "fields": { + "card_number": "9426-6911-3750-7998", + "full_name": "1041c13c-1a3c-4a09-a556-686d8bba307b", + "skyflow_id": "9a567659-fe5c-4ecc-80aa-059a9644138e" + } + } + ], +} +``` + **Insert call [example](https://github.com/skyflowapi/skyflow-python/blob/main/samples/insert_upsert_sample.py) with `upsert` options** ```python @@ -302,12 +367,20 @@ Skyflow returns tokens, with `upsert` support, for the record you just inserted. "fields": { "cardNumber": "f3907186-e7e2-466f-91e5-48e12c2bcbc1", "cvv": "1989cb56-63da-4482-a2df-1f74cd0dd1a5", + "skyflow_id": "60b32788-12ec-4dd7-9da5-0146c3afbe11" }, } ] } ``` +#### BYOT +There are 3 accepted values in Skyflow.BYOT: + +- `DISABLE` +- `ENABLE` +- `ENABLE_STRICT` + ### Detokenize To retrieve tokens from your vault, you can use the `Detokenize(records: dict, options: DetokenizeOptions)` method.The records parameter takes a dictionary that contains the `records` key that takes an array of records to return. The options parameter is a `DetokenizeOptions` object that provides further options, including `continueOnError` operation, for your detokenize call, as shown below: diff --git a/samples/insert_byot_sample.py b/samples/insert_byot_sample.py new file mode 100644 index 0000000..a06d038 --- /dev/null +++ b/samples/insert_byot_sample.py @@ -0,0 +1,41 @@ +''' + Copyright (c) 2022 Skyflow, Inc. +''' +from skyflow.errors import SkyflowError +from skyflow.service_account import generate_bearer_token, is_expired +from skyflow.vault import Client, InsertOptions, Configuration, BYOT + +# cache token for reuse +bearerToken = '' + +def token_provider(): + global bearerToken + if is_expired(bearerToken): + bearerToken, _ = generate_bearer_token('') + return bearerToken + + +try: + config = Configuration( + '', '', token_provider) + client = Client(config) + + options = InsertOptions(tokens=True, byot=BYOT.ENABLE) + + data = { + "records": [ + { + "table": "", + "fields": { + "": "" + }, + "tokens": { + "": "" + } + } + ] + } + response = client.insert(data, options=options) + print('Response:', response) +except SkyflowError as e: + print('Error Occurred:', e) diff --git a/tests/vault/test_insert.py b/tests/vault/test_insert.py index d5b83c1..db3b4f0 100644 --- a/tests/vault/test_insert.py +++ b/tests/vault/test_insert.py @@ -584,6 +584,14 @@ def testValidUpsertOptions(self): self.assertEqual( e.message, SkyflowErrorMessages.EMPTY_UPSERT_OPTION_COLUMN.value % 0) + def testInvalidByotModeTypePassed(self): + try: + options = InsertOptions(byot='BYOT.DISABLE') + getInsertRequestBody(self.data, options) + self.fail("Should have thrown an error") + except SkyflowError as e: + self.assertEqual(e.message, SkyflowErrorMessages.INVALID_BYOT_TYPE.value % (type(options.byot))) + def testTokensPassedWithByotModeDisable(self): try: options = InsertOptions(byot=BYOT.DISABLE)