Skip to content

Commit

Permalink
Merge branch 'main' into SK-1038-readme-changelog-samples-byot-strict…
Browse files Browse the repository at this point in the history
…-mode-in-insert-options
  • Loading branch information
skyflow-vivek authored Oct 9, 2023
2 parents 7d844fb + 5605cb3 commit ca27906
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 14 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

All notable changes to this project will be documented in this file.

## [1.14.0] - 2023-09-11
## [1.14.0] - 2023-09-29
## Added
- Support for different BYOT modes in Insert method.

## [1.13.1] - 2023-09-14
### Changed
- Add `request_index` in responses for insert method.

## [1.13.0] - 2023-09-04
### Added
- Added new Query method.
Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ client.insert(

Skyflow returns tokens for the record you just inserted.

```python
```json
{
"records": [
{
Expand All @@ -225,6 +225,7 @@ Skyflow returns tokens for the record you just inserted.
"cvv": "1989cb56-63da-4482-a2df-1f74cd0dd1a5",
"skyflow_id": "d863633c-8c75-44fc-b2ed-2b58162d1117"
},
"request_index": 0
}
]
}
Expand Down Expand Up @@ -266,14 +267,16 @@ Sample Response
"card_number": "f37186-e7e2-466f-91e5-48e2bcbc1",
"full_name": "1989cb56-63a-4482-adf-1f74cd1a5",
"skyflow_id": "3daf1a7f-bc7f-4fc9-8c56-a6e4e93231e6"
}
},
"request_index": 0
}
],
"errors": [
{
"error": {
"code": 404,
"description": "Object Name pii_field was not found for Vault - requestId : af4aad11-f276-474d-b626-c75c8b35d49e"
"description": "Object Name pii_field was not found for Vault - requestId : af4aad11-f276-474d-b626-c75c8b35d49e",
"request_index": 1
}
}
]
Expand Down Expand Up @@ -359,7 +362,7 @@ client.insert(

Skyflow returns tokens, with `upsert` support, for the record you just inserted.

```python
```json
{
"records": [
{
Expand All @@ -369,6 +372,7 @@ Skyflow returns tokens, with `upsert` support, for the record you just inserted.
"cvv": "1989cb56-63da-4482-a2df-1f74cd0dd1a5",
"skyflow_id": "60b32788-12ec-4dd7-9da5-0146c3afbe11"
},
"request_index": 0
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

if sys.version_info < (3, 7):
raise RuntimeError("skyflow requires Python 3.7+")
current_version = '1.13.0'
current_version = '1.14.0'

setup(
name='skyflow',
Expand Down
2 changes: 1 addition & 1 deletion skyflow/errors/_skyflow_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class SkyflowErrorMessages(Enum):

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"
TOKENS_PASSED_FOR_BYOT_DISABLE = "Pass byot parameter with ENABLE for token insertion"
INSUFFICIENT_TOKENS_PASSED_FOR_BYOT_ENABLE_STRICT = "For byot as ENABLE_STRICT, tokens should be passed for all fields"

class SkyflowError(Exception):
Expand Down
10 changes: 5 additions & 5 deletions skyflow/vault/_insert.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,14 @@ def buildResponseWithContinueOnError(responseArray, records, tokens: bool, reque
if tokens:
fieldsDict = body['records'][0]['tokens']
fieldsDict['skyflow_id'] = skyflow_id
result.append({'table': table, 'fields': fieldsDict})
result.append({'table': table, 'fields': fieldsDict, 'request_index': idx})
else:
result.append({'table': table, 'skyflow_id': skyflow_id})
result.append({'table': table, 'skyflow_id': skyflow_id, 'request_index': idx})
elif 'error' in body:
partial = True
message = body['error']
message += ' - request id: ' + requestId
error = {"code": status, "description": message}
error = {"code": status, "description": message, "request_index": idx}
errors.append({"error": error})
finalResponse = {"records": result, "errors": errors}
if len(result) == 0:
Expand All @@ -203,9 +203,9 @@ def buildResponseWithoutContinueOnError(responseArray, records, tokens: bool):
if tokens:
fieldsDict = responseArray[idx]['records'][0]['tokens']
fieldsDict['skyflow_id'] = skyflow_id
result.append({'table': table, 'fields': fieldsDict})
result.append({'table': table, 'fields': fieldsDict, 'request_index': idx})
else:
result.append({'table': table, 'skyflow_id': skyflow_id})
result.append({'table': table, 'skyflow_id': skyflow_id, 'request_index': idx})
return {'records': result}, False

def getUpsertColumn(tableName, upsertOptions):
Expand Down
2 changes: 1 addition & 1 deletion skyflow/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SDK_VERSION = '1.13.0'
SDK_VERSION = '1.14.0'
35 changes: 34 additions & 1 deletion tests/vault/test_insert.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ def testConvertResponseNoTokens(self):
self.assertEqual(len(result["records"]), 1)
self.assertEqual(result["records"][0]["skyflow_id"], 123)
self.assertEqual(result["records"][0]["table"], "pii_fields")
self.assertEqual(result["records"][0]["request_index"], 0)
self.assertNotIn("tokens", result["records"][0])

def testConvertResponseWithTokens(self):
Expand All @@ -465,6 +466,7 @@ def testConvertResponseWithTokens(self):

self.assertIn("fields", result["records"][0])
self.assertEqual(result["records"][0]["fields"]["skyflow_id"], 123)
self.assertEqual(result["records"][0]["request_index"], 0)

self.assertEqual(result["records"][0]["fields"]
["cardNumber"], "card_number_token")
Expand All @@ -486,6 +488,29 @@ def testConvertResponseWithContinueoOnErrorSuccess(self):
self.assertEqual(result["records"][0]["fields"]["skyflow_id"], 123)
self.assertEqual(result["records"][0]["fields"]["cardNumber"], "card_number_token")
self.assertEqual(result["records"][0]["fields"]["cvv"], "cvv_token")

self.assertIn("request_index", result["records"][0])
self.assertEqual(result["records"][0]["request_index"], 0)

def testConvertResponseWithContinueoOnErrorAndNoTokensSuccess(self):
options = InsertOptions(tokens=False, continueOnError=True)
result, partial = convertResponse(self.mockRequest, self.mockResponseCOESuccess, options)
self.assertFalse(partial)

self.assertEqual(len(result["records"]), 1)
self.assertNotIn("errors", result)

self.assertIn("skyflow_id", result["records"][0])
self.assertEqual(result["records"][0]["skyflow_id"], 123)

self.assertIn("table", result["records"][0])
self.assertEqual(result["records"][0]["table"], "pii_fields")

self.assertNotIn("fields", result["records"][0])
self.assertNotIn("tokens", result["records"][0])

self.assertIn("request_index", result["records"][0])
self.assertEqual(result["records"][0]["request_index"], 0)

def testConvertResponseWithContinueoOnErrorPartialSuccess(self):
options = InsertOptions(tokens=True, continueOnError=True)
Expand All @@ -509,11 +534,17 @@ def testConvertResponseWithContinueoOnErrorPartialSuccess(self):
self.assertEqual(result["records"][0]["fields"]["cardNumber"], "card_number_token")
self.assertEqual(result["records"][0]["fields"]["cvv"], "cvv_token")

self.assertIn("request_index", result["records"][0])
self.assertEqual(result["records"][0]["request_index"], 0)

message = self.mockResponseCOEErrorObject['Body']['error']
message += ' - request id: ' + self.mockResponse['requestId']
self.assertEqual(result["errors"][0]["error"]["code"], 400)
self.assertEqual(result["errors"][0]["error"]["description"], message)

self.assertIn("request_index", result["errors"][0]["error"])
self.assertEqual(result["errors"][0]["error"]["request_index"], 1)

def testConvertResponseWithContinueoOnErrorFailure(self):
options = InsertOptions(tokens=True, continueOnError=True)
result, partial = convertResponse(self.mockRequest, self.mockResponseCOEFailure, options)
Expand All @@ -526,7 +557,9 @@ def testConvertResponseWithContinueoOnErrorFailure(self):
message += ' - request id: ' + self.mockResponse['requestId']
self.assertEqual(result["errors"][0]["error"]["code"], 400)
self.assertEqual(result["errors"][0]["error"]["description"], message)

self.assertIn("request_index", result["errors"][0]["error"])
self.assertEqual(result["errors"][0]["error"]["request_index"], 0)

def testInsertInvalidToken(self):
config = Configuration('id', 'url', lambda: 'invalid-token')
try:
Expand Down

0 comments on commit ca27906

Please sign in to comment.