Skip to content

Commit 664fd3e

Browse files
committed
chore(modelarmor): refactored floor settings snippets
1 parent 29e6cdf commit 664fd3e

File tree

6 files changed

+166
-135
lines changed

6 files changed

+166
-135
lines changed

model-armor/snippets/getFolderFloorSettings.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
* @param {string} folderId - The ID of the Google Cloud folder for which to retrieve floor settings.
2121
*/
22-
async function getFolderFloorSettings(folderId) {
22+
async function main(folderId) {
2323
// [START modelarmor_get_folder_floor_settings]
2424
/**
2525
* TODO(developer): Uncomment these variables before running the sample.
@@ -29,22 +29,27 @@ async function getFolderFloorSettings(folderId) {
2929
const name = `folders/${folderId}/locations/global/floorSetting`;
3030

3131
// Imports the Modelarmor library
32-
const {ModelArmorClient} = require('@google-cloud/modelarmor').v1;
32+
const { ModelArmorClient } = require('@google-cloud/modelarmor').v1;
3333

3434
// Instantiates a client
3535
const modelarmorClient = new ModelArmorClient();
3636

37-
// Construct request
38-
const request = {
39-
name,
40-
};
37+
async function getFolderFloorSettings() {
38+
// Construct request
39+
const request = {
40+
name,
41+
};
4142

42-
const [response] = await modelarmorClient.getFloorSetting(request);
43-
return response;
43+
const [response] = await modelarmorClient.getFloorSetting(request);
44+
return response;
45+
46+
}
47+
48+
return await getFolderFloorSettings();
4449
// [END modelarmor_get_folder_floor_settings]
4550
}
4651

47-
module.exports = getFolderFloorSettings;
52+
module.exports.main = main;
4853

4954
/* c8 ignore next 10 */
5055
if (require.main === module) {

model-armor/snippets/getOrganizationFloorSettings.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,37 @@
2020
* @param {string} organizationId - The ID of the Google Cloud organization for which to retrieve
2121
* floor settings.
2222
*/
23-
async function getOrganizationFloorSettings(organizationId) {
23+
async function main(organizationId) {
2424
// [START modelarmor_get_organization_floor_settings]
2525
/**
2626
* TODO(developer): Uncomment these variables before running the sample.
2727
*/
2828
// const organizationId = 'your-organization-id';
29-
3029
const name = `organizations/${organizationId}/locations/global/floorSetting`;
3130

3231
// Imports the Modelarmor library
33-
const {ModelArmorClient} = require('@google-cloud/modelarmor').v1;
32+
const { ModelArmorClient } = require('@google-cloud/modelarmor').v1;
3433

3534
// Instantiates a client
3635
const modelarmorClient = new ModelArmorClient();
3736

38-
// Construct request
39-
const request = {
40-
name,
41-
};
37+
async function getOrganizationFloorSettings() {
38+
// Construct request
39+
const request = {
40+
name,
41+
};
42+
43+
// Run request
44+
const [response] = await modelarmorClient.getFloorSetting(request);
45+
return response;
46+
47+
}
4248

43-
// Run request
44-
const [response] = await modelarmorClient.getFloorSetting(request);
45-
return response;
49+
return await getOrganizationFloorSettings();
4650
// [END modelarmor_get_organization_floor_settings]
4751
}
4852

49-
module.exports = getOrganizationFloorSettings;
53+
module.exports.main = main;
5054

5155
/* c8 ignore next 10 */
5256
if (require.main === module) {

model-armor/snippets/getProjectFloorSettings.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* @param {string} projectId - The ID of the Google Cloud project for which to retrieve
2121
* floor settings.
2222
*/
23-
async function getProjectFloorSettings(projectId) {
23+
async function main(projectId) {
2424
// [START modelarmor_get_project_floor_settings]
2525
/**
2626
* TODO(developer): Uncomment these variables before running the sample.
@@ -30,23 +30,27 @@ async function getProjectFloorSettings(projectId) {
3030
const name = `projects/${projectId}/locations/global/floorSetting`;
3131

3232
// Imports the Modelarmor library
33-
const {ModelArmorClient} = require('@google-cloud/modelarmor').v1;
33+
const { ModelArmorClient } = require('@google-cloud/modelarmor').v1;
3434

3535
// Instantiates a client
3636
const modelarmorClient = new ModelArmorClient();
3737

38-
// Construct request
39-
const request = {
40-
name,
41-
};
38+
async function getProjectFloorSettings() {
39+
// Construct request
40+
const request = {
41+
name,
42+
};
4243

43-
// Run request
44-
const [response] = await modelarmorClient.getFloorSetting(request);
45-
return response;
44+
// Run request
45+
const [response] = await modelarmorClient.getFloorSetting(request);
46+
return response;
47+
}
48+
49+
return await getProjectFloorSettings();
4650
// [END modelarmor_get_project_floor_settings]
4751
}
4852

49-
module.exports = getProjectFloorSettings;
53+
module.exports.main = main;
5054

5155
/* c8 ignore next 10 */
5256
if (require.main === module) {

model-armor/snippets/updateFolderFloorSettings.js

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
* @param {string} folderId - Google Cloud folder ID for which floor settings need to be updated.
2121
*/
22-
async function updateFolderFloorSettings(folderId) {
22+
async function main(folderId) {
2323
// [START modelarmor_update_folder_floor_settings]
2424
/**
2525
* TODO(developer): Uncomment these variables before running the sample.
@@ -28,51 +28,57 @@ async function updateFolderFloorSettings(folderId) {
2828

2929
// Imports the Model Armor library
3030
const modelarmor = require('@google-cloud/modelarmor');
31-
const {ModelArmorClient} = modelarmor.v1;
32-
const {protos} = modelarmor;
31+
const { ModelArmorClient } = modelarmor.v1;
32+
const { protos } = modelarmor;
3333

3434
// Instantiates a client
3535
const client = new ModelArmorClient();
3636

37-
const floorSettingsName = `folders/${folderId}/locations/global/floorSetting`;
37+
async function updateFolderFloorSettings() {
3838

39-
// Build the floor settings with your preferred filters
40-
// For more details on filters, please refer to the following doc:
41-
// https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
42-
const floorSetting = {
43-
name: floorSettingsName,
44-
filterConfig: {
45-
raiSettings: {
46-
raiFilters: [
47-
{
48-
filterType:
49-
protos.google.cloud.modelarmor.v1.RaiFilterType.HARASSMENT,
50-
confidenceLevel:
51-
protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel
52-
.LOW_AND_ABOVE,
53-
},
54-
{
55-
filterType:
56-
protos.google.cloud.modelarmor.v1.RaiFilterType.SEXUALLY_EXPLICIT,
57-
confidenceLevel:
58-
protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel.HIGH,
59-
},
60-
],
39+
const floorSettingsName = `folders/${folderId}/locations/global/floorSetting`;
40+
41+
// Build the floor settings with your preferred filters
42+
// For more details on filters, please refer to the following doc:
43+
// https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
44+
const floorSetting = {
45+
name: floorSettingsName,
46+
filterConfig: {
47+
raiSettings: {
48+
raiFilters: [
49+
{
50+
filterType:
51+
protos.google.cloud.modelarmor.v1.RaiFilterType.HARASSMENT,
52+
confidenceLevel:
53+
protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel
54+
.LOW_AND_ABOVE,
55+
},
56+
{
57+
filterType:
58+
protos.google.cloud.modelarmor.v1.RaiFilterType.SEXUALLY_EXPLICIT,
59+
confidenceLevel:
60+
protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel.HIGH,
61+
},
62+
],
63+
},
6164
},
62-
},
63-
enableFloorSettingEnforcement: true,
64-
};
65+
enableFloorSettingEnforcement: true,
66+
};
67+
68+
const request = {
69+
floorSetting: floorSetting,
70+
};
71+
72+
const [response] = await client.updateFloorSetting(request);
73+
return response;
6574

66-
const request = {
67-
floorSetting: floorSetting,
68-
};
75+
}
6976

70-
const [response] = await client.updateFloorSetting(request);
71-
return response;
77+
return await updateFolderFloorSettings();
7278
// [END modelarmor_update_folder_floor_settings]
7379
}
7480

75-
module.exports = updateFolderFloorSettings;
81+
module.exports.main = main;
7682

7783
/* c8 ignore next 10 */
7884
if (require.main === module) {

model-armor/snippets/updateOrganizationFloorSettings.js

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,58 +19,64 @@
1919
*
2020
* @param {string} organizationId - Google Cloud organization ID for which floor settings need to be updated.
2121
*/
22-
async function updateOrganizationFloorSettings(organizationId) {
22+
async function main(organizationId) {
23+
2324
// [START modelarmor_update_organization_floor_settings]
2425
/**
2526
* TODO(developer): Uncomment these variables before running the sample.
2627
*/
2728
// const organizationId = 'your-organization-id';
2829

2930
const modelarmor = require('@google-cloud/modelarmor');
30-
const {ModelArmorClient} = modelarmor.v1;
31-
const {protos} = modelarmor;
31+
const { ModelArmorClient } = modelarmor.v1;
32+
const { protos } = modelarmor;
3233

3334
const client = new ModelArmorClient();
3435

35-
const floorSettingsName = `organizations/${organizationId}/locations/global/floorSetting`;
36+
async function updateOrganizationFloorSettings() {
37+
38+
const floorSettingsName = `organizations/${organizationId}/locations/global/floorSetting`;
3639

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.HARASSMENT,
48-
confidenceLevel:
49-
protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel
50-
.LOW_AND_ABOVE,
51-
},
52-
{
53-
filterType:
54-
protos.google.cloud.modelarmor.v1.RaiFilterType.SEXUALLY_EXPLICIT,
55-
confidenceLevel:
56-
protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel.HIGH,
57-
},
58-
],
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.HARASSMENT,
51+
confidenceLevel:
52+
protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel
53+
.LOW_AND_ABOVE,
54+
},
55+
{
56+
filterType:
57+
protos.google.cloud.modelarmor.v1.RaiFilterType.SEXUALLY_EXPLICIT,
58+
confidenceLevel:
59+
protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel.HIGH,
60+
},
61+
],
62+
},
5963
},
60-
},
61-
enableFloorSettingEnforcement: true,
62-
};
64+
enableFloorSettingEnforcement: true,
65+
};
66+
67+
const request = {
68+
floorSetting: floorSetting,
69+
};
6370

64-
const request = {
65-
floorSetting: floorSetting,
66-
};
71+
const [response] = await client.updateFloorSetting(request);
72+
return response;
73+
}
6774

68-
const [response] = await client.updateFloorSetting(request);
69-
return response;
75+
return await updateOrganizationFloorSettings();
7076
// [END modelarmor_update_organization_floor_settings]
7177
}
7278

73-
module.exports = updateOrganizationFloorSettings;
79+
module.exports.main = main;
7480

7581
/* c8 ignore next 10 */
7682
if (require.main === module) {

0 commit comments

Comments
 (0)