יצירת תבניות להסרת פרטי הזיהוי באמצעות Sensitive Data Protection

אתם יכולים להשתמש בתבניות כדי ליצור ולשמור מידע על הגדרות לשימוש עם Sensitive Data Protection. תבניות שימושיות להפרדת ההגדרה, למשל מה בודקים ואיך מסירים את הפרטים המזהים, מההטמעה של הבקשות. תבניות הן דרך יעילה לעשות שימוש חוזר בהגדרות, ולשמור על עקביות בין משתמשים ומערכי נתונים.

הכלי Sensitive Data Protection תומך בשני סוגים של תבניות:

  • תבניות להסרת פרטי הזיהוי: תבניות לשמירת פרטי ההגדרה של משימות להסרת פרטי הזיהוי, כולל טרנספורמציות של infoType ושל רשומות (מערך נתונים מובנה).
  • תבניות בדיקה: תבניות לשמירת פרטי ההגדרה של משימות סריקה לבדיקה, כולל גלאים מוגדרים מראש או גלאים בהתאמה אישית שבהם יש להשתמש. מידע נוסף על תבניות בדיקה זמין במאמר יצירה של תבניות בדיקה של Sensitive Data Protection.

מידע על תבניות ב-Sensitive Data Protection זמין במאמר תבניות.

בהמשך המאמר מוסבר איך ליצור תבניות לביטול הזיהוי לשימוש עם Sensitive Data Protection.

יצירת תבנית להסרת פרטים מזהים

המסוף

נכנסים לדף Create template במסוף Google Cloud .

כניסה לדף Create template

בקטעים הבאים מוסבר איך למלא את הדף Create template (יצירת תבנית).

הגדרת תבנית

בקטע Define template (הגדרת תבנית), ממלאים את השדות באופן הבא:

  1. בקטע סוג התבנית, בוחרים באפשרות הסרת פרטים מזהים (הסרת מידע אישי רגיש).
  2. בקטע סוג הטרנספורמציה של הנתונים, בוחרים את סוג הטרנספורמציה שרוצים להחיל:

    • InfoType. הכלי Sensitive Data Protection מחיל כל טרנספורמציה רק על הערך שזוהה כ-infoType ספציפי. סוג הטרנספורמציה הזה שימושי לטקסט לא מובנה.

    • הקלטה. התכונה Sensitive Data Protection מתייחסת לפורמט המובנה של הנתונים כשהיא מבצעת טרנספורמציה. סוג השינוי הזה שימושי לנתונים טבלאיים.

    • תמונה. Sensitive Data Protection מצנזר את כל הטקסט שזוהה בתמונה או רק טקסט שתואם ל-infoType ספציפי.

  3. בשדה מזהה תבנית, מזינים מזהה ייחודי לתבנית.

  4. בשדה Display name, מזינים שם לתבנית.

  5. בשדה תיאור, מתארים את התבנית.

  6. בשדה Resource location, בוחרים באפשרות Global או במיקום של הנתונים שרוצים להסיר מהם את הפרטים המזהים.

  7. לוחצים על Continue.

הגדרת הסרת פרטי זיהוי

השדות שמופיעים בקטע הגדרת הסרת פרטים מזהים מבוססים על סוג השינוי בנתונים שבחרתם.

InfoType

אם בחרתם באפשרות InfoType כסוג המרת הנתונים, מבצעים את הפעולות הבאות:

  1. בשדה Transformation (טרנספורמציה), בוחרים שיטת טרנספורמציה להחלה על הממצאים.

    יופיעו עוד שדות בהתאם לבחירה שלכם. ממלאים את השדות לפי הצורך. מידע נוסף זמין במאמר בנושא הפניות לטרנספורמציות.

  2. בקטע InfoTypes to transform (סוגי מידע להמרה), מציינים אם רוצים להחיל את ההמרה על כל סוגי המידע שזוהו ומוגדרים בהגדרות הבדיקה.

    אם בוחרים באפשרות Specify infoTypes, צריך לבחור את סוגי המידע שרוצים להחיל עליהם את שיטת ההמרה.

  3. אם רוצים להוסיף כללי טרנספורמציה לסוגי מידע שלא נכללים בכלל הטרנספורמציה, לוחצים על הוספת כלל טרנספורמציה. לאחר מכן, ממלאים את השדות לפי הצורך. חוזרים על השלב הזה עד שמגדירים כלל טרנספורמציה לכל סוגי המידע שרוצים לבצע בהם טרנספורמציה.

  4. לוחצים על יצירה.

הקלטה

אם בחרתם באפשרות רשומה כסוג של שינוי הנתונים, מבצעים את הפעולות הבאות:

  1. בשדה Field(s) or column(s) to transform (שדות או עמודות להמרה), מקלידים את השם של עמודת הטבלה שמכילה את הנתונים שרוצים להמיר. ואז לוחצים על ENTER. חוזרים על השלב הזה לכל עמודה שמכילה נתונים שרוצים לשנות.
  2. מציינים את סוג הטרנספורמציה:

    • התאמה לפי infoType. ב-Sensitive Data Protection, כל תא נחשב לטקסט לא מובנה, וההמרה חלה רק על ה-infoTypes שנמצאים בתא. הכלי Sensitive Data Protection לא משנה נתונים שמקיפים infoType.

      אם בוחרים באפשרות הזו, צריך:

      1. לוחצים על הוספת שינוי. בשדה Transformation (שינוי), בוחרים שיטת שינוי להחלה על הממצאים.
      2. מציינים אם רוצים להחיל את השינוי על כל סוגי המידע שזוהו ומוגדרים בהגדרות הבדיקה.

        אם בוחרים באפשרות Specify infoTypes (ציון סוגי מידע), בוחרים את סוגי המידע שרוצים להחיל עליהם את כלל השינוי.

      אם רוצים להקצות כללי טרנספורמציה מסוימים לסוגי מידע מסוימים, אפשר להוסיף עוד טרנספורמציות לפי הצורך.

    • שינוי שדה פרימיטיבי. התכונה Sensitive Data Protection תמיד משנה את כל התא לפי שיטת טרנספורמציה שתבחרו. האפשרות הזו שימושית אם רוצים לבצע טרנספורמציה של עמודות שלמות של נתונים, בלי קשר לשאלה אם התאים בעמודות האלה כוללים סוגי מידע שזוהו.

      אם בוחרים באפשרות הזו, בשדה טרנספורמציה בוחרים שיטת טרנספורמציה להחלה על העמודות שציינתם.

    בשני המקרים, יופיעו עוד שדות בהתאם לשיטת הטרנספורמציה שבחרתם. ממלאים את השדות לפי הצורך. מידע נוסף זמין במאמר בנושא הפניות לטרנספורמציות.

  3. לוחצים על יצירה.

תמונה

אם בחרתם באפשרות תמונה כסוג המרת הנתונים, מבצעים את הפעולות הבאות:

  1. אופציונלי: כדי לשנות את הצבע של התיבה שמכסה את הטקסט שנערך, לוחצים על התיבה השחורה בשדה צבע הצנזורה ובוחרים צבע אחר.

  2. בקטע InfoTypes to transform (סוגי מידע להמרה), מציינים מה רוצים לצנזר: את כל הטקסט שזוהה, את כל סוגי המידע שהוגדרו בהגדרות הבדיקה או רק סוגי מידע ספציפיים.

    אם בוחרים באפשרות Specify infoTypes, בוחרים את סוגי המידע שרוצים להחיל עליהם את כלל השינוי.

  3. אם רוצים להוסיף כללי טרנספורמציה לסוגי מידע שלא נכללים בכלל הטרנספורמציה, לוחצים על הוספת כלל טרנספורמציה. לאחר מכן, ממלאים את השדות לפי הצורך. חוזרים על השלב הזה עד שמגדירים כלל טרנספורמציה לכל סוגי המידע שרוצים לבצע בהם טרנספורמציה.

  4. לוחצים על יצירה.

פרוטוקול

חשוב לציין שתבנית לביטול הזיהוי היא פשוט הגדרה לביטול הזיהוי שאפשר לעשות בה שימוש חוזר, בתוספת מטא-נתונים. במונחי API, האובייקט DeidentifyTemplate הוא למעשה אובייקט DeidentifyConfigשכולל עוד כמה שדות של מטא-נתונים, כמו שם מוצג ותיאור. לכן, כדי ליצור תבנית חדשה לביטול הזיהוי, השלבים הבסיסיים הם:

  1. מתחילים עם אובייקט DeidentifyConfig.
  2. קוראים לשיטה create של משאב projects.deidentifyTemplates או שולחים בקשת POST אליה, כולל אובייקט DeidentifyTemplate שמכיל שם מוצג, תיאור ואובייקט DeidentifyConfig.

