Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/java/com/skyflow/VaultClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
insertRecordBody.setTokenization(request.getReturnTokens());
insertRecordBody.setHomogeneous(request.getHomogeneous());
insertRecordBody.setUpsert(request.getUpsert());
insertRecordBody.setByot(request.getTokenStrict().getBYOT());
insertRecordBody.setByot(request.getTokenMode().getBYOT());

Check warning on line 100 in src/main/java/com/skyflow/VaultClient.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L100 was not covered by tests

List<HashMap<String, Object>> values = request.getValues();
List<HashMap<String, Object>> tokens = request.getTokens();
Expand All @@ -117,7 +117,7 @@
protected RecordServiceBatchOperationBody getBatchInsertRequestBody(InsertRequest request) {
RecordServiceBatchOperationBody insertRequestBody = new RecordServiceBatchOperationBody();
insertRequestBody.setContinueOnError(true);
insertRequestBody.setByot(request.getTokenStrict().getBYOT());
insertRequestBody.setByot(request.getTokenMode().getBYOT());

Check warning on line 120 in src/main/java/com/skyflow/VaultClient.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L120 was not covered by tests

ArrayList<HashMap<String, Object>> values = request.getValues();
ArrayList<HashMap<String, Object>> tokens = request.getTokens();
Expand All @@ -142,7 +142,7 @@

protected RecordServiceUpdateRecordBody getUpdateRequestBody(UpdateRequest request) {
RecordServiceUpdateRecordBody updateRequestBody = new RecordServiceUpdateRecordBody();
updateRequestBody.byot(request.getTokenStrict().getBYOT());
updateRequestBody.byot(request.getTokenMode().getBYOT());

Check warning on line 145 in src/main/java/com/skyflow/VaultClient.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L145 was not covered by tests
updateRequestBody.setTokenization(request.getReturnTokens());
HashMap<String, Object> values = request.getData();
HashMap<String, Object> tokens = request.getTokens();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

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

public enum Byot {
public enum TokenMode {
DISABLE(V1BYOT.DISABLE),
ENABLE(V1BYOT.ENABLE),
ENABLE_STRICT(V1BYOT.ENABLE_STRICT);

private final V1BYOT byot;

Byot(V1BYOT byot) {
TokenMode(V1BYOT byot) {
this.byot = byot;
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/skyflow/errors/ErrorMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ public enum ErrorMessage {
EmptyValueInTokens("%s0 Validation error. Invalid value in tokens. Specify a valid value."),
EmptyUpsert("%s0 Validation error. 'upsert' key can't be empty. Specify an upsert column."),
HomogenousNotSupportedWithUpsert("%s0 Validation error. 'homogenous' is not supported with 'upsert'. Specify either 'homogenous' or 'upsert'."),
TokensPassedForByotDisable("%s0 Validation error. 'tokenStrict' wasn't specified. Set 'tokenStrict' to 'ENABLE' to insert tokens."),
NoTokensWithByot("%s0 Validation error. Tokens weren't specified for records while 'tokenStrict' was %s1. Specify tokens."),
TokensPassedForTokenModeDisable("%s0 Validation error. 'tokenMode' wasn't specified. Set 'tokenMode' to 'ENABLE' to insert tokens."),
NoTokensWithTokenMode("%s0 Validation error. Tokens weren't specified for records while 'tokenMode' was %s1. Specify tokens."),
MismatchOfFieldsAndTokens("%s0 Validation error. 'fields' and 'tokens' have different columns names. Verify that 'fields' and 'tokens' columns match."),
InsufficientTokensPassedForByotEnableStrict("%s0 Validation error. 'tokenStrict' is set to 'ENABLE_STRICT', but some fields are missing tokens. Specify tokens for all fields."),
InsufficientTokensPassedForTokenModeEnableStrict("%s0 Validation error. 'tokenMode' is set to 'ENABLE_STRICT', but some fields are missing tokens. Specify tokens for all fields."),
BatchInsertPartialSuccess("%s0 Insert operation completed with partial success."),
BatchInsertFailure("%s0 Insert operation failed."),

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/skyflow/logs/ErrorLogs.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ public enum ErrorLogs {
EMPTY_OR_NULL_KEY_IN_VALUES("Invalid %s1 request. Key can not be null or empty in values"),
EMPTY_UPSERT("Invalid %s1 request. Upsert can not be empty."),
HOMOGENOUS_NOT_SUPPORTED_WITH_UPSERT("Invalid %s1 request. Homogenous is not supported when upsert is passed."),
TOKENS_NOT_ALLOWED_WITH_BYOT_DISABLE("Invalid %s1 request. Tokens are not allowed when tokenStrict is DISABLE."),
TOKENS_REQUIRED_WITH_BYOT("Invalid %s1 request. Tokens are required when tokenStrict is %s2."),
TOKENS_NOT_ALLOWED_WITH_TOKEN_MODE_DISABLE("Invalid %s1 request. Tokens are not allowed when tokenMode is DISABLE."),
TOKENS_REQUIRED_WITH_TOKEN_MODE("Invalid %s1 request. Tokens are required when tokenMode is %s2."),
EMPTY_TOKENS("Invalid %s1 request. Tokens can not be empty."),
EMPTY_OR_NULL_VALUE_IN_TOKENS("Invalid %s1 request. Value can not be null or empty in tokens for key \"%s2\"."),
EMPTY_OR_NULL_KEY_IN_TOKENS("Invalid %s1 request. Key can not be null or empty in tokens."),
INSUFFICIENT_TOKENS_PASSED_FOR_BYOT_ENABLE_STRICT("Invalid %s1 request. For tokenStrict as ENABLE_STRICT, tokens should be passed for all fields."),
INSUFFICIENT_TOKENS_PASSED_FOR_TOKEN_MODE_ENABLE_STRICT("Invalid %s1 request. For tokenMode as ENABLE_STRICT, tokens should be passed for all fields."),
MISMATCH_OF_FIELDS_AND_TOKENS("Invalid %s1 request. Keys for values and tokens are not matching."),
INSERT_RECORDS_REJECTED("Insert request resulted in failure."),
TOKENS_REQUIRED("Invalid %s1 request. Tokens are required."),
Expand Down
78 changes: 42 additions & 36 deletions src/main/java/com/skyflow/utils/validations/Validations.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import com.skyflow.config.ConnectionConfig;
import com.skyflow.config.Credentials;
import com.skyflow.config.VaultConfig;
import com.skyflow.enums.Byot;
import com.skyflow.enums.InterfaceName;
import com.skyflow.enums.RedactionType;
import com.skyflow.enums.TokenMode;
import com.skyflow.errors.ErrorCode;
import com.skyflow.errors.ErrorMessage;
import com.skyflow.errors.SkyflowException;
Expand Down Expand Up @@ -238,7 +238,7 @@
ArrayList<HashMap<String, Object>> tokens = insertRequest.getTokens();
String upsert = insertRequest.getUpsert();
Boolean homogeneous = insertRequest.getHomogeneous();
Byot tokenStrict = insertRequest.getTokenStrict();
TokenMode tokenMode = insertRequest.getTokenMode();

if (table == null) {
LogUtil.printErrorLog(Utils.parameterizedString(
Expand Down Expand Up @@ -296,46 +296,46 @@
}
}

switch (tokenStrict) {
switch (tokenMode) {
case DISABLE:
if (tokens != null) {
LogUtil.printErrorLog(Utils.parameterizedString(
ErrorLogs.TOKENS_NOT_ALLOWED_WITH_BYOT_DISABLE.getLog(), InterfaceName.INSERT.getName()
ErrorLogs.TOKENS_NOT_ALLOWED_WITH_TOKEN_MODE_DISABLE.getLog(), InterfaceName.INSERT.getName()
));
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.TokensPassedForByotDisable.getMessage());
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.TokensPassedForTokenModeDisable.getMessage());
}
break;
case ENABLE:
if (tokens == null) {
LogUtil.printErrorLog(Utils.parameterizedString(
ErrorLogs.TOKENS_REQUIRED_WITH_BYOT.getLog(),
InterfaceName.INSERT.getName(), Byot.ENABLE.toString()
ErrorLogs.TOKENS_REQUIRED_WITH_TOKEN_MODE.getLog(),
InterfaceName.INSERT.getName(), TokenMode.ENABLE.toString()
));
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(),
Utils.parameterizedString(ErrorMessage.NoTokensWithByot.getMessage(), Byot.ENABLE.toString())
Utils.parameterizedString(ErrorMessage.NoTokensWithTokenMode.getMessage(), TokenMode.ENABLE.toString())
);
}
validateTokensForInsertRequest(tokens, values, tokenStrict);
validateTokensForInsertRequest(tokens, values, tokenMode);
break;
case ENABLE_STRICT:
if (tokens == null) {
LogUtil.printErrorLog(Utils.parameterizedString(
ErrorLogs.TOKENS_REQUIRED_WITH_BYOT.getLog(),
InterfaceName.INSERT.getName(), Byot.ENABLE_STRICT.toString()
ErrorLogs.TOKENS_REQUIRED_WITH_TOKEN_MODE.getLog(),
InterfaceName.INSERT.getName(), TokenMode.ENABLE_STRICT.toString()
));
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(),
Utils.parameterizedString(ErrorMessage.NoTokensWithByot.getMessage(), Byot.ENABLE_STRICT.toString())
Utils.parameterizedString(ErrorMessage.NoTokensWithTokenMode.getMessage(), TokenMode.ENABLE_STRICT.toString())
);
} else if (tokens.size() != values.size()) {
LogUtil.printErrorLog(Utils.parameterizedString(
ErrorLogs.INSUFFICIENT_TOKENS_PASSED_FOR_BYOT_ENABLE_STRICT.getLog(),
ErrorLogs.INSUFFICIENT_TOKENS_PASSED_FOR_TOKEN_MODE_ENABLE_STRICT.getLog(),
InterfaceName.INSERT.getName()
));
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(),
ErrorMessage.InsufficientTokensPassedForByotEnableStrict.getMessage()
ErrorMessage.InsufficientTokensPassedForTokenModeEnableStrict.getMessage()
);
}
validateTokensForInsertRequest(tokens, values, tokenStrict);
validateTokensForInsertRequest(tokens, values, tokenMode);

Check warning on line 338 in src/main/java/com/skyflow/utils/validations/Validations.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L338 was not covered by tests
break;
}
}
Expand Down Expand Up @@ -488,7 +488,7 @@
String table = updateRequest.getTable();
HashMap<String, Object> data = updateRequest.getData();
HashMap<String, Object> tokens = updateRequest.getTokens();
Byot tokenStrict = updateRequest.getTokenStrict();
TokenMode tokenMode = updateRequest.getTokenMode();

if (table == null) {
LogUtil.printErrorLog(Utils.parameterizedString(
Expand Down Expand Up @@ -550,42 +550,42 @@
}
}

switch (tokenStrict) {
switch (tokenMode) {
case DISABLE:
if (tokens != null) {
LogUtil.printErrorLog(Utils.parameterizedString(
ErrorLogs.TOKENS_NOT_ALLOWED_WITH_BYOT_DISABLE.getLog(), InterfaceName.INSERT.getName()
ErrorLogs.TOKENS_NOT_ALLOWED_WITH_TOKEN_MODE_DISABLE.getLog(), InterfaceName.UPDATE.getName()
));
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(),
ErrorMessage.TokensPassedForByotDisable.getMessage());
ErrorMessage.TokensPassedForTokenModeDisable.getMessage());
}
break;
case ENABLE:
if (tokens == null) {
LogUtil.printErrorLog(Utils.parameterizedString(
ErrorLogs.TOKENS_REQUIRED_WITH_BYOT.getLog(),
InterfaceName.INSERT.getName(), Byot.ENABLE.toString()
ErrorLogs.TOKENS_REQUIRED_WITH_TOKEN_MODE.getLog(),
InterfaceName.UPDATE.getName(), TokenMode.ENABLE.toString()
));
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), Utils.parameterizedString(
ErrorMessage.NoTokensWithByot.getMessage(), Byot.ENABLE.toString()));
ErrorMessage.NoTokensWithTokenMode.getMessage(), TokenMode.ENABLE.toString()));
}
validateTokensMapWithTokenStrict(tokens, data);
break;
case ENABLE_STRICT:
if (tokens == null) {
LogUtil.printErrorLog(Utils.parameterizedString(
ErrorLogs.TOKENS_REQUIRED_WITH_BYOT.getLog(),
InterfaceName.INSERT.getName(), Byot.ENABLE_STRICT.toString()
ErrorLogs.TOKENS_REQUIRED_WITH_TOKEN_MODE.getLog(),
InterfaceName.UPDATE.getName(), TokenMode.ENABLE_STRICT.toString()
));
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), Utils.parameterizedString(
ErrorMessage.NoTokensWithByot.getMessage(), Byot.ENABLE_STRICT.toString()));
ErrorMessage.NoTokensWithTokenMode.getMessage(), TokenMode.ENABLE_STRICT.toString()));
} else if (tokens.size() != (data.size() - 1)) {
LogUtil.printErrorLog(Utils.parameterizedString(
ErrorLogs.INSUFFICIENT_TOKENS_PASSED_FOR_BYOT_ENABLE_STRICT.getLog(),
InterfaceName.INSERT.getName()
ErrorLogs.INSUFFICIENT_TOKENS_PASSED_FOR_TOKEN_MODE_ENABLE_STRICT.getLog(),
InterfaceName.UPDATE.getName()
));
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(),
ErrorMessage.InsufficientTokensPassedForByotEnableStrict.getMessage());
ErrorMessage.InsufficientTokensPassedForTokenModeEnableStrict.getMessage());
}
validateTokensMapWithTokenStrict(tokens, data);
break;
Expand Down Expand Up @@ -692,7 +692,7 @@
private static void validateTokensForInsertRequest(
ArrayList<HashMap<String, Object>> tokens,
ArrayList<HashMap<String, Object>> values,
Byot tokenStrict
TokenMode tokenStrict
) throws SkyflowException {
if (tokens.isEmpty()) {
LogUtil.printErrorLog(Utils.parameterizedString(
Expand All @@ -704,39 +704,45 @@
for (int index = 0; index < tokens.size(); index++) {
HashMap<String, Object> tokensMap = tokens.get(index);
HashMap<String, Object> valuesMap = values.get(index);
if (tokensMap.size() != valuesMap.size() && tokenStrict == Byot.ENABLE_STRICT) {
if (tokensMap.size() != valuesMap.size() && tokenStrict == TokenMode.ENABLE_STRICT) {
LogUtil.printErrorLog(Utils.parameterizedString(
ErrorLogs.INSUFFICIENT_TOKENS_PASSED_FOR_BYOT_ENABLE_STRICT.getLog(),
ErrorLogs.INSUFFICIENT_TOKENS_PASSED_FOR_TOKEN_MODE_ENABLE_STRICT.getLog(),
InterfaceName.INSERT.getName()
));
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(),
ErrorMessage.InsufficientTokensPassedForByotEnableStrict.getMessage()
ErrorMessage.InsufficientTokensPassedForTokenModeEnableStrict.getMessage()
);
}
validateTokensMapWithTokenStrict(tokensMap, valuesMap);
validateTokensMapWithTokenStrict(tokensMap, valuesMap, InterfaceName.INSERT.getName());
}
}

private static void validateTokensMapWithTokenStrict(
HashMap<String, Object> tokensMap, HashMap<String, Object> valuesMap
) throws SkyflowException {
validateTokensMapWithTokenStrict(tokensMap, valuesMap, InterfaceName.UPDATE.getName());
}

private static void validateTokensMapWithTokenStrict(
HashMap<String, Object> tokensMap, HashMap<String, Object> valuesMap, String interfaceName
) throws SkyflowException {
for (String key : tokensMap.keySet()) {
if (key == null || key.trim().isEmpty()) {
LogUtil.printErrorLog(Utils.parameterizedString(
ErrorLogs.EMPTY_OR_NULL_KEY_IN_TOKENS.getLog(), InterfaceName.INSERT.getName()
ErrorLogs.EMPTY_OR_NULL_KEY_IN_TOKENS.getLog(), interfaceName
));
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyKeyInTokens.getMessage());
} else if (!valuesMap.containsKey(key)) {
LogUtil.printErrorLog(Utils.parameterizedString(
ErrorLogs.MISMATCH_OF_FIELDS_AND_TOKENS.getLog(), InterfaceName.INSERT.getName()
ErrorLogs.MISMATCH_OF_FIELDS_AND_TOKENS.getLog(), interfaceName
));
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.MismatchOfFieldsAndTokens.getMessage());
} else {
Object value = tokensMap.get(key);
if (value == null || value.toString().trim().isEmpty()) {
LogUtil.printErrorLog(Utils.parameterizedString(
ErrorLogs.EMPTY_OR_NULL_VALUE_IN_TOKENS.getLog(),
InterfaceName.INSERT.getName(), key
interfaceName, key
));
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyValueInTokens.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.skyflow.enums.RequestMethod;

import java.util.HashMap;
import java.util.Map;

public class InvokeConnectionRequest {
Expand All @@ -17,8 +16,8 @@ public static InvokeConnectionRequestBuilder builder() {
return new InvokeConnectionRequestBuilder();
}

public RequestMethod getMethodName() {
return builder.methodName;
public RequestMethod getMethod() {
return builder.method;
}

public Map<String, String> getPathParams() {
Expand All @@ -38,19 +37,19 @@ public Object getRequestBody() {
}

public static final class InvokeConnectionRequestBuilder {
private RequestMethod methodName;
private RequestMethod method;
private Map<String, String> pathParams;
private Map<String, String> queryParams;
private Map<String, String> requestHeaders;
private Object requestBody;

private InvokeConnectionRequestBuilder() {
this.methodName = RequestMethod.POST;
this.method = RequestMethod.POST;
this.requestBody = new Object();
}

public InvokeConnectionRequestBuilder methodName(RequestMethod methodName) {
this.methodName = methodName == null ? RequestMethod.POST : methodName;
public InvokeConnectionRequestBuilder method(RequestMethod method) {
this.method = method == null ? RequestMethod.POST : method;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
headers.put("x-skyflow-authorization", token == null ? apiKey : token);
}

RequestMethod requestMethod = invokeConnectionRequest.getMethodName();
RequestMethod requestMethod = invokeConnectionRequest.getMethod();

Check warning on line 51 in src/main/java/com/skyflow/vault/controller/ConnectionController.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L51 was not covered by tests
JsonObject requestBody = null;
Object requestBodyObject = invokeConnectionRequest.getRequestBody();

Expand Down
Loading
Loading