Unterstützte vordefinierte infoType-Detektoren auflisten

InfoTypes sind Arten sensibler Daten. In dem Cloud Data Loss Prevention (DLP) gibt es vordefinierte sowie benutzerdefinierte infoTypes. Sie können alle vordefinierten infoTypes in der InfoTypes-Referenz einsehen oder die Cloud DLP API verwenden, um alle vordefinierten infoTypes programmatisch aufzulisten.

Die Methode infoTypes.list listet alle integrierten infoTypes auf, die derzeit in Cloud DLP unterstützt werden. Jeder infoType enthält die folgenden Informationen:

  • Interner InfoType-Name.
  • Lesbarer infoType-Name.
  • Angabe, ob der infoType von Inspektionen oder Risikoanalysen unterstützt wird.

Codebeispiele

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

Hat Ihnen diese Seite weitergeholfen? Teilen Sie uns Ihr Feedback mit:

Feedback geben zu...

Cloud Data Loss Prevention