Skip to content

Conversation

@scmacdon
Copy link
Contributor

This pull request adds Javas V2 Inspector examples


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@scmacdon scmacdon self-assigned this Nov 24, 2025
@scmacdon scmacdon added Java-v1 This issue relates to the AWS SDK for Java V1 Basics A basic code example showing the core actions for a particular service. labels Nov 24, 2025
@github-actions github-actions bot added Java-v2 This issue relates to the AWS SDK for Java V2 and removed Java-v1 This issue relates to the AWS SDK for Java V1 labels Nov 24, 2025
@scmacdon scmacdon changed the title Javas V2 Add Inspector examples Java V2 Add Inspector examples Nov 24, 2025
Copy link
Contributor

@debora-ito debora-ito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just left one comment, looks good otherwise.

@scmacdon scmacdon requested a review from tejasgn1 December 4, 2025 15:03
## Scenario

The Hello example is a separate runnable example. - Set up the Inspector service client - Check the current account status for Inspector - Display available scan types and regions
This scenario demonstrates the basic usage of **Amazon Inspector** using a Java program. It focuses on checking account status, enabling Inspector, listing findings, reviewing coverage, and managing filters.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The specification shouldn't mention a particular SDK, it should be generic for all SDKs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

* Display final account status
### Notes

* The program **does not retrieve detailed vulnerability (CVE) information**.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do these notes mean? Why are we specifying features that are not in the example?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

|`ListCoverage` |ValidationException |Validate filter and pagination parameters. |
|`Disable` |ValidationException |Validate resource types for disabling. |
|`Disable` |ConflictException |Handle cases where Inspector cannot be disabled. |
The Java SDK examples include basic exception handling for each Inspector action. The table below describes the exceptions actually handled in the program for each action.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mentions Java again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


| Action | Exception | Handling |
|-------------------------------|---------------------------|--------------------------------------------------------------------------|
| `Enable` | `ValidationException` | Prints a message indicating Inspector may already be enabled. |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The table should only include one specific exception for each action, not the more generic Inspector2Exception (which also looks like a Java class).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

| `ListCoverageStatistics` | `Exception` | Wraps and throws a `RuntimeException` for unexpected errors. |
| `ListUsageTotals` | `ValidationException` | Prints validation error details. |
| `ListUsageTotals` | `Inspector2Exception` | Prints AWS service error details and rethrows the exception. |
| `ListUsageTotals` | `Exception` | Wraps and throws a `RuntimeException` for unexpected errors. |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this action even used? I don't see it in the metadata.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both operations are in metadata - ListCoverageStatistics and ListUsageTotals

System.out.println("Step 2: Ensuring Inspector is enabled...");

try {
inspectorActions.enableInspector(inspectorClient, null);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a try and a catch in each of the inspectorAction methods, so why do we need an additional try/catch here? Shouldn't there be one try/catch around the scenario with a cleanup in the catch? This applies to all the steps in the scenario.

inspectorActions.getAccountStatus(inspectorClient);

} catch (Exception e) {
System.err.println(" Could not create example filter: " + e.getMessage());
Copy link
Collaborator

@rlhagerm rlhagerm Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These error messages don't match the actions called? Seems to be the same error message (copy/paste?) for all the actions. But I'm not sure they are needed anyway - see my other comment about the try/catches.

* @throws Exception If an unexpected error occurs during the filter creation process.
*
*/
public void createFilter(Inspector2Client inspector2Client, String description) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is creating a low severity filter, the name of the method should reflect that. Right now the name indicates you can create any filter.

System.out.println(" • Generate detailed findings reports");
System.out.println(" • Integrate with AWS Security Hub");
waitForInputToContinue(scanner);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a cleanup method that removes the example filters and gives the option to disable inspector.

public void testScenario() {
assertDoesNotThrow(() -> {
int maxResults = 10;
inspectorActions.getAccountStatus(inspector);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn't run the scenario, it runs the actions only. Needs a true integration test that actually runs the scenario.

Collections.synchronizedList(new ArrayList<>());

CompletableFuture<String> future = new CompletableFuture<>();
paginator.subscribe(new Subscriber<ListFindingsResponse>() {
Copy link
Collaborator

@rlhagerm rlhagerm Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pagination in the latest updates looks way more complicated than necessary. It should follow the simplest pagination pattern, without page limits or overrides, like this:

`

List<JobSummary> jobSummaries = new ArrayList<>();
        ListJobsPublisher listJobsPaginator = getAsyncClient().listJobsPaginator(listJobsRequest);
        CompletableFuture<Void> future = listJobsPaginator.subscribe(response -> {
            jobSummaries.addAll(response.jobSummaryList());
        });
        future.join();
        return jobSummaries;

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Basics A basic code example showing the core actions for a particular service. Java-v2 This issue relates to the AWS SDK for Java V2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants