Skip to content

Commit 0e42dcc

Browse files
SK-2824 add support for request id
1 parent 150a895 commit 0e42dcc

22 files changed

Lines changed: 2968 additions & 203 deletions

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ public enum ErrorMessage {
186186

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

191193
private final String message;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ public enum ErrorLogs {
162162
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."),
163163
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."),
164164
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."),
165-
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.");
165+
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."),
166+
NULL_CUSTOM_HEADER_KEY("Invalid %s1 request. Custom header key can not be null."),
167+
EMPTY_OR_NULL_VALUE_IN_CUSTOM_HEADERS("Invalid %s1 request. Custom header value can not be null or empty for key \"%s2\".");
166168
private final String log;
167169

168170
ErrorLogs(String log) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.skyflow.enums;
2+
3+
public enum CustomHeaderKey {
4+
SkyflowAccountID("x-skyflow-account-id"),
5+
SkyflowAccountName("x-skyflow-account-name"),
6+
RequestIDHeader("x-request-id");
7+
8+
private final String value;
9+
10+
CustomHeaderKey(String value) {
11+
this.value = value;
12+
}
13+
14+
@Override
15+
public String toString() {
16+
return this.value;
17+
}
18+
}

v3/src/main/java/com/skyflow/utils/Utils.java

Lines changed: 113 additions & 29 deletions
Large diffs are not rendered by default.

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

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

33
import java.util.ArrayList;
44
import java.util.List;
5+
import java.util.Map;
56

67
import com.skyflow.config.Credentials;
78
import com.skyflow.config.VaultConfig;
9+
import com.skyflow.enums.CustomHeaderKey;
810
import com.skyflow.enums.InterfaceName;
911
import com.skyflow.errors.ErrorCode;
1012
import com.skyflow.errors.ErrorMessage;
@@ -140,15 +142,15 @@ public static void validateDetokenizeRequest(DetokenizeRequest request) throws S
140142
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.DetokenizeRequestNull.getMessage());
141143
}
142144
List<String> tokens = request.getTokens();
143-
if (tokens.size() > 10000) {
144-
LogUtil.printErrorLog(ErrorLogs.TOKENS_SIZE_EXCEED.getLog());
145-
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.TokensSizeExceedError.getMessage());
146-
}
147145
if (tokens == null || tokens.isEmpty()) {
148146
LogUtil.printErrorLog(Utils.parameterizedString(
149147
ErrorLogs.EMPTY_DETOKENIZE_DATA.getLog(), InterfaceName.DETOKENIZE.getName()
150-
));
151-
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyDetokenizeData.getMessage());
148+
));
149+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyDetokenizeData.getMessage());
150+
}
151+
if (tokens.size() > 10000) {
152+
LogUtil.printErrorLog(ErrorLogs.TOKENS_SIZE_EXCEED.getLog());
153+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.TokensSizeExceedError.getMessage());
152154
}
153155
for (int index = 0; index < tokens.size(); index++) {
154156
String token = tokens.get(index);
@@ -264,6 +266,25 @@ public static void validateTokenizeRequest(TokenizeRequest request) throws Skyfl
264266
}
265267
}
266268

269+
public static void validateCustomHeaders(Map<CustomHeaderKey, String> customHeaders, InterfaceName interfaceName) throws SkyflowException {
270+
if (customHeaders == null || customHeaders.isEmpty()) return;
271+
for (Map.Entry<CustomHeaderKey, String> entry : customHeaders.entrySet()) {
272+
if (entry.getKey() == null) {
273+
LogUtil.printErrorLog(Utils.parameterizedString(
274+
ErrorLogs.NULL_CUSTOM_HEADER_KEY.getLog(), interfaceName.getName()
275+
));
276+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.NullCustomHeaderKey.getMessage());
277+
}
278+
String value = entry.getValue();
279+
if (value == null || value.trim().isEmpty()) {
280+
LogUtil.printErrorLog(Utils.parameterizedString(
281+
ErrorLogs.EMPTY_OR_NULL_VALUE_IN_CUSTOM_HEADERS.getLog(), interfaceName.getName(), entry.getKey().toString()
282+
));
283+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyValueInCustomHeaders.getMessage());
284+
}
285+
}
286+
}
287+
267288
public static void validateVaultConfiguration(VaultConfig vaultConfig) throws SkyflowException {
268289
String vaultId = vaultConfig.getVaultId();
269290
String clusterId = vaultConfig.getClusterId();

0 commit comments

Comments
 (0)