-
Notifications
You must be signed in to change notification settings - Fork 2k
chore(modelarmor): Added floor settings tests and marked them as skip #4108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
040ade4
29e6cdf
664fd3e
5b87090
ff148e0
567a1da
290723a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ | |
| * | ||
| * @param {string} folderId - The ID of the Google Cloud folder for which to retrieve floor settings. | ||
| */ | ||
| async function getFolderFloorSettings(folderId) { | ||
| async function main(folderId) { | ||
| // [START modelarmor_get_folder_floor_settings] | ||
| /** | ||
| * TODO(developer): Uncomment these variables before running the sample. | ||
|
|
@@ -34,14 +34,30 @@ async function getFolderFloorSettings(folderId) { | |
| // Instantiates a client | ||
| const modelarmorClient = new ModelArmorClient(); | ||
|
|
||
| // Construct request | ||
| const request = { | ||
| name, | ||
| }; | ||
| async function getFolderFloorSettings() { | ||
| // Construct request | ||
| const request = { | ||
| name, | ||
| }; | ||
|
|
||
| const [response] = await modelarmorClient.getFloorSetting(request); | ||
| return response; | ||
| const [response] = await modelarmorClient.getFloorSetting(request); | ||
| return response; | ||
| } | ||
|
Comment on lines
+37
to
+45
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| return await getFolderFloorSettings(); | ||
| // [END modelarmor_get_folder_floor_settings] | ||
| } | ||
|
|
||
| module.exports = getFolderFloorSettings; | ||
| module.exports.main = main; | ||
|
|
||
| /* c8 ignore next 10 */ | ||
| if (require.main === module) { | ||
| main(...process.argv.slice(2)).catch(err => { | ||
| console.error(err.message); | ||
| process.exitCode = 1; | ||
| }); | ||
| process.on('unhandledRejection', err => { | ||
| console.error(err.message); | ||
| process.exitCode = 1; | ||
| }); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,13 +20,12 @@ | |
| * @param {string} organizationId - The ID of the Google Cloud organization for which to retrieve | ||
| * floor settings. | ||
| */ | ||
| async function getOrganizationFloorSettings(organizationId) { | ||
| async function main(organizationId) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| // [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 | ||
|
|
@@ -35,15 +34,31 @@ async function getOrganizationFloorSettings(organizationId) { | |
| // Instantiates a client | ||
| const modelarmorClient = new ModelArmorClient(); | ||
|
|
||
| // Construct request | ||
| const request = { | ||
| name, | ||
| }; | ||
| async function getOrganizationFloorSettings() { | ||
| // Construct request | ||
| const request = { | ||
| name, | ||
| }; | ||
|
|
||
| // Run request | ||
| const [response] = await modelarmorClient.getFloorSetting(request); | ||
| return response; | ||
|
Comment on lines
+37
to
+45
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| // Run request | ||
| const [response] = await modelarmorClient.getFloorSetting(request); | ||
| return response; | ||
| return await getOrganizationFloorSettings(); | ||
| // [END modelarmor_get_organization_floor_settings] | ||
| } | ||
|
|
||
| module.exports = getOrganizationFloorSettings; | ||
| module.exports.main = main; | ||
|
|
||
| /* c8 ignore next 10 */ | ||
| if (require.main === module) { | ||
| main(...process.argv.slice(2)).catch(err => { | ||
| console.error(err.message); | ||
| process.exitCode = 1; | ||
| }); | ||
| process.on('unhandledRejection', err => { | ||
| console.error(err.message); | ||
| process.exitCode = 1; | ||
| }); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ | |
| * @param {string} projectId - The ID of the Google Cloud project for which to retrieve | ||
| * floor settings. | ||
| */ | ||
| async function getProjectFloorSettings(projectId) { | ||
| async function main(projectId) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| // [START modelarmor_get_project_floor_settings] | ||
| /** | ||
| * TODO(developer): Uncomment these variables before running the sample. | ||
|
|
@@ -35,15 +35,31 @@ async function getProjectFloorSettings(projectId) { | |
| // Instantiates a client | ||
| const modelarmorClient = new ModelArmorClient(); | ||
|
|
||
| // Construct request | ||
| const request = { | ||
| name, | ||
| }; | ||
| async function getProjectFloorSettings() { | ||
| // Construct request | ||
| const request = { | ||
| name, | ||
| }; | ||
|
|
||
| // Run request | ||
| const [response] = await modelarmorClient.getFloorSetting(request); | ||
| return response; | ||
| // Run request | ||
| const [response] = await modelarmorClient.getFloorSetting(request); | ||
| return response; | ||
|
Comment on lines
+38
to
+46
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| return await getProjectFloorSettings(); | ||
| // [END modelarmor_get_project_floor_settings] | ||
| } | ||
|
|
||
| module.exports = getProjectFloorSettings; | ||
| module.exports.main = main; | ||
|
|
||
| /* c8 ignore next 10 */ | ||
| if (require.main === module) { | ||
| main(...process.argv.slice(2)).catch(err => { | ||
| console.error(err.message); | ||
| process.exitCode = 1; | ||
| }); | ||
| process.on('unhandledRejection', err => { | ||
| console.error(err.message); | ||
| process.exitCode = 1; | ||
| }); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ | |
| * | ||
| * @param {string} folderId - Google Cloud folder ID for which floor settings need to be updated. | ||
| */ | ||
| async function updateFolderFloorSettings(folderId) { | ||
| async function main(folderId) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| // [START modelarmor_update_folder_floor_settings] | ||
| /** | ||
| * TODO(developer): Uncomment these variables before running the sample. | ||
|
|
@@ -34,42 +34,59 @@ async function updateFolderFloorSettings(folderId) { | |
| // Instantiates a client | ||
| const client = new ModelArmorClient(); | ||
|
|
||
| const floorSettingsName = `folders/${folderId}/locations/global/floorSetting`; | ||
| async function updateFolderFloorSettings() { | ||
| 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, | ||
| }, | ||
| ], | ||
| // 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, | ||
| }; | ||
| enableFloorSettingEnforcement: true, | ||
| }; | ||
|
|
||
| const request = { | ||
| floorSetting: floorSetting, | ||
| }; | ||
| const request = { | ||
| floorSetting: floorSetting, | ||
| }; | ||
|
|
||
| const [response] = await client.updateFloorSetting(request); | ||
| return response; | ||
| const [response] = await client.updateFloorSetting(request); | ||
| return response; | ||
|
Comment on lines
+37
to
+73
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This inner function introduces unnecessary nesting. The logic can be directly placed within the 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; |
||
| } | ||
|
|
||
| return await updateFolderFloorSettings(); | ||
| // [END modelarmor_update_folder_floor_settings] | ||
| } | ||
|
|
||
| module.exports = updateFolderFloorSettings; | ||
| module.exports.main = main; | ||
|
|
||
| /* c8 ignore next 10 */ | ||
| if (require.main === module) { | ||
| main(...process.argv.slice(2)).catch(err => { | ||
| console.error(err.message); | ||
| process.exitCode = 1; | ||
| }); | ||
| process.on('unhandledRejection', err => { | ||
| console.error(err.message); | ||
| process.exitCode = 1; | ||
| }); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ | |
| * | ||
| * @param {string} organizationId - Google Cloud organization ID for which floor settings need to be updated. | ||
| */ | ||
| async function updateOrganizationFloorSettings(organizationId) { | ||
| async function main(organizationId) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| // [START modelarmor_update_organization_floor_settings] | ||
| /** | ||
| * TODO(developer): Uncomment these variables before running the sample. | ||
|
|
@@ -32,42 +32,59 @@ async function updateOrganizationFloorSettings(organizationId) { | |
|
|
||
| const client = new ModelArmorClient(); | ||
|
|
||
| const floorSettingsName = `organizations/${organizationId}/locations/global/floorSetting`; | ||
| async function updateOrganizationFloorSettings() { | ||
| 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, | ||
| }, | ||
| ], | ||
| // 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, | ||
| }; | ||
| enableFloorSettingEnforcement: true, | ||
| }; | ||
|
|
||
| const request = { | ||
| floorSetting: floorSetting, | ||
| }; | ||
| const request = { | ||
| floorSetting: floorSetting, | ||
| }; | ||
|
|
||
| const [response] = await client.updateFloorSetting(request); | ||
| return response; | ||
| const [response] = await client.updateFloorSetting(request); | ||
| return response; | ||
|
Comment on lines
+35
to
+71
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This inner function introduces unnecessary nesting. The logic can be directly placed within the 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; |
||
| } | ||
|
|
||
| return await updateOrganizationFloorSettings(); | ||
| // [END modelarmor_update_organization_floor_settings] | ||
| } | ||
|
|
||
| module.exports = updateOrganizationFloorSettings; | ||
| module.exports.main = main; | ||
|
|
||
| /* c8 ignore next 10 */ | ||
| if (require.main === module) { | ||
| main(...process.argv.slice(2)).catch(err => { | ||
| console.error(err.message); | ||
| process.exitCode = 1; | ||
| }); | ||
| process.on('unhandledRejection', err => { | ||
| console.error(err.message); | ||
| process.exitCode = 1; | ||
| }); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider renaming the
mainfunction togetFolderFloorSettingsto align with the file's purpose and improve readability.