Skip to content

Commit b03c677

Browse files
SK-2286 V3 release/25.9.3 (#224)
* SK-2286 take vault url from env and override (#223) * SK-2286 take vault url from env and override * SK-2286 add validation for vault url format * SK-2286 add validation for vault url format * [AUTOMATED] Private Release 2.0.0-beta.4-dev-b64524d * SK-2286 throw skyflow exception for empty vault url * SK-2286 add error logs for vault url validations * SK-2286 add error logs for vault url validations * [AUTOMATED] Private Release 2.0.0-beta.4-dev-f012079 --------- Co-authored-by: skyflow-shravan <skyflow-shravan@users.noreply.github.com>
1 parent bb87aa9 commit b03c677

File tree

10 files changed

+81
-7
lines changed

10 files changed

+81
-7
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public enum ErrorMessage {
1616
EmptyVaultId("%s0 Initialization failed. Invalid vault ID. Vault ID must not be empty."),
1717
InvalidClusterId("%s0 Initialization failed. Invalid cluster ID. Specify cluster ID."),
1818
EmptyClusterId("%s0 Initialization failed. Invalid cluster ID. Specify a valid cluster ID."),
19+
EmptyVaultUrl("%s0 Initialization failed. Vault URL is empty. Specify a valid vault URL."),
20+
InvalidVaultUrlFormat("%s0 Initialization failed. Vault URL must start with 'https://'."),
1921

2022
// Connection config
2123
InvalidConnectionId("%s0 Initialization failed. Invalid connection ID. Specify a valid connection ID."),
@@ -73,11 +75,13 @@ public enum ErrorMessage {
7375
InsufficientTokensPassedForTokenModeEnableStrict("%s0 Validation error. 'tokenMode' is set to 'ENABLE_STRICT', but some fields are missing tokens. Specify tokens for all fields."),
7476
BatchInsertPartialSuccess("%s0 Insert operation completed with partial success."),
7577
BatchInsertFailure("%s0 Insert operation failed."),
78+
RecordSizeExceedError("%s0 Maximum number of records exceeded. The limit is 10000."),
7679

7780
// Detokenize
7881
InvalidDetokenizeData("%s0 Validation error. Invalid detokenize data. Specify valid detokenize data."),
7982
EmptyDetokenizeData("%s0 Validation error. Invalid data tokens. Specify at least one data token."),
8083
EmptyTokenInDetokenizeData("%s0 Validation error. Invalid data tokens. Specify a valid data token."),
84+
TokensSizeExceedError("%s0 Maximum number of tokens exceeded. The limit is 10000."),
8185

8286
// Get
8387
IdsKeyError("%s0 Validation error. 'ids' key is missing from the payload. Specify an 'ids' key."),

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public enum ErrorLogs {
2525
EMPTY_ROLES("Invalid credentials. Roles can not be empty."),
2626
EMPTY_OR_NULL_ROLE_IN_ROLES("Invalid credentials. Role can not be null or empty in roles at index %s1."),
2727
EMPTY_OR_NULL_CONTEXT("Invalid credentials. Context can not be empty."),
28+
EMPTY_VAULT_URL("Invalid vault config. Vault URL can not be empty."),
29+
INVALID_VAULT_URL_FORMAT("Invalid vault config. Vault URL format is incorrect"),
2830

2931
// Bearer token generation
3032
INVALID_BEARER_TOKEN("Bearer token is invalid or expired."),
@@ -49,6 +51,8 @@ public enum ErrorLogs {
4951
EMPTY_TABLE_NAME("Invalid %s1 request. Table name can not be empty."),
5052
VALUES_IS_REQUIRED("Invalid %s1 request. Values are required."),
5153
EMPTY_VALUES("Invalid %s1 request. Values can not be empty."),
54+
RECORD_SIZE_EXCEED("Maximum number of records exceeded. The limit is 10000."),
55+
TOKENS_SIZE_EXCEED("Maximum number of tokens exceeded. The limit is 10000."),
5256
EMPTY_OR_NULL_VALUE_IN_VALUES("Invalid %s1 request. Value can not be null or empty in values for key \"%s2\"."),
5357
EMPTY_OR_NULL_KEY_IN_VALUES("Invalid %s1 request. Key can not be null or empty in values"),
5458
EMPTY_UPSERT("Invalid %s1 request. Upsert can not be empty."),

common/src/main/java/com/skyflow/utils/BaseUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import com.skyflow.serviceaccount.util.BearerToken;
1212
import com.skyflow.serviceaccount.util.Token;
1313
import com.skyflow.utils.logger.LogUtil;
14+
import io.github.cdimascio.dotenv.Dotenv;
15+
import io.github.cdimascio.dotenv.DotenvException;
1416
import org.apache.commons.codec.binary.Base64;
1517

1618
import java.io.File;
@@ -43,6 +45,7 @@ public static String getVaultURL(String clusterId, Env env, String vaultDomain)
4345
return sb.toString();
4446
}
4547

48+
4649
public static String generateBearerToken(Credentials credentials) throws SkyflowException {
4750
String bearerToken;
4851
if (credentials.getPath() != null) {

common/src/main/java/com/skyflow/utils/validations/BaseValidations.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ public static void validateVaultConfig(VaultConfig vaultConfig) throws SkyflowEx
3434
} else if (clusterId.trim().isEmpty()) {
3535
LogUtil.printErrorLog(ErrorLogs.EMPTY_CLUSTER_ID.getLog());
3636
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyClusterId.getMessage());
37-
} else if (credentials != null) {
37+
}
38+
else if (credentials != null) {
3839
validateCredentials(credentials);
3940
}
4041
}

v3/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</parent>
1212

1313
<artifactId>skyflow-java</artifactId>
14-
<version>3.0.0-beta.3</version>
14+
<version>2.0.0-beta.4-dev.f012079</version>
1515
<packaging>jar</packaging>
1616
<name>${project.groupId}:${project.artifactId}</name>
1717
<description>Skyflow V3 SDK for the Java programming language</description>

v3/src/main/java/com/skyflow/Skyflow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public SkyflowClientBuilder() {
5656

5757
public SkyflowClientBuilder addVaultConfig(VaultConfig vaultConfig) throws SkyflowException {
5858
LogUtil.printInfoLog(InfoLogs.VALIDATING_VAULT_CONFIG.getLog());
59-
Validations.validateVaultConfig(vaultConfig);
59+
Validations.validateVaultConfiguration(vaultConfig);
6060
VaultConfig vaultConfigCopy;
6161
try {
6262
vaultConfigCopy = (VaultConfig) vaultConfig.clone();

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class VaultClient {
3939
private String token;
4040
private String apiKey;
4141

42-
protected VaultClient(VaultConfig vaultConfig, Credentials credentials) {
42+
protected VaultClient(VaultConfig vaultConfig, Credentials credentials) throws SkyflowException {
4343
super();
4444
this.vaultConfig = vaultConfig;
4545
this.commonCredentials = credentials;
@@ -79,8 +79,11 @@ protected void setBearerToken() throws SkyflowException {
7979
this.apiClient = this.apiClientBuilder.build();
8080
}
8181

82-
private void updateVaultURL() {
83-
String vaultURL = Utils.getVaultURL(this.vaultConfig.getClusterId(), this.vaultConfig.getEnv());
82+
private void updateVaultURL() throws SkyflowException {
83+
String vaultURL = Utils.getEnvVaultURL();
84+
if (vaultURL == null || vaultURL.isEmpty()) {
85+
vaultURL = Utils.getVaultURL(this.vaultConfig.getClusterId(), this.vaultConfig.getEnv());
86+
}
8487
this.apiClientBuilder.url(vaultURL);
8588
}
8689

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,23 @@
22

33
import com.google.gson.JsonObject;
44
import com.skyflow.enums.Env;
5+
import com.skyflow.errors.ErrorCode;
6+
import com.skyflow.errors.ErrorMessage;
7+
import com.skyflow.errors.SkyflowException;
58
import com.skyflow.generated.rest.core.ApiClientApiException;
69
import com.skyflow.generated.rest.resources.recordservice.requests.DetokenizeRequest;
710
import com.skyflow.generated.rest.types.InsertRecordData;
811
import com.skyflow.generated.rest.types.InsertResponse;
912
import com.skyflow.generated.rest.types.RecordResponseObject;
1013
import com.skyflow.generated.rest.types.TokenGroupRedactions;
14+
import com.skyflow.logs.ErrorLogs;
15+
import com.skyflow.utils.logger.LogUtil;
1116
import com.skyflow.vault.data.DetokenizeResponse;
1217
import com.skyflow.vault.data.ErrorRecord;
1318
import com.skyflow.vault.data.Success;
1419
import com.skyflow.vault.data.Token;
20+
import io.github.cdimascio.dotenv.Dotenv;
21+
import io.github.cdimascio.dotenv.DotenvException;
1522

1623
import java.util.ArrayList;
1724
import java.util.HashMap;
@@ -239,4 +246,24 @@ public static com.skyflow.vault.data.InsertResponse formatResponse(InsertRespons
239246
return formattedResponse;
240247
}
241248

249+
public static String getEnvVaultURL() throws SkyflowException {
250+
try {
251+
String vaultURL = System.getenv("VAULT_URL");
252+
if (vaultURL == null) {
253+
Dotenv dotenv = Dotenv.load();
254+
vaultURL = dotenv.get("VAULT_URL");
255+
}
256+
if (vaultURL != null && vaultURL.trim().isEmpty()) {
257+
LogUtil.printErrorLog(ErrorLogs.EMPTY_VAULT_URL.getLog());
258+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyVaultUrl.getMessage());
259+
} else if (vaultURL != null && !vaultURL.startsWith(BaseConstants.SECURE_PROTOCOL)) {
260+
LogUtil.printErrorLog(ErrorLogs.INVALID_VAULT_URL_FORMAT.getLog());
261+
throw new SkyflowException( ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.InvalidVaultUrlFormat.getMessage());
262+
}
263+
return vaultURL;
264+
} catch (DotenvException e) {
265+
return null;
266+
}
267+
}
268+
242269
}

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package com.skyflow.utils.validations;
22

3+
import com.skyflow.config.Credentials;
4+
import com.skyflow.config.VaultConfig;
35
import com.skyflow.enums.InterfaceName;
46
import com.skyflow.errors.ErrorCode;
57
import com.skyflow.errors.ErrorMessage;
68
import com.skyflow.errors.SkyflowException;
79
import com.skyflow.logs.ErrorLogs;
10+
import com.skyflow.utils.BaseUtils;
811
import com.skyflow.utils.Utils;
912
import com.skyflow.utils.logger.LogUtil;
1013
import com.skyflow.vault.data.DetokenizeRequest;
@@ -46,6 +49,9 @@ public static void validateInsertRequest(InsertRequest insertRequest) throws Sky
4649
ErrorLogs.EMPTY_VALUES.getLog(), InterfaceName.INSERT.getName()
4750
));
4851
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyValues.getMessage());
52+
} else if(values.size() > 10000) {
53+
LogUtil.printErrorLog(ErrorLogs.RECORD_SIZE_EXCEED.getLog());
54+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.RecordSizeExceedError.getMessage());
4955
} else if (upsert != null && upsert.isEmpty()){
5056
LogUtil.printErrorLog(Utils.parameterizedString(
5157
ErrorLogs.EMPTY_UPSERT.getLog(), InterfaceName.INSERT.getName()
@@ -82,6 +88,10 @@ public static void validateDetokenizeRequest(DetokenizeRequest request) throws S
8288
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.DetokenizeRequestNull.getMessage());
8389
}
8490
List<String> tokens = request.getTokens();
91+
if(tokens.size() > 10000) {
92+
LogUtil.printErrorLog(ErrorLogs.TOKENS_SIZE_EXCEED.getLog());
93+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.TokensSizeExceedError.getMessage());
94+
}
8595
if (tokens == null || tokens.isEmpty()) {
8696
LogUtil.printErrorLog(Utils.parameterizedString(
8797
ErrorLogs.EMPTY_DETOKENIZE_DATA.getLog(), InterfaceName.DETOKENIZE.getName()
@@ -118,4 +128,26 @@ public static void validateDetokenizeRequest(DetokenizeRequest request) throws S
118128

119129
}
120130

131+
public static void validateVaultConfiguration(VaultConfig vaultConfig) throws SkyflowException {
132+
String vaultId = vaultConfig.getVaultId();
133+
String clusterId = vaultConfig.getClusterId();
134+
Credentials credentials = vaultConfig.getCredentials();
135+
if (vaultId == null) {
136+
LogUtil.printErrorLog(ErrorLogs.VAULT_ID_IS_REQUIRED.getLog());
137+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.InvalidVaultId.getMessage());
138+
} else if (vaultId.trim().isEmpty()) {
139+
LogUtil.printErrorLog(ErrorLogs.EMPTY_VAULT_ID.getLog());
140+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyVaultId.getMessage());
141+
} else if (Utils.getEnvVaultURL() == null) {
142+
if (clusterId == null) {
143+
LogUtil.printErrorLog(ErrorLogs.CLUSTER_ID_IS_REQUIRED.getLog());
144+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.InvalidClusterId.getMessage());
145+
} else if (clusterId.trim().isEmpty()) {
146+
LogUtil.printErrorLog(ErrorLogs.EMPTY_CLUSTER_ID.getLog());
147+
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyClusterId.getMessage());
148+
}
149+
} else if (credentials != null) {
150+
validateCredentials(credentials);
151+
}
152+
}
121153
}

v3/src/main/java/com/skyflow/vault/controller/VaultController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public final class VaultController extends VaultClient {
3434
private int detokenizeBatchSize;
3535
private int detokenizeConcurrencyLimit;
3636

37-
public VaultController(VaultConfig vaultConfig, Credentials credentials) {
37+
public VaultController(VaultConfig vaultConfig, Credentials credentials) throws SkyflowException {
3838
super(vaultConfig, credentials);
3939
this.insertBatchSize = Constants.INSERT_BATCH_SIZE;
4040
this.insertConcurrencyLimit = Constants.INSERT_CONCURRENCY_LIMIT;

0 commit comments

Comments
 (0)