Sono disponibili altri esempi AWS SDK nel repository AWS Doc SDK Examples. GitHub
Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.
Utilizzare BatchGetFindingDetails con un AWS SDK
Il seguente esempio di codice mostra come utilizzareBatchGetFindingDetails.
Gli esempi di operazioni sono estratti di codice da programmi più grandi e devono essere eseguiti nel contesto. È possibile visualizzare questa operazione nel contesto nel seguente esempio di codice:
- Java
-
- SDK per Java 2.x
-
/**
* Retrieves detailed information about a specific AWS Inspector2 finding asynchronously.
*
* @param findingArn The ARN of the finding to look up.
* @return A {@link CompletableFuture} that, when completed, provides a formatted string
* containing all available details for the finding.
* @throws RuntimeException if the async call to Inspector2 fails.
*/
public CompletableFuture<String> getFindingDetailsAsync(String findingArn) {
BatchGetFindingDetailsRequest request = BatchGetFindingDetailsRequest.builder()
.findingArns(findingArn)
.build();
return getAsyncClient().batchGetFindingDetails(request)
.thenApply(response -> {
if (response.findingDetails() == null || response.findingDetails().isEmpty()) {
return String.format("No details found for ARN: ", findingArn);
}
StringBuilder sb = new StringBuilder();
response.findingDetails().forEach(detail -> {
sb.append("Finding ARN: ").append(detail.findingArn()).append("\n")
.append("Risk Score: ").append(detail.riskScore()).append("\n");
// ExploitObserved timings
if (detail.exploitObserved() != null) {
sb.append("Exploit First Seen: ").append(detail.exploitObserved().firstSeen()).append("\n")
.append("Exploit Last Seen: ").append(detail.exploitObserved().lastSeen()).append("\n");
}
// Reference URLs
if (detail.hasReferenceUrls()) {
sb.append("Reference URLs:\n");
detail.referenceUrls().forEach(url -> sb.append(" • ").append(url).append("\n"));
}
// Tools
if (detail.hasTools()) {
sb.append("Tools:\n");
detail.tools().forEach(tool -> sb.append(" • ").append(tool).append("\n"));
}
// TTPs
if (detail.hasTtps()) {
sb.append("TTPs:\n");
detail.ttps().forEach(ttp -> sb.append(" • ").append(ttp).append("\n"));
}
// CWEs
if (detail.hasCwes()) {
sb.append("CWEs:\n");
detail.cwes().forEach(cwe -> sb.append(" • ").append(cwe).append("\n"));
}
// Evidence
if (detail.hasEvidences()) {
sb.append("Evidence:\n");
detail.evidences().forEach(ev -> {
sb.append(" - Severity: ").append(ev.severity()).append("\n");
});
}
sb.append("\n");
});
return sb.toString();
})
.exceptionally(ex -> {
Throwable cause = ex.getCause() != null ? ex.getCause() : ex;
if (cause instanceof ResourceNotFoundException rnfe) {
return "Finding not found: %s".formatted(findingArn);
}
// Fallback for other exceptions
throw new RuntimeException("Failed to get finding details for ARN: " + findingArn, cause);
});
}