Skip to content
Open
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
2 changes: 2 additions & 0 deletions common/src/main/java/com/skyflow/errors/ErrorMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ public enum ErrorMessage {

NullTokenGroupNameInTokenGroup("%s0 Validation error. TokenGroupName in TokenGroupRedactions is null or empty. Specify a valid tokenGroupName."),
InvalidRecord("%s0 Validation error. InsertRecord object in the list is invalid. Specify a valid InsertRecord object."),
NullCustomHeaderKey("%s0 Validation error. Custom header key must not be null. Specify a valid custom header key."),
EmptyValueInCustomHeaders("%s0 Validation error. Custom header value must not be null or empty. Specify a valid value."),
;

private final String message;
Expand Down
4 changes: 3 additions & 1 deletion common/src/main/java/com/skyflow/logs/ErrorLogs.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ public enum ErrorLogs {
TABLE_SPECIFIED_AT_BOTH_PLACE("Invalid %s1 request. Table name cannot be specified at both the request and record levels. Please specify the table name at only one place."),
TABLE_NOT_SPECIFIED_AT_BOTH_PLACE("Invalid %s1 request. Table name is missing. Table name should be specified at one place either at the request level or record level. Please specify the table name at one place."),
UPSERT_TABLE_REQUEST_AT_RECORD_LEVEL("Invalid %s1 request. Table name should be present at each record level when upsert is present at record level."),
UPSERT_TABLE_REQUEST_AT_REQUEST_LEVEL("Invalid %s1 request. Upsert should be present at each record level when table name is present at record level.");
UPSERT_TABLE_REQUEST_AT_REQUEST_LEVEL("Invalid %s1 request. Upsert should be present at each record level when table name is present at record level."),
NULL_CUSTOM_HEADER_KEY("Invalid %s1 request. Custom header key can not be null."),
EMPTY_OR_NULL_VALUE_IN_CUSTOM_HEADERS("Invalid %s1 request. Custom header value can not be null or empty for key \"%s2\".");
private final String log;

ErrorLogs(String log) {
Expand Down
18 changes: 18 additions & 0 deletions v3/src/main/java/com/skyflow/enums/CustomHeaderKey.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.skyflow.enums;

public enum CustomHeaderKey {
SkyflowAccountID("x-skyflow-account-id"),
SkyflowAccountName("x-skyflow-account-name"),
RequestIDHeader("x-request-id");

private final String value;

CustomHeaderKey(String value) {
this.value = value;
}

@Override
public String toString() {
return this.value;
}
}
142 changes: 113 additions & 29 deletions v3/src/main/java/com/skyflow/utils/Utils.java

Large diffs are not rendered by default.

33 changes: 27 additions & 6 deletions v3/src/main/java/com/skyflow/utils/validations/Validations.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.skyflow.config.Credentials;
import com.skyflow.config.VaultConfig;
import com.skyflow.enums.CustomHeaderKey;
import com.skyflow.enums.InterfaceName;
import com.skyflow.errors.ErrorCode;
import com.skyflow.errors.ErrorMessage;
Expand Down Expand Up @@ -140,15 +142,15 @@ public static void validateDetokenizeRequest(DetokenizeRequest request) throws S
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.DetokenizeRequestNull.getMessage());
}
List<String> tokens = request.getTokens();
if (tokens.size() > 10000) {
LogUtil.printErrorLog(ErrorLogs.TOKENS_SIZE_EXCEED.getLog());
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.TokensSizeExceedError.getMessage());
}
if (tokens == null || tokens.isEmpty()) {
LogUtil.printErrorLog(Utils.parameterizedString(
ErrorLogs.EMPTY_DETOKENIZE_DATA.getLog(), InterfaceName.DETOKENIZE.getName()
));
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyDetokenizeData.getMessage());
));
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyDetokenizeData.getMessage());
}
if (tokens.size() > 10000) {
LogUtil.printErrorLog(ErrorLogs.TOKENS_SIZE_EXCEED.getLog());
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.TokensSizeExceedError.getMessage());
}
for (int index = 0; index < tokens.size(); index++) {
String token = tokens.get(index);
Expand Down Expand Up @@ -264,6 +266,25 @@ public static void validateTokenizeRequest(TokenizeRequest request) throws Skyfl
}
}

public static void validateCustomHeaders(Map<CustomHeaderKey, String> customHeaders, InterfaceName interfaceName) throws SkyflowException {
if (customHeaders == null || customHeaders.isEmpty()) return;
for (Map.Entry<CustomHeaderKey, String> entry : customHeaders.entrySet()) {
if (entry.getKey() == null) {
LogUtil.printErrorLog(Utils.parameterizedString(
ErrorLogs.NULL_CUSTOM_HEADER_KEY.getLog(), interfaceName.getName()
));
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.NullCustomHeaderKey.getMessage());
}
String value = entry.getValue();
if (value == null || value.trim().isEmpty()) {
LogUtil.printErrorLog(Utils.parameterizedString(
ErrorLogs.EMPTY_OR_NULL_VALUE_IN_CUSTOM_HEADERS.getLog(), interfaceName.getName(), entry.getKey().toString()
));
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyValueInCustomHeaders.getMessage());
}
}
}

public static void validateVaultConfiguration(VaultConfig vaultConfig) throws SkyflowException {
String vaultId = vaultConfig.getVaultId();
String clusterId = vaultConfig.getClusterId();
Expand Down
Loading
Loading