Skip to content

Conversation

@agggaurav2024
Copy link
Contributor

@agggaurav2024 agggaurav2024 commented Jan 13, 2025

…Module code samples

Description

Fixes # b/347347427, b/347347480, b/347347258, b/347347835
This PR adds SCC Managament API Org Security Health Analytics Custom Module Code Samples for Create, Update, Get and GetEffective.

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

Checklist

  • I have followed guidelines from CONTRIBUTING.MD and Samples Style Guide
  • Tests pass: npm test (see Testing)
  • Lint pass: npm run lint (see Style)
  • 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)
  • This pull request is from a branch created directly off of GoogleCloudPlatform/nodejs-docs-samples. Not a fork.
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new sample directory, and I created GitHub Actions workflow 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

@agggaurav2024 agggaurav2024 requested review from a team as code owners January 13, 2025 05:49
@snippet-bot
Copy link

snippet-bot bot commented Jan 13, 2025

Here is the summary of changes.

You are about to add 4 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

@product-auto-label product-auto-label bot added samples Issues that are directly related to samples. api: securitycenter Issues related to the Security Command Center API. labels Jan 13, 2025
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Hi team,

I'm currently reviewing this pull request and will provide feedback shortly. In the meantime, here's a summary for you and other reviewers to quickly get up to speed:

This pull request adds code samples for the Security Command Center Management API's Org Security Health Analytics Custom Module. The intent is to provide examples for creating, updating, getting, and getting the effective state of custom modules. The PR addresses issues b/347347427, b/347347480, b/347347258, and b/347347835.

Here's a breakdown of the changes:

  • New files added:
    • security-center/snippets/management_api/createSecurityHealthAnalyticsCustomModule.js: This file contains a sample for creating a custom module. (Lines 1-99)
    • security-center/snippets/management_api/getEffectiveSecurityHealthAnalyticsCustomModule.js: This file shows how to retrieve an existing effective custom module. (Lines 1-52)
    • security-center/snippets/management_api/getSecurityHealthAnalyticsCustomModule.js: This file demonstrates retrieving an existing custom module. (Lines 1-51)
    • security-center/snippets/management_api/updateSecurityHealthAnalyticsCustomModule.js: This file provides a sample for updating a custom module. (Lines 1-69)
    • security-center/snippets/system-test/managemnt_api/securityHealthAnalyticsCustomModule.test.js: This file contains system tests for the new samples. (Lines 1-175)
  • security-center/snippets/package.json updated: Added @google-cloud/securitycentermanagement as a dependency and updated versions of other dependencies. (Lines 13-27)

The code samples utilize the @google-cloud/securitycentermanagement library. The tests use Mocha and Chai for assertions and include setup and teardown to create and delete the custom module for testing purposes.

I'll be checking the following during my review:

  • Adherence to the CONTRIBUTING.MD and Samples Style Guide.
  • Test coverage and correctness.
  • Code style and readability.
  • Error handling and robustness.

Let me know if you have any questions.


And now, a little haiku to lighten the mood:

Code flows like a stream,
Tests run, a green light appears,
A bug's silent scream.

Copy link

@ghost ghost 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 Security Health Analytics custom module code samples. The code generally looks good, but there are some minor improvements that can be made. The system tests could be improved by parameterizing the organization ID and cleaning up after themselves. The checklist is incomplete, so please review and update it accordingly.

Comment on lines +54 to +55
// define the CEL expression here and this will scans for keys that have not been rotated in
// the last 30 days, change it according to the your requirements
Copy link

Choose a reason for hiding this comment

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

low

The comment mentions 30 days, but the expression uses '2592000s', which is also 30 days. It would be clearer to use duration('30d') for consistency and readability.

Suggested change
// define the CEL expression here and this will scans for keys that have not been rotated in
// the last 30 days, change it according to the your requirements
// define the CEL expression here and this will scans for keys that have not been rotated in
// the last 30 days, change it according to the your requirements
const expr = {
expression: `has(resource.rotationPeriod) && (resource.rotationPeriod > duration('30d'))`,
};

Comment on lines +71 to +72
description: 'add your description here',
recommendation: 'add your recommendation here',
Copy link

Choose a reason for hiding this comment

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

low

Instead of placeholder comments, provide a more descriptive example or remove them entirely. This will make the sample more practical.

Suggested change
description: 'add your description here',
recommendation: 'add your recommendation here',
description: 'CryptoKey has not been rotated in the last 30 days.',
recommendation: 'Rotate the CryptoKey within 30 days of creation or last rotation.'

Comment on lines 27 to 28
// TODO(developers): update for your own environment
const organizationId = '1081635000895';
Copy link

Choose a reason for hiding this comment

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

medium

Replace the placeholder organization ID with a valid one or a way to dynamically get the organization ID for testing. Don't hardcode global since it's already a default parameter.

Suggested change
// TODO(developers): update for your own environment
const organizationId = '1081635000895';
// TODO(developer): Replace with your organization ID
const organizationId = process.env.SCC_ORGANIZATION_ID || 'YOUR_ORGANIZATION_ID';
const locationId = 'global';

Comment on lines 109 to 110
console.log(
`Custome Module ${customModuleDisplayName} deleted successfully.`
Copy link

Choose a reason for hiding this comment

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

low

Typo: 'Custome' should be 'Custom'.

`Custom Module ${customModuleDisplayName} deleted successfully.`

const output = exec(
`node management_api/updateSecurityHealthAnalyticsCustomModule.js ${data.orgId} ${data.customModuleId} ${locationId}`
);
// assert.include(output, data.customModuleName);
Copy link

Choose a reason for hiding this comment

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

low

Uncomment or remove this line. If it's needed, explain why.

assert.include(output, data.customModuleName);

@agggaurav2024 agggaurav2024 changed the title Security health analytics feat(securitycenter): Add Resource SCC Management API Org SHA Custom … Jan 13, 2025
@agggaurav2024
Copy link
Contributor Author

closing this PR, has raised the same PR from the main branch #3952

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.

1 participant