Inspecionar texto confidencial usando a API DLP
Saiba como verificar uma string de amostra em busca de informações sensíveis usando a API Cloud Data Loss Prevention da Proteção de dados sensíveis e o JSON.
Para seguir as instruções detalhadas desta tarefa diretamente no console do Google Cloud , clique em Orientação:
Antes de começar
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
 - 
      
Install the Google Cloud CLI.
 - 
          
Ao usar um provedor de identidade (IdP) externo, primeiro faça login na gcloud CLI com sua identidade federada.
 - 
        
Para inicializar a gcloud CLI, execute o seguinte comando:
gcloud init - 
  
  
    
Create or select a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
 - 
      Create a project: To create a project, you need the Project Creator
      (
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles. 
- 
        
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_IDwith a name for the Google Cloud project you are creating. - 
        
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace
PROJECT_IDwith your Google Cloud project name. 
 - 
  
    
Verify that billing is enabled for your Google Cloud project.
 - 
  
  
    
      
Enable the DLP API:
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.gcloud services enable dlp.googleapis.com
 - 
    
        
Grant roles to your user account. Run the following command once for each of the following IAM roles:
roles/dlp.usergcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE
Replace the following:
PROJECT_ID: Your project ID.USER_IDENTIFIER: The identifier for your user account. For example,myemail@example.com.ROLE: The IAM role that you grant to your user account.
 - 
      
Install the Google Cloud CLI.
 - 
          
Ao usar um provedor de identidade (IdP) externo, primeiro faça login na gcloud CLI com sua identidade federada.
 - 
        
Para inicializar a gcloud CLI, execute o seguinte comando:
gcloud init - 
  
  
    
Create or select a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
 - 
      Create a project: To create a project, you need the Project Creator
      (
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles. 
- 
        
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_IDwith a name for the Google Cloud project you are creating. - 
        
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace
PROJECT_IDwith your Google Cloud project name. 
 - 
  
    
Verify that billing is enabled for your Google Cloud project.
 - 
  
  
    
      
Enable the DLP API:
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.gcloud services enable dlp.googleapis.com
 - 
    
        
Grant roles to your user account. Run the following command once for each of the following IAM roles:
roles/dlp.usergcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE
Replace the following:
PROJECT_ID: Your project ID.USER_IDENTIFIER: The identifier for your user account. For example,myemail@example.com.ROLE: The IAM role that you grant to your user account.
 - 
    
PROJECT_ID: o ID do projeto do Google Cloud . Os IDs do projeto são strings alfanuméricas, comomy-project. Para começar a inspecionar textos e imagens em busca de dados sensíveis, consulte os Guias de instruções.
Para entender melhor inspeção, edição, infoTypes e probabilidade, consulte Conceitos.
Saiba mais sobre a API DLP.
Verificar se há informações confidenciais em uma string
Nesta seção, mostramos como configurar a API DLP para verificar
o texto de amostra usando o método REST projects.content.inspect.
Nesta seção, você precisa salvar a solicitação de amostra em um arquivo JSON. Se você estiver usando o Cloud Shell, poderá usar o editor do Cloud Shell para criar o arquivo. Para iniciar o editor, clique em Abrir editor na barra de ferramentas da janela do Cloud Shell.
Antes de usar os dados da solicitação abaixo, faça as substituições a seguir:
Método HTTP e URL:
POST https://dlp.googleapis.com/v2/projects/PROJECT_ID/content:inspect
Corpo JSON da solicitação:
{
  "item": {
    "value": "My phone number is (800) 555-0123."
  },
  "inspectConfig": {
    "infoTypes": [
      {
        "name": "PHONE_NUMBER"
      },
      {
        "name": "US_TOLLFREE_PHONE_NUMBER"
      }
    ],
    "minLikelihood": "POSSIBLE",
    "limits": {
      "maxFindingsPerItem": 0
    },
    "includeQuote": true
  }
}
Para enviar a solicitação, expanda uma destas opções:
Você receberá uma resposta JSON semelhante a esta:
{
  "result": {
    "findings": [
      {
        "quote": "(800) 555-0123",
        "infoType": {
          "name": "US_TOLLFREE_PHONE_NUMBER"
        },
        "likelihood": "LIKELY",
        "location": {
          "byteRange": {
            "start": "19",
            "end": "33"
          },
          "codepointRange": {
            "start": "19",
            "end": "33"
          }
        },
        "createTime": "2022-09-23T01:53:05.303Z",
        "findingId": "2022-09-23T01:53:05.306348Z5328915744504121862"
      }
    ]
  }
}Limpar
Para evitar cobranças na conta do Google Cloud pelos recursos usados nesta página, exclua o projeto do Google Cloud e os recursos.
Excluir o projeto
Se você criou um novo projeto para este guia de início rápido, a maneira mais fácil de evitar cobranças adicionais é excluir o projeto.
Delete a Google Cloud project:
gcloud projects delete PROJECT_ID
Revogar suas credenciais
Optional: Revoke credentials from the gcloud CLI.
gcloud auth revoke