本文介绍了用户如何通过API方式进行固件安全检测、检测任务管理。

准备工作:

引入依赖包

在您的项目中集成SDK,下载FSS OpenAPI SDK,将src/main/java/com/aliyuncs/fss_api文件夹拷贝到您项目中的对应位置。

引入以下包:
<dependency>
  <groupId>com.aliyun</groupId>
  <artifactId>aliyun-java-sdk-core</artifactId>
  <version>[version]</version>
</dependency>

创建接口调用客户端实例

String regionId ="cn-shanghai";
String domain = "fssapi.cn-shanghai.aliyuncs.com";
String akId = "";//您账号的AccessKeyId
String akSecret = "";//您账号的AccessKeySecret
DefaultProfile.addEndpoint(regionId, "Fss-api", domain);
DefaultProfile profile = DefaultProfile.getProfile(regionId, akId, akSecret);
iAcsClient = DefaultAcsClient(profile);

创建检测任务

CreateScanTaskRequest createScanTaskRequest = new CreateScanTaskRequest();
createScanTaskRequest.setEmail("<your email address>");//邮箱地址用于接收任务检测完成通知
createScanTaskRequest.setFwId("test-fwId");
createScanTaskRequest.setFwName("固件名称");
createScanTaskRequest.setFwVersion("1.0.0");
createScanTaskRequest.setFwUrl("固件的OSS链接地址");
CreateScanTaskResponse cResponse = iAcsClient.getAcsResponse(createScanTaskRequest);
System.out.println("TaskId:"+ cResponse.getData().getTaskId());
System.out.println("Code:"+ cResponse.getCode());
System.out.println("Message:"+ cResponse.getMessage());
说明 OSS文件的权限应允许:读。

查询任务检测状态

QueryTaskStatusRequest queryTaskStatusRequest = new QueryTaskStatusRequest();
queryTaskStatusRequest.setTaskId("<taskId>");//创建检测任务时,返回的任务ID
QueryTaskStatusResponse response = iAcsClient.getAcsResponse(queryTaskStatusRequest);
System.out.println("code:"+response.getCode());
System.out.println("description:"+response.getData().getDescription());
System.out.println("scannedRate:"+response.getData().getScannedRate());
System.out.println("ScanStatus:"+response.getData().getScanStatus());

查询任务检测结果

QueryTaskReportRequest queryTaskReportRequest = new QueryTaskReportRequest();
queryTaskReportRequest.setTaskId("<taskId>");//创建检测任务时,返回的任务ID
QueryTaskReportResponse qtResponse = iAcsClient.getAcsResponse(queryTaskReportRequest);
System.out.println("reportJson:"+qtResponse.getData().getReportJson());
System.out.println("reportUrl:"+qtResponse.getData().getReportUrl());

删除任务

DeleteScanTaskRequest deleteScanTaskRequest = new DeleteScanTaskRequest();
deleteScanTaskRequest.setTaskId("<taskId>");//创建检测任务时,返回的任务ID
DeleteScanTaskResponse dResponse = iAcsClient.getAcsResponse(deleteScanTaskRequest);
System.out.println("删除任务:"+dResponse.getCode()+":"+dResponse.getMessage());

查询主账号授权

QueryLicenseRequest queryLicenseRequest = new QueryLicenseRequest();
QueryLicenseResponse qlrResponse = iAcsClient.getAcsResponse(queryLicenseRequest);
System.out.println("MaxCount:"+qlrResponse.getData().getMaxCount());
System.out.println("UsedCount:"+qlrResponse.getData().getUsedCount());
System.out.println("scanningCount:" + qlrResponse.getData().getScanningCount());