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