机器管理密钥解绑接口
This commit is contained in:
parent
8189a825d3
commit
6b8165028e
@ -44,13 +44,20 @@ public class SecretKeyController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/bindingMachine")
|
@PutMapping("/bindingMachine")
|
||||||
@Operation(summary = "绑定机器") //todo解绑机器
|
@Operation(summary = "绑定机器")
|
||||||
// @PreAuthorize("@ss.hasPermission('ci:secretKey:binding')")
|
// @PreAuthorize("@ss.hasPermission('ci:secretKey:binding')")
|
||||||
public CommonResult<Boolean> bindingMachine(@Valid @RequestBody SecretKeyVO secretKeyVO) {
|
public CommonResult<Boolean> bindingMachine(@Valid @RequestBody SecretKeyVO secretKeyVO) {
|
||||||
secretKeyService.bindingMachine(secretKeyVO);
|
secretKeyService.bindingMachine(secretKeyVO);
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PutMapping("unbindMachine")
|
||||||
|
@Operation(summary = "解绑机器")
|
||||||
|
public CommonResult<Boolean> unbindMachine(@Valid @RequestBody SecretKeyVO secretKeyVO) {
|
||||||
|
secretKeyService.unbindMachine(secretKeyVO);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/getSecretKey")
|
@GetMapping("/getSecretKey")
|
||||||
@Operation(summary = "获取机器的环境变量")
|
@Operation(summary = "获取机器的环境变量")
|
||||||
public CommonResult<SecretKeyVO> getSecretKey(@RequestParam("id") Long id) {
|
public CommonResult<SecretKeyVO> getSecretKey(@RequestParam("id") Long id) {
|
||||||
@ -76,6 +83,4 @@ public class SecretKeyController {
|
|||||||
}
|
}
|
||||||
return success(BeanUtils.toBean(pageResult, SecretKeyVO.class));
|
return success(BeanUtils.toBean(pageResult, SecretKeyVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -35,13 +35,6 @@ public interface MachineInfoMapper extends BaseMapperX<MachineInfoDO> {
|
|||||||
this.update(null, wrapper);
|
this.update(null, wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
default void unBindingSecretKey(List<Long> secretKeyId) {
|
|
||||||
LambdaUpdateWrapper<MachineInfoDO> wrapper = new LambdaUpdateWrapper<MachineInfoDO>()
|
|
||||||
.set(MachineInfoDO::getSecretKeyId, null)
|
|
||||||
.in(MachineInfoDO::getSecretKeyId, secretKeyId);
|
|
||||||
this.update(null, wrapper);
|
|
||||||
}
|
|
||||||
|
|
||||||
default PageResult<MachineInfoDO> selectPage(MachineInfoVO machineInfoVO) {
|
default PageResult<MachineInfoDO> selectPage(MachineInfoVO machineInfoVO) {
|
||||||
LambdaQueryWrapperX<MachineInfoDO> machineInfoDOLambdaQueryWrapperX = new LambdaQueryWrapperX<MachineInfoDO>()
|
LambdaQueryWrapperX<MachineInfoDO> machineInfoDOLambdaQueryWrapperX = new LambdaQueryWrapperX<MachineInfoDO>()
|
||||||
.likeIfPresent(MachineInfoDO::getName, machineInfoVO.getName())
|
.likeIfPresent(MachineInfoDO::getName, machineInfoVO.getName())
|
||||||
|
@ -17,6 +17,8 @@ import java.util.Objects;
|
|||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
import static cd.casic.framework.commons.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
import static cd.casic.module.machine.contants.MachineErrorCodeConstants.*;
|
||||||
/**
|
/**
|
||||||
* 优化后的SSH连接会话类
|
* 优化后的SSH连接会话类
|
||||||
*/
|
*/
|
||||||
@ -57,7 +59,7 @@ public class ConnectionSession implements AutoCloseable {
|
|||||||
*/
|
*/
|
||||||
public synchronized void connect() throws JSchException {
|
public synchronized void connect() throws JSchException {
|
||||||
if (status == ConnectionStatus.CONNECTED) {
|
if (status == ConnectionStatus.CONNECTED) {
|
||||||
log.debug("Already connected to {}", machineInfo.getHostIp());
|
log.debug("已经连接到 {}", machineInfo.getHostIp());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +133,7 @@ public class ConnectionSession implements AutoCloseable {
|
|||||||
if (machineInfo.getAuthenticationType() == AuthenticationType.SECRET_KEY.getCode()) {
|
if (machineInfo.getAuthenticationType() == AuthenticationType.SECRET_KEY.getCode()) {
|
||||||
// 密钥认证
|
// 密钥认证
|
||||||
if (machineInfo.getSecretKeyId() == null) {
|
if (machineInfo.getSecretKeyId() == null) {
|
||||||
throw new JSchException("Secret key ID is required for key-based authentication");
|
throw exception(SECRET_KEY_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
String privateKeyContent = getPrivateKeyContent(machineInfo.getSecretKeyId());
|
String privateKeyContent = getPrivateKeyContent(machineInfo.getSecretKeyId());
|
||||||
|
@ -94,6 +94,4 @@ public interface MachineInfoService {
|
|||||||
* @return 操作结果
|
* @return 操作结果
|
||||||
*/
|
*/
|
||||||
boolean downloadFile(String sessionId, String remoteFilePath, String localFilePath);
|
boolean downloadFile(String sessionId, String remoteFilePath, String localFilePath);
|
||||||
|
|
||||||
void unBindingSecretKey(List<Long> SecretKeyIds);
|
|
||||||
}
|
}
|
||||||
|
@ -19,5 +19,7 @@ public interface SecretKeyService {
|
|||||||
void deleteSecretKeyList(List<Long> ids);
|
void deleteSecretKeyList(List<Long> ids);
|
||||||
|
|
||||||
SecretKeyVO getSecretKey(Long id);
|
SecretKeyVO getSecretKey(Long id);
|
||||||
|
|
||||||
|
void unbindMachine(@Valid SecretKeyVO secretKeyVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ import static cd.casic.module.machine.contants.MachineErrorCodeConstants.*;
|
|||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service("machineInfoService")
|
@Service("machineInfoService")
|
||||||
public class MachineinfoServiceImpl implements MachineInfoService {
|
public class MachineInfoServiceImpl implements MachineInfoService {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private SecretKeyService secretKeyService;
|
private SecretKeyService secretKeyService;
|
||||||
@ -281,11 +281,6 @@ public class MachineinfoServiceImpl implements MachineInfoService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void unBindingSecretKey(List<Long> SecretKeyIds) {
|
|
||||||
machineInfoMapper.unBindingSecretKey(SecretKeyIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void validateMachineEnvAdd(MachineInfoVO machineInfoVO) {
|
void validateMachineEnvAdd(MachineInfoVO machineInfoVO) {
|
||||||
if (machineInfoVO.getHostIp().isEmpty()) {
|
if (machineInfoVO.getHostIp().isEmpty()) {
|
@ -42,6 +42,11 @@ public class SecretKeyServiceImpl implements SecretKeyService {
|
|||||||
return BeanUtils.toBean(secretKeyDO, SecretKeyVO.class);
|
return BeanUtils.toBean(secretKeyDO, SecretKeyVO.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unbindMachine(SecretKeyVO secretKeyVO) {
|
||||||
|
machineInfoService.bindingSecretKey(secretKeyVO.getMachineInfoIds(),null);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long createSecretKey(SecretKeyVO secretKeyVO) {
|
public Long createSecretKey(SecretKeyVO secretKeyVO) {
|
||||||
validateSecretKeyAdd(secretKeyVO);
|
validateSecretKeyAdd(secretKeyVO);
|
||||||
@ -99,7 +104,7 @@ public class SecretKeyServiceImpl implements SecretKeyService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
//绑定的机器全部设置为空
|
//绑定的机器全部设置为空
|
||||||
machineInfoService.unBindingSecretKey(ids);
|
machineInfoService.bindingSecretKey(ids,null);
|
||||||
|
|
||||||
secretKeyMapper.deleteBatchIds(ids);
|
secretKeyMapper.deleteBatchIds(ids);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user