Skip to content

Commit b38fa96

Browse files
SK-2467: add checkstyle linter and configuration
1 parent 18a2449 commit b38fa96

File tree

7 files changed

+78
-34
lines changed

7 files changed

+78
-34
lines changed

checkstyle.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE module PUBLIC
3+
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
4+
"https://checkstyle.org/dtds/configuration_1_3.dtd">
5+
6+
<module name="Checker">
7+
<module name="SuppressWarningsFilter"/>
8+
9+
<module name="TreeWalker">
10+
<module name="SuppressWarningsHolder"/>
11+
12+
<module name="MethodName"/>
13+
<module name="LocalVariableName"/>
14+
<module name="ParameterName"/>
15+
<module name="MemberName"/>
16+
<module name="StaticVariableName"/>
17+
<module name="ConstantName"/>
18+
<module name="TypeName"/>
19+
</module>
20+
</module>

pom.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,28 @@
190190
</includes>
191191
</configuration>
192192
</plugin>
193+
<plugin>
194+
<groupId>org.apache.maven.plugins</groupId>
195+
<artifactId>maven-checkstyle-plugin</artifactId>
196+
<version>3.3.1</version>
197+
<configuration>
198+
<configLocation>checkstyle.xml</configLocation>
199+
200+
<failsOnError>false</failsOnError>
201+
<consoleOutput>true</consoleOutput>
202+
203+
<excludes>**/generated/**</excludes>
204+
</configuration>
205+
<executions>
206+
<execution>
207+
<id>validate</id>
208+
<phase>validate</phase>
209+
<goals>
210+
<goal>check</goal>
211+
</goals>
212+
</execution>
213+
</executions>
214+
</plugin>
193215
<plugin>
194216
<groupId>org.jacoco</groupId>
195217
<artifactId>jacoco-maven-plugin</artifactId>

src/main/java/com/skyflow/serviceaccount/util/BearerToken.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
import java.util.Objects;
2828

2929
public class BearerToken {
30-
private static final Gson gson = new GsonBuilder().serializeNulls().create();
31-
private static final ApiClientBuilder apiClientBuilder = new ApiClientBuilder();
30+
private static final Gson GSON = new GsonBuilder().serializeNulls().create();
31+
private static final ApiClientBuilder API_CLIENT_BUILDER = new ApiClientBuilder();
3232
private final File credentialsFile;
3333
private final String credentialsString;
3434
private final String ctx;
@@ -122,8 +122,8 @@ private static V1GetAuthTokenResponse getBearerTokenFromCredentials(
122122
);
123123

124124
String basePath = Utils.getBaseURL(tokenURI.getAsString());
125-
apiClientBuilder.url(basePath);
126-
ApiClient apiClient = apiClientBuilder.token("token").build();
125+
API_CLIENT_BUILDER.url(basePath);
126+
ApiClient apiClient = API_CLIENT_BUILDER.token("token").build();
127127
AuthenticationClient authenticationApi = apiClient.authentication();
128128

129129
V1GetAuthTokenRequest._FinalStage authTokenBuilder = V1GetAuthTokenRequest.builder().grantType(Constants.GRANT_TYPE).assertion(signedUserJWT);
@@ -137,7 +137,7 @@ private static V1GetAuthTokenResponse getBearerTokenFromCredentials(
137137
LogUtil.printErrorLog(ErrorLogs.INVALID_TOKEN_URI.getLog());
138138
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.InvalidTokenUri.getMessage());
139139
} catch (ApiClientApiException e) {
140-
String bodyString = gson.toJson(e.body());
140+
String bodyString = GSON.toJson(e.body());
141141
LogUtil.printErrorLog(ErrorLogs.BEARER_TOKEN_REJECTED.getLog());
142142
throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString);
143143
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ public static String generateBearerToken(Credentials credentials) throws Skyflow
6868
}
6969

7070
public static PrivateKey getPrivateKeyFromPem(String pemKey) throws SkyflowException {
71+
@SuppressWarnings("checkstyle:LocalVariableName")
7172
String PKCS8PrivateHeader = Constants.PKCS8_PRIVATE_HEADER;
73+
@SuppressWarnings("checkstyle:LocalVariableName")
7274
String PKCS8PrivateFooter = Constants.PKCS8_PRIVATE_FOOTER;
7375

7476
String privateKeyContent = pemKey;

src/main/java/com/skyflow/utils/logger/LogUtil.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
public final class LogUtil {
1010
private static final Logger LOGGER = Logger.getLogger(LogUtil.class.getName());
1111
private static final String SDK_LOG_PREFIX = "[" + Constants.SDK_PREFIX + "] ";
12-
private static boolean IS_LOGGER_SETUP_DONE = false;
12+
private static boolean isLoggerSetupDone = false;
1313

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

4040
public static void printErrorLog(String message) {
41-
if (IS_LOGGER_SETUP_DONE)
41+
if (isLoggerSetupDone)
4242
LOGGER.severe(SDK_LOG_PREFIX + message);
4343
else {
4444
setupLogger(LogLevel.ERROR);
@@ -47,17 +47,17 @@ public static void printErrorLog(String message) {
4747
}
4848

4949
public static void printDebugLog(String message) {
50-
if (IS_LOGGER_SETUP_DONE)
50+
if (isLoggerSetupDone)
5151
LOGGER.config(SDK_LOG_PREFIX + message);
5252
}
5353

5454
public static void printWarningLog(String message) {
55-
if (IS_LOGGER_SETUP_DONE)
55+
if (isLoggerSetupDone)
5656
LOGGER.warning(SDK_LOG_PREFIX + message);
5757
}
5858

5959
public static void printInfoLog(String message) {
60-
if (IS_LOGGER_SETUP_DONE)
60+
if (isLoggerSetupDone)
6161
LOGGER.info(SDK_LOG_PREFIX + message);
6262
}
6363

src/main/java/com/skyflow/vault/controller/DetectController.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public final class DetectController extends VaultClient {
3535
src.map(context::serialize).orElse(null))
3636
.serializeNulls()
3737
.create();
38-
private static final JsonObject skyMetadata = Utils.getMetrics();
38+
private static final JsonObject SKY_METADATA = Utils.getMetrics();
3939

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

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

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

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

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

208-
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, skyMetadata.toString()).build();
208+
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, SKY_METADATA.toString()).build();
209209
response = super.getDetectFileAPi()
210210
.getRun(runId, getRunRequest, requestOptions);
211211

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@
3131
import java.util.*;
3232

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

3737
public VaultController(VaultConfig vaultConfig, Credentials credentials) {
3838
super(vaultConfig, credentials);
3939
}
4040

4141
private static synchronized HashMap<String, Object> getFormattedBatchInsertRecord(Object record, Integer requestIndex) {
4242
HashMap<String, Object> insertRecord = new HashMap<>();
43-
String jsonString = gson.toJson(record);
43+
String jsonString = GSON.toJson(record);
4444
JsonObject bodyObject = JsonParser.parseString(jsonString).getAsJsonObject().get("Body").getAsJsonObject();
4545
JsonArray records = bodyObject.getAsJsonArray("records");
4646
JsonPrimitive error = bodyObject.getAsJsonPrimitive("error");
@@ -122,7 +122,7 @@ public InsertResponse insert(InsertRequest insertRequest) throws SkyflowExceptio
122122
setBearerToken();
123123
if (continueOnError) {
124124
RecordServiceBatchOperationBody insertBody = super.getBatchInsertRequestBody(insertRequest);
125-
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, skyMetadata.toString()).build();
125+
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, SKY_METADATA.toString()).build();
126126
batchInsertResult = super.getRecordsApi().withRawResponse().recordServiceBatchOperation(super.getVaultConfig().getVaultId(), insertBody, requestOptions);
127127
LogUtil.printInfoLog(InfoLogs.INSERT_REQUEST_RESOLVED.getLog());
128128
Optional<List<Map<String, Object>>> records = batchInsertResult.body().getResponses();
@@ -157,7 +157,7 @@ public InsertResponse insert(InsertRequest insertRequest) throws SkyflowExceptio
157157
}
158158
}
159159
} catch (ApiClientApiException e) {
160-
String bodyString = gson.toJson(e.body());
160+
String bodyString = GSON.toJson(e.body());
161161
LogUtil.printErrorLog(ErrorLogs.INSERT_RECORDS_REJECTED.getLog());
162162
throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString);
163163
}
@@ -181,7 +181,7 @@ public DetokenizeResponse detokenize(DetokenizeRequest detokenizeRequest) throws
181181
Validations.validateDetokenizeRequest(detokenizeRequest);
182182
setBearerToken();
183183
V1DetokenizePayload payload = super.getDetokenizePayload(detokenizeRequest);
184-
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, skyMetadata.toString()).build();
184+
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, SKY_METADATA.toString()).build();
185185
result = super.getTokensApi().withRawResponse().recordServiceDetokenize(super.getVaultConfig().getVaultId(), payload, requestOptions);
186186
LogUtil.printInfoLog(InfoLogs.DETOKENIZE_REQUEST_RESOLVED.getLog());
187187
Map<String, List<String>> responseHeaders = result.headers();
@@ -202,7 +202,7 @@ public DetokenizeResponse detokenize(DetokenizeRequest detokenizeRequest) throws
202202
}
203203
}
204204
} catch (ApiClientApiException e) {
205-
String bodyString = gson.toJson(e.body());
205+
String bodyString = GSON.toJson(e.body());
206206
LogUtil.printErrorLog(ErrorLogs.DETOKENIZE_REQUEST_REJECTED.getLog());
207207
throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString);
208208
}
@@ -244,7 +244,7 @@ public GetResponse get(GetRequest getRequest) throws SkyflowException {
244244
.orderBy(RecordServiceBulkGetRecordRequestOrderBy.valueOf(getRequest.getOrderBy()))
245245
.build();
246246

247-
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, skyMetadata.toString()).build();
247+
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, SKY_METADATA.toString()).build();
248248
result = super.getRecordsApi().recordServiceBulkGetRecord(
249249
super.getVaultConfig().getVaultId(),
250250
getRequest.getTable(),
@@ -259,7 +259,7 @@ public GetResponse get(GetRequest getRequest) throws SkyflowException {
259259
}
260260
}
261261
} catch (ApiClientApiException e) {
262-
String bodyString = gson.toJson(e.body());
262+
String bodyString = GSON.toJson(e.body());
263263
LogUtil.printErrorLog(ErrorLogs.GET_REQUEST_REJECTED.getLog());
264264
throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString);
265265
}
@@ -277,7 +277,7 @@ public UpdateResponse update(UpdateRequest updateRequest) throws SkyflowExceptio
277277
Validations.validateUpdateRequest(updateRequest);
278278
setBearerToken();
279279
RecordServiceUpdateRecordBody updateBody = super.getUpdateRequestBody(updateRequest);
280-
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, skyMetadata.toString()).build();
280+
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, SKY_METADATA.toString()).build();
281281
result = super.getRecordsApi().recordServiceUpdateRecord(
282282
super.getVaultConfig().getVaultId(),
283283
updateRequest.getTable(),
@@ -289,7 +289,7 @@ public UpdateResponse update(UpdateRequest updateRequest) throws SkyflowExceptio
289289
skyflowId = String.valueOf(result.getSkyflowId());
290290
tokensMap = getFormattedUpdateRecord(result);
291291
} catch (ApiClientApiException e) {
292-
String bodyString = gson.toJson(e.body());
292+
String bodyString = GSON.toJson(e.body());
293293
LogUtil.printErrorLog(ErrorLogs.UPDATE_REQUEST_REJECTED.getLog());
294294
throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString);
295295
}
@@ -307,12 +307,12 @@ public DeleteResponse delete(DeleteRequest deleteRequest) throws SkyflowExceptio
307307
RecordServiceBulkDeleteRecordBody deleteBody = RecordServiceBulkDeleteRecordBody.builder().skyflowIds(deleteRequest.getIds())
308308
.build();
309309

310-
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, skyMetadata.toString()).build();
310+
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, SKY_METADATA.toString()).build();
311311
result = super.getRecordsApi().recordServiceBulkDeleteRecord(
312312
super.getVaultConfig().getVaultId(), deleteRequest.getTable(), deleteBody, requestOptions);
313313
LogUtil.printInfoLog(InfoLogs.DELETE_REQUEST_RESOLVED.getLog());
314314
} catch (ApiClientApiException e) {
315-
String bodyString = gson.toJson(e.body());
315+
String bodyString = GSON.toJson(e.body());
316316
LogUtil.printErrorLog(ErrorLogs.DELETE_REQUEST_REJECTED.getLog());
317317
throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString);
318318
}
@@ -328,7 +328,7 @@ public QueryResponse query(QueryRequest queryRequest) throws SkyflowException {
328328
LogUtil.printInfoLog(InfoLogs.VALIDATING_QUERY_REQUEST.getLog());
329329
Validations.validateQueryRequest(queryRequest);
330330
setBearerToken();
331-
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, skyMetadata.toString()).build();
331+
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, SKY_METADATA.toString()).build();
332332
result = super.getQueryApi().queryServiceExecuteQuery(
333333
super.getVaultConfig().getVaultId(),
334334
QueryServiceExecuteQueryBody.builder().query(queryRequest.getQuery()).build(),
@@ -342,7 +342,7 @@ public QueryResponse query(QueryRequest queryRequest) throws SkyflowException {
342342
}
343343
}
344344
} catch (ApiClientApiException e) {
345-
String bodyString = gson.toJson(e.body());
345+
String bodyString = GSON.toJson(e.body());
346346
LogUtil.printErrorLog(ErrorLogs.QUERY_REQUEST_REJECTED.getLog());
347347
throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString);
348348
}
@@ -359,7 +359,7 @@ public TokenizeResponse tokenize(TokenizeRequest tokenizeRequest) throws Skyflow
359359
Validations.validateTokenizeRequest(tokenizeRequest);
360360
setBearerToken();
361361
V1TokenizePayload payload = super.getTokenizePayload(tokenizeRequest);
362-
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, skyMetadata.toString()).build();
362+
RequestOptions requestOptions = RequestOptions.builder().addHeader(Constants.SDK_METRICS_HEADER_KEY, SKY_METADATA.toString()).build();
363363
result = super.getTokensApi().recordServiceTokenize(super.getVaultConfig().getVaultId(), payload, requestOptions);
364364
LogUtil.printInfoLog(InfoLogs.TOKENIZE_REQUEST_RESOLVED.getLog());
365365
if (result != null && result.getRecords().isPresent() && !result.getRecords().get().isEmpty()) {
@@ -370,7 +370,7 @@ public TokenizeResponse tokenize(TokenizeRequest tokenizeRequest) throws Skyflow
370370
}
371371
}
372372
} catch (ApiClientApiException e) {
373-
String bodyString = gson.toJson(e.body());
373+
String bodyString = GSON.toJson(e.body());
374374
LogUtil.printErrorLog(ErrorLogs.TOKENIZE_REQUEST_REJECTED.getLog());
375375
throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString);
376376
}
@@ -395,7 +395,7 @@ public FileUploadResponse uploadFile(FileUploadRequest fileUploadRequest) throws
395395
.returnFileMetadata(false)
396396
.build();
397397

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

411411
} catch (ApiClientApiException e) {
412-
String bodyString = gson.toJson(e.body());
412+
String bodyString = GSON.toJson(e.body());
413413
LogUtil.printErrorLog(ErrorLogs.UPLOAD_FILE_REQUEST_REJECTED.getLog());
414414
throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString);
415415
} catch (IOException e) {

0 commit comments

Comments
 (0)