Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(securitycenter): Add Resource SCC Management API Org Security Center Service Custom Module samples (Get, List, Update) #9913

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lovenishs04
Copy link
Contributor

Description

Fixes # b/347346449, b/347346682, b/347346802
This PR adds SCC Managament API Org Security Center Service Custom Module Samples for Get, List and Update.

Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.

Checklist

  • I have followed Sample Format Guide
  • pom.xml parent set to latest shared-configuration
  • Appropriate changes to README are included in PR
  • These samples need a new API enabled in testing projects to pass (let us know which ones)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
  • Tests pass: mvn clean verify required
  • Lint passes: mvn -P lint checkstyle:check required
  • Static Analysis: mvn -P lint clean compile pmd:cpd-check spotbugs:check advisory only
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved

@lovenishs04 lovenishs04 requested review from yoshi-approver and a team as code owners December 23, 2024 08:30
Copy link

snippet-bot bot commented Dec 23, 2024

Here is the summary of changes.

You are about to add 3 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

Copy link
Contributor

@code-review-assist code-review-assist bot left a comment

Choose a reason for hiding this comment

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

Hi @lovenishs04 and reviewers,

I'm currently reviewing this pull request and will post my detailed review in a few minutes. In the meantime, here's a quick summary to help everyone get up to speed:

This pull request adds Java samples for the Security Command Center Management API's Organization Security Center Service Custom Module. Specifically, it includes samples for:

  • Get: Retrieving a Security Center service.
  • List: Listing all Security Center services.
  • Update: Updating a Security Center service.

The changes involve creating new Java classes (GetSecurityCenterService.java, ListSecurityCenterServices.java, UpdateSecurityCenterService.java) and corresponding unit tests (SecurityCenterServiceTest.java). These classes use the google-cloud-securitycentermanagement library to interact with the Security Command Center API. The code is well-documented and includes clear instructions and comments.

The intent is to provide developers with clear, concise, and readily usable code examples for common Security Command Center tasks. This will improve the developer experience and make it easier to integrate Security Command Center into their applications.

Here's a little haiku to lighten the mood:

Secure the cloud's keep,
Code samples guide the way clear,
Safety's code unfolds.

Looking forward to the discussion!

Best,
Gemini

@product-auto-label product-auto-label bot added api: securitycenter Issues related to the Security Command Center API. samples Issues that are directly related to samples. labels Dec 23, 2024
Copy link
Contributor

@code-review-assist code-review-assist bot left a comment

Choose a reason for hiding this comment

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

This pull request adds samples for the Security Command Center Management API's Organization Security Center Service Custom Module. The samples cover Get, List, and Update operations. The code generally looks good, but there are a few improvements that can be made regarding clarity, error handling, and documentation.

I've referenced the Sample Format Guide in this review, specifically the sections on TODO comments and placeholder values.

It's important to address the TODOs and ensure the README is updated before merging. The checklist in the PR description mentions several important items that need to be confirmed.


