-
Notifications
You must be signed in to change notification settings - Fork 2k
feat(modelarmor): Added snippets for floor settings #4053
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
Merged
utsav1810
merged 23 commits into
GoogleCloudPlatform:main
from
rudrakhsha-crest:model-armor-floor-settings
Jun 11, 2025
Merged
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
874955b
Added CRUD code snippets with codeowners file
rudrakhsha-crest 8270ed7
Solved linting errors
rudrakhsha-crest 3824b65
Added header comment
rudrakhsha-crest 0b9faee
Removed hardcoded value from test
rudrakhsha-crest 16111a5
Added floor settings snippets
rudrakhsha-crest d15d006
Removed crud specific files
rudrakhsha-crest 313bd64
Updated test to disable floor settings in the after code
rudrakhsha-crest 441fe5d
Merge branch 'main' into model-armor-floor-settings
rudrakhsha-crest 8bd4854
Updated variable names in tests for org id and folder id
rudrakhsha-crest f145160
Merge branch 'model-armor-floor-settings' of github.com:rudrakhsha-cr…
rudrakhsha-crest e73984e
Updated model armor code snippets to use module exports
rudrakhsha-crest 5f9ff8a
add-endofline-and-fix-copyright-year
harshnasitcrest b14a42a
Merge branch 'main' into model-armor-floor-settings
harshnasitcrest da8baec
Merge branch 'main' into model-armor-floor-settings
harshnasitcrest 65f9c1e
resolve-merge-conflicts
harshnasitcrest f91919c
fix-package-json-formatting
harshnasitcrest 49f96b8
change-metadata-in-create-template-snippet
harshnasitcrest 7ee95d2
Merge branch 'main' into model-armor-floor-settings
harshnasitcrest 13dd5d1
Merge branch 'main' into model-armor-floor-settings
glasnt 544e43c
Merge branch 'main' into model-armor-floor-settings
harshnasitcrest 1dd05f1
add testing envvars
glasnt 832d423
Removed floor setting tests
harshnasitcrest d0e1df5
Merge branch 'main' into model-armor-floor-settings
harshnasitcrest File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,26 @@ | ||
| { | ||
| "name": "nodejs-model-armor-samples", | ||
| "private": true, | ||
| "license": "Apache-2.0", | ||
| "files": [ | ||
| "*.js" | ||
| ], | ||
| "author": "Google LLC", | ||
| "repository": "googleapis/nodejs-model-armor", | ||
| "engines": { | ||
| "node": ">=16.0.0" | ||
| }, | ||
| "scripts": { | ||
| "test": "c8 mocha -p -j 2 --recursive test/ --timeout=60000" | ||
| }, | ||
| "dependencies": { | ||
| "@google-cloud/modelarmor": "^0.1.0", | ||
| "@google-cloud/dlp": "^5.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "c8": "^10.0.0", | ||
| "chai": "^4.5.0", | ||
| "mocha": "^10.0.0", | ||
| "uuid": "^10.0.0" | ||
| } | ||
| "name": "nodejs-model-armor-samples", | ||
| "private": true, | ||
| "license": "Apache-2.0", | ||
| "files": [ | ||
| "*.js" | ||
| ], | ||
| "author": "Google LLC", | ||
| "repository": "googleapis/nodejs-model-armor", | ||
| "engines": { | ||
| "node": ">=16.0.0" | ||
| }, | ||
| "scripts": { | ||
| "test": "c8 mocha -p -j 2 --recursive test/ --timeout=60000" | ||
| }, | ||
| "dependencies": { | ||
| "@google-cloud/modelarmor": "^0.1.0", | ||
| "@google-cloud/dlp": "^5.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "c8": "^10.0.0", | ||
| "chai": "^4.5.0", | ||
| "mocha": "^10.0.0", | ||
| "uuid": "^10.0.0" | ||
| } | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "env": { | ||
| "MA_FOLDER_ID": 695279264361, | ||
| "MA_ORG_ID": 951890214235 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // Copyright 2025 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| 'use strict'; | ||
|
|
||
| /** | ||
| * Retrieves the floor settings for a Google Cloud folder. | ||
| * | ||
| * @param {string} folderId - The ID of the Google Cloud folder for which to retrieve floor settings. | ||
| */ | ||
| async function getFolderFloorSettings(folderId) { | ||
| // [START modelarmor_get_folder_floor_settings] | ||
| /** | ||
| * TODO(developer): Uncomment these variables before running the sample. | ||
| */ | ||
| // const folderId = 'your-folder-id'; | ||
|
|
||
| const name = `folders/${folderId}/locations/global/floorSetting`; | ||
|
|
||
| // Imports the Modelarmor library | ||
| const {ModelArmorClient} = require('@google-cloud/modelarmor').v1; | ||
|
|
||
| // Instantiates a client | ||
| const modelarmorClient = new ModelArmorClient(); | ||
|
|
||
| // Construct request | ||
| const request = { | ||
| name, | ||
| }; | ||
|
|
||
| const [response] = await modelarmorClient.getFloorSetting(request); | ||
| return response; | ||
| // [END modelarmor_get_folder_floor_settings] | ||
| } | ||
|
|
||
| module.exports = getFolderFloorSettings; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Copyright 2025 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| 'use strict'; | ||
|
|
||
| /** | ||
| * Retrieves the floor settings for a Google Cloud organization. | ||
| * | ||
| * @param {string} organizationId - The ID of the Google Cloud organization for which to retrieve | ||
| * floor settings. | ||
| */ | ||
| async function getOrganizationFloorSettings(organizationId) { | ||
| // [START modelarmor_get_organization_floor_settings] | ||
| /** | ||
| * TODO(developer): Uncomment these variables before running the sample. | ||
| */ | ||
| // const organizationId = 'your-organization-id'; | ||
|
|
||
| const name = `organizations/${organizationId}/locations/global/floorSetting`; | ||
|
|
||
| // Imports the Modelarmor library | ||
| const {ModelArmorClient} = require('@google-cloud/modelarmor').v1; | ||
|
|
||
| // Instantiates a client | ||
| const modelarmorClient = new ModelArmorClient(); | ||
|
|
||
| // Construct request | ||
| const request = { | ||
| name, | ||
| }; | ||
|
|
||
| // Run request | ||
| const [response] = await modelarmorClient.getFloorSetting(request); | ||
| return response; | ||
| // [END modelarmor_get_organization_floor_settings] | ||
| } | ||
|
|
||
| module.exports = getOrganizationFloorSettings; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Copyright 2025 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| 'use strict'; | ||
|
|
||
| /** | ||
| * Retrieves the floor settings for a Google Cloud project. | ||
| * | ||
| * @param {string} projectId - The ID of the Google Cloud project for which to retrieve | ||
| * floor settings. | ||
| */ | ||
| async function getProjectFloorSettings(projectId) { | ||
| // [START modelarmor_get_project_floor_settings] | ||
| /** | ||
| * TODO(developer): Uncomment these variables before running the sample. | ||
| */ | ||
| // const projectId = 'your-project-id'; | ||
|
|
||
| const name = `projects/${projectId}/locations/global/floorSetting`; | ||
|
|
||
| // Imports the Modelarmor library | ||
| const {ModelArmorClient} = require('@google-cloud/modelarmor').v1; | ||
rudrakhsha-crest marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Instantiates a client | ||
| const modelarmorClient = new ModelArmorClient(); | ||
|
|
||
| // Construct request | ||
| const request = { | ||
| name, | ||
| }; | ||
|
|
||
| // Run request | ||
| const [response] = await modelarmorClient.getFloorSetting(request); | ||
| return response; | ||
| // [END modelarmor_get_project_floor_settings] | ||
| } | ||
|
|
||
| module.exports = getProjectFloorSettings; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| // Copyright 2025 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| 'use strict'; | ||
|
|
||
| /** | ||
| * Updates the floor settings of a folder in Model Armor. | ||
| * | ||
| * @param {string} folderId - Google Cloud folder ID for which floor settings need to be updated. | ||
| */ | ||
| async function updateFolderFloorSettings(folderId) { | ||
| // [START modelarmor_update_folder_floor_settings] | ||
| /** | ||
| * TODO(developer): Uncomment these variables before running the sample. | ||
| */ | ||
| // const folderId = 'your-folder-id'; | ||
|
|
||
| // Imports the Model Armor library | ||
| const modelarmor = require('@google-cloud/modelarmor'); | ||
| const {ModelArmorClient} = modelarmor.v1; | ||
| const {protos} = modelarmor; | ||
|
|
||
| // Instantiates a client | ||
| const client = new ModelArmorClient(); | ||
|
|
||
| const floorSettingsName = `folders/${folderId}/locations/global/floorSetting`; | ||
|
|
||
| // Build the floor settings with your preferred filters | ||
| // For more details on filters, please refer to the following doc: | ||
| // https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters | ||
| const floorSetting = { | ||
| name: floorSettingsName, | ||
| filterConfig: { | ||
| raiSettings: { | ||
| raiFilters: [ | ||
| { | ||
| filterType: | ||
| protos.google.cloud.modelarmor.v1.RaiFilterType.HATE_SPEECH, | ||
| confidenceLevel: | ||
| protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel.HIGH, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| enableFloorSettingEnforcement: true, | ||
| }; | ||
|
|
||
| const request = { | ||
| floorSetting: floorSetting, | ||
| }; | ||
|
|
||
| const [response] = await client.updateFloorSetting(request); | ||
| return response; | ||
| // [END modelarmor_update_folder_floor_settings] | ||
| } | ||
|
|
||
| module.exports = updateFolderFloorSettings; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // Copyright 2025 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| 'use strict'; | ||
|
|
||
| /** | ||
| * Updates the floor settings of an organization in Model Armor. | ||
| * | ||
| * @param {string} organizationId - Google Cloud organization ID for which floor settings need to be updated. | ||
| */ | ||
| async function updateOrganizationFloorSettings(organizationId) { | ||
| // [START modelarmor_update_organization_floor_settings] | ||
| /** | ||
| * TODO(developer): Uncomment these variables before running the sample. | ||
| */ | ||
| // const organizationId = 'your-organization-id'; | ||
|
|
||
| const modelarmor = require('@google-cloud/modelarmor'); | ||
| const {ModelArmorClient} = modelarmor.v1; | ||
| const {protos} = modelarmor; | ||
|
|
||
| const client = new ModelArmorClient(); | ||
|
|
||
| const floorSettingsName = `organizations/${organizationId}/locations/global/floorSetting`; | ||
|
|
||
| // Build the floor settings with your preferred filters | ||
| // For more details on filters, please refer to the following doc: | ||
| // https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters | ||
| const floorSetting = { | ||
| name: floorSettingsName, | ||
| filterConfig: { | ||
| raiSettings: { | ||
| raiFilters: [ | ||
| { | ||
| filterType: | ||
| protos.google.cloud.modelarmor.v1.RaiFilterType.HATE_SPEECH, | ||
| confidenceLevel: | ||
| protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel.HIGH, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| enableFloorSettingEnforcement: true, | ||
| }; | ||
|
|
||
| const request = { | ||
| floorSetting: floorSetting, | ||
| }; | ||
|
|
||
| const [response] = await client.updateFloorSetting(request); | ||
| return response; | ||
| // [END modelarmor_update_organization_floor_settings] | ||
| } | ||
|
|
||
| module.exports = updateOrganizationFloorSettings; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.