Change to CCSDK and ODL Carbon
[appc.git] / appc-config / appc-encryption-tool / provider / src / main / java / org / openecomp / appc / encryptiontool / wrapper / EncryptionToolDGWrapper.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property.  All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.appc.encryptiontool.wrapper;
22
23 import java.util.Map;
24
25 import org.apache.commons.configuration.PropertiesConfiguration;
26 import org.apache.commons.lang.StringUtils;
27
28 import com.att.eelf.configuration.EELFLogger;
29 import com.att.eelf.configuration.EELFManager;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
33
34 public class EncryptionToolDGWrapper implements SvcLogicJavaPlugin {
35
36     private static final EELFLogger log = EELFManager.getInstance().getLogger(EncryptionToolDGWrapper.class);
37
38     public void runEncryption(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException
39     {
40         String responsePrefix = inParams.get("prefix");
41         String userName = inParams.get("userName");
42         String password = inParams.get("password");
43         String vnf_type = inParams.get("vnf_type");
44
45         try{
46             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""  ;
47             if(StringUtils.isBlank(userName) || StringUtils.isBlank(password) || StringUtils.isBlank(vnf_type)){
48                 throw new Exception("username or Password is missing");
49             }
50
51             String [] input = new String[] {vnf_type,userName,password};
52             WrapperEncryptionTool.main(input);
53         }
54         catch (Exception e)
55         {
56             throw new SvcLogicException(e.getMessage());
57         }
58
59     }
60     public void getProperty(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException
61     {
62         String responsePrefix = inParams.get("prefix");
63         String propertyName = inParams.get("propertyName");
64
65         try{
66             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : ""  ;
67             PropertiesConfiguration conf = new PropertiesConfiguration(Constants.APPC_CONFIG_DIR + "/appc_southbound.properties");
68             conf.setBasePath(null);
69             EncryptionTool et = EncryptionTool.getInstance();
70
71             ctx.setAttribute(responsePrefix + "propertyName", et.decrypt(conf.getProperty(propertyName).toString()));
72         }
73         catch (Exception e) {
74             ctx.setAttribute(responsePrefix + "status", "failure");
75             ctx.setAttribute(responsePrefix + "error-message", e.getMessage());
76             e.printStackTrace();
77             throw new SvcLogicException(e.getMessage());
78         }
79     }
80 }