public static void main(String[] args) throws IOException {
// https://cloud.google.com/security-command-center/docs/reference/security-center-management/rest/v1/organizations.locations.securityCenterServices/get
// TODO: Developer should replace project_id with a real project ID before running this code
Copy link
Contributor

Choose a reason for hiding this comment

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

low

The TODO comment should be more actionable. Instead of just stating what the developer needs to do, consider providing a more descriptive placeholder or example. Per the Sample Format Guide, placeholder values should be enclosed in angle brackets.

Suggested change
// TODO: Developer should replace project_id with a real project ID before running this code
// TODO: Replace <project-id> with your project ID
String projectId = "<project-id>";

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed

public static void main(String[] args) throws IOException {
// https://cloud.google.com/security-command-center/docs/reference/security-center-management/rest/v1/organizations.locations.securityCenterServices/get
// TODO: Developer should replace project_id with a real project ID before running this code
String projectId = "project_id";
Copy link
Contributor

Choose a reason for hiding this comment

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

low

Per the Sample Format Guide, use angle brackets for placeholders. This makes it clear what needs replacing and improves readability.

Suggested change
String projectId = "project_id";
String projectId = "<project-id>";

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed

// Replace service with one of the valid values:
// container-threat-detection, event-threat-detection, security-health-analytics,
// vm-threat-detection, web-security-scanner
String service = "service";
Copy link
Contributor

Choose a reason for hiding this comment

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

low

Use angle brackets for the placeholder to adhere to the Sample Format Guide.

Suggested change
String service = "service";
String service = "<service>";

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed


public static void main(String[] args) throws IOException {
// https://cloud.google.com/security-command-center/docs/reference/security-center-management/rest/v1/organizations.locations.securityCenterServices/list
// TODO: Developer should replace project_id with a real project ID before running this code
Copy link
Contributor

Choose a reason for hiding this comment

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

low

Make this TODO comment more actionable and use angle brackets for the placeholder, as per the Sample Format Guide.

Suggested change
// TODO: Developer should replace project_id with a real project ID before running this code
// TODO: Replace <project-id> with your project ID
String projectId = "<project-id>";

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed

public static void main(String[] args) throws IOException {
// https://cloud.google.com/security-command-center/docs/reference/security-center-management/rest/v1/organizations.locations.securityCenterServices/list
// TODO: Developer should replace project_id with a real project ID before running this code
String projectId = "project_id";
Copy link
Contributor

Choose a reason for hiding this comment

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

low

Use angle brackets for placeholders to follow the Sample Format Guide.

Suggested change
String projectId = "project_id";
String projectId = "<project-id>";

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed


public static void main(String[] args) throws IOException {
// https://cloud.google.com/security-command-center/docs/reference/security-center-management/rest/v1/organizations.locations.securityCenterServices/patch
// TODO: Developer should replace project_id with a real project ID before running this code
Copy link
Contributor

Choose a reason for hiding this comment

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

low

Ensure the TODO comment is actionable and uses angle brackets for placeholders, consistent with the Sample Format Guide.

Suggested change
// TODO: Developer should replace project_id with a real project ID before running this code
// TODO: Replace <project-id> with your project ID
String projectId = "<project-id>";

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed

public static void main(String[] args) throws IOException {
// https://cloud.google.com/security-command-center/docs/reference/security-center-management/rest/v1/organizations.locations.securityCenterServices/patch
// TODO: Developer should replace project_id with a real project ID before running this code
String projectId = "project_id";
Copy link
Contributor

Choose a reason for hiding this comment

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

low

Use angle brackets for placeholders as per the Sample Format Guide.

Suggested change
String projectId = "project_id";
String projectId = "<project-id>";

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed

// Replace service with one of the valid values:
// container-threat-detection, event-threat-detection, security-health-analytics,
// vm-threat-detection, web-security-scanner
String service = "service";
Copy link
Contributor

Choose a reason for hiding this comment

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

low

Use angle brackets for the placeholder to be consistent with the Sample Format Guide.

Suggested change
String service = "service";
String service = "<service>";

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed


@RunWith(JUnit4.class)
public class SecurityCenterServiceTest {
// TODO(Developer): Replace the below variable
Copy link
Contributor

Choose a reason for hiding this comment

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

low

Instead of a TODO, provide clear instructions on setting the environment variable. This improves the clarity and usability of the test code. For example:

// Set the SCC_PROJECT_ID environment variable. See https://cloud.google.com/docs/authentication/getting-started for more details.
private static final String PROJECT_ID = System.getenv("SCC_PROJECT_ID");
Suggested change
// TODO(Developer): Replace the below variable
// Set the SCC_PROJECT_ID environment variable. See https://cloud.google.com/docs/authentication/getting-started for more details.
private static final String PROJECT_ID = System.getenv("SCC_PROJECT_ID");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: securitycenter Issues related to the Security Command Center API. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants