|
2 | 2 |
|
3 | 3 | import java.util.ArrayList; |
4 | 4 | import java.util.List; |
| 5 | +import java.util.Map; |
5 | 6 |
|
6 | 7 | import com.skyflow.config.Credentials; |
7 | 8 | import com.skyflow.config.VaultConfig; |
| 9 | +import com.skyflow.enums.CustomHeaderKey; |
8 | 10 | import com.skyflow.enums.InterfaceName; |
9 | 11 | import com.skyflow.errors.ErrorCode; |
10 | 12 | import com.skyflow.errors.ErrorMessage; |
@@ -140,15 +142,15 @@ public static void validateDetokenizeRequest(DetokenizeRequest request) throws S |
140 | 142 | throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.DetokenizeRequestNull.getMessage()); |
141 | 143 | } |
142 | 144 | 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 | | - } |
147 | 145 | if (tokens == null || tokens.isEmpty()) { |
148 | 146 | LogUtil.printErrorLog(Utils.parameterizedString( |
149 | 147 | 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()); |
152 | 154 | } |
153 | 155 | for (int index = 0; index < tokens.size(); index++) { |
154 | 156 | String token = tokens.get(index); |
@@ -264,6 +266,25 @@ public static void validateTokenizeRequest(TokenizeRequest request) throws Skyfl |
264 | 266 | } |
265 | 267 | } |
266 | 268 |
|
| 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 | + |
267 | 288 | public static void validateVaultConfiguration(VaultConfig vaultConfig) throws SkyflowException { |
268 | 289 | String vaultId = vaultConfig.getVaultId(); |
269 | 290 | String clusterId = vaultConfig.getClusterId(); |
|
0 commit comments