2 * # ============LICENSE_START=======================================================
3 * # Copyright (c) 2021 AT&T Intellectual Property. All rights reserved.
4 * # ================================================================================
5 * # Licensed under the Apache License, Version 2.0 (the "License");
6 * # you may not use this file except in compliance with the License.
7 * # You may obtain a copy of the License at
9 * # http://www.apache.org/licenses/LICENSE-2.0
11 * # Unless required by applicable law or agreed to in writing, software
12 * # distributed under the License is distributed on an "AS IS" BASIS,
13 * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * # See the License for the specific language governing permissions and
15 * # limitations under the License.
16 * # ============LICENSE_END=========================================================
19 package org.onap.dcaegen2.platform.helmchartgenerator.validation;
21 import org.springframework.stereotype.Component;
23 import java.nio.file.Files;
24 import java.nio.file.Path;
25 import java.nio.file.Paths;
28 * A class to validate structure of the base helm directory
31 public class ChartTemplateStructureValidatorImpl implements ChartTemplateStructureValidator {
34 * validates base helm chart directory and throws error if the structure is not proper.
35 * @param chartTemplateLocation base helm chart dir location
38 public void validateChartTemplateStructure(String chartTemplateLocation) {
39 checkBaseDirectory(chartTemplateLocation);
42 private void checkBaseDirectory(String chartTemplateLocation) {
43 Path base = Paths.get(chartTemplateLocation, "base");
44 Path templates = Paths.get(chartTemplateLocation, "base/templates");
45 Path chart = Paths.get(chartTemplateLocation, "base/Chart.yaml");
46 Path values = Paths.get(chartTemplateLocation, "base/values.yaml");
47 if(!Files.exists(base)){
48 throw new RuntimeException("base directory not found in chart template location");
50 if(!Files.exists(templates)){
51 throw new RuntimeException("templates directory not found in base directory");
53 if(!Files.exists(chart)){
54 throw new RuntimeException("chart.yaml not found in base directory");
56 if(!Files.exists(values)){
57 throw new RuntimeException("values.yaml not found in base directory");