From 8ab5a33f5ba95732163714d3d87f2b0239e1e65d Mon Sep 17 00:00:00 2001 From: skyflow-vivek Date: Thu, 7 Sep 2023 10:46:46 +0530 Subject: [PATCH] SK-1036 TDD - Byot option in Insert method - Worked on feedback --- skyflow/errors/_skyflow_errors.py | 1 + skyflow/vault/_insert.py | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/skyflow/errors/_skyflow_errors.py b/skyflow/errors/_skyflow_errors.py index 2924b5b..59125a8 100644 --- a/skyflow/errors/_skyflow_errors.py +++ b/skyflow/errors/_skyflow_errors.py @@ -94,6 +94,7 @@ class SkyflowErrorMessages(Enum): BATCH_INSERT_PARTIAL_SUCCESS = "Insert Operation is partially successful" BATCH_INSERT_FAILURE = "Insert Operation is unsuccessful" + INVALID_BYOT_TYPE = "byot option has value of type %s, expected Skyflow.BYOT" NO_TOKENS_IN_INSERT = "Tokens are not passed in records for byot as %s" TOKENS_PASSED_FOR_BYOT_DISABLE = "To consider tokens struct pass byot value as ENABLE" INSUFFICIENT_TOKENS_PASSED_FOR_BYOT_ENABLE_STRICT = "For byot as ENABLE_STRICT, tokens should be passed for all fields" diff --git a/skyflow/vault/_insert.py b/skyflow/vault/_insert.py index 7053751..5864117 100644 --- a/skyflow/vault/_insert.py +++ b/skyflow/vault/_insert.py @@ -58,7 +58,6 @@ def getInsertRequestBody(data, options: InsertOptions): if options.continueOnError == None: requestBody.pop('continueOnError') try: - print('request body', requestBody) jsonBody = json.dumps(requestBody) except Exception as e: raise SkyflowError(SkyflowErrorCodes.INVALID_INPUT, SkyflowErrorMessages.INVALID_JSON.value % ( @@ -92,7 +91,12 @@ def getTableAndFields(record): return (table, fields) -def validateTokensAndByotMode(record, byot:BYOT): +def validateTokensAndByotMode(record, byot:BYOT): + + if not isinstance(byot, BYOT): + byotType = str(type(byot)) + raise SkyflowError(SkyflowErrorCodes.INVALID_INPUT, SkyflowErrorMessages.INVALID_BYOT_TYPE.value % (byotType), interface=interface) + if byot == BYOT.DISABLE: if "tokens" in record: raise SkyflowError(SkyflowErrorCodes.INVALID_INPUT, SkyflowErrorMessages.TOKENS_PASSED_FOR_BYOT_DISABLE, interface=interface)