Skip to content

Commit 6e6208a

Browse files
chore(modelarmor): Added floor settings tests and marked them as skip (#4108)
* chore(modelarmor): added floor settings tests and marked as skip for now * chore(modelarmor): fixed floorsetting clean up and refactoring of tests * chore(modelarmor): refactored floor settings snippets * chore(modelarmor): fixed linting for floorsettings snippets * chore(modelarmor): Refactored tests assertion for floor settings tests * chore(modelarmor): fixed linting --------- Co-authored-by: Katie McLaughlin <[email protected]>
1 parent 2557514 commit 6e6208a

7 files changed

+361
-130
lines changed

model-armor/snippets/getFolderFloorSettings.js

Lines changed: 24 additions & 8 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.
@@ -34,14 +34,30 @@ async function getFolderFloorSettings(folderId) {
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+
return await getFolderFloorSettings();
4448
// [END modelarmor_get_folder_floor_settings]
4549
}
4650

47-
module.exports = getFolderFloorSettings;
51+
module.exports.main = main;
52+
53+
/* c8 ignore next 10 */
54+
if (require.main === module) {
55+
main(...process.argv.slice(2)).catch(err => {
56+
console.error(err.message);
57+
process.exitCode = 1;
58+
});
59+
process.on('unhandledRejection', err => {
60+
console.error(err.message);
61+
process.exitCode = 1;
62+
});
63+
}

model-armor/snippets/getOrganizationFloorSettings.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@
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
@@ -35,15 +34,31 @@ async function getOrganizationFloorSettings(organizationId) {
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+
}
4247

43-
// Run request
44-
const [response] = await modelarmorClient.getFloorSetting(request);
45-
return response;
48+
return await getOrganizationFloorSettings();
4649
// [END modelarmor_get_organization_floor_settings]
4750
}
4851

49-
module.exports = getOrganizationFloorSettings;
52+
module.exports.main = main;
53+
54+
/* c8 ignore next 10 */
55+
if (require.main === module) {
56+
main(...process.argv.slice(2)).catch(err => {
57+
console.error(err.message);
58+
process.exitCode = 1;
59+
});
60+
process.on('unhandledRejection', err => {
61+
console.error(err.message);
62+
process.exitCode = 1;
63+
});
64+
}

model-armor/snippets/getProjectFloorSettings.js

Lines changed: 25 additions & 9 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.
@@ -35,15 +35,31 @@ async function getProjectFloorSettings(projectId) {
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;
54+
55+
/* c8 ignore next 10 */
56+
if (require.main === module) {
57+
main(...process.argv.slice(2)).catch(err => {
58+
console.error(err.message);
59+
process.exitCode = 1;
60+
});
61+
process.on('unhandledRejection', err => {
62+
console.error(err.message);
63+
process.exitCode = 1;
64+
});
65+
}

model-armor/snippets/updateFolderFloorSettings.js

Lines changed: 50 additions & 33 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.
@@ -34,42 +34,59 @@ async function updateFolderFloorSettings(folderId) {
3434
// Instantiates a client
3535
const client = new ModelArmorClient();
3636

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

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-
],
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
58+
.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+
};
6567

66-
const request = {
67-
floorSetting: floorSetting,
68-
};
68+
const request = {
69+
floorSetting: floorSetting,
70+
};
6971

70-
const [response] = await client.updateFloorSetting(request);
71-
return response;
72+
const [response] = await client.updateFloorSetting(request);
73+
return response;
74+
}
75+
76+
return await updateFolderFloorSettings();
7277
// [END modelarmor_update_folder_floor_settings]
7378
}
7479

75-
module.exports = updateFolderFloorSettings;
80+
module.exports.main = main;
81+
82+
/* c8 ignore next 10 */
83+
if (require.main === module) {
84+
main(...process.argv.slice(2)).catch(err => {
85+
console.error(err.message);
86+
process.exitCode = 1;
87+
});
88+
process.on('unhandledRejection', err => {
89+
console.error(err.message);
90+
process.exitCode = 1;
91+
});
92+
}

model-armor/snippets/updateOrganizationFloorSettings.js

Lines changed: 50 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
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) {
2323
// [START modelarmor_update_organization_floor_settings]
2424
/**
2525
* TODO(developer): Uncomment these variables before running the sample.
@@ -32,42 +32,59 @@ async function updateOrganizationFloorSettings(organizationId) {
3232

3333
const client = new ModelArmorClient();
3434

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

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-
],
38+
// Build the floor settings with your preferred filters
39+
// For more details on filters, please refer to the following doc:
40+
// https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
41+
const floorSetting = {
42+
name: floorSettingsName,
43+
filterConfig: {
44+
raiSettings: {
45+
raiFilters: [
46+
{
47+
filterType:
48+
protos.google.cloud.modelarmor.v1.RaiFilterType.HARASSMENT,
49+
confidenceLevel:
50+
protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel
51+
.LOW_AND_ABOVE,
52+
},
53+
{
54+
filterType:
55+
protos.google.cloud.modelarmor.v1.RaiFilterType
56+
.SEXUALLY_EXPLICIT,
57+
confidenceLevel:
58+
protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel.HIGH,
59+
},
60+
],
61+
},
5962
},
60-
},
61-
enableFloorSettingEnforcement: true,
62-
};
63+
enableFloorSettingEnforcement: true,
64+
};
6365

64-
const request = {
65-
floorSetting: floorSetting,
66-
};
66+
const request = {
67+
floorSetting: floorSetting,
68+
};
6769

68-
const [response] = await client.updateFloorSetting(request);
69-
return response;
70+
const [response] = await client.updateFloorSetting(request);
71+
return response;
72+
}
73+
74+
return await updateOrganizationFloorSettings();
7075
// [END modelarmor_update_organization_floor_settings]
7176
}
7277

73-
module.exports = updateOrganizationFloorSettings;
78+
module.exports.main = main;
79+
80+
/* c8 ignore next 10 */
81+
if (require.main === module) {
82+
main(...process.argv.slice(2)).catch(err => {
83+
console.error(err.message);
84+
process.exitCode = 1;
85+
});
86+
process.on('unhandledRejection', err => {
87+
console.error(err.message);
88+
process.exitCode = 1;
89+
});
90+
}

0 commit comments

Comments
 (0)