use of io.bastillion.manage.model.HostSystem in project KeyBox by skavanagh.
the class SystemDB method getSystem.
/**
* returns system by id
*
* @param id system id
* @return system
*/
public static HostSystem getSystem(Long id) throws SQLException, GeneralSecurityException {
Connection con = DBUtils.getConn();
HostSystem hostSystem = getSystem(con, id);
DBUtils.closeConn(con);
return hostSystem;
}
use of io.bastillion.manage.model.HostSystem in project KeyBox by skavanagh.
the class SystemDB method getSystemSet.
/**
* method to do order by based on the sorted set object for systems
*
* @param sortedSet sorted set object
* @return sortedSet with list of host systems
*/
public static SortedSet getSystemSet(SortedSet sortedSet) throws SQLException, GeneralSecurityException {
List<HostSystem> hostSystemList = new ArrayList<>();
String orderBy = "";
if (sortedSet.getOrderByField() != null && !sortedSet.getOrderByField().trim().equals("")) {
orderBy = "order by " + sortedSet.getOrderByField() + " " + sortedSet.getOrderByDirection();
}
String sql = "select * from system s ";
// if profile id exists add to statement
sql += StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_PROFILE_ID)) ? ",system_map m where s.id=m.system_id and m.profile_id=? " : "";
sql += orderBy;
Connection con = DBUtils.getConn();
PreparedStatement stmt = con.prepareStatement(sql);
if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_PROFILE_ID))) {
stmt.setLong(1, Long.parseLong(sortedSet.getFilterMap().get(FILTER_BY_PROFILE_ID)));
}
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
HostSystem hostSystem = new HostSystem();
hostSystem.setId(rs.getLong("id"));
hostSystem.setDisplayNm(rs.getString(DISPLAY_NM));
hostSystem.setUser(rs.getString("username"));
hostSystem.setHost(rs.getString("host"));
hostSystem.setPort(rs.getInt("port"));
hostSystem.setAuthorizedKeys(rs.getString(AUTHORIZED_KEYS));
hostSystem.setStatusCd(rs.getString(STATUS_CD));
hostSystemList.add(hostSystem);
}
DBUtils.closeRs(rs);
DBUtils.closeStmt(stmt);
DBUtils.closeConn(con);
sortedSet.setItemList(hostSystemList);
return sortedSet;
}
use of io.bastillion.manage.model.HostSystem in project KeyBox by skavanagh.
the class SystemDB method getSystem.
/**
* returns system by id
*
* @param con DB connection
* @param id system id
* @return system
*/
public static HostSystem getSystem(Connection con, Long id) throws SQLException {
HostSystem hostSystem = null;
PreparedStatement stmt = con.prepareStatement("select * from system where id=?");
stmt.setLong(1, id);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
hostSystem = new HostSystem();
hostSystem.setId(rs.getLong("id"));
hostSystem.setDisplayNm(rs.getString(DISPLAY_NM));
hostSystem.setUser(rs.getString("username"));
hostSystem.setHost(rs.getString("host"));
hostSystem.setPort(rs.getInt("port"));
hostSystem.setAuthorizedKeys(rs.getString(AUTHORIZED_KEYS));
hostSystem.setStatusCd(rs.getString(STATUS_CD));
}
DBUtils.closeRs(rs);
DBUtils.closeStmt(stmt);
return hostSystem;
}
use of io.bastillion.manage.model.HostSystem in project KeyBox by skavanagh.
the class SSHUtil method distributePubKeysToAllSystems.
/**
* distributes public keys to all systems
*/
public static void distributePubKeysToAllSystems() throws SQLException, GeneralSecurityException {
if (keyManagementEnabled) {
List<HostSystem> hostSystemList = SystemDB.getAllSystems();
for (HostSystem hostSystem : hostSystemList) {
hostSystem = SSHUtil.authAndAddPubKey(hostSystem, null, null);
SystemDB.updateSystem(hostSystem);
}
}
}
Aggregations