From 4bff1528f42ea5705a02cc8ba5c08bf2453b31f1 Mon Sep 17 00:00:00 2001 From: Tomasz Wrobel Date: Mon, 22 Mar 2021 16:07:38 +0100 Subject: Fix Sonar issues - Remove blank characters from input data on validation service - Add NOSONAR to test application context Issue-ID: SDC-3185 Signed-off-by: Tomasz Wrobel Change-Id: I3a8c3cdf447a2ffa49ee1c961fd73229144349b8 --- .../helm/validation/ValidationService.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/main/java/org/onap') diff --git a/src/main/java/org/onap/sdc/helmvalidator/helm/validation/ValidationService.java b/src/main/java/org/onap/sdc/helmvalidator/helm/validation/ValidationService.java index 53689c2..87363f9 100644 --- a/src/main/java/org/onap/sdc/helmvalidator/helm/validation/ValidationService.java +++ b/src/main/java/org/onap/sdc/helmvalidator/helm/validation/ValidationService.java @@ -47,6 +47,7 @@ public class ValidationService { private static final String LINT_OPTION = "lint"; private static final String HELM_SUMMARY_MESSAGE_PATTERN = "Error: \\d* chart\\(s\\) linted, \\d* chart\\(s\\) failed"; + private static final String WHITESPACE_CHARACTER = "[\\s]"; private static final boolean INVALID_RESULT = false; private final FileManager fileManager; @@ -91,7 +92,9 @@ public class ValidationService { String chartPath = fileManager.saveFile(file); try { String helmVersion = getSupportedHelmVersion(desiredVersion, chartPath); - return validateChart(helmVersion, file, isLinted, isStrictLinted, chartPath); + LOGGER.info("Start validation of file: {}, with helm version: {}", + replaceBlankCharacters(file.getOriginalFilename()), helmVersion); + return validateChart(helmVersion, isLinted, isStrictLinted, chartPath); } finally { LOGGER.info("File process finished"); fileManager.removeFile(chartPath); @@ -115,11 +118,15 @@ public class ValidationService { .orElseThrow(() -> new NotSupportedVersionException(desiredVersion)); } - private ValidationResult validateChart(String version, MultipartFile file, boolean isLinted, boolean isStrictLinted, - String chartPath) { - LOGGER.info("Start validation of file: {}, with helm version: {}", - file.getOriginalFilename(), version); + private String replaceBlankCharacters(String string) { + if (string != null) { + return string.replaceAll(WHITESPACE_CHARACTER, "_"); + } + return "_"; + } + private ValidationResult validateChart(String version, boolean isLinted, boolean isStrictLinted, + String chartPath) { TemplateValidationResult templateValidationResult = runHelmTemplate( buildHelmTemplateCommand(version, chartPath)); LOGGER.info("Helm template finished"); -- cgit 1.2.3-korg