-
Notifications
You must be signed in to change notification settings - Fork 2k
feat(security-center): Add Resource v2 API Assets Security Marks Samples #3916
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
Conversation
|
🤖 I detect that the PR title and the commit message differ and there's only one commit. To use the PR title for the commit history, you can use Github's automerge feature with squashing, or use -- conventional-commit-lint bot |
|
Here is the summary of changes. You are about to add 3 region tags.
This comment is generated by snippet-bot.
|
…form/nodejs-docs-samples into security-marks-assets-v2 merge remote to local
feywind
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This generally looks fine, maybe just check on that exec() vs execSync() thing. Let's see if we can get someone closer to docs/samples to approve the rest of the way.
| parent: client.organizationPath(organizationId), | ||
| }); | ||
| const randomAsset = | ||
| assetResults[Math.floor(Math.random() * assetResults.length)].asset; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seeing random() in a test makes me worry that it's going to end up being flaky, but I guess if all the items are more or less equivalent, should be okay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored it.
|
|
||
| it('client can add and delete security marks', () => { | ||
| // Ensure marks are set. | ||
| exec(`node v2/addSecurityMarks.js ${data.assetName}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these be execSync()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed. Other tests were using the exec() method so I have used the same but I have updated it.
|
@gemini review |
There was a problem hiding this 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 Center v2 API's Asset Security Marks in Node.js. The new samples demonstrate adding, deleting, and adding/deleting security marks. The changes also include updates to the system tests to incorporate these new functionalities. The implementation looks good overall, but I have a few suggestions to improve clarity, consistency, and robustness.
One improvement could be to add more comprehensive documentation in the README file for the security-center/snippets/v2 directory. This documentation should explain the purpose of each sample, how to run them, and the expected outcomes. It should also clearly outline the prerequisites, such as setting up a Security Center project and enabling the necessary APIs.
Additionally, the system tests could be enhanced by adding more assertions to validate the state of the security marks after each operation. This would ensure that the samples are functioning correctly and provide more confidence in the code's reliability.
| try { | ||
| /*eslint no-unused-vars: ["error", { "varsIgnorePattern": "^_" }]*/ | ||
| const [_response] = await client.createNotificationConfig({ | ||
| parent: orgName, | ||
| configId: configId, | ||
| notificationConfig: { | ||
| description: 'Sample config for node.js', | ||
| pubsubTopic: pubsubTopic, | ||
| streamingConfig: {filter: 'state = "ACTIVE"'}, | ||
| }, | ||
| }); | ||
| } catch (err) { | ||
| console.error(`Error creating config ${configId}:`, err.message); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed
| await createNotificationConfig(deleteConfig); | ||
| await new Promise(resolve => setTimeout(resolve, 1000)); // 1-second delay | ||
| await createNotificationConfig(getConfig); | ||
| await new Promise(resolve => setTimeout(resolve, 1000)); // 1-second delay | ||
| await createNotificationConfig(listConfig); | ||
| await new Promise(resolve => setTimeout(resolve, 1000)); // 1-second delay | ||
| await createNotificationConfig(updateConfig); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed
| async function deleteNotificationConfig(configId) { | ||
| const name = client.organizationNotificationConfigPath( | ||
| organizationId, | ||
| configId | ||
| ); | ||
| await client.deleteNotificationConfig({name: name}); | ||
| try { | ||
| const name = client.organizationNotificationConfigPath( | ||
| organizationId, | ||
| configId | ||
| ); | ||
| await client.deleteNotificationConfig({name: name}); | ||
| } catch (err) { | ||
| console.error(`Error deleting config ${configId}:`, err.message); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed
| await deleteNotificationConfig(createConfig); | ||
| await new Promise(resolve => setTimeout(resolve, 1000)); // 1-second delay | ||
| await deleteNotificationConfig(getConfig); | ||
| await new Promise(resolve => setTimeout(resolve, 1000)); // 1-second delay | ||
| await deleteNotificationConfig(listConfig); | ||
| await new Promise(resolve => setTimeout(resolve, 1000)); // 1-second delay | ||
| await deleteNotificationConfig(updateConfig); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed
| const {execSync} = require('child_process'); | ||
|
|
||
| // TODO(developers): update for your own environment | ||
| const organizationId = '1081635000895'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The organization ID is hardcoded. Consider storing this in an environment variable or a configuration file to make the test more portable and avoid exposing sensitive information directly in the code.
| const organizationId = '1081635000895'; | |
| // Retrieve organization ID from environment variable | |
| const organizationId = process.env.ORGANIZATION_ID || 'YOUR_ORGANIZATION_ID'; | |
| if (!organizationId) { | |
| throw new Error('Environment variable ORGANIZATION_ID is not set.'); | |
| } |
| // assetName is the full resource path for the asset to update. | ||
| /* | ||
| * TODO(developer): Uncomment the following lines | ||
| */ | ||
| // Specify the value of 'assetName' in one of the following formats: | ||
| // `organizations/${org-id}/assets/${asset-id}`; | ||
| // `projects/${project-id}/assets/${asset-id}`; | ||
| // `folders/${folder-id}/assets/${asset-id}`; | ||
| // const assetName = "organizations/123123342/assets/12312321"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed
Description
This PR adds v2 API Assets Security Marks Node js client samples to Add Security Marks, Delete Security Marks, Add Delete Security Marks.
Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.
Checklist
npm test(see Testing)npm run lint(see Style)GoogleCloudPlatform/nodejs-docs-samples. Not a fork.