Enumera detectores de Infotipos predefinidos

Los Infotipos son tipos de datos sensibles. En Cloud Data Loss Prevention (DLP), hay Infotipos predefinidos y personalizados. Puedes ver todos los Infotipos predefinidos en la referencia de Infotipos o puedes usar la API de Cloud DLP para enumerar todos los Infotipos predefinidos de manera programática.

El método infoTypes.list enumera todos los Infotipos integrados compatibles con Cloud DLP. Cada Infotipo incluye la siguiente información:

  • Nombre interno del Infotipo
  • Nombre de Infotipo legible
  • Si el Infotipo es compatible con la inspección o las operaciones de análisis de riesgo

Ejemplos de código

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

// infoTypes returns the info types in the given language and matching the given filter.
func infoTypes(w io.Writer, client *dlp.Client, languageCode, filter string) {
	req := &dlppb.ListInfoTypesRequest{
		LanguageCode: languageCode,
		Filter:       filter,
	}
	resp, err := client.ListInfoTypes(context.Background(), req)
	if err != nil {
		log.Fatal(err)
	}
	for _, it := range resp.GetInfoTypes() {
		fmt.Fprintln(w, it.GetName())
	}
}

PHP

use Google\Cloud\Dlp\V2\DlpServiceClient;

/**
 * Lists all Info Types for the Data Loss Prevention (DLP) API.
 *
 * @param string $category Optional filter to use, empty for ''.
 * @param string $languageCode Optional language code, empty for 'en-US'.
 */
function list_info_types($filter = '', $languageCode = '')
{
    // 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;
}

¿Te sirvió esta página? Envíanos tu opinión:

Enviar comentarios sobre…

Documentación sobre prevención de pérdida de datos