Skip to content
Merged
32 changes: 24 additions & 8 deletions model-armor/snippets/getFolderFloorSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider renaming the main function to getFolderFloorSettings to align with the file's purpose and improve readability.

Suggested change
async function main(folderId) {
async function getFolderFloorSettings(folderId) {

// [START modelarmor_get_folder_floor_settings]
/**
* TODO(developer): Uncomment these variables before running the sample.
Expand All @@ -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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This inner function introduces unnecessary nesting. The logic can be directly placed within the main function.

// Construct request
  const request = {
    name,
  };

  const [response] = await modelarmorClient.getFloorSetting(request);
  return response;


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;
});
}
35 changes: 25 additions & 10 deletions model-armor/snippets/getOrganizationFloorSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider renaming the main function to getOrganizationFloorSettings to align with the file's purpose and improve readability.

Suggested change
async function main(organizationId) {
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
Expand All @@ -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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This inner function introduces unnecessary nesting. The logic can be directly placed within the main function.

// 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;
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;
});
}
34 changes: 25 additions & 9 deletions model-armor/snippets/getProjectFloorSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider renaming the main function to getProjectFloorSettings to align with the file's purpose and improve readability.

Suggested change
async function main(projectId) {
async function getProjectFloorSettings(projectId) {

// [START modelarmor_get_project_floor_settings]
/**
* TODO(developer): Uncomment these variables before running the sample.
Expand All @@ -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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This inner function introduces unnecessary nesting. The logic can be directly placed within the main function.

// Construct request
  const request = {
    name,
  };

  // Run request
  const [response] = await modelarmorClient.getFloorSetting(request);
  return response;

}

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;
});
}
83 changes: 50 additions & 33 deletions model-armor/snippets/updateFolderFloorSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider renaming the main function to updateFolderFloorSettings to align with the file's purpose and improve readability.

Suggested change
async function main(folderId) {
async function updateFolderFloorSettings(folderId) {

// [START modelarmor_update_folder_floor_settings]
/**
* TODO(developer): Uncomment these variables before running the sample.
Expand All @@ -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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This inner function introduces unnecessary nesting. The logic can be directly placed within the main function.

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;
});
}
83 changes: 50 additions & 33 deletions model-armor/snippets/updateOrganizationFloorSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider renaming the main function to updateOrganizationFloorSettings to align with the file's purpose and improve readability.

Suggested change
async function main(organizationId) {
async function updateOrganizationFloorSettings(organizationId) {

// [START modelarmor_update_organization_floor_settings]
/**
* TODO(developer): Uncomment these variables before running the sample.
Expand All @@ -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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This inner function introduces unnecessary nesting. The logic can be directly placed within the main function.

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;
});
}
Loading
Loading