summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Changelog.md7
-rw-r--r--README.md12
-rw-r--r--pom.xml2
-rw-r--r--src/main/java/org/onap/sdc/helmvalidator/HelmValidatorApplication.java8
-rw-r--r--src/main/java/org/onap/sdc/helmvalidator/config/EnvProvider.java46
-rw-r--r--src/main/java/org/onap/sdc/helmvalidator/config/LogLevel.java44
-rw-r--r--src/main/java/org/onap/sdc/helmvalidator/config/LoggerConfig.java84
-rw-r--r--src/main/resources/application.properties9
-rw-r--r--src/test/java/org/onap/sdc/helmvalidator/config/LoggerConfigTest.java92
-rw-r--r--version.properties2
10 files changed, 299 insertions, 7 deletions
diff --git a/Changelog.md b/Changelog.md
index 3c167f8..8db90ee 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
+## [1.2.0] - 21/04/2021
+
+- Add a configuration of logging level by 'LOG_LEVEL' system environment variable
+- Supported Helm Versions:
+ - Helm v3: 3.5.2, 3.4.1, 3.3.4
+
+
## [1.1.0] - 12/04/2021
- Remove mapping to helm v2 when version desired is not provided
diff --git a/README.md b/README.md
index b14820e..d95c4e4 100644
--- a/README.md
+++ b/README.md
@@ -11,7 +11,7 @@ or
```
make build-docker-local
```
-
+##### Helm versions change
To modify helm versions:
1. Modify `Dockerfile`, add desired version in line:
@@ -25,6 +25,7 @@ build-docker-local:
```
If you want to clean downloaded files run: `make clean-local-files`
+##### Run container locally
In order to run docker container locally use:
```
make run-docker
@@ -33,6 +34,15 @@ Example charts are located in the following directory:
```
./dev-resources/sample-charts
```
+##### Change log level
+To change log level by system environment add to dockerfile following code:
+```
+ENV LOG_LEVEL=<expected level e.g. DEBUG>
+```
+or run container with LOG_LEVEL ENV
+```
+docker run -p 8080:8080 -e LOG_LEVEL=INFO onap/org.onap.sdc.sdc-helm-validator:latest
+```
## Available endpoints
* Chart validation:
diff --git a/pom.xml b/pom.xml
index b38cca9..eed6d51 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
</parent>
<groupId>org.onap.sdc</groupId>
<artifactId>sdc-helm-validator</artifactId>
- <version>1.1.0-SNAPSHOT</version>
+ <version>1.2.0-SNAPSHOT</version>
<name>helmvalidator</name>
<description>Spring-Boot application for validating helm charts</description>
diff --git a/src/main/java/org/onap/sdc/helmvalidator/HelmValidatorApplication.java b/src/main/java/org/onap/sdc/helmvalidator/HelmValidatorApplication.java
index b8bed69..0d094f6 100644
--- a/src/main/java/org/onap/sdc/helmvalidator/HelmValidatorApplication.java
+++ b/src/main/java/org/onap/sdc/helmvalidator/HelmValidatorApplication.java
@@ -20,14 +20,18 @@
package org.onap.sdc.helmvalidator;
-import org.springframework.boot.SpringApplication;
+import org.onap.sdc.helmvalidator.config.LoggerConfig;
+import org.onap.sdc.helmvalidator.config.EnvProvider;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
@SpringBootApplication
public class HelmValidatorApplication {
public static void main(String[] args) {
- SpringApplication.run(HelmValidatorApplication.class, args);
+ new SpringApplicationBuilder(HelmValidatorApplication.class)
+ .properties(new LoggerConfig(EnvProvider.getStandardProvider()).getLoggerProperties())
+ .run(args);
}
}
diff --git a/src/main/java/org/onap/sdc/helmvalidator/config/EnvProvider.java b/src/main/java/org/onap/sdc/helmvalidator/config/EnvProvider.java
new file mode 100644
index 0000000..47b82ec
--- /dev/null
+++ b/src/main/java/org/onap/sdc/helmvalidator/config/EnvProvider.java
@@ -0,0 +1,46 @@
+/*
+ * ============LICENSE_START=======================================================
+ * SDC-HELM-VALIDATOR
+ * ================================================================================
+ * Copyright (C) 2021 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdc.helmvalidator.config;
+
+import java.util.Optional;
+import org.springframework.stereotype.Service;
+
+@Service
+public class EnvProvider {
+
+ public static EnvProvider getStandardProvider() {
+ return new EnvProvider();
+ }
+
+ public String readEnvVariable(String envVariableName) {
+ return Optional.ofNullable(getSystemEnv(envVariableName))
+ .orElseGet(this::getDefaultValue);
+ }
+
+ private String getSystemEnv(String envVariableName) {
+ return System.getenv(envVariableName);
+ }
+
+ private String getDefaultValue() {
+ return LogLevel.getDefaultLevel();
+ }
+
+}
diff --git a/src/main/java/org/onap/sdc/helmvalidator/config/LogLevel.java b/src/main/java/org/onap/sdc/helmvalidator/config/LogLevel.java
new file mode 100644
index 0000000..c97e9dd
--- /dev/null
+++ b/src/main/java/org/onap/sdc/helmvalidator/config/LogLevel.java
@@ -0,0 +1,44 @@
+/*
+ * ============LICENSE_START=======================================================
+ * SDC-HELM-VALIDATOR
+ * ================================================================================
+ * Copyright (C) 2021 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdc.helmvalidator.config;
+
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public enum LogLevel {
+ FATAL,
+ ERROR,
+ WARN,
+ INFO,
+ DEBUG,
+ TRACE;
+
+ static String getDefaultLevel() {
+ return ERROR.toString();
+ }
+
+ static List<String> getSupportedLevels() {
+ return Stream.of(values())
+ .map(Enum::toString)
+ .collect(Collectors.toList());
+ }
+}
diff --git a/src/main/java/org/onap/sdc/helmvalidator/config/LoggerConfig.java b/src/main/java/org/onap/sdc/helmvalidator/config/LoggerConfig.java
new file mode 100644
index 0000000..dc27800
--- /dev/null
+++ b/src/main/java/org/onap/sdc/helmvalidator/config/LoggerConfig.java
@@ -0,0 +1,84 @@
+/*
+ * ============LICENSE_START=======================================================
+ * SDC-HELM-VALIDATOR
+ * ================================================================================
+ * Copyright (C) 2021 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdc.helmvalidator.config;
+
+import java.util.Optional;
+import java.util.Properties;
+import javax.annotation.PostConstruct;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+@Service
+public class LoggerConfig {
+
+ private static final String LOG_LEVEL_ENV = "LOG_LEVEL";
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(LoggerConfig.class);
+
+ private final EnvProvider envProvider;
+
+ public LoggerConfig(EnvProvider envProvider) {
+ this.envProvider = envProvider;
+ }
+
+ public Properties getLoggerProperties() {
+ String level = getLogLevel();
+ Properties loggerProperties = new Properties();
+ loggerProperties.setProperty("logging.level.web", level);
+ loggerProperties.setProperty("logging.level.org.springframework", level);
+ loggerProperties.setProperty("logging.level.org.apache.catalina.core", level);
+ loggerProperties.setProperty("logging.level.org.onap.sdc.helmvalidator", level);
+ loggerProperties.setProperty("spring.mvc.log-request-details", isDebugLevel().toString());
+
+ return loggerProperties;
+ }
+
+ private String getLogLevel() {
+ return Optional.of(getLogLevelEnvVariable())
+ .map(String::toUpperCase)
+ .filter(this::isSupportedLevel)
+ .orElseGet(LogLevel::getDefaultLevel);
+ }
+
+ private String getLogLevelEnvVariable() {
+ return envProvider.readEnvVariable(LOG_LEVEL_ENV);
+ }
+
+ private Boolean isDebugLevel() {
+ return getLogLevel().equals("DEBUG");
+ }
+
+ private boolean isSupportedLevel(String level) {
+ return LogLevel.getSupportedLevels().stream()
+ .anyMatch(logLevel -> logLevel.equalsIgnoreCase(level));
+ }
+
+ @PostConstruct
+ private void logConfigurationLevelValue() {
+ String logLevel = getLogLevelEnvVariable();
+ if (!isSupportedLevel(logLevel)) {
+ LOGGER.error("Log level '{}' not match to supported levels. Available values: {}", logLevel,
+ LogLevel.getSupportedLevels());
+ LOGGER.error("Log level set to default: {}", LogLevel.getDefaultLevel());
+ }
+ }
+}
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 3fef31f..f9dea88 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -1,4 +1,9 @@
-logging.level.web="ERROR"
-spring.mvc.log-request-details=false
app.config.charts-base-path=/charts
spring.jackson.default-property-inclusion=NON_NULL
+
+logging.file.name=/var/log/onap/application.log
+logging.logback.rollingpolicy.file-name-pattern=/var/log/onap/application-%d{yyyy-MM-dd}.%i.log
+logging.logback.rollingpolicy.max-file-size=1MB
+logging.logback.rollingpolicy.total-size-cap=10MB
+logging.logback.rollingpolicy.max-history=30
+logging.logback.rollingpolicy.clean-history-on-start=true
diff --git a/src/test/java/org/onap/sdc/helmvalidator/config/LoggerConfigTest.java b/src/test/java/org/onap/sdc/helmvalidator/config/LoggerConfigTest.java
new file mode 100644
index 0000000..b2ae9e5
--- /dev/null
+++ b/src/test/java/org/onap/sdc/helmvalidator/config/LoggerConfigTest.java
@@ -0,0 +1,92 @@
+/*
+ * ============LICENSE_START=======================================================
+ * SDC-HELM-VALIDATOR
+ * ================================================================================
+ * Copyright (C) 2021 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdc.helmvalidator.config;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Properties;
+import org.junit.jupiter.api.Test;
+
+class LoggerConfigTest {
+
+ private static final boolean WITHOUT_DETAILS = false;
+ private static final boolean WITH_DETAILS = true;
+ private static final String EXPECTED_ERROR = "ERROR";
+ private static final String EXPECTED_DEBUG = "DEBUG";
+
+ private final EnvProvider envProvider = mock(EnvProvider.class);
+ private final LoggerConfig loggerConfig = new LoggerConfig(envProvider);
+
+ @Test
+ void shouldProvideCorrectPropertiesForErrorLogLevel() {
+ when(envProvider.readEnvVariable(anyString())).thenReturn("ERROR");
+
+ Properties properties = loggerConfig.getLoggerProperties();
+
+ assertThatAllLogPropertiesHasExpectedValue(properties, EXPECTED_ERROR);
+ assertThatRequestDetailsPropertyHasExpectedValue(properties, WITHOUT_DETAILS);
+ }
+
+ @Test
+ void shouldProvideCorrectPropertiesForEnvInLowerCase() {
+ when(envProvider.readEnvVariable(anyString())).thenReturn("error");
+
+ Properties properties = loggerConfig.getLoggerProperties();
+
+ assertThatAllLogPropertiesHasExpectedValue(properties, EXPECTED_ERROR);
+ assertThatRequestDetailsPropertyHasExpectedValue(properties, WITHOUT_DETAILS);
+ }
+
+ @Test
+ void shouldProvideCorrectPropertiesForDebugLevel() {
+ when(envProvider.readEnvVariable(anyString())).thenReturn("DEBUG");
+
+ Properties properties = loggerConfig.getLoggerProperties();
+
+ assertThatAllLogPropertiesHasExpectedValue(properties, EXPECTED_DEBUG);
+ assertThatRequestDetailsPropertyHasExpectedValue(properties, WITH_DETAILS);
+ }
+
+ @Test
+ void shouldProvideCorrectPropertiesForNotSupportedLevel() {
+ when(envProvider.readEnvVariable(anyString())).thenReturn("notSupportedLevel");
+
+ Properties properties = loggerConfig.getLoggerProperties();
+
+ assertThatAllLogPropertiesHasExpectedValue(properties, "ERROR");
+ assertThatRequestDetailsPropertyHasExpectedValue(properties, WITHOUT_DETAILS);
+ }
+
+ private void assertThatAllLogPropertiesHasExpectedValue(Properties properties, String expectedValue) {
+ assertThat(properties.getProperty("logging.level.web")).isEqualTo(expectedValue);
+ assertThat(properties.getProperty("logging.level.org.springframework")).isEqualTo(expectedValue);
+ assertThat(properties.getProperty("logging.level.org.apache.catalina.core")).isEqualTo(expectedValue);
+ assertThat(properties.getProperty("logging.level.org.onap.sdc.helmvalidator")).isEqualTo(expectedValue);
+ }
+
+ private void assertThatRequestDetailsPropertyHasExpectedValue(Properties properties, Boolean expected) {
+ assertThat(properties.getProperty("spring.mvc.log-request-details")).isEqualTo(expected.toString());
+ }
+
+}
diff --git a/version.properties b/version.properties
index 7b8b963..00ef564 100644
--- a/version.properties
+++ b/version.properties
@@ -1,5 +1,5 @@
major=1
-minor=1
+minor=2
patch=0
base_version=${major}.${minor}.${patch}
release_version=${base_version}