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
20 changes: 20 additions & 0 deletions checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">

<module name="Checker">
<module name="SuppressWarningsFilter"/>

<module name="TreeWalker">
<module name="SuppressWarningsHolder"/>

<module name="MethodName"/>
<module name="LocalVariableName"/>
<module name="ParameterName"/>
<module name="MemberName"/>
<module name="StaticVariableName"/>
<module name="ConstantName"/>
<module name="TypeName"/>
</module>
</module>
22 changes: 22 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,28 @@
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.3.1</version>
<configuration>
<configLocation>checkstyle.xml</configLocation>

<failsOnError>false</failsOnError>
<consoleOutput>true</consoleOutput>

<excludes>**/generated/**</excludes>
</configuration>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/skyflow/serviceaccount/util/BearerToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import java.util.Objects;

public class BearerToken {
private static final Gson gson = new GsonBuilder().serializeNulls().create();
private static final ApiClientBuilder apiClientBuilder = new ApiClientBuilder();
private static final Gson GSON = new GsonBuilder().serializeNulls().create();
private static final ApiClientBuilder API_CLIENT_BUILDER = new ApiClientBuilder();
private final File credentialsFile;
private final String credentialsString;
private final String ctx;
Expand Down Expand Up @@ -122,8 +122,8 @@ private static V1GetAuthTokenResponse getBearerTokenFromCredentials(
);

String basePath = Utils.getBaseURL(tokenURI.getAsString());
apiClientBuilder.url(basePath);
ApiClient apiClient = apiClientBuilder.token("token").build();
API_CLIENT_BUILDER.url(basePath);
ApiClient apiClient = API_CLIENT_BUILDER.token("token").build();
AuthenticationClient authenticationApi = apiClient.authentication();

V1GetAuthTokenRequest._FinalStage authTokenBuilder = V1GetAuthTokenRequest.builder().grantType(Constants.GRANT_TYPE).assertion(signedUserJWT);
Expand All @@ -137,7 +137,7 @@ private static V1GetAuthTokenResponse getBearerTokenFromCredentials(
LogUtil.printErrorLog(ErrorLogs.INVALID_TOKEN_URI.getLog());
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.InvalidTokenUri.getMessage());
} catch (ApiClientApiException e) {
String bodyString = gson.toJson(e.body());
String bodyString = GSON.toJson(e.body());
LogUtil.printErrorLog(ErrorLogs.BEARER_TOKEN_REJECTED.getLog());
throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import com.skyflow.utils.Constants;

public class SignedDataTokenResponse {
private static final String prefix = Constants.SIGNED_DATA_TOKEN_PREFIX;
private static final String PREFIX = Constants.SIGNED_DATA_TOKEN_PREFIX;
private final String token;
private final String signedToken;

public SignedDataTokenResponse(String token, String signedToken) {
this.token = token;
this.signedToken = new StringBuilder(prefix).append(signedToken).toString();
this.signedToken = new StringBuilder(PREFIX).append(signedToken).toString();
}

public String getToken() {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/skyflow/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ public static String generateBearerToken(Credentials credentials) throws Skyflow
}

public static PrivateKey getPrivateKeyFromPem(String pemKey) throws SkyflowException {
@SuppressWarnings("checkstyle:LocalVariableName")
String PKCS8PrivateHeader = Constants.PKCS8_PRIVATE_HEADER;
@SuppressWarnings("checkstyle:LocalVariableName")
String PKCS8PrivateFooter = Constants.PKCS8_PRIVATE_FOOTER;

String privateKeyContent = pemKey;
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/skyflow/utils/logger/LogUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
public final class LogUtil {
private static final Logger LOGGER = Logger.getLogger(LogUtil.class.getName());
private static final String SDK_LOG_PREFIX = "[" + Constants.SDK_PREFIX + "] ";
private static boolean IS_LOGGER_SETUP_DONE = false;
private static boolean isLoggerSetupDone = false;

synchronized public static void setupLogger(LogLevel logLevel) {
IS_LOGGER_SETUP_DONE = true;
isLoggerSetupDone = true;
LogManager.getLogManager().reset();
LOGGER.setUseParentHandlers(false);
Formatter formatter = new SimpleFormatter() {
Expand All @@ -38,7 +38,7 @@ public synchronized String format(LogRecord logRecord) {
}

public static void printErrorLog(String message) {
if (IS_LOGGER_SETUP_DONE)
if (isLoggerSetupDone)
LOGGER.severe(SDK_LOG_PREFIX + message);
else {
setupLogger(LogLevel.ERROR);
Expand All @@ -47,17 +47,17 @@ public static void printErrorLog(String message) {
}

public static void printDebugLog(String message) {
if (IS_LOGGER_SETUP_DONE)
if (isLoggerSetupDone)
LOGGER.config(SDK_LOG_PREFIX + message);
}

public static void printWarningLog(String message) {
if (IS_LOGGER_SETUP_DONE)
if (isLoggerSetupDone)
LOGGER.warning(SDK_LOG_PREFIX + message);
}

public static void printInfoLog(String message) {
if (IS_LOGGER_SETUP_DONE)
if (isLoggerSetupDone)
LOGGER.info(SDK_LOG_PREFIX + message);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public final class DetectController extends VaultClient {
src.map(context::serialize).orElse(null))
.serializeNulls()
.create();
private static final JsonObject skyMetadata = Utils.getMetrics();
private static final JsonObject SKY_METADATA = Utils.getMetrics();

public DetectController(VaultConfig vaultConfig, Credentials credentials) {
super(vaultConfig, credentials);
Expand All @@ -56,7 +56,7 @@ public DeidentifyTextResponse deidentifyText(DeidentifyTextRequest deidentifyTex
DeidentifyStringRequest request = getDeidentifyStringRequest(deidentifyTextRequest, vaultId);

// get SDK metrics and call the API to de-identify the string
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, skyMetadata.toString()).build();
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, SKY_METADATA.toString()).build();
deidentifyStringResponse = super.getDetectTextApi().deidentifyString(request, requestOptions);

// Parse the response to DeIdentifyTextResponse
Expand Down Expand Up @@ -84,7 +84,7 @@ public ReidentifyTextResponse reidentifyText(ReidentifyTextRequest reidentifyTex
ReidentifyStringRequest request = getReidentifyStringRequest(reidentifyTextRequest, vaultId);

// Get SDK metrics and call the API to re-identify the string
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, skyMetadata.toString()).build();
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, SKY_METADATA.toString()).build();
IdentifyResponse reidentifyStringResponse = super.getDetectTextApi().reidentifyString(request, requestOptions);

// Parse the response to ReidentifyTextResponse
Expand Down Expand Up @@ -205,7 +205,7 @@ private DeidentifyFileResponse pollForResults(String runId, Integer maxWaitTime)
.vaultId(super.getVaultConfig().getVaultId())
.build();

RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, skyMetadata.toString()).build();
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, SKY_METADATA.toString()).build();
response = super.getDetectFileAPi()
.getRun(runId, getRunRequest, requestOptions);

Expand Down
38 changes: 19 additions & 19 deletions src/main/java/com/skyflow/vault/controller/VaultController.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@
import java.util.*;

public final class VaultController extends VaultClient {
private static final Gson gson = new GsonBuilder().serializeNulls().create();
private static final JsonObject skyMetadata = Utils.getMetrics();
private static final Gson GSON = new GsonBuilder().serializeNulls().create();
private static final JsonObject SKY_METADATA = Utils.getMetrics();

public VaultController(VaultConfig vaultConfig, Credentials credentials) {
super(vaultConfig, credentials);
}

private static synchronized HashMap<String, Object> getFormattedBatchInsertRecord(Object record, Integer requestIndex) {
HashMap<String, Object> insertRecord = new HashMap<>();
String jsonString = gson.toJson(record);
String jsonString = GSON.toJson(record);
JsonObject bodyObject = JsonParser.parseString(jsonString).getAsJsonObject().get("Body").getAsJsonObject();
JsonArray records = bodyObject.getAsJsonArray("records");
JsonPrimitive error = bodyObject.getAsJsonPrimitive("error");
Expand Down Expand Up @@ -122,7 +122,7 @@ public InsertResponse insert(InsertRequest insertRequest) throws SkyflowExceptio
setBearerToken();
if (continueOnError) {
RecordServiceBatchOperationBody insertBody = super.getBatchInsertRequestBody(insertRequest);
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, skyMetadata.toString()).build();
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, SKY_METADATA.toString()).build();
batchInsertResult = super.getRecordsApi().withRawResponse().recordServiceBatchOperation(super.getVaultConfig().getVaultId(), insertBody, requestOptions);
LogUtil.printInfoLog(InfoLogs.INSERT_REQUEST_RESOLVED.getLog());
Optional<List<Map<String, Object>>> records = batchInsertResult.body().getResponses();
Expand Down Expand Up @@ -157,7 +157,7 @@ public InsertResponse insert(InsertRequest insertRequest) throws SkyflowExceptio
}
}
} catch (ApiClientApiException e) {
String bodyString = gson.toJson(e.body());
String bodyString = GSON.toJson(e.body());
LogUtil.printErrorLog(ErrorLogs.INSERT_RECORDS_REJECTED.getLog());
throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString);
}
Expand All @@ -181,7 +181,7 @@ public DetokenizeResponse detokenize(DetokenizeRequest detokenizeRequest) throws
Validations.validateDetokenizeRequest(detokenizeRequest);
setBearerToken();
V1DetokenizePayload payload = super.getDetokenizePayload(detokenizeRequest);
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, skyMetadata.toString()).build();
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, SKY_METADATA.toString()).build();
result = super.getTokensApi().withRawResponse().recordServiceDetokenize(super.getVaultConfig().getVaultId(), payload, requestOptions);
LogUtil.printInfoLog(InfoLogs.DETOKENIZE_REQUEST_RESOLVED.getLog());
Map<String, List<String>> responseHeaders = result.headers();
Expand All @@ -202,7 +202,7 @@ public DetokenizeResponse detokenize(DetokenizeRequest detokenizeRequest) throws
}
}
} catch (ApiClientApiException e) {
String bodyString = gson.toJson(e.body());
String bodyString = GSON.toJson(e.body());
LogUtil.printErrorLog(ErrorLogs.DETOKENIZE_REQUEST_REJECTED.getLog());
throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString);
}
Expand Down Expand Up @@ -244,7 +244,7 @@ public GetResponse get(GetRequest getRequest) throws SkyflowException {
.orderBy(RecordServiceBulkGetRecordRequestOrderBy.valueOf(getRequest.getOrderBy()))
.build();

RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, skyMetadata.toString()).build();
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, SKY_METADATA.toString()).build();
result = super.getRecordsApi().recordServiceBulkGetRecord(
super.getVaultConfig().getVaultId(),
getRequest.getTable(),
Expand All @@ -259,7 +259,7 @@ public GetResponse get(GetRequest getRequest) throws SkyflowException {
}
}
} catch (ApiClientApiException e) {
String bodyString = gson.toJson(e.body());
String bodyString = GSON.toJson(e.body());
LogUtil.printErrorLog(ErrorLogs.GET_REQUEST_REJECTED.getLog());
throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString);
}
Expand All @@ -277,7 +277,7 @@ public UpdateResponse update(UpdateRequest updateRequest) throws SkyflowExceptio
Validations.validateUpdateRequest(updateRequest);
setBearerToken();
RecordServiceUpdateRecordBody updateBody = super.getUpdateRequestBody(updateRequest);
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, skyMetadata.toString()).build();
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, SKY_METADATA.toString()).build();
result = super.getRecordsApi().recordServiceUpdateRecord(
super.getVaultConfig().getVaultId(),
updateRequest.getTable(),
Expand All @@ -289,7 +289,7 @@ public UpdateResponse update(UpdateRequest updateRequest) throws SkyflowExceptio
skyflowId = String.valueOf(result.getSkyflowId());
tokensMap = getFormattedUpdateRecord(result);
} catch (ApiClientApiException e) {
String bodyString = gson.toJson(e.body());
String bodyString = GSON.toJson(e.body());
LogUtil.printErrorLog(ErrorLogs.UPDATE_REQUEST_REJECTED.getLog());
throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString);
}
Expand All @@ -307,12 +307,12 @@ public DeleteResponse delete(DeleteRequest deleteRequest) throws SkyflowExceptio
RecordServiceBulkDeleteRecordBody deleteBody = RecordServiceBulkDeleteRecordBody.builder().skyflowIds(deleteRequest.getIds())
.build();

RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, skyMetadata.toString()).build();
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, SKY_METADATA.toString()).build();
result = super.getRecordsApi().recordServiceBulkDeleteRecord(
super.getVaultConfig().getVaultId(), deleteRequest.getTable(), deleteBody, requestOptions);
LogUtil.printInfoLog(InfoLogs.DELETE_REQUEST_RESOLVED.getLog());
} catch (ApiClientApiException e) {
String bodyString = gson.toJson(e.body());
String bodyString = GSON.toJson(e.body());
LogUtil.printErrorLog(ErrorLogs.DELETE_REQUEST_REJECTED.getLog());
throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString);
}
Expand All @@ -328,7 +328,7 @@ public QueryResponse query(QueryRequest queryRequest) throws SkyflowException {
LogUtil.printInfoLog(InfoLogs.VALIDATING_QUERY_REQUEST.getLog());
Validations.validateQueryRequest(queryRequest);
setBearerToken();
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, skyMetadata.toString()).build();
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, SKY_METADATA.toString()).build();
result = super.getQueryApi().queryServiceExecuteQuery(
super.getVaultConfig().getVaultId(),
QueryServiceExecuteQueryBody.builder().query(queryRequest.getQuery()).build(),
Expand All @@ -342,7 +342,7 @@ public QueryResponse query(QueryRequest queryRequest) throws SkyflowException {
}
}
} catch (ApiClientApiException e) {
String bodyString = gson.toJson(e.body());
String bodyString = GSON.toJson(e.body());
LogUtil.printErrorLog(ErrorLogs.QUERY_REQUEST_REJECTED.getLog());
throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString);
}
Expand All @@ -359,7 +359,7 @@ public TokenizeResponse tokenize(TokenizeRequest tokenizeRequest) throws Skyflow
Validations.validateTokenizeRequest(tokenizeRequest);
setBearerToken();
V1TokenizePayload payload = super.getTokenizePayload(tokenizeRequest);
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, skyMetadata.toString()).build();
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, SKY_METADATA.toString()).build();
result = super.getTokensApi().recordServiceTokenize(super.getVaultConfig().getVaultId(), payload, requestOptions);
LogUtil.printInfoLog(InfoLogs.TOKENIZE_REQUEST_RESOLVED.getLog());
if (result != null && result.getRecords().isPresent() && !result.getRecords().get().isEmpty()) {
Expand All @@ -370,7 +370,7 @@ public TokenizeResponse tokenize(TokenizeRequest tokenizeRequest) throws Skyflow
}
}
} catch (ApiClientApiException e) {
String bodyString = gson.toJson(e.body());
String bodyString = GSON.toJson(e.body());
LogUtil.printErrorLog(ErrorLogs.TOKENIZE_REQUEST_REJECTED.getLog());
throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString);
}
Expand All @@ -395,7 +395,7 @@ public FileUploadResponse uploadFile(FileUploadRequest fileUploadRequest) throws
.returnFileMetadata(false)
.build();

RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, skyMetadata.toString()).build();
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, SKY_METADATA.toString()).build();
UploadFileV2Response uploadFileV2Response = super.getRecordsApi().uploadFileV2(
super.getVaultConfig().getVaultId(),
file,
Expand All @@ -409,7 +409,7 @@ public FileUploadResponse uploadFile(FileUploadRequest fileUploadRequest) throws
);

} catch (ApiClientApiException e) {
String bodyString = gson.toJson(e.body());
String bodyString = GSON.toJson(e.body());
LogUtil.printErrorLog(ErrorLogs.UPLOAD_FILE_REQUEST_REJECTED.getLog());
throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString);
} catch (IOException e) {
Expand Down
Loading