אפשר להשתמש ב-DeidentifyTemplate שמוחזר באופן מיידי. אפשר להפנות אליו בשיחות או בעבודות אחרות באמצעות name. כדי להציג את התבניות הקיימות, קוראים לשיטה *.deidentifyTemplates.list. כדי להציג תבנית ספציפית, מבצעים קריאה ל-method‏ *.deidentifyTemplates.get. הערה: אפשר ליצור עד 1,000 תבניות.

אם כבר יש לכם ניסיון בהסרת פרטים מזהים מנתונים רגישים בטקסט, בתמונות או בתוכן מובנה באמצעות הכלי להגנה על מידע אישי רגיש, כבר יצרתם אובייקט DeidentifyConfig. עוד שלב אחד והוא הופך לאובייקט DeidentifyTemplate.

דוגמה ל-REST

ה-JSON הבא הוא דוגמה למה שאפשר לשלוח לשיטה projects.deidentifyTemplates.create. קובץ ה-JSON הזה יוצר תבנית חדשה עם השם המוצג והתיאור שצוינו, ומחפש התאמות בסוגי המידע EMAIL_ADDRESS ו-GENERIC_ID. אם המערכת תמצא תוכן שתואם לסוגי המידע האלה, היא תסתיר את שלושת התווים הראשונים באמצעות כוכבית (*).

ה-method של ה-HTTP וכתובת ה-URL

POST https://dlp.googleapis.com/v2/projects/PROJECT_ID/deidentifyTemplates

מחליפים את PROJECT_ID במזהה הפרויקט.

קלט JSON

{
  "deidentifyTemplate":{
    "displayName":"Email and id masker",
    "description":"De-identifies emails and ids with a series of asterisks.",
    "deidentifyConfig":{
      "infoTypeTransformations":{
        "transformations":[
          {
            "infoTypes":[
              {
                "name":"GENERIC_ID"
              }
            ],
            "primitiveTransformation":{
              "replaceWithInfoTypeConfig":{

              }
            }
          },
          {
            "infoTypes":[
              {
                "name":"EMAIL_ADDRESS"
              }
            ],
            "primitiveTransformation":{
              "characterMaskConfig":{
                "charactersToIgnore":[
                  {
                    "charactersToSkip":"@"
                  }
                ],
                "maskingCharacter":"*"
              }
            }
          }
        ]
      }
    }
  }
}

פלט מסוג JSON

    {
      "name":"projects/PROJECT_ID/deidentifyTemplates/JOB-ID",
      "displayName":"Email and id masker",
      "description":"De-identifies emails and ids with a series of asterisks.",
      "createTime":"2018-11-30T07:17:59.536022Z",
      "updateTime":"2018-11-30T07:17:59.536022Z",
      "deidentifyConfig":{
        "infoTypeTransformations":{
          "transformations":[
            {
              "infoTypes":[
                {
                  "name":"GENERIC_ID"
                }
              ],
              "primitiveTransformation":{
                "replaceWithInfoTypeConfig":{

                }
              }
            },
            {
              "infoTypes":[
                {
                  "name":"EMAIL_ADDRESS"
                }
              ],
              "primitiveTransformation":{
                "characterMaskConfig":{
                  "maskingCharacter":"*",
                  "charactersToIgnore":[
                    {
                      "charactersToSkip":"@"
                    }
                  ]
                }
              }
            }
          ]
        }
      }
    }

כדי להתנסות בזה במהירות, אפשר להשתמש ב-APIs Explorer שמוטמע בהמשך. מידע כללי על שימוש ב-JSON כדי לשלוח בקשות ל-DLP API זמין במדריך לתחילת העבודה עם JSON.

שימוש בתבניות להסרת פרטי זיהוי

אחרי שיוצרים תבנית חדשה, אפשר להשתמש במזהה name שלה בכל מקום שבו deidentifyTemplateName מתקבל, למשל:

  • projects.content.deidentify: מסיר פרטי זיהוי ממידע אישי רגיש פוטנציאלי בתוכן באמצעות התבנית כהגדרה שלו. חשוב לדעת שבשיטה הזו אפשר להשתמש בתבנית בדיקה או בתבנית להסרת פרטים מזהים.

