Skip to content

Commit 16111a5

Browse files
Added floor settings snippets
1 parent 0b9faee commit 16111a5

File tree

7 files changed

+410
-155
lines changed

7 files changed

+410
-155
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
/**
18+
* Retrieves the floor settings for a Google Cloud folder.
19+
*
20+
* @param {string} folderId - The ID of the Google Cloud folder for which to retrieve floor settings.
21+
*/
22+
async function main(folderId) {
23+
// [START modelarmor_get_folder_floor_settings]
24+
/**
25+
* TODO(developer): Uncomment these variables before running the sample.
26+
*/
27+
// const folderId = 'your-folder-id';
28+
29+
const name = `folders/${folderId}/locations/global/floorSetting`;
30+
31+
// Imports the Modelarmor library
32+
const {ModelArmorClient} = require('@google-cloud/modelarmor').v1;
33+
34+
// Instantiates a client
35+
const modelarmorClient = new ModelArmorClient();
36+
37+
async function getFolderFloorSettings() {
38+
// Construct request
39+
const request = {
40+
name,
41+
};
42+
43+
const response = await modelarmorClient.getFloorSetting(request);
44+
console.log(response);
45+
}
46+
47+
getFolderFloorSettings();
48+
// [END modelarmor_get_folder_floor_settings]
49+
}
50+
51+
const args = process.argv.slice(2);
52+
main(...args).catch(console.error);
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
/**
18+
* Retrieves the floor settings for a Google Cloud organization.
19+
*
20+
* @param {string} organizationId - The ID of the Google Cloud organization for which to retrieve
21+
* floor settings.
22+
*/
23+
async function main(organizationId) {
24+
// [START modelarmor_get_organization_floor_settings]
25+
/**
26+
* TODO(developer): Uncomment these variables before running the sample.
27+
*/
28+
// const organizationId = 'your-organization-id';
29+
30+
const name = `organizations/${organizationId}/locations/global/floorSetting`;
31+
32+
// Imports the Modelarmor library
33+
const {ModelArmorClient} = require('@google-cloud/modelarmor').v1;
34+
35+
// Instantiates a client
36+
const modelarmorClient = new ModelArmorClient();
37+
38+
async function getOrganizationFloorSettings() {
39+
// Construct request
40+
const request = {
41+
name,
42+
};
43+
44+
// Run request
45+
const response = await modelarmorClient.getFloorSetting(request);
46+
console.log(response);
47+
}
48+
49+
getOrganizationFloorSettings();
50+
// [END modelarmor_get_organization_floor_settings]
51+
}
52+
53+
const args = process.argv.slice(2);
54+
main(...args).catch(console.error);
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
/**
18+
* Retrieves the floor settings for a Google Cloud project.
19+
*
20+
* @param {string} projectId - The ID of the Google Cloud project for which to retrieve
21+
* floor settings.
22+
*/
23+
async function main(projectId) {
24+
// [START modelarmor_get_project_floor_settings]
25+
/**
26+
* TODO(developer): Uncomment these variables before running the sample.
27+
*/
28+
// const projectId = 'your-project-id';
29+
30+
const name = `projects/${projectId}/locations/global/floorSetting`;
31+
32+
// Imports the Modelarmor library
33+
const {ModelArmorClient} = require('@google-cloud/modelarmor').v1;
34+
35+
// Instantiates a client
36+
const modelarmorClient = new ModelArmorClient();
37+
38+
async function getProjectFloorSettings() {
39+
// Construct request
40+
const request = {
41+
name,
42+
};
43+
44+
// Run request
45+
const response = await modelarmorClient.getFloorSetting(request);
46+
console.log(response);
47+
}
48+
49+
getProjectFloorSettings();
50+
// [END modelarmor_get_project_floor_settings]
51+
}
52+
53+
const args = process.argv.slice(2);
54+
main(...args).catch(console.error);
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
/**
18+
* Updates the floor settings of a folder in Model Armor.
19+
*
20+
* @param {string} folderId - Google Cloud folder ID for which floor settings need to be updated.
21+
*/
22+
async function main(folderId) {
23+
// [START modelarmor_update_folder_floor_settings]
24+
/**
25+
* TODO(developer): Uncomment these variables before running the sample.
26+
*/
27+
// const folderId = 'your-folder-id';
28+
29+
// Imports the Model Armor library
30+
const modelarmor = require('@google-cloud/modelarmor');
31+
const {ModelArmorClient} = modelarmor.v1;
32+
const {protos} = modelarmor;
33+
34+
// Instantiates a client
35+
const client = new ModelArmorClient();
36+
37+
async function updateFolderFloorSettings() {
38+
const floorSettingsName = `folders/${folderId}/locations/global/floorSetting`;
39+
40+
// Build the floor settings with your preferred filters
41+
// For more details on filters, please refer to the following doc:
42+
// https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
43+
const floorSetting = {
44+
name: floorSettingsName,
45+
filterConfig: {
46+
raiSettings: {
47+
raiFilters: [
48+
{
49+
filterType:
50+
protos.google.cloud.modelarmor.v1.RaiFilterType.HATE_SPEECH,
51+
confidenceLevel:
52+
protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel.HIGH,
53+
},
54+
],
55+
},
56+
},
57+
enableFloorSettingEnforcement: true,
58+
};
59+
60+
const request = {
61+
floorSetting: floorSetting,
62+
};
63+
64+
const [response] = await client.updateFloorSetting(request);
65+
console.log('Updated folder floor settings', response);
66+
}
67+
68+
updateFolderFloorSettings();
69+
// [END modelarmor_update_folder_floor_settings]
70+
}
71+
72+
const args = process.argv.slice(2);
73+
main(...args).catch(console.error);
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
/**
18+
* Updates the floor settings of an organization in Model Armor.
19+
*
20+
* @param {string} organizationId - Google Cloud organization ID for which floor settings need to be updated.
21+
*/
22+
async function main(organizationId) {
23+
// [START modelarmor_update_organization_floor_settings]
24+
/**
25+
* TODO(developer): Uncomment these variables before running the sample.
26+
*/
27+
// const organizationId = 'your-organization-id';
28+
29+
const modelarmor = require('@google-cloud/modelarmor');
30+
const {ModelArmorClient} = modelarmor.v1;
31+
const {protos} = modelarmor;
32+
33+
const client = new ModelArmorClient();
34+
35+
const floorSettingsName = `organizations/${organizationId}/locations/global/floorSetting`;
36+
37+
// Build the floor settings with your preferred filters
38+
// For more details on filters, please refer to the following doc:
39+
// https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
40+
const floorSetting = {
41+
name: floorSettingsName,
42+
filterConfig: {
43+
raiSettings: {
44+
raiFilters: [
45+
{
46+
filterType:
47+
protos.google.cloud.modelarmor.v1.RaiFilterType.HATE_SPEECH,
48+
confidenceLevel:
49+
protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel.HIGH,
50+
},
51+
],
52+
},
53+
},
54+
enableFloorSettingEnforcement: true,
55+
};
56+
57+
const request = {
58+
floorSetting: floorSetting,
59+
};
60+
61+
const [response] = await client.updateFloorSetting(request);
62+
console.log('Updated organization floor settings:', response);
63+
64+
// [END modelarmor_update_organization_floor_settings]
65+
}
66+
67+
const args = process.argv.slice(2);
68+
main(...args).catch(console.error);
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
/**
18+
* Updates the floor settings of a project in Model Armor.
19+
*
20+
* @param {string} projectId - Google Cloud project ID for which floor settings need to be updated.
21+
*/
22+
async function main(projectId) {
23+
// [START modelarmor_update_project_floor_settings]
24+
/**
25+
* TODO(developer): Uncomment these variables before running the sample.
26+
*/
27+
// const projectId = 'your-project-id';
28+
29+
const modelarmor = require('@google-cloud/modelarmor');
30+
const {ModelArmorClient} = modelarmor.v1;
31+
const {protos} = modelarmor;
32+
33+
const client = new ModelArmorClient();
34+
35+
const floorSettingsName = `projects/${projectId}/locations/global/floorSetting`;
36+
37+
// Build the floor settings with your preferred filters
38+
// For more details on filters, please refer to the following doc:
39+
// https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
40+
const floorSetting = {
41+
name: floorSettingsName,
42+
filterConfig: {
43+
raiSettings: {
44+
raiFilters: [
45+
{
46+
filterType:
47+
protos.google.cloud.modelarmor.v1.RaiFilterType.HATE_SPEECH,
48+
confidenceLevel:
49+
protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel.HIGH,
50+
},
51+
],
52+
},
53+
},
54+
enableFloorSettingEnforcement: true,
55+
};
56+
57+
const request = {
58+
floorSetting: floorSetting,
59+
};
60+
61+
const [response] = await client.updateFloorSetting(request);
62+
console.log('Updated project floor settings:', response);
63+
// [END modelarmor_update_project_floor_settings]
64+
}
65+
66+
const args = process.argv.slice(2);
67+
main(...args).catch(console.error);

0 commit comments

Comments
 (0)