diff --git a/README.md b/README.md index 8313322..7571b6b 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 @@ -277,6 +284,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 @@ -315,6 +378,13 @@ Skyflow returns tokens, with `upsert` support, for the record you just inserted. } ``` +#### 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 c39e8e3..99f277f 100644 --- a/tests/vault/test_insert.py +++ b/tests/vault/test_insert.py @@ -617,6 +617,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)