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.chartbuilder;
21 import lombok.extern.slf4j.Slf4j;
22 import org.apache.commons.io.FileUtils;
23 import org.onap.dcaegen2.platform.helmchartgenerator.Utils;
24 import org.onap.dcaegen2.platform.helmchartgenerator.models.componentspec.base.ComponentSpec;
25 import org.onap.dcaegen2.platform.helmchartgenerator.models.componentspec.common.TlsInfo;
26 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.stereotype.Component;
30 import java.io.IOException;
31 import java.nio.file.Files;
32 import java.nio.file.Path;
33 import java.nio.file.Paths;
36 * manages addOn template files
40 public class AddOnsManager {
42 public AddOnsManager(Utils utils) {
50 * include addons template files based on parameters in componentSpec file
51 * @param specFileLocation spec file location
52 * @param chart chart directory
53 * @param chartTemplateLocation chart template location
55 public void includeAddons(String specFileLocation, File chart, String chartTemplateLocation) {
56 if(externalTlsExists(specFileLocation)){
57 includeCertificateYamlAddOn(chart, chartTemplateLocation);
61 private void includeCertificateYamlAddOn(File chart, String chartTemplateLocation) {
62 Path certificateYaml = Paths.get(chartTemplateLocation, "addons/templates/certificates.yaml");
63 if(!Files.exists(certificateYaml)) {
64 throw new RuntimeException("certificates.yaml not found under templates directory in addons");
67 File templates = new File(chart, "templates");
68 FileUtils.copyFileToDirectory(certificateYaml.toFile(), templates);
69 } catch (IOException e) {
70 log.error(e.getMessage(), e);
71 throw new RuntimeException("could not add certificates.yaml to templates directory");
75 private boolean externalTlsExists(String specFileLocation) {
76 ComponentSpec cs = utils.deserializeJsonFileToModel(specFileLocation, ComponentSpec.class);
77 TlsInfo tlsInfo = cs.getAuxilary().getTlsInfo();
78 return tlsInfo != null && tlsInfo.getUseExternalTls() != null && tlsInfo.getUseExternalTls();