תבניות להסרת פרטי הזיהוי מדף האפליקציה בחנות

כדי לראות את הרשימה של כל התבניות להסרת פרטים מזהים שנוצרו, משתמשים באחת מהשיטות *.*.list:

בקטע הזה מוסבר איך להשתמש ב-Sensitive Data Protection כדי להציג רשימה של תבניות בדיקה. התהליך זהה לזה של הצגת תבניות להסרת פרטי הזיהוי.

C#

מידע על התקנת ספריית הלקוח של Sensitive Data Protection והשימוש בה מופיע במאמר ספריות הלקוח של Sensitive Data Protection.

כדי לבצע אימות ב-Sensitive Data Protection, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.


using Google.Api.Gax.ResourceNames;
using Google.Cloud.Dlp.V2;
using System;
using Google.Api.Gax;

public class InspectTemplateList
{
    public static PagedEnumerable<ListInspectTemplatesResponse, InspectTemplate> List(string projectId)
    {
        var client = DlpServiceClient.Create();

        var response = client.ListInspectTemplates(
            new ListInspectTemplatesRequest
            {
                Parent = new LocationName(projectId, "global").ToString(),
            }
        );

        // Uncomment to list templates
        //PrintTemplates(response);

        return response;
    }

    public static void PrintTemplates(PagedEnumerable<ListInspectTemplatesResponse, InspectTemplate> response)
    {
        foreach (var template in response)
        {
            Console.WriteLine($"Template {template.Name}:");
            Console.WriteLine($"\tDisplay Name: {template.DisplayName}");
            Console.WriteLine($"\tDescription: {template.Description}");
            Console.WriteLine($"\tCreated: {template.CreateTime}");
            Console.WriteLine($"\tUpdated: {template.UpdateTime}");
            Console.WriteLine("Configuration:");
            Console.WriteLine($"\tMin Likelihood: {template.InspectConfig?.MinLikelihood}");
            Console.WriteLine($"\tInclude quotes: {template.InspectConfig?.IncludeQuote}");
            Console.WriteLine($"\tMax findings per request: {template.InspectConfig?.Limits.MaxFindingsPerRequest}");
        }
    }
}

Go

מידע על התקנת ספריית הלקוח של Sensitive Data Protection והשימוש בה מופיע במאמר ספריות הלקוח של Sensitive Data Protection.

כדי לבצע אימות ב-Sensitive Data Protection, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.

import (
	"context"
	"fmt"
	"io"
	"time"

	dlp "cloud.google.com/go/dlp/apiv2"
	"cloud.google.com/go/dlp/apiv2/dlppb"
	"github.com/golang/protobuf/ptypes"
	"google.golang.org/api/iterator"
)

// listInspectTemplates lists the inspect templates in the project.
func listInspectTemplates(w io.Writer, projectID string) error {
	// projectID := "my-project-id"

	ctx := context.Background()

	client, err := dlp.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("dlp.NewClient: %w", err)
	}
	defer client.Close()

	// Create a configured request.
	req := &dlppb.ListInspectTemplatesRequest{
		Parent: fmt.Sprintf("projects/%s/locations/global", projectID),
	}

	// Send the request and iterate over the results.
	it := client.ListInspectTemplates(ctx, req)
	for {
		t, err := it.Next()
		if err == iterator.Done {
			break
		}
		if err != nil {
			return fmt.Errorf("Next: %w", err)
		}
		fmt.Fprintf(w, "Inspect template %v\n", t.GetName())
		c, err := ptypes.Timestamp(t.GetCreateTime())
		if err != nil {
			return fmt.Errorf("CreateTime Timestamp: %w", err)
		}
		fmt.Fprintf(w, "  Created: %v\n", c.Format(time.RFC1123))
		u, err := ptypes.Timestamp(t.GetUpdateTime())
		if err != nil {
			return fmt.Errorf("UpdateTime Timestamp: %w", err)
		}
		fmt.Fprintf(w, "  Updated: %v\n", u.Format(time.RFC1123))
		fmt.Fprintf(w, "  Display Name: %q\n", t.GetDisplayName())
		fmt.Fprintf(w, "  Description: %q\n", t.GetDescription())
	}

	return nil
}

Java

