diff options
author | Remigiusz Janeczek <remigiusz.janeczek@nokia.com> | 2021-03-16 16:00:26 +0100 |
---|---|---|
committer | Remigiusz Janeczek <remigiusz.janeczek@nokia.com> | 2021-03-17 12:07:37 +0100 |
commit | e0437a4237c99a16955d5ec56ff5fe9996c76b57 (patch) | |
tree | e069f513aae60fcc4636dd80978ce477c9ed47a7 /src/main/java/org/onap/sdc/helmvalidator/helm/versions/SupportedVersionsProvider.java | |
parent | 919ae37310243f676eafee0ebf01c9d64ee5b925 (diff) |
Add helm validator sources
Issue-ID: SDC-3185
Signed-off-by: Remigiusz Janeczek <remigiusz.janeczek@nokia.com>
Change-Id: I32dea3b4294a90c4dfc75864fb4200f044e7a0b6
Diffstat (limited to 'src/main/java/org/onap/sdc/helmvalidator/helm/versions/SupportedVersionsProvider.java')
-rw-r--r-- | src/main/java/org/onap/sdc/helmvalidator/helm/versions/SupportedVersionsProvider.java | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/main/java/org/onap/sdc/helmvalidator/helm/versions/SupportedVersionsProvider.java b/src/main/java/org/onap/sdc/helmvalidator/helm/versions/SupportedVersionsProvider.java new file mode 100644 index 0000000..ff1cdde --- /dev/null +++ b/src/main/java/org/onap/sdc/helmvalidator/helm/versions/SupportedVersionsProvider.java @@ -0,0 +1,65 @@ +/* + * ============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.helm.versions; + +import java.util.Comparator; +import java.util.List; +import java.util.function.Predicate; +import java.util.stream.Collectors; +import org.onap.sdc.helmvalidator.helm.validation.exception.NotSupportedVersionException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class SupportedVersionsProvider { + + private final SystemEnvVersionsReader versionsReader; + + @Autowired + public SupportedVersionsProvider(SystemEnvVersionsReader versionsReader) { + this.versionsReader = versionsReader; + } + + /** + * Retrieves list of available Helm client versions. + * + * @return list of available Helm client versions + */ + public List<String> getVersions() { + return versionsReader.readVersions().stream() + .filter(Predicate.not(String::isBlank)) + .sorted(Comparator.reverseOrder()) + .collect(Collectors.toList()); + } + + /** + * Retrieves latest available Helm client with given major version. + * + * @param helmMajorVersion major version of Helm client + * @return latest available Helm client with given major version + */ + public String getLatestVersion(String helmMajorVersion) { + return getVersions().stream() + .filter(supportedVersion -> supportedVersion.startsWith(helmMajorVersion + ".")) + .findFirst() + .orElseThrow(() -> new NotSupportedVersionException(helmMajorVersion)); + } +} |