2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.ccsdk.sli.adaptors.saltstack.impl;
27 import java.io.IOException;
28 import java.security.KeyManagementException;
29 import java.security.KeyStoreException;
30 import java.security.NoSuchAlgorithmException;
31 import java.security.cert.CertificateException;
32 import org.onap.ccsdk.sli.adaptors.saltstack.model.SaltstackResult;
33 import org.onap.ccsdk.sli.adaptors.saltstack.model.SaltstackResultCodes;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
35 import com.att.eelf.configuration.EELFLogger;
36 import com.att.eelf.configuration.EELFManager;
39 * Returns a custom SSH client
41 * - can create one with ssl using an X509 certificate that does NOT have a known CA
42 * - create one which trusts ALL SSL certificates
43 * - return default sshclient (which only trusts known CAs from default cacerts file for process) this is the default
46 //TODO: This class is to be altered completely based on the SALTSTACK server communication.
47 public class ConnectionBuilder {
49 private static final EELFLogger logger = EELFManager.getInstance().getLogger(ConnectionBuilder.class);
53 * Constructor that initializes an ssh client based on certificate
55 public ConnectionBuilder(String userName, String userPasswd) throws KeyStoreException, CertificateException, IOException,
56 KeyManagementException, NoSuchAlgorithmException, SvcLogicException {
62 * Constructor which trusts all certificates in a specific java keystore file (assumes a JKS
65 public ConnectionBuilder(String certFile) throws KeyStoreException, IOException,
66 KeyManagementException, NoSuchAlgorithmException, CertificateException {
71 * Connect to SSH server.
73 public SaltstackResult connect(String agentUrl, String payload) {
75 SaltstackResult result = new SaltstackResult();
77 //TODO: to implement SSH connected client to Saltstack Server
78 } catch (Exception io) {
79 logger.error("Caught Exception", io);
80 result.setStatusCode(SaltstackResultCodes.IO_EXCEPTION.getValue());
81 result.setStatusMessage(io.getMessage());
87 * Disconnect from SSH server.
89 public SaltstackResult disConnect(){
91 SaltstackResult result = new SaltstackResult();
93 //TODO: to implement SSH connected client to Saltstack Server
94 } catch (Exception io) {
95 logger.error("Caught Exception", io);
96 result.setStatusCode(SaltstackResultCodes.IO_EXCEPTION.getValue());
97 result.setStatusMessage(io.getMessage());
103 * Exec remote command over SSH. Return command execution status.
104 * Command output is written to out or err stream.
106 * @param cmd command to execute
107 * @param out content of sysout will go to this stream
108 * @param err content of syserr will go to this stream
109 * @return command execution status
111 public SaltstackResult execute(String cmd) {
113 SaltstackResult result = new SaltstackResult();
116 //TODO: to implement SSH command execute
117 } catch (Exception io) {
118 result.setStatusCode(SaltstackResultCodes.IO_EXCEPTION.getValue());
119 result.setStatusMessage(io.getMessage());
120 logger.error("Caught IOException", io);