Skip to content

Commit

Permalink
Report bdio header upload operation
Browse files Browse the repository at this point in the history
  • Loading branch information
niravrsynopsys committed Oct 5, 2023
1 parent 7b44e85 commit a9924af
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ public UUID initiateStatelessBdbaScan(BlackDuckRunData blackDuckRunData) throws
);
}

return uploadBdioHeaderToInitiateScan(blackDuckRunData, bdioHeader);
String uploadHeaderOperationName = "Upload BDIO Header to Initiate Scan";
return uploadBdioHeaderToInitiateScan(blackDuckRunData, bdioHeader, uploadHeaderOperationName);
});
}

Expand Down Expand Up @@ -473,22 +474,24 @@ public Response uploadJsonToStorageService(BlackDuckRunData blackDuckRunData, St
});
}

public UUID uploadBdioHeaderToInitiateScan(BlackDuckRunData blackDuckRunData, File bdioHeaderFile) throws IntegrationException {
BlackDuckServicesFactory blackDuckServicesFactory = blackDuckRunData.getBlackDuckServicesFactory();
BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
public UUID uploadBdioHeaderToInitiateScan(BlackDuckRunData blackDuckRunData, File bdioHeaderFile, String operationName) throws OperationException {
return auditLog.namedInternal(operationName, () -> {
BlackDuckServicesFactory blackDuckServicesFactory = blackDuckRunData.getBlackDuckServicesFactory();
BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();

String scanServicePostEndpoint = getScanServicePostEndpoint();
HttpUrl postUrl = blackDuckRunData.getBlackDuckServerConfig().getBlackDuckUrl().appendRelativeUrl(scanServicePostEndpoint);
String scanServicePostEndpoint = getScanServicePostEndpoint();
HttpUrl postUrl = blackDuckRunData.getBlackDuckServerConfig().getBlackDuckUrl().appendRelativeUrl(scanServicePostEndpoint);

String scanServicePostContentType = getScanServicePostContentType();
BlackDuckResponseRequest buildBlackDuckResponseRequest = new BlackDuckRequestBuilder()
.postFile(bdioHeaderFile, ContentType.create(scanServicePostContentType))
.buildBlackDuckResponseRequest(postUrl);
String scanServicePostContentType = getScanServicePostContentType();
BlackDuckResponseRequest buildBlackDuckResponseRequest = new BlackDuckRequestBuilder()
.postFile(bdioHeaderFile, ContentType.create(scanServicePostContentType))
.buildBlackDuckResponseRequest(postUrl);

HttpUrl responseUrl = blackDuckApiClient.executePostRequestAndRetrieveURL(buildBlackDuckResponseRequest);
String path = responseUrl.uri().getPath();
HttpUrl responseUrl = blackDuckApiClient.executePostRequestAndRetrieveURL(buildBlackDuckResponseRequest);
String path = responseUrl.uri().getPath();

return UUID.fromString(path.substring(path.lastIndexOf('/') + 1));
return UUID.fromString(path.substring(path.lastIndexOf('/') + 1));
});
}

public void uploadBdioEntries(BlackDuckRunData blackDuckRunData, UUID bdScanId) throws IntegrationException, IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,16 @@ private String getContainerScanCodeLocationName() {
return codeLocationNameManager.createContainerScanCodeLocationName(containerImage, projectNameVersion.getName(), projectNameVersion.getVersion());
}

public void initiateScan() throws IOException, IntegrationException {
public void initiateScan() throws IOException, IntegrationException, OperationException {
DetectProtobufBdioHeaderUtil detectProtobufBdioHeaderUtil = new DetectProtobufBdioHeaderUtil(
UUID.randomUUID().toString(),
"CONTAINER",
projectNameVersion,
projectGroupName,
getContainerScanCodeLocationName());
File bdioHeaderFile = detectProtobufBdioHeaderUtil.createProtobufBdioHeader(binaryRunDirectory);
scanId = operationRunner.uploadBdioHeaderToInitiateScan(blackDuckRunData, bdioHeaderFile);
String operationName = "Upload Container Scan BDIO Header to Initiate Scan";
scanId = operationRunner.uploadBdioHeaderToInitiateScan(blackDuckRunData, bdioHeaderFile, operationName);
if (scanId == null) {
logger.warn("Scan ID was not found in the response from the server.");
throw new IntegrationException("Scan ID was not found in the response from the server.");
Expand Down

0 comments on commit a9924af

Please sign in to comment.