Merge "Changes to Regex for Name and version Issue-ID: DCAEGEN2-1867"
[dcaegen2/platform.git] / mod / bpgenerator / onap / src / main / java / org / onap / blueprintgenerator / service / common / ExternalTlsInfoFactoryService.java
1 /*
2  *
3  *  * ============LICENSE_START=======================================================
4  *  *  org.onap.dcae
5  *  *  ================================================================================
6  *  *  Copyright (c) 2020  AT&T Intellectual Property. All rights reserved.
7  *  *  ================================================================================
8  *  *  Licensed under the Apache License, Version 2.0 (the "License");
9  *  *  you may not use this file except in compliance with the License.
10  *  *  You may obtain a copy of the License at
11  *  *
12  *  *       http://www.apache.org/licenses/LICENSE-2.0
13  *  *
14  *  *  Unless required by applicable law or agreed to in writing, software
15  *  *  distributed under the License is distributed on an "AS IS" BASIS,
16  *  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  *  *  See the License for the specific language governing permissions and
18  *  *  limitations under the License.
19  *  *  ============LICENSE_END=========================================================
20  *
21  *
22  */
23
24 package org.onap.blueprintgenerator.service.common;
25
26 import org.onap.blueprintgenerator.constants.Constants;
27 import org.onap.blueprintgenerator.model.common.ExternalTlsInfo;
28 import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec;
29 import org.onap.blueprintgenerator.service.base.BlueprintHelperService;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.stereotype.Service;
32
33 import java.util.HashMap;
34 import java.util.LinkedHashMap;
35 import java.util.Map;
36
37 /**
38  * @author : Ravi Mantena
39  * @date 10/16/2020
40  * Application: ONAP - Blueprint Generator
41  * Common ONAP Service used by ONAP and DMAAP Blueprint to add External TLS Info
42  */
43
44
45 @Service
46 public class ExternalTlsInfoFactoryService extends ExternalCertificateDataFactoryService {
47
48     @Autowired
49     private ExternalCertificateParametersFactoryService externalCertificateParametersFactoryService;
50
51     @Autowired
52     private BlueprintHelperService blueprintHelperService;
53
54     //Method to create External TLS Info from Component Spec
55     public ExternalTlsInfo createFromComponentSpec(OnapComponentSpec cs) {
56         ExternalTlsInfo externalTlsInfoBp = new ExternalTlsInfo();
57         Map<String, Object> tlsInfoCs = cs.getAuxilary().getTls_info();
58
59         externalTlsInfoBp.setExternalCertDirectory((String) tlsInfoCs.get(Constants.CERT_DIRECTORY_FIELD));
60         externalTlsInfoBp.setUseExternalTls(createPrefixedGetInput(Constants.USE_EXTERNAL_TLS_FIELD));
61         externalTlsInfoBp.setCaName(createPrefixedGetInput(Constants.CA_NAME_FIELD));
62         externalTlsInfoBp.setCertType(createPrefixedGetInput(Constants.CERT_TYPE_FIELD));
63         externalTlsInfoBp.setExternalCertificateParameters(externalCertificateParametersFactoryService.create());
64
65         return externalTlsInfoBp;
66     }
67
68     //Method to create Input List for External TLS Info from Component Spec
69     public Map<String, LinkedHashMap<String, Object>> createInputListFromComponentSpec(OnapComponentSpec cs) {
70
71         Map<String, LinkedHashMap<String, Object>> retInputs = new HashMap<>();
72
73         Map<String, Object> externalTlsInfoCs = cs.getAuxilary().getTls_info();
74         LinkedHashMap<String, Object> useTlsFlagInput = blueprintHelperService.createBooleanInput("Flag to indicate external tls enable/disable.",externalTlsInfoCs.get(Constants.USE_EXTERNAL_TLS_FIELD));
75         retInputs.put(addPrefix(Constants.USE_EXTERNAL_TLS_FIELD), useTlsFlagInput);
76
77         LinkedHashMap<String, Object> caNameInputMap = blueprintHelperService.createStringInput("Name of Certificate Authority configured on CertService side.",Constants.DEFAULT_CA);
78         retInputs.put(addPrefix(Constants.CA_NAME_FIELD), caNameInputMap);
79
80         LinkedHashMap<String, Object> certTypeInputMap = blueprintHelperService.createStringInput("Format of provided certificates",Constants.DEFAULT_CERT_TYPE);
81         retInputs.put(addPrefix(Constants.CERT_TYPE_FIELD), certTypeInputMap);
82
83         retInputs.putAll(externalCertificateParametersFactoryService.createInputList());
84         return retInputs;
85     }
86
87 }