Compare commits

..

No commits in common. "fd94a43f9ccdf028418668b48bf61a1a90ec00a6" and "27c5da846e5e081dbad15bf527232ba8431d66e4" have entirely different histories.

4 changed files with 20 additions and 34 deletions

View File

@ -58,11 +58,6 @@
<artifactId>winrm4j</artifactId> <artifactId>winrm4j</artifactId>
<version>0.12.0</version> <!-- 最新稳定版 --> <version>0.12.0</version> <!-- 最新稳定版 -->
</dependency> </dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.2.1</version> <!-- 建议使用最新稳定版本 -->
</dependency>
</dependencies> </dependencies>

View File

@ -62,7 +62,6 @@ public class DIYImageExecuteCommandWorker extends SshWorker {
); );
} catch (Exception e) { } catch (Exception e) {
String errorMessage = "该节点配置信息为空,请先配置该节点信息" + "\r\n"; String errorMessage = "该节点配置信息为空,请先配置该节点信息" + "\r\n";
log.error("执行ssh失败:",e);
// errorHandle(e, errorMessage); // errorHandle(e, errorMessage);
} }
if (statusCode == 0) { if (statusCode == 0) {

View File

@ -1,13 +1,10 @@
package cd.casic.ci.process.engine.worker; package cd.casic.ci.process.engine.worker;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.hc.client5.http.impl.classic.HttpClients; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder; import org.apache.http.impl.client.HttpClients;
import org.apache.hc.client5.http.ssl.NoopHostnameVerifier; import org.apache.http.ssl.SSLContextBuilder;
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactoryBuilder;
import org.apache.hc.core5.ssl.SSLContextBuilder;
import org.apache.hc.core5.ssl.TrustStrategy;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
@ -15,7 +12,6 @@ import javax.net.ssl.SSLContext;
import java.security.KeyManagementException; import java.security.KeyManagementException;
import java.security.KeyStoreException; import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
/** /**
* @author HopeLi * @author HopeLi
@ -25,27 +21,23 @@ import java.security.cert.X509Certificate;
* @Description: * @Description:
*/ */
public abstract class HttpWorker extends BaseWorker{ public abstract class HttpWorker extends BaseWorker{
public static RestTemplate getRestTemplateWithoutSANCheck() throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, KeyStoreException { public static RestTemplate getRestTemplateWithoutSANCheck() throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException {
// 创建信任所有证书的SSL上下文 // 创建一个信任所有证书的 SSL 上下文
SSLContext sslContext = SSLContextBuilder.create() SSLContext sslContext = new SSLContextBuilder()
.loadTrustMaterial(null, (TrustStrategy) (chain, authType) -> true) .loadTrustMaterial(null, new TrustSelfSignedStrategy())
.build(); .build();
// 配置连接工厂 // 创建一个不验证主机名的主机名验证器
CloseableHttpClient httpClient = HttpClients.custom() CloseableHttpClient httpClient = HttpClients.custom()
.setConnectionManager( .setSSLContext(sslContext)
PoolingHttpClientConnectionManagerBuilder.create() .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
.setSSLSocketFactory(SSLConnectionSocketFactoryBuilder.create()
.setSslContext(sslContext)
.setHostnameVerifier(NoopHostnameVerifier.INSTANCE)
.build())
.build())
.build(); .build();
// 创建RestTemplate // 创建一个自定义的请求工厂
HttpComponentsClientHttpRequestFactory factory = HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
new HttpComponentsClientHttpRequestFactory(httpClient); requestFactory.setHttpClient(httpClient);
return new RestTemplate(factory);
return new RestTemplate(requestFactory);
} }
public static void main(String[] args) { public static void main(String[] args) {

View File

@ -41,7 +41,7 @@ import java.util.*;
*/ */
@Slf4j @Slf4j
@Plugin(taskType = "ScaSbom") @Plugin(taskType = "ScaSbom")
public class ScaSbomWorker extends HttpWorker{ public class ScaSbomWorker extends BaseWorker{
private static final int POLLING_INTERVAL = 5000; // 轮询间隔单位毫秒 private static final int POLLING_INTERVAL = 5000; // 轮询间隔单位毫秒
private static final int MAX_POLLING_TIMES = 100; // 最大退出次数 private static final int MAX_POLLING_TIMES = 100; // 最大退出次数
@ -78,7 +78,7 @@ public class ScaSbomWorker extends HttpWorker{
PipPipeline pipeline = pipelineService.getById(pipelineId); PipPipeline pipeline = pipelineService.getById(pipelineId);
//根据目标id查询目标信息 //根据目标id查询目标信息
if (StringUtils.isEmpty(pipeline.getTargetVersionId())){ if (StringUtils.isEmpty(pipeline.getTargetVersionId())){
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"目标文件不存在"); throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"目标文件不存在")
} }
TargetVersion targetVersion = targetVersionService.getById(pipeline.getTargetVersionId()); TargetVersion targetVersion = targetVersionService.getById(pipeline.getTargetVersionId());
filePath = targetVersion.getFilePath(); filePath = targetVersion.getFilePath();
@ -95,7 +95,7 @@ public class ScaSbomWorker extends HttpWorker{
handleUpload(workerParam, contextDef, pipTask.getTaskProperties(), file); handleUpload(workerParam, contextDef, pipTask.getTaskProperties(), file);
}catch (Exception e){ }catch (Exception e){
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"SCA-SBOM节点执行失败"); throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"SCA-SBOM节点执行失败")
} }
} }