Helm-generator - seedcode delivery for helm chart generation tool from component...
[dcaegen2/platform.git] / mod2 / helm-generator / helmchartgenerator-core / src / main / java / org / onap / dcaegen2 / platform / helmchartgenerator / validation / ChartTemplateStructureValidator.java
1 /*
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
8  * #
9  * #      http://www.apache.org/licenses/LICENSE-2.0
10  * #
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=========================================================
17  */
18
19 package org.onap.dcaegen2.platform.helmchartgenerator.validation;
20
21 import java.nio.file.Files;
22 import java.nio.file.Path;
23 import java.nio.file.Paths;
24
25 /**
26  * A class to validate structure of the base helm directory
27  */
28 public class ChartTemplateStructureValidator {
29
30     /**
31      * validates base helm chart directory and throws error if the structure is not proper.
32      * @param chartTemplateLocation base helm chart dir location
33      */
34     public static void validateChartTemplateStructure(String chartTemplateLocation) {
35         checkBaseDirectory(chartTemplateLocation);
36     }
37
38     private static void checkBaseDirectory(String chartTemplateLocation) {
39         Path base = Paths.get(chartTemplateLocation, "base");
40         Path charts = Paths.get(chartTemplateLocation, "base/charts");
41         Path templates = Paths.get(chartTemplateLocation, "base/templates");
42         Path chart = Paths.get(chartTemplateLocation, "base/Chart.yaml");
43         Path values = Paths.get(chartTemplateLocation, "base/values.yaml");
44         if(!Files.exists(base)){
45             throw new RuntimeException("base directory not found in chart template location");
46         }
47         if(!Files.exists(charts)){
48             throw new RuntimeException("charts directory not found in base directory");
49         }
50         if(!Files.exists(templates)){
51             throw new RuntimeException("templates directory not found in base directory");
52         }
53         if(!Files.exists(chart)){
54             throw new RuntimeException("chart.yaml not found in base directory");
55         }
56         if(!Files.exists(values)){
57             throw new RuntimeException("values.yaml not found in base directory");
58         }
59     }
60 }