List table data profiles (v2)

Lists Sensitive Data Protection table data profiles in an organization.

Code sample

Node.js

To learn how to install and use the client library for Sensitive Data Protection, see Sensitive Data Protection client libraries.

To authenticate to Sensitive Data Protection, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

'use strict';

const {DlpServiceClient} = require('@google-cloud/dlp');
const {status} = require('@grpc/grpc-js');

const client = new DlpServiceClient();

/**
 * Lists Sensitive Data Protection table data profiles in an organization.
 *
 * @param {string} organization_id - The Google Cloud organization ID.
 * @param {string} location_id - The geographic location where the table data profiles are stored.
 */
async function listTableDataProfiles(organization_id, location_id) {
  const parent = `organizations/${organization_id}/locations/${location_id}`;
  const request = {
    parent,
  };

  if (!organization_id) {
    console.error('Organization ID is required.');
    return;
  }

  try {
    const [profiles] = await client.listTableDataProfiles(request);
    console.log(`Retrieved ${profiles.length} table data profile(s).`);
    for (const profile of profiles) {
      console.log(`Table data profile: ${profile.name}`);
      console.log(`  Full resource: ${profile.fullResource}`);
    }
  } catch (err) {
    if (err.code === status.NOT_FOUND) {
      console.error('Parent resource not found.');
    } else if (err.code === status.PERMISSION_DENIED) {
      console.error('Permission denied accessing table data profiles.');
    } else if (err.code === status.INVALID_ARGUMENT) {
      console.error('Invalid argument provided.');
    } else {
      console.error(`Error listing table data profiles: ${err.code || err}`);
    }
  }
}

module.exports = {listTableDataProfiles};

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.