diff --git a/model-armor/package.json b/model-armor/package.json index 03f9142166..56649a6c2e 100644 --- a/model-armor/package.json +++ b/model-armor/package.json @@ -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" + } } - \ No newline at end of file diff --git a/model-armor/snippets/ci-setup.json b/model-armor/snippets/ci-setup.json new file mode 100644 index 0000000000..3fb11b81f8 --- /dev/null +++ b/model-armor/snippets/ci-setup.json @@ -0,0 +1,6 @@ +{ + "env": { + "MA_FOLDER_ID": 695279264361, + "MA_ORG_ID": 951890214235 + } +} diff --git a/model-armor/snippets/createTemplateWithMetadata.js b/model-armor/snippets/createTemplateWithMetadata.js index d1e182eb4d..3e7a57fd59 100644 --- a/model-armor/snippets/createTemplateWithMetadata.js +++ b/model-armor/snippets/createTemplateWithMetadata.js @@ -66,7 +66,7 @@ async function createTemplateWithMetadata(projectId, locationId, templateId) { }, }, templateMetadata: { - ignorePartialInvocationFailures: true, + logTemplateOperations: true, logSanitizeOperations: true, }, }; diff --git a/model-armor/snippets/getFolderFloorSettings.js b/model-armor/snippets/getFolderFloorSettings.js new file mode 100644 index 0000000000..bacb9570de --- /dev/null +++ b/model-armor/snippets/getFolderFloorSettings.js @@ -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; diff --git a/model-armor/snippets/getOrganizationFloorSettings.js b/model-armor/snippets/getOrganizationFloorSettings.js new file mode 100644 index 0000000000..10a0186777 --- /dev/null +++ b/model-armor/snippets/getOrganizationFloorSettings.js @@ -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; diff --git a/model-armor/snippets/getProjectFloorSettings.js b/model-armor/snippets/getProjectFloorSettings.js new file mode 100644 index 0000000000..9a37d96a6c --- /dev/null +++ b/model-armor/snippets/getProjectFloorSettings.js @@ -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; + + // 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; diff --git a/model-armor/snippets/updateFolderFloorSettings.js b/model-armor/snippets/updateFolderFloorSettings.js new file mode 100644 index 0000000000..1b59c6562f --- /dev/null +++ b/model-armor/snippets/updateFolderFloorSettings.js @@ -0,0 +1,75 @@ +// 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.HARASSMENT, + confidenceLevel: + protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel + .LOW_AND_ABOVE, + }, + { + filterType: + protos.google.cloud.modelarmor.v1.RaiFilterType.SEXUALLY_EXPLICIT, + 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; diff --git a/model-armor/snippets/updateOrganizationFloorSettings.js b/model-armor/snippets/updateOrganizationFloorSettings.js new file mode 100644 index 0000000000..f4ce121394 --- /dev/null +++ b/model-armor/snippets/updateOrganizationFloorSettings.js @@ -0,0 +1,73 @@ +// 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.HARASSMENT, + confidenceLevel: + protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel + .LOW_AND_ABOVE, + }, + { + filterType: + protos.google.cloud.modelarmor.v1.RaiFilterType.SEXUALLY_EXPLICIT, + 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; diff --git a/model-armor/snippets/updateProjectFloorSettings.js b/model-armor/snippets/updateProjectFloorSettings.js new file mode 100644 index 0000000000..c740836553 --- /dev/null +++ b/model-armor/snippets/updateProjectFloorSettings.js @@ -0,0 +1,73 @@ +// 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 project in Model Armor. + * + * @param {string} projectId - Google Cloud project ID for which floor settings need to be updated. + */ +async function updateProjectFloorSettings(projectId) { + // [START modelarmor_update_project_floor_settings] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // const projectId = 'your-project-id'; + + const modelarmor = require('@google-cloud/modelarmor'); + const {ModelArmorClient} = modelarmor.v1; + const {protos} = modelarmor; + + const client = new ModelArmorClient(); + + const floorSettingsName = `projects/${projectId}/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.HARASSMENT, + confidenceLevel: + protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel + .LOW_AND_ABOVE, + }, + { + filterType: + protos.google.cloud.modelarmor.v1.RaiFilterType.SEXUALLY_EXPLICIT, + 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_project_floor_settings] +} + +module.exports = updateProjectFloorSettings; diff --git a/model-armor/test/modelarmor.test.js b/model-armor/test/modelarmor.test.js index 4350357999..2f813b1f4f 100644 --- a/model-armor/test/modelarmor.test.js +++ b/model-armor/test/modelarmor.test.js @@ -298,6 +298,10 @@ describe('Model Armor tests', () => { await deleteDlpTemplates(); }); + // =================== Floor Settings Tests =================== + + // TODO: Add tests for floor settings once the floor setting API issues are resolved. + // =================== Template Creation Tests =================== it('should create a basic template', async () => {