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): Adding SCC's BigQueryExport resource #3847

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

Conversation

vijaykanthm
Copy link

Description

Fixes #349577531
Reference to https://b.corp.google.com/issues/349577531
This PR adds v2 API Big Query Node js client samples to Create, List, Get, Delete & Update.

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

@vijaykanthm vijaykanthm requested review from a team as code owners September 11, 2024 22:52
Copy link

snippet-bot bot commented Sep 11, 2024

Here is the summary of changes.

You are about to add 5 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 api: bigquery Issues related to the BigQuery API. samples Issues that are directly related to samples. api: securitycenter Issues related to the Security Command Center API. api: workflows Issues related to the Workflows API. labels Sep 11, 2024
@iennae iennae assigned subfuzion and unassigned iennae Sep 12, 2024
@product-auto-label product-auto-label bot removed api: securitycenter Issues related to the Security Command Center API. api: workflows Issues related to the Workflows API. labels Sep 12, 2024
@grayside grayside assigned grayside and unassigned subfuzion Sep 20, 2024
Copy link
Collaborator

@grayside grayside left a comment

Choose a reason for hiding this comment

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

This PR has combined changes for samples across products. Please clean up or delete and send a new PR. The title specifies bigquery, the referenced bug specifies security center, the code includes changes for both.

Once this is done, we can proceed with a code review.

@vijaykanthm vijaykanthm reopened this Sep 20, 2024
@vijaykanthm vijaykanthm requested a review from a team as a code owner September 20, 2024 17:39
@vijaykanthm
Copy link
Author

This PR has combined changes for samples across products. Please clean up or delete and send a new PR. The title specifies bigquery, the referenced bug specifies security center, the code includes changes for both.

Once this is done, we can proceed with a code review.

I didn't understand what you meant, can you please elaborate on the comment. The bug doesn't have all the details but the requirement is to create samples for different components which are raised in separate PR's. This one has changes only related to the Big query.

@grayside
Copy link
Collaborator

I didn't understand what you meant, can you please elaborate on the comment. The bug doesn't have all the details but the requirement is to create samples for different components which are raised in separate PR's. This one has changes only related to the Big query.

The changes in this PR have accidentally picked up changes for BigQuery and Security Center. If this PR is meant to make changes for BigQuery samples, please remove accidentally included Security Center code.

@grayside grayside requested review from a team September 20, 2024 21:09
@vijaykanthm vijaykanthm changed the title feat(bigquery): Add Resource v2 API Big Query Samples feat(securityCenter): Adding SCC's BigQueryExport resource Sep 20, 2024
@vijaykanthm
Copy link
Author

I didn't understand what you meant, can you please elaborate on the comment. The bug doesn't have all the details but the requirement is to create samples for different components which are raised in separate PR's. This one has changes only related to the Big query.

The changes in this PR have accidentally picked up changes for BigQuery and Security Center. If this PR is meant to make changes for BigQuery samples, please remove accidentally included Security Center code.

Thank you for the clarification. I realize the title of the PR might have been misleading.
To clarify, the changes in this PR are specifically for Security Center's integration with BigQuery via the BigQueryExport resource.

The changes are scoped to Security Center snippets, and the BigQueryExport is a resource type under the Security Center that integrates with BigQuery. I will update the PR title to reflect this and avoid further confusion.

@@ -81,7 +81,7 @@ jobs:
- run: npm test
env:
GCLOUD_ORGANIZATION: 1081635000895
GOOGLE_SAMPLES_PROJECT: "long-door-651"
GOOGLE_SAMPLES_PROJECT: "project-a-id"
Copy link
Collaborator

Choose a reason for hiding this comment

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

issue: Use of this project is under discussion in #3830. It is probably not usable.

Copy link
Author

Choose a reason for hiding this comment

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

Addressed.

@@ -94,5 +94,6 @@
"video-intelligence",
"vision/productSearch",
"workflows",
"workflows/invoke-private-endpoint"
"workflows/invoke-private-endpoint",
"security-center/snippets/v2"
Copy link
Collaborator

Choose a reason for hiding this comment

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

issue: #3883 means we shouldn't separately add v2.

Copy link
Author

Choose a reason for hiding this comment

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

Addressed.

