Skip to content

Commit 984221c

Browse files
Merge pull request #138 from skyflowapi/SK-1790-change-tokenstrict-to-tokenmode
SK-1790 Implement feedback for SDK v2
2 parents 9533d03 + 3817de6 commit 984221c

19 files changed

Lines changed: 131 additions & 239 deletions

src/main/java/com/skyflow/VaultClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ protected RecordServiceInsertRecordBody getBulkInsertRequestBody(InsertRequest r
9797
insertRecordBody.setTokenization(request.getReturnTokens());
9898
insertRecordBody.setHomogeneous(request.getHomogeneous());
9999
insertRecordBody.setUpsert(request.getUpsert());
100-
insertRecordBody.setByot(request.getTokenStrict().getBYOT());
100+
insertRecordBody.setByot(request.getTokenMode().getBYOT());
101101

102102
List<HashMap<String, Object>> values = request.getValues();
103103
List<HashMap<String, Object>> tokens = request.getTokens();
@@ -117,7 +117,7 @@ protected RecordServiceInsertRecordBody getBulkInsertRequestBody(InsertRequest r
117117
protected RecordServiceBatchOperationBody getBatchInsertRequestBody(InsertRequest request) {
118118
RecordServiceBatchOperationBody insertRequestBody = new RecordServiceBatchOperationBody();
119119
insertRequestBody.setContinueOnError(true);
120-
insertRequestBody.setByot(request.getTokenStrict().getBYOT());
120+
insertRequestBody.setByot(request.getTokenMode().getBYOT());
121121

122122
ArrayList<HashMap<String, Object>> values = request.getValues();
123123
ArrayList<HashMap<String, Object>> tokens = request.getTokens();
@@ -142,7 +142,7 @@ protected RecordServiceBatchOperationBody getBatchInsertRequestBody(InsertReques
142142

143143
protected RecordServiceUpdateRecordBody getUpdateRequestBody(UpdateRequest request) {
144144
RecordServiceUpdateRecordBody updateRequestBody = new RecordServiceUpdateRecordBody();
145-
updateRequestBody.byot(request.getTokenStrict().getBYOT());
145+
updateRequestBody.byot(request.getTokenMode().getBYOT());
146146
updateRequestBody.setTokenization(request.getReturnTokens());
147147
HashMap<String, Object> values = request.getData();
148148
HashMap<String, Object> tokens = request.getTokens();

src/main/java/com/skyflow/enums/Byot.java renamed to src/main/java/com/skyflow/enums/TokenMode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
import com.skyflow.generated.rest.models.V1BYOT;
44

5-
public enum Byot {
5+
public enum TokenMode {
66
DISABLE(V1BYOT.DISABLE),
77
ENABLE(V1BYOT.ENABLE),
88
ENABLE_STRICT(V1BYOT.ENABLE_STRICT);
99

1010
private final V1BYOT byot;
1111

12-
Byot(V1BYOT byot) {
12+
TokenMode(V1BYOT byot) {
1313
this.byot = byot;
1414
}
1515

src/main/java/com/skyflow/errors/ErrorMessage.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ public enum ErrorMessage {
6565
EmptyValueInTokens("%s0 Validation error. Invalid value in tokens. Specify a valid value."),
6666
EmptyUpsert("%s0 Validation error. 'upsert' key can't be empty. Specify an upsert column."),
6767
HomogenousNotSupportedWithUpsert("%s0 Validation error. 'homogenous' is not supported with 'upsert'. Specify either 'homogenous' or 'upsert'."),
68-
TokensPassedForByotDisable("%s0 Validation error. 'tokenStrict' wasn't specified. Set 'tokenStrict' to 'ENABLE' to insert tokens."),
69-
NoTokensWithByot("%s0 Validation error. Tokens weren't specified for records while 'tokenStrict' was %s1. Specify tokens."),
68+
TokensPassedForTokenModeDisable("%s0 Validation error. 'tokenMode' wasn't specified. Set 'tokenMode' to 'ENABLE' to insert tokens."),
69+
NoTokensWithTokenMode("%s0 Validation error. Tokens weren't specified for records while 'tokenMode' was %s1. Specify tokens."),
7070
MismatchOfFieldsAndTokens("%s0 Validation error. 'fields' and 'tokens' have different columns names. Verify that 'fields' and 'tokens' columns match."),
71-
InsufficientTokensPassedForByotEnableStrict("%s0 Validation error. 'tokenStrict' is set to 'ENABLE_STRICT', but some fields are missing tokens. Specify tokens for all fields."),
71+
InsufficientTokensPassedForTokenModeEnableStrict("%s0 Validation error. 'tokenMode' is set to 'ENABLE_STRICT', but some fields are missing tokens. Specify tokens for all fields."),
7272
BatchInsertPartialSuccess("%s0 Insert operation completed with partial success."),
7373
BatchInsertFailure("%s0 Insert operation failed."),
7474

src/main/java/com/skyflow/logs/ErrorLogs.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ public enum ErrorLogs {
5353
EMPTY_OR_NULL_KEY_IN_VALUES("Invalid %s1 request. Key can not be null or empty in values"),
5454
EMPTY_UPSERT("Invalid %s1 request. Upsert can not be empty."),
5555
HOMOGENOUS_NOT_SUPPORTED_WITH_UPSERT("Invalid %s1 request. Homogenous is not supported when upsert is passed."),
56-
TOKENS_NOT_ALLOWED_WITH_BYOT_DISABLE("Invalid %s1 request. Tokens are not allowed when tokenStrict is DISABLE."),
57-
TOKENS_REQUIRED_WITH_BYOT("Invalid %s1 request. Tokens are required when tokenStrict is %s2."),
56+
TOKENS_NOT_ALLOWED_WITH_TOKEN_MODE_DISABLE("Invalid %s1 request. Tokens are not allowed when tokenMode is DISABLE."),
57+
TOKENS_REQUIRED_WITH_TOKEN_MODE("Invalid %s1 request. Tokens are required when tokenMode is %s2."),
5858
EMPTY_TOKENS("Invalid %s1 request. Tokens can not be empty."),
5959
EMPTY_OR_NULL_VALUE_IN_TOKENS("Invalid %s1 request. Value can not be null or empty in tokens for key \"%s2\"."),
6060
EMPTY_OR_NULL_KEY_IN_TOKENS("Invalid %s1 request. Key can not be null or empty in tokens."),
61-
INSUFFICIENT_TOKENS_PASSED_FOR_BYOT_ENABLE_STRICT("Invalid %s1 request. For tokenStrict as ENABLE_STRICT, tokens should be passed for all fields."),
61+
INSUFFICIENT_TOKENS_PASSED_FOR_TOKEN_MODE_ENABLE_STRICT("Invalid %s1 request. For tokenMode as ENABLE_STRICT, tokens should be passed for all fields."),
6262
MISMATCH_OF_FIELDS_AND_TOKENS("Invalid %s1 request. Keys for values and tokens are not matching."),
6363
INSERT_RECORDS_REJECTED("Insert request resulted in failure."),
6464
TOKENS_REQUIRED("Invalid %s1 request. Tokens are required."),

src/main/java/com/skyflow/utils/validations/Validations.java

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import com.skyflow.config.ConnectionConfig;
44
import com.skyflow.config.Credentials;
55
import com.skyflow.config.VaultConfig;
6-
import com.skyflow.enums.Byot;
76
import com.skyflow.enums.InterfaceName;
87
import com.skyflow.enums.RedactionType;
8+
import com.skyflow.enums.TokenMode;
99
import com.skyflow.errors.ErrorCode;
1010
import com.skyflow.errors.ErrorMessage;
1111
import com.skyflow.errors.SkyflowException;
@@ -238,7 +238,7 @@ public static void validateInsertRequest(InsertRequest insertRequest) throws Sky
238238
ArrayList<HashMap<String, Object>> tokens = insertRequest.getTokens();
239239
String upsert = insertRequest.getUpsert();
240240
Boolean homogeneous = insertRequest.getHomogeneous();
241-
Byot tokenStrict = insertRequest.getTokenStrict();
241+
TokenMode tokenMode = insertRequest.getTokenMode();
242242

243243
if (table == null) {
244244
LogUtil.printErrorLog(Utils.parameterizedString(
@@ -296,46 +296,46 @@ public static void validateInsertRequest(InsertRequest insertRequest) throws Sky
296296
}
297297
}
298298

299-
switch (tokenStrict) {
299+
switch (tokenMode) {
300300
case DISABLE:
301301
if (tokens != null) {
302302
LogUtil.printErrorLog(Utils.parameterizedString(
303-
ErrorLogs.TOKENS_NOT_ALLOWED_WITH_BYOT_DISABLE.getLog(), InterfaceName.INSERT.getName()
303+
ErrorLogs.TOKENS_NOT_ALLOWED_WITH_TOKEN_MODE_DISABLE.getLog(), InterfaceName.INSERT.getName()
304304
));
305-
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.TokensPassedForByotDisable.getMessage());
305+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.TokensPassedForTokenModeDisable.getMessage());
306306
}
307307
break;
308308
case ENABLE:
309309
if (tokens == null) {
310310
LogUtil.printErrorLog(Utils.parameterizedString(
311-
ErrorLogs.TOKENS_REQUIRED_WITH_BYOT.getLog(),
312-
InterfaceName.INSERT.getName(), Byot.ENABLE.toString()
311+
ErrorLogs.TOKENS_REQUIRED_WITH_TOKEN_MODE.getLog(),
312+
InterfaceName.INSERT.getName(), TokenMode.ENABLE.toString()
313313
));
314314
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(),
315-
Utils.parameterizedString(ErrorMessage.NoTokensWithByot.getMessage(), Byot.ENABLE.toString())
315+
Utils.parameterizedString(ErrorMessage.NoTokensWithTokenMode.getMessage(), TokenMode.ENABLE.toString())
316316
);
317317
}
318-
validateTokensForInsertRequest(tokens, values, tokenStrict);
318+
validateTokensForInsertRequest(tokens, values, tokenMode);
319319
break;
320320
case ENABLE_STRICT:
321321
if (tokens == null) {
322322
LogUtil.printErrorLog(Utils.parameterizedString(
323-
ErrorLogs.TOKENS_REQUIRED_WITH_BYOT.getLog(),
324-
InterfaceName.INSERT.getName(), Byot.ENABLE_STRICT.toString()
323+
ErrorLogs.TOKENS_REQUIRED_WITH_TOKEN_MODE.getLog(),
324+
InterfaceName.INSERT.getName(), TokenMode.ENABLE_STRICT.toString()
325325
));
326326
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(),
327-
Utils.parameterizedString(ErrorMessage.NoTokensWithByot.getMessage(), Byot.ENABLE_STRICT.toString())
327+
Utils.parameterizedString(ErrorMessage.NoTokensWithTokenMode.getMessage(), TokenMode.ENABLE_STRICT.toString())
328328
);
329329
} else if (tokens.size() != values.size()) {
330330
LogUtil.printErrorLog(Utils.parameterizedString(
331-
ErrorLogs.INSUFFICIENT_TOKENS_PASSED_FOR_BYOT_ENABLE_STRICT.getLog(),
331+
ErrorLogs.INSUFFICIENT_TOKENS_PASSED_FOR_TOKEN_MODE_ENABLE_STRICT.getLog(),
332332
InterfaceName.INSERT.getName()
333333
));
334334
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(),
335-
ErrorMessage.InsufficientTokensPassedForByotEnableStrict.getMessage()
335+
ErrorMessage.InsufficientTokensPassedForTokenModeEnableStrict.getMessage()
336336
);
337337
}
338-
validateTokensForInsertRequest(tokens, values, tokenStrict);
338+
validateTokensForInsertRequest(tokens, values, tokenMode);
339339
break;
340340
}
341341
}
@@ -488,7 +488,7 @@ public static void validateUpdateRequest(UpdateRequest updateRequest) throws Sky
488488
String table = updateRequest.getTable();
489489
HashMap<String, Object> data = updateRequest.getData();
490490
HashMap<String, Object> tokens = updateRequest.getTokens();
491-
Byot tokenStrict = updateRequest.getTokenStrict();
491+
TokenMode tokenMode = updateRequest.getTokenMode();
492492

493493
if (table == null) {
494494
LogUtil.printErrorLog(Utils.parameterizedString(
@@ -550,42 +550,42 @@ public static void validateUpdateRequest(UpdateRequest updateRequest) throws Sky
550550
}
551551
}
552552

553-
switch (tokenStrict) {
553+
switch (tokenMode) {
554554
case DISABLE:
555555
if (tokens != null) {
556556
LogUtil.printErrorLog(Utils.parameterizedString(
557-
ErrorLogs.TOKENS_NOT_ALLOWED_WITH_BYOT_DISABLE.getLog(), InterfaceName.INSERT.getName()
557+
ErrorLogs.TOKENS_NOT_ALLOWED_WITH_TOKEN_MODE_DISABLE.getLog(), InterfaceName.UPDATE.getName()
558558
));
559559
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(),
560-
ErrorMessage.TokensPassedForByotDisable.getMessage());
560+
ErrorMessage.TokensPassedForTokenModeDisable.getMessage());
561561
}
562562
break;
563563
case ENABLE:
564564
if (tokens == null) {
565565
LogUtil.printErrorLog(Utils.parameterizedString(
566-
ErrorLogs.TOKENS_REQUIRED_WITH_BYOT.getLog(),
567-
InterfaceName.INSERT.getName(), Byot.ENABLE.toString()
566+
ErrorLogs.TOKENS_REQUIRED_WITH_TOKEN_MODE.getLog(),
567+
InterfaceName.UPDATE.getName(), TokenMode.ENABLE.toString()
568568
));
569569
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), Utils.parameterizedString(
570-
ErrorMessage.NoTokensWithByot.getMessage(), Byot.ENABLE.toString()));
570+
ErrorMessage.NoTokensWithTokenMode.getMessage(), TokenMode.ENABLE.toString()));
571571
}
572572
validateTokensMapWithTokenStrict(tokens, data);
573573
break;
574574
case ENABLE_STRICT:
575575
if (tokens == null) {
576576
LogUtil.printErrorLog(Utils.parameterizedString(
577-
ErrorLogs.TOKENS_REQUIRED_WITH_BYOT.getLog(),
578-
InterfaceName.INSERT.getName(), Byot.ENABLE_STRICT.toString()
577+
ErrorLogs.TOKENS_REQUIRED_WITH_TOKEN_MODE.getLog(),
578+
InterfaceName.UPDATE.getName(), TokenMode.ENABLE_STRICT.toString()
579579
));
580580
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), Utils.parameterizedString(
581-
ErrorMessage.NoTokensWithByot.getMessage(), Byot.ENABLE_STRICT.toString()));
581+
ErrorMessage.NoTokensWithTokenMode.getMessage(), TokenMode.ENABLE_STRICT.toString()));
582582
} else if (tokens.size() != (data.size() - 1)) {
583583
LogUtil.printErrorLog(Utils.parameterizedString(
584-
ErrorLogs.INSUFFICIENT_TOKENS_PASSED_FOR_BYOT_ENABLE_STRICT.getLog(),
585-
InterfaceName.INSERT.getName()
584+
ErrorLogs.INSUFFICIENT_TOKENS_PASSED_FOR_TOKEN_MODE_ENABLE_STRICT.getLog(),
585+
InterfaceName.UPDATE.getName()
586586
));
587587
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(),
588-
ErrorMessage.InsufficientTokensPassedForByotEnableStrict.getMessage());
588+
ErrorMessage.InsufficientTokensPassedForTokenModeEnableStrict.getMessage());
589589
}
590590
validateTokensMapWithTokenStrict(tokens, data);
591591
break;
@@ -692,7 +692,7 @@ private static boolean isInvalidURL(String configURL) {
692692
private static void validateTokensForInsertRequest(
693693
ArrayList<HashMap<String, Object>> tokens,
694694
ArrayList<HashMap<String, Object>> values,
695-
Byot tokenStrict
695+
TokenMode tokenStrict
696696
) throws SkyflowException {
697697
if (tokens.isEmpty()) {
698698
LogUtil.printErrorLog(Utils.parameterizedString(
@@ -704,39 +704,45 @@ private static void validateTokensForInsertRequest(
704704
for (int index = 0; index < tokens.size(); index++) {
705705
HashMap<String, Object> tokensMap = tokens.get(index);
706706
HashMap<String, Object> valuesMap = values.get(index);
707-
if (tokensMap.size() != valuesMap.size() && tokenStrict == Byot.ENABLE_STRICT) {
707+
if (tokensMap.size() != valuesMap.size() && tokenStrict == TokenMode.ENABLE_STRICT) {
708708
LogUtil.printErrorLog(Utils.parameterizedString(
709-
ErrorLogs.INSUFFICIENT_TOKENS_PASSED_FOR_BYOT_ENABLE_STRICT.getLog(),
709+
ErrorLogs.INSUFFICIENT_TOKENS_PASSED_FOR_TOKEN_MODE_ENABLE_STRICT.getLog(),
710710
InterfaceName.INSERT.getName()
711711
));
712712
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(),
713-
ErrorMessage.InsufficientTokensPassedForByotEnableStrict.getMessage()
713+
ErrorMessage.InsufficientTokensPassedForTokenModeEnableStrict.getMessage()
714714
);
715715
}
716-
validateTokensMapWithTokenStrict(tokensMap, valuesMap);
716+
validateTokensMapWithTokenStrict(tokensMap, valuesMap, InterfaceName.INSERT.getName());
717717
}
718718
}
719719

720720
private static void validateTokensMapWithTokenStrict(
721721
HashMap<String, Object> tokensMap, HashMap<String, Object> valuesMap
722+
) throws SkyflowException {
723+
validateTokensMapWithTokenStrict(tokensMap, valuesMap, InterfaceName.UPDATE.getName());
724+
}
725+
726+
private static void validateTokensMapWithTokenStrict(
727+
HashMap<String, Object> tokensMap, HashMap<String, Object> valuesMap, String interfaceName
722728
) throws SkyflowException {
723729
for (String key : tokensMap.keySet()) {
724730
if (key == null || key.trim().isEmpty()) {
725731
LogUtil.printErrorLog(Utils.parameterizedString(
726-
ErrorLogs.EMPTY_OR_NULL_KEY_IN_TOKENS.getLog(), InterfaceName.INSERT.getName()
732+
ErrorLogs.EMPTY_OR_NULL_KEY_IN_TOKENS.getLog(), interfaceName
727733
));
728734
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyKeyInTokens.getMessage());
729735
} else if (!valuesMap.containsKey(key)) {
730736
LogUtil.printErrorLog(Utils.parameterizedString(
731-
ErrorLogs.MISMATCH_OF_FIELDS_AND_TOKENS.getLog(), InterfaceName.INSERT.getName()
737+
ErrorLogs.MISMATCH_OF_FIELDS_AND_TOKENS.getLog(), interfaceName
732738
));
733739
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.MismatchOfFieldsAndTokens.getMessage());
734740
} else {
735741
Object value = tokensMap.get(key);
736742
if (value == null || value.toString().trim().isEmpty()) {
737743
LogUtil.printErrorLog(Utils.parameterizedString(
738744
ErrorLogs.EMPTY_OR_NULL_VALUE_IN_TOKENS.getLog(),
739-
InterfaceName.INSERT.getName(), key
745+
interfaceName, key
740746
));
741747
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyValueInTokens.getMessage());
742748
}

src/main/java/com/skyflow/vault/connection/InvokeConnectionRequest.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.skyflow.enums.RequestMethod;
44

5-
import java.util.HashMap;
65
import java.util.Map;
76

87
public class InvokeConnectionRequest {
@@ -17,8 +16,8 @@ public static InvokeConnectionRequestBuilder builder() {
1716
return new InvokeConnectionRequestBuilder();
1817
}
1918

20-
public RequestMethod getMethodName() {
21-
return builder.methodName;
19+
public RequestMethod getMethod() {
20+
return builder.method;
2221
}
2322

2423
public Map<String, String> getPathParams() {
@@ -38,19 +37,19 @@ public Object getRequestBody() {
3837
}
3938

4039
public static final class InvokeConnectionRequestBuilder {
41-
private RequestMethod methodName;
40+
private RequestMethod method;
4241
private Map<String, String> pathParams;
4342
private Map<String, String> queryParams;
4443
private Map<String, String> requestHeaders;
4544
private Object requestBody;
4645

4746
private InvokeConnectionRequestBuilder() {
48-
this.methodName = RequestMethod.POST;
47+
this.method = RequestMethod.POST;
4948
this.requestBody = new Object();
5049
}
5150

52-
public InvokeConnectionRequestBuilder methodName(RequestMethod methodName) {
53-
this.methodName = methodName == null ? RequestMethod.POST : methodName;
51+
public InvokeConnectionRequestBuilder method(RequestMethod method) {
52+
this.method = method == null ? RequestMethod.POST : method;
5453
return this;
5554
}
5655

src/main/java/com/skyflow/vault/controller/ConnectionController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public InvokeConnectionResponse invoke(InvokeConnectionRequest invokeConnectionR
4848
headers.put("x-skyflow-authorization", token == null ? apiKey : token);
4949
}
5050

51-
RequestMethod requestMethod = invokeConnectionRequest.getMethodName();
51+
RequestMethod requestMethod = invokeConnectionRequest.getMethod();
5252
JsonObject requestBody = null;
5353
Object requestBodyObject = invokeConnectionRequest.getRequestBody();
5454

0 commit comments

Comments
 (0)