מידע על התקנת ספריית הלקוח של Sensitive Data Protection והשימוש בה מופיע במאמר ספריות הלקוח של Sensitive Data Protection.

כדי לבצע אימות ב-Sensitive Data Protection, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.


import com.google.cloud.dlp.v2.DlpServiceClient;
import com.google.cloud.dlp.v2.DlpServiceClient.ListInspectTemplatesPagedResponse;
import com.google.privacy.dlp.v2.InfoType;
import com.google.privacy.dlp.v2.InspectConfig;
import com.google.privacy.dlp.v2.InspectTemplate;
import com.google.privacy.dlp.v2.ListInspectTemplatesRequest;
import com.google.privacy.dlp.v2.LocationName;
import java.io.IOException;

class TemplatesList {

  public static void main(String[] args) throws Exception {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "your-project-id";
    listInspectTemplates(projectId);
  }

  // Lists all templates associated with a given project
  public static void listInspectTemplates(String projectId) throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {

      // Create the request to be sent by the client
      ListInspectTemplatesRequest request =
          ListInspectTemplatesRequest.newBuilder()
              .setParent(LocationName.of(projectId, "global").toString())
              .setPageSize(1)
              .build();

      // Send the request
      ListInspectTemplatesPagedResponse response = dlpServiceClient.listInspectTemplates(request);

      // Parse through and process the response
      System.out.println("Templates found:");
      for (InspectTemplate template : response.getPage().getResponse().getInspectTemplatesList()) {
        System.out.printf("Template name: %s\n", template.getName());
        if (template.getDisplayName() != null) {
          System.out.printf("\tDisplay name: %s \n", template.getDisplayName());
          System.out.printf("\tCreate time: %s \n", template.getCreateTime());
          System.out.printf("\tUpdate time: %s \n", template.getUpdateTime());

          // print inspection config
          InspectConfig inspectConfig = template.getInspectConfig();
          for (InfoType infoType : inspectConfig.getInfoTypesList()) {
            System.out.printf("\tInfoType: %s\n", infoType.getName());
          }
          System.out.printf("\tMin likelihood: %s\n", inspectConfig.getMinLikelihood());
          System.out.printf("\tLimits: %s\n", inspectConfig.getLimits().getMaxFindingsPerRequest());
        }
      }
    }
  }
}

Node.js

מידע על התקנת ספריית הלקוח של Sensitive Data Protection והשימוש בה מופיע במאמר ספריות הלקוח של Sensitive Data Protection.

כדי לבצע אימות ב-Sensitive Data Protection, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.

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

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

// The project ID to run the API call under
// const projectId = 'my-project';

// Helper function to pretty-print dates
const formatDate = date => {
  const msSinceEpoch = parseInt(date.seconds, 10) * 1000;
  return new Date(msSinceEpoch).toLocaleString('en-US');
};

async function listInspectTemplates() {
  // Construct template-listing request
  const request = {
    parent: `projects/${projectId}/locations/global`,
  };

  // Run template-deletion request
  const [templates] = await dlp.listInspectTemplates(request);

  templates.forEach(template => {
    console.log(`Template ${template.name}`);
    if (template.displayName) {
      console.log(`  Display name: ${template.displayName}`);
    }

    console.log(`  Created: ${formatDate(template.createTime)}`);
    console.log(`  Updated: ${formatDate(template.updateTime)}`);

    const inspectConfig = template.inspectConfig;
    const infoTypes = inspectConfig.infoTypes.map(x => x.name);
    console.log('  InfoTypes:', infoTypes.join(' '));
    console.log('  Minimum likelihood:', inspectConfig.minLikelihood);
    console.log('  Include quotes:', inspectConfig.includeQuote);

    const limits = inspectConfig.limits;
    console.log('  Max findings per request:', limits.maxFindingsPerRequest);
  });
}

listInspectTemplates();

PHP

מידע על התקנת ספריית הלקוח של Sensitive Data Protection והשימוש בה מופיע במאמר ספריות הלקוח של Sensitive Data Protection.

כדי לבצע אימות ב-Sensitive Data Protection, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.

use Google\Cloud\Dlp\V2\Client\DlpServiceClient;
use Google\Cloud\Dlp\V2\ListInspectTemplatesRequest;

/**
 * List DLP inspection configuration templates.
 *
 * @param string $callingProjectId  The project ID to run the API call under
 */