@@ -9,7 +9,7 @@
"node": ">=16.0.0"
},
"scripts": {
"test": "c8 mocha -p -j 2 --recursive --timeout 6000000 system-test/v2/findings.test.js"
"test": "c8 mocha -p -j 2 --recursive --timeout 6000000 system-test/v2/"
Copy link
Collaborator

Choose a reason for hiding this comment

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

issue: The test command for security center snippets overall should run all snippet tests, not just v2.

Copy link
Author

Choose a reason for hiding this comment

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

Addressed.

Comment on lines 24 to 25
const organizationId = '1081635000895';
const projectId = 'project-a-id';
Copy link
Collaborator

Choose a reason for hiding this comment

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

question: Shouldn't these be populated from environment variables configured on the workflow?

Copy link
Author

Choose a reason for hiding this comment

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

Addressed.

@@ -27,7 +27,7 @@ const exec = cmd => execSync(cmd, {encoding: 'utf8'});

// TODO(developers): update for your own environment
const organizationId = '1081635000895';
const projectId = 'long-door-651';
const projectId = 'project-a-id';
Copy link
Collaborator

Choose a reason for hiding this comment

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

question: Shouldn't these be populated from environment variables configured on the workflow?

Copy link
Author

Choose a reason for hiding this comment

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

Addressed.

* characters or less.
*/
const bigQueryExportId =
'bigqueryexportid-' + uuidv1().replace(/-/g, '').substring(0, 20);
Copy link
Collaborator

Choose a reason for hiding this comment

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

issue: Please remove the unneeded dependency on uuid, apply the Math.random approach from #3830

Copy link
Author

Choose a reason for hiding this comment

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

Addressed.

* "folders/[folder_id]/locations/[location_id]", or
* "projects/[project_id]/locations/[location_id]".
*/
const parent = client.organizationLocationPath(organizationId, location);
Copy link
Collaborator

Choose a reason for hiding this comment

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

issue: Referencing organizationId and location from outside the region tag scope is a violation of the copy-paste-runnable goal for samples.

suggestion: Minimally, any referenced variable should have a commented out variable declaration with an instruction for use on each variable.

For example,

  /**
   * TODO(developer): Uncomment the following line before running the sample.
   */

  // const projectId = 'YOUR_PROJECT_ID';

In https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/main/security-center/snippets/v2/createFinding.js it appears the decision was made to hard-code location to global. If that's how we're testing, hardcoding the global value without comment and adding an inline comment explaining would be better than a commented out instantiation.

See #3830 for previously discussed instances

Copy link
Author

Choose a reason for hiding this comment

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

Addressed.

* + `folders/{folder}/locations/{location}/bigQueryExports/{export_id}`
* + `projects/{project}locations/{location}/bigQueryExports/{export_id}`
*/
const name = `organizations/${organizationId}/locations/${location}/bigQueryExports/${exportId}`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

issue: Referencing organizationId and location from outside the region tag scope is a violation of the copy-paste-runnable goal for samples.

suggestion: Minimally, any referenced variable should have a commented out variable declaration with an instruction for use on each variable.

For example,

  /**
   * TODO(developer): Uncomment the following line before running the sample.
   */

  // const projectId = 'YOUR_PROJECT_ID';

In https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/main/security-center/snippets/v2/createFinding.js it appears the decision was made to hard-code location to global. If that's how we're testing, hardcoding the global value without comment and adding an inline comment explaining would be better than a commented out instantiation.

Copy link
Author

Choose a reason for hiding this comment

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

Addressed.

* When paginating, all other parameters provided to `ListBigQueryExports`
* must match the call that provided the page token.
*/
// const pageToken = 'abc123'
Copy link
Collaborator

Choose a reason for hiding this comment

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

issue: I don't see how the commented out variables are used in the snippet below. How is this guidance meant to be used?

Copy link
Author

Choose a reason for hiding this comment

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

Addressed.

updateBigQueryExportRequest,
fieldMask
);
console.log('BigQueryExport updated successfully!: %j', response);
Copy link
Collaborator

Choose a reason for hiding this comment

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

issue: The guideline to process the result calls for outputting specific attributes in the response.
https://googlecloudplatform.github.io/samples-style-guide/#result

Copy link
Author

Choose a reason for hiding this comment

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

Addressed.

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

Successfully merging this pull request may close these issues.

4 participants