Listing built-in infoType detectors

InfoTypes are types of sensitive data. Cloud Data Loss Prevention (DLP) supports both built-in and custom infoTypes. You can view all built-in infoTypes in the infoTypes reference, or you can use the Cloud DLP API to list all built-in infoTypes programmatically.

The infoTypes.list method lists all built-in infoTypes that are currently supported in Cloud DLP. Each infoType includes the following information:

  • The infoType identifier (ID), the internal name of the infoType.
  • The infoType display name, a human readable infoType name.
  • Whether the infoType is supported by inspection or risk analysis operations.

Code examples

To list all built-in infoType detectors:

Console

  1. In the GCP Console, open Cloud DLP.

    Go to Cloud DLP UI

  2. Click the Configuration tab, and then click InfoTypes.

  3. A table containing all built-in infoType detectors appears.

Protocol

JSON input:

GET https://dlp.googleapis.com/v2/infoTypes?key={YOUR_API_KEY}

The preceding request, when sent to the indicated endpoint, returns a list of all predefined detectors in the following format, where:

  • [INFOTYPE-NAME] represents the name of the infoType detector.
  • [INFOTYPE-DISPLAY-NAME] represents the display name for the detector
  • "supportedBy" is set to "INSPECT", "RISK_ANALYSIS", or both, depending on whether the detector is supported by inspection or risk analysis operations
  • [INFOTYPE-DESCRIPTION] represents the detector's description.

JSON output:

{
  "infoTypes":[
    {
      "name":"[INFOTYPE-NAME]",
      "displayName":"[INFOTYPE-DISPLAY-NAME]",
      "supportedBy":[
        "INSPECT"
      ],
      "description":"[INFOTYPE-DESCRIPTION]"
    },
    ...
  ]
}

Java

/*
 * List the types of sensitive information the DLP API supports.
 *
 * @param filter The filter to use, e.g. "supported_by=INSPECT"
 * @param languageCode The BCP-47 language code to use, e.g. 'en-US'
 */
private static void listInfoTypes(String filter, String languageCode) throws Exception {

  // Instantiate a DLP client
  try (DlpServiceClient dlpClient = DlpServiceClient.create()) {
    ListInfoTypesRequest listInfoTypesRequest =
        ListInfoTypesRequest.newBuilder().setFilter(filter).setLanguageCode(languageCode).build();
    ListInfoTypesResponse infoTypesResponse = dlpClient.listInfoTypes(listInfoTypesRequest);
    List<InfoTypeDescription> infoTypeDescriptions = infoTypesResponse.getInfoTypesList();
    for (InfoTypeDescription infoTypeDescription : infoTypeDescriptions) {
      System.out.println("Name : " + infoTypeDescription.getName());
      System.out.println("Display name : " + infoTypeDescription.getDisplayName());
    }
  }
}

Node.js

// Imports the Google Cloud Data Loss Prevention library
const DLP = require('@google-cloud/dlp');

// Instantiates a client
const dlp = new DLP.DlpServiceClient();

// The BCP-47 language code to use, e.g. 'en-US'
// const languageCode = 'en-US';

// The filter to use
// const filter = 'supported_by=INSPECT'

const [response] = await dlp.listInfoTypes({
  languageCode: languageCode,
  filter: filter,
});
const infoTypes = response.infoTypes;
console.log(`Info types:`);
infoTypes.forEach(infoType => {
  console.log(`\t${infoType.name} (${infoType.displayName})`);
});

Python

def list_info_types(language_code=None, result_filter=None):
    """List types of sensitive information within a category.
    Args:
        language_code: The BCP-47 language code to use, e.g. 'en-US'.
        filter: An optional filter to only return info types supported by
                certain parts of the API. Defaults to "supported_by=INSPECT".
    Returns:
        None; the response from the API is printed to the terminal.
    """
    # Import the client library
    import google.cloud.dlp

    # Instantiate a client.
    dlp = google.cloud.dlp.DlpServiceClient()

    # Make the API call.
    response = dlp.list_info_types(language_code, result_filter)

    # Print the results to the console.
    print('Info types:')
    for info_type in response.info_types:
        print('{name}: {display_name}'.format(
            name=info_type.name, display_name=info_type.display_name))

Go

import (
	"context"
	"fmt"
	"io"

	dlp "cloud.google.com/go/dlp/apiv2"
	dlppb "google.golang.org/genproto/googleapis/privacy/dlp/v2"
)

// infoTypes returns the info types in the given language and matching the given filter.
func infoTypes(w io.Writer, languageCode, filter string) error {
	// languageCode := "en-US"
	// filter := "supported_by=INSPECT"
	ctx := context.Background()
	client, err := dlp.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("dlp.NewClient: %v", err)
	}

	req := &dlppb.ListInfoTypesRequest{
		LanguageCode: languageCode,
		Filter:       filter,
	}
	resp, err := client.ListInfoTypes(ctx, req)
	if err != nil {
		return fmt.Errorf("ListInfoTypes: %v", err)
	}
	for _, it := range resp.GetInfoTypes() {
		fmt.Fprintln(w, it.GetName())
	}
	return nil
}

PHP

/**
 * Lists all Info Types for the Data Loss Prevention (DLP) API.
 */
use Google\Cloud\Dlp\V2\DlpServiceClient;

/** Uncomment and populate these variables in your code */
// $filter = ''; // (Optional) filter to use, empty for ''.
// $languageCode = ''; // (Optional) language code, empty for 'en-US'.

// Instantiate a client.
$dlp = new DlpServiceClient();

// Run request
$response = $dlp->listInfoTypes([
    'languageCode' => $languageCode,
    'filter' => $filter
]);

// Print the results
print('Info Types:' . PHP_EOL);
foreach ($response->getInfoTypes() as $infoType) {
    printf(
        '  %s (%s)' . PHP_EOL,
        $infoType->getDisplayName(),
        $infoType->getName()
    );
}

C#

public static object ListInfoTypes(
    string languageCode,
    string filter)
{
    DlpServiceClient dlp = DlpServiceClient.Create();
    var response = dlp.ListInfoTypes(
        new ListInfoTypesRequest
        {
            LanguageCode = languageCode,
            Filter = filter
        });

    Console.WriteLine("Info Types:");
    foreach (var InfoType in response.InfoTypes)
    {
        Console.WriteLine($"\t{InfoType.Name} ({InfoType.DisplayName})");
    }

    return 0;
}

APIs Explorer

You can list infoType detectors using APIs Explorer:

  1. Go to the infoTypes.list page in APIs Explorer.
  2. Click Execute without OAuth.

APIs Explorer sends a request to Cloud DLP, which sends back a JSON object containing all supported infoType detectors.

Was this page helpful? Let us know how we did:

Send feedback about...

Cloud Data Loss Prevention