D'autres exemples de AWS SDK sont disponibles dans le référentiel AWS Doc SDK Examples GitHub .
Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.
Utilisation BatchGetFindingDetails avec un AWS SDK
L'exemple de code suivant montre comment utiliserBatchGetFindingDetails.
Les exemples d’actions sont des extraits de code de programmes de plus grande envergure et doivent être exécutés en contexte. Vous pouvez voir cette action en contexte dans l’exemple de code suivant :
- Java
-
- SDK pour 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);
});
}