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
4 changes: 4 additions & 0 deletions common/src/main/java/com/skyflow/errors/ErrorMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public enum ErrorMessage {
EmptyVaultId("%s0 Initialization failed. Invalid vault ID. Vault ID must not be empty."),
InvalidClusterId("%s0 Initialization failed. Invalid cluster ID. Specify cluster ID."),
EmptyClusterId("%s0 Initialization failed. Invalid cluster ID. Specify a valid cluster ID."),
EmptyVaultUrl("%s0 Initialization failed. Vault URL is empty. Specify a valid vault URL."),
InvalidVaultUrlFormat("%s0 Initialization failed. Vault URL must start with 'https://'."),

// Connection config
InvalidConnectionId("%s0 Initialization failed. Invalid connection ID. Specify a valid connection ID."),
Expand Down Expand Up @@ -73,11 +75,13 @@ public enum ErrorMessage {
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."),
RecordSizeExceedError("%s0 Maximum number of records exceeded. The limit is 10000."),

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

// Get
IdsKeyError("%s0 Validation error. 'ids' key is missing from the payload. Specify an 'ids' key."),
Expand Down
19 changes: 19 additions & 0 deletions common/src/main/java/com/skyflow/utils/BaseUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.skyflow.serviceaccount.util.BearerToken;
import com.skyflow.serviceaccount.util.Token;
import com.skyflow.utils.logger.LogUtil;
import io.github.cdimascio.dotenv.Dotenv;
import io.github.cdimascio.dotenv.DotenvException;
import org.apache.commons.codec.binary.Base64;

import java.io.File;
Expand Down Expand Up @@ -43,6 +45,23 @@ public static String getVaultURL(String clusterId, Env env, String vaultDomain)
return sb.toString();
}

public static String getEnvVaultURL() {
try {
Dotenv dotenv = Dotenv.load();
String vaultURL = dotenv.get("VAULT_URL");
if (vaultURL != null && vaultURL.trim().isEmpty()) {
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyVaultUrl.getMessage());
} else if (vaultURL != null && !vaultURL.startsWith(BaseConstants.SECURE_PROTOCOL)) {
throw new SkyflowException( ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.InvalidVaultUrlFormat.getMessage());
}
return vaultURL;
} catch (DotenvException e) {
return null;
} catch (SkyflowException e) {
throw new RuntimeException(e);
}
}

public static String generateBearerToken(Credentials credentials) throws SkyflowException {
String bearerToken;
if (credentials.getPath() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ public static void validateVaultConfig(VaultConfig vaultConfig) throws SkyflowEx
} else if (vaultId.trim().isEmpty()) {
LogUtil.printErrorLog(ErrorLogs.EMPTY_VAULT_ID.getLog());
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyVaultId.getMessage());
} else if (clusterId == null) {
LogUtil.printErrorLog(ErrorLogs.CLUSTER_ID_IS_REQUIRED.getLog());
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.InvalidClusterId.getMessage());
} else if (clusterId.trim().isEmpty()) {
LogUtil.printErrorLog(ErrorLogs.EMPTY_CLUSTER_ID.getLog());
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyClusterId.getMessage());
} else if (BaseUtils.getEnvVaultURL() == null) {
if (clusterId == null) {
LogUtil.printErrorLog(ErrorLogs.CLUSTER_ID_IS_REQUIRED.getLog());
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.InvalidClusterId.getMessage());
} else if (clusterId.trim().isEmpty()) {
LogUtil.printErrorLog(ErrorLogs.EMPTY_CLUSTER_ID.getLog());
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyClusterId.getMessage());
}
} else if (credentials != null) {
validateCredentials(credentials);
}
Expand Down
5 changes: 4 additions & 1 deletion v3/src/main/java/com/skyflow/VaultClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ protected void setBearerToken() throws SkyflowException {
}

private void updateVaultURL() {
String vaultURL = Utils.getVaultURL(this.vaultConfig.getClusterId(), this.vaultConfig.getEnv());
String vaultURL = Utils.getEnvVaultURL();
if (vaultURL == null || vaultURL.isEmpty()) {
vaultURL = Utils.getVaultURL(this.vaultConfig.getClusterId(), this.vaultConfig.getEnv());
}
this.apiClientBuilder.url(vaultURL);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public static void validateInsertRequest(InsertRequest insertRequest) throws Sky
ErrorLogs.EMPTY_VALUES.getLog(), InterfaceName.INSERT.getName()
));
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyValues.getMessage());
} else if(values.size() > 10000) {
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.RecordSizeExceedError.getMessage());
} else if (upsert != null && upsert.isEmpty()){
LogUtil.printErrorLog(Utils.parameterizedString(
ErrorLogs.EMPTY_UPSERT.getLog(), InterfaceName.INSERT.getName()
Expand Down Expand Up @@ -82,6 +84,9 @@ 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) {
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()
Expand Down
Loading