function list_inspect_templates(string $callingProjectId): void
{
    // Instantiate a client.
    $dlp = new DlpServiceClient();

    $parent = "projects/$callingProjectId/locations/global";

    // Run request
    $listInspectTemplatesRequest = (new ListInspectTemplatesRequest())
        ->setParent($parent);
    $response = $dlp->listInspectTemplates($listInspectTemplatesRequest);

    // Print results
    $templates = $response->iterateAllElements();

    foreach ($templates as $template) {
        printf('Template %s' . PHP_EOL, $template->getName());
        printf('  Created: %s' . PHP_EOL, $template->getCreateTime()->getSeconds());
        printf('  Updated: %s' . PHP_EOL, $template->getUpdateTime()->getSeconds());
        printf('  Display Name: %s' . PHP_EOL, $template->getDisplayName());
        printf('  Description: %s' . PHP_EOL, $template->getDescription());

        $inspectConfig = $template->getInspectConfig();
        if ($inspectConfig === null) {
            print('  No inspect config.' . PHP_EOL);
        } else {
            printf('  Minimum likelihood: %s' . PHP_EOL, $inspectConfig->getMinLikelihood());
            printf('  Include quotes: %s' . PHP_EOL, $inspectConfig->getIncludeQuote());
            $limits = $inspectConfig->getLimits();
            printf('  Max findings per request: %s' . PHP_EOL, $limits->getMaxFindingsPerRequest());
        }
    }
}

Python

מידע על התקנת ספריית הלקוח של Sensitive Data Protection והשימוש בה מופיע במאמר ספריות הלקוח של Sensitive Data Protection.

כדי לבצע אימות ב-Sensitive Data Protection, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.

import google.cloud.dlp


def list_inspect_templates(project: str) -> None:
    """Lists all Data Loss Prevention API inspect templates.
    Args:
        project: The Google Cloud project id to use as a parent resource.
    Returns:
        None; the response from the API is printed to the terminal.
    """

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

    # Convert the project id into a full resource id.
    parent = f"projects/{project}"

    # Call the API.
    response = dlp.list_inspect_templates(request={"parent": parent})

    for template in response:
        print(f"Template {template.name}:")
        if template.display_name:
            print(f"  Display Name: {template.display_name}")
        print(f"  Created: {template.create_time}")
        print(f"  Updated: {template.update_time}")

        config = template.inspect_config
        print(
            "  InfoTypes: {}".format(", ".join([it.name for it in config.info_types]))
        )
        print(f"  Minimum likelihood: {config.min_likelihood}")
        print(f"  Include quotes: {config.include_quote}")
        print(
            "  Max findings per request: {}".format(
                config.limits.max_findings_per_request
            )
        )

מחיקה של תבניות להסרת פרטי הזיהוי

כדי למחוק תבנית ספציפית לביטול הזיהוי, משתמשים באחת מהשיטות הבאות: *.*.delete

בכל שיטה של *.*.delete, צריך לכלול את שם המשאב של התבנית שרוצים למחוק.

C#

מידע על התקנת ספריית הלקוח של Sensitive Data Protection והשימוש בה מופיע במאמר ספריות הלקוח של Sensitive Data Protection.

כדי לבצע אימות ב-Sensitive Data Protection, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.


using Google.Cloud.Dlp.V2;
using System;

public class InspectTemplateDelete
{
    public static object Delete(string projectId, string templateName)
    {
        var client = DlpServiceClient.Create();

        var request = new DeleteInspectTemplateRequest
        {
            Name = templateName
        };

        client.DeleteInspectTemplate(request);
        Console.WriteLine($"Successfully deleted template {templateName}.");

        return templateName;
    }
}

Go

מידע על התקנת ספריית הלקוח של Sensitive Data Protection והשימוש בה מופיע במאמר ספריות הלקוח של Sensitive Data Protection.

כדי לבצע אימות ב-Sensitive Data Protection, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.

import (
	"context"
	"fmt"
	"io"

	dlp "cloud.google.com/go/dlp/apiv2"
	"cloud.google.com/go/dlp/apiv2/dlppb"
)

