Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 Mar 28, 2025
8270ed7
Solved linting errors
rudrakhsha-crest Mar 28, 2025
3824b65
Added header comment
rudrakhsha-crest Mar 28, 2025
0b9faee
Removed hardcoded value from test
rudrakhsha-crest Mar 28, 2025
16111a5
Added floor settings snippets
rudrakhsha-crest Mar 28, 2025
d15d006
Removed crud specific files
rudrakhsha-crest Mar 28, 2025
313bd64
Updated test to disable floor settings in the after code
rudrakhsha-crest Apr 18, 2025
441fe5d
Merge branch 'main' into model-armor-floor-settings
rudrakhsha-crest Apr 18, 2025
8bd4854
Updated variable names in tests for org id and folder id
rudrakhsha-crest Apr 21, 2025
f145160
Merge branch 'model-armor-floor-settings' of github.com:rudrakhsha-cr…
rudrakhsha-crest Apr 21, 2025
e73984e
Updated model armor code snippets to use module exports
rudrakhsha-crest May 6, 2025
5f9ff8a
add-endofline-and-fix-copyright-year
harshnasitcrest May 6, 2025
b14a42a
Merge branch 'main' into model-armor-floor-settings
harshnasitcrest May 7, 2025
da8baec
Merge branch 'main' into model-armor-floor-settings
harshnasitcrest May 19, 2025
65f9c1e
resolve-merge-conflicts
harshnasitcrest May 19, 2025
f91919c
fix-package-json-formatting
harshnasitcrest May 19, 2025
49f96b8
change-metadata-in-create-template-snippet
harshnasitcrest May 22, 2025
7ee95d2
Merge branch 'main' into model-armor-floor-settings
harshnasitcrest May 23, 2025
13dd5d1
Merge branch 'main' into model-armor-floor-settings
glasnt May 30, 2025
544e43c
Merge branch 'main' into model-armor-floor-settings
harshnasitcrest Jun 6, 2025
1dd05f1
add testing envvars
glasnt Jun 10, 2025
832d423
Removed floor setting tests
harshnasitcrest Jun 11, 2025
d0e1df5
Merge branch 'main' into model-armor-floor-settings
harshnasitcrest Jun 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 24 additions & 25 deletions model-armor/package.json
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"
}
}

6 changes: 6 additions & 0 deletions model-armor/snippets/ci-setup.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"env": {
"MA_FOLDER_ID": 695279264361,
"MA_ORG_ID": 951890214235
}
}
2 changes: 1 addition & 1 deletion model-armor/snippets/createTemplateWithMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async function createTemplateWithMetadata(projectId, locationId, templateId) {
},
},
templateMetadata: {
ignorePartialInvocationFailures: true,
logTemplateOperations: true,
logSanitizeOperations: true,
},
};
Expand Down
47 changes: 47 additions & 0 deletions model-armor/snippets/getFolderFloorSettings.js
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;
49 changes: 49 additions & 0 deletions model-armor/snippets/getOrganizationFloorSettings.js
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;
49 changes: 49 additions & 0 deletions model-armor/snippets/getProjectFloorSettings.js
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;

// 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;
75 changes: 75 additions & 0 deletions model-armor/snippets/updateFolderFloorSettings.js
Original file line number Diff line number Diff line change
@@ -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;
73 changes: 73 additions & 0 deletions model-armor/snippets/updateOrganizationFloorSettings.js
Original file line number Diff line number Diff line change
@@ -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;
Loading
Loading