// deleteInspectTemplate deletes the given template.
func deleteInspectTemplate(w io.Writer, templateID string) error {
	// projectID := "my-project-id"
	// templateID := "my-template"

	ctx := context.Background()

	client, err := dlp.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("dlp.NewClient: %w", err)
	}
	defer client.Close()

	req := &dlppb.DeleteInspectTemplateRequest{
		Name: templateID,
	}

	if err := client.DeleteInspectTemplate(ctx, req); err != nil {
		return fmt.Errorf("DeleteInspectTemplate: %w", err)
	}
	fmt.Fprintf(w, "Successfully deleted inspect template %v", templateID)
	return nil
}

Java

מידע על התקנת ספריית הלקוח של Sensitive Data Protection והשימוש בה מופיע במאמר ספריות הלקוח של Sensitive Data Protection.

כדי לבצע אימות ב-Sensitive Data Protection, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.


import com.google.cloud.dlp.v2.DlpServiceClient;
import com.google.privacy.dlp.v2.DeleteInspectTemplateRequest;
import java.io.IOException;

class TemplatesDelete {

  public static void main(String[] args) throws Exception {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "your-project-id";
    String templateId = "your-template-id";
    deleteInspectTemplate(projectId, templateId);
  }

  // Delete an existing template
  public static void deleteInspectTemplate(String projectId, String templateId) throws IOException {
    // Construct the template name to be deleted
    String templateName = String.format("projects/%s/inspectTemplates/%s", projectId, templateId);

    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {

      // Create delete template request to be sent by the client
      DeleteInspectTemplateRequest request =
          DeleteInspectTemplateRequest.newBuilder().setName(templateName).build();

      // Send the request with the client
      dlpServiceClient.deleteInspectTemplate(request);
      System.out.printf("Deleted template: %s\n", templateName);
    }
  }
}

Node.js

מידע על התקנת ספריית הלקוח של Sensitive Data Protection והשימוש בה מופיע במאמר ספריות הלקוח של Sensitive Data Protection.

כדי לבצע אימות ב-Sensitive Data Protection, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.

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

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

// The project ID to run the API call under
// const projectId = 'my-project';

// The name of the template to delete
// Parent project ID is automatically extracted from this parameter
// const templateName = 'projects/YOUR_PROJECT_ID/inspectTemplates/#####'
async function deleteInspectTemplate() {
  // Construct template-deletion request
  const request = {
    name: templateName,
  };

  // Run template-deletion request
  await dlp.deleteInspectTemplate(request);
  console.log(`Successfully deleted template ${templateName}.`);
}

deleteInspectTemplate();

PHP

מידע על התקנת ספריית הלקוח של Sensitive Data Protection והשימוש בה מופיע במאמר ספריות הלקוח של Sensitive Data Protection.

כדי לבצע אימות ב-Sensitive Data Protection, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.

use Google\Cloud\Dlp\V2\Client\DlpServiceClient;
use Google\Cloud\Dlp\V2\DeleteInspectTemplateRequest;

/**
 * Delete a DLP inspection configuration template.
 *
 * @param string $callingProjectId  The project ID to run the API call under
 * @param string $templateId        The name of the template to delete
 */
function delete_inspect_template(
    string $callingProjectId,
    string $templateId
): void {
    // Instantiate a client.
    $dlp = new DlpServiceClient();

    // Run template deletion request
    $templateName = "projects/$callingProjectId/locations/global/inspectTemplates/$templateId";
    $deleteInspectTemplateRequest = (new DeleteInspectTemplateRequest())
        ->setName($templateName);
    $dlp->deleteInspectTemplate($deleteInspectTemplateRequest);

    // Print results
    printf('Successfully deleted template %s' . PHP_EOL, $templateName);
}

Python

מידע על התקנת ספריית הלקוח של Sensitive Data Protection והשימוש בה מופיע במאמר ספריות הלקוח של Sensitive Data Protection.

כדי לבצע אימות ב-Sensitive Data Protection, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.

import google.cloud.dlp


def delete_inspect_template(project: str, template_id: str) -> None:
    """Deletes a Data Loss Prevention API template.
    Args:
        project: The id of the Google Cloud project which owns the template.
        template_id: The id of the template to delete.
    Returns:
        None; the response from the API is printed to the terminal.
    """

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

    # Convert the project id into a full resource id.
    parent = f"projects/{project}"

    # Combine the template id with the parent id.
    template_resource = f"{parent}/inspectTemplates/{template_id}"

    # Call the API.
    dlp.delete_inspect_template(request={"name": template_resource})

    print(f"Template {template_resource} successfully deleted.")