Get an inspection job

Get DLP inspection job.

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample

C#

To learn how to install and use the client library for Sensitive Data Protection, see Sensitive Data Protection client libraries .

To authenticate to Sensitive Data Protection, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  using 
  
  Google.Cloud.Dlp.V2 
 
 ; 
 using 
  
 System 
 ; 
 public 
  
 class 
  
 JobsGet 
 { 
  
 public 
  
 static 
  
 DlpJob 
  
 GetDlpJob 
 ( 
 string 
  
 jobName 
 ) 
  
 { 
  
 var 
  
 dlp 
  
 = 
  
  DlpServiceClient 
 
 . 
  Create 
 
 (); 
  
 var 
  
 response 
  
 = 
  
 dlp 
 . 
 GetDlpJob 
 ( 
 jobName 
 ); 
  
 Console 
 . 
 WriteLine 
 ( 
 $"Job: {response.Name} status: {response.State}" 
 ); 
  
 return 
  
 response 
 ; 
  
 } 
 } 
 

Go

To learn how to install and use the client library for Sensitive Data Protection, see Sensitive Data Protection client libraries .

To authenticate to Sensitive Data Protection, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  import 
  
 ( 
  
 "context" 
  
 "fmt" 
  
 "io" 
  
 dlp 
  
 "cloud.google.com/go/dlp/apiv2" 
  
 "cloud.google.com/go/dlp/apiv2/dlppb" 
 ) 
 // jobsGet gets an inspection job using jobName 
 func 
  
 jobsGet 
 ( 
 w 
  
 io 
 . 
 Writer 
 , 
  
 projectID 
  
 string 
 , 
  
 jobName 
  
 string 
 ) 
  
 error 
  
 { 
  
 // projectId := "my-project-id" 
  
 // jobName := "your-job-id" 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 // Initialize a client once and reuse it to send multiple requests. Clients 
  
 // are safe to use across goroutines. When the client is no longer needed, 
  
 // call the Close method to cleanup its resources. 
  
 client 
 , 
  
 err 
  
 := 
  
 dlp 
 . 
  NewClient 
 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 return 
  
 err 
  
 } 
  
 // Closing the client safely cleans up background resources. 
  
 defer 
  
 client 
 . 
  Close 
 
 () 
  
 // Construct the request to be sent by the client. 
  
 req 
  
 := 
  
& dlppb 
 . 
 GetDlpJobRequest 
 { 
  
 Name 
 : 
  
 jobName 
 , 
  
 } 
  
 // Send the request. 
  
 resp 
 , 
  
 err 
  
 := 
  
 client 
 . 
 GetDlpJob 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 return 
  
 err 
  
 } 
  
 // Print the results. 
  
 fmt 
 . 
 Fprintf 
 ( 
 w 
 , 
  
 "Job Name: %v Job Status: %v" 
 , 
  
 resp 
 . 
 Name 
 , 
  
 resp 
 . 
 State 
 ) 
  
 return 
  
 nil 
 } 
 

Java

To learn how to install and use the client library for Sensitive Data Protection, see Sensitive Data Protection client libraries .

To authenticate to Sensitive Data Protection, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  import 
  
 com.google.cloud.dlp.v2. DlpServiceClient 
 
 ; 
 import 
  
 com.google.privacy.dlp.v2. DlpJobName 
 
 ; 
 import 
  
 com.google.privacy.dlp.v2. GetDlpJobRequest 
 
 ; 
 import 
  
 java.io.IOException 
 ; 
 public 
  
 class 
 JobsGet 
  
 { 
  
 public 
  
 static 
  
 void 
  
 main 
 ( 
 String 
 [] 
  
 args 
 ) 
  
 throws 
  
 Exception 
  
 { 
  
 // TODO(developer): Replace these variables before running the sample. 
  
 String 
  
 projectId 
  
 = 
  
 "your-project-id" 
 ; 
  
 String 
  
 jobId 
  
 = 
  
 "your-job-id" 
 ; 
  
 getJobs 
 ( 
 projectId 
 , 
  
 jobId 
 ); 
  
 } 
  
 // Gets a DLP Job with the given jobId 
  
 public 
  
 static 
  
 void 
  
 getJobs 
 ( 
 String 
  
 projectId 
 , 
  
 String 
  
 jobId 
 ) 
  
 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 
 ()) 
  
 { 
  
 // Construct the complete job name from the projectId and jobId 
  
  DlpJobName 
 
  
 jobName 
  
 = 
  
  DlpJobName 
 
 . 
 of 
 ( 
 projectId 
 , 
  
 jobId 
 ); 
  
 // Construct the get job request to be sent by the client. 
  
  GetDlpJobRequest 
 
  
 getDlpJobRequest 
  
 = 
  
  GetDlpJobRequest 
 
 . 
 newBuilder 
 (). 
 setName 
 ( 
 jobName 
 . 
  toString 
 
 ()). 
 build 
 (); 
  
 // Send the get job request 
  
 dlpServiceClient 
 . 
 getDlpJob 
 ( 
 getDlpJobRequest 
 ); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Job got successfully." 
 ); 
  
 } 
  
 } 
 } 
 

Node.js

To learn how to install and use the client library for Sensitive Data Protection, see Sensitive Data Protection client libraries .

To authenticate to Sensitive Data Protection, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  // Imports the Google Cloud Data Loss Prevention library 
 const 
  
 DLP 
  
 = 
  
 require 
 ( 
 ' @google-cloud/dlp 
' 
 ); 
 // Instantiates a client 
 const 
  
 dlp 
  
 = 
  
 new 
  
 DLP 
 . 
  DlpServiceClient 
 
 (); 
 // Job name to look for 
 // const jobName = 'your-job-name'; 
 async 
  
 function 
  
 getJob 
 () 
  
 { 
  
 // Construct request for finding job using job name. 
  
 const 
  
 request 
  
 = 
  
 { 
  
 name 
 : 
  
 jobName 
 , 
  
 }; 
  
 // Send the request and receive response from the service 
  
 const 
  
 [ 
 job 
 ] 
  
 = 
  
 await 
  
 dlp 
 . 
 getDlpJob 
 ( 
 request 
 ); 
  
 // Print results. 
  
 console 
 . 
 log 
 ( 
 `Job 
 ${ 
 job 
 . 
 name 
 } 
 status: 
 ${ 
 job 
 . 
 state 
 } 
 ` 
 ); 
 } 
 getJob 
 (); 
 

PHP

To learn how to install and use the client library for Sensitive Data Protection, see Sensitive Data Protection client libraries .

To authenticate to Sensitive Data Protection, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  use Google\Cloud\Dlp\V2\Client\DlpServiceClient; 
 use Google\Cloud\Dlp\V2\GetDlpJobRequest; 
 /** 
 * Get DLP inspection job. 
 * @param string $jobName           Dlp job name 
 */ 
 function get_job( 
 string $jobName 
 ): void { 
 // Instantiate a client. 
 $dlp = new DlpServiceClient(); 
 try { 
 // Send the get job request 
 $getDlpJobRequest = (new GetDlpJobRequest()) 
 ->setName($jobName); 
 $response = $dlp->getDlpJob($getDlpJobRequest); 
 printf('Job %s status: %s' . PHP_EOL, $response->getName(), $response->getState()); 
 } finally { 
 $dlp->close(); 
 } 
 } 
 

Python

To learn how to install and use the client library for Sensitive Data Protection, see Sensitive Data Protection client libraries .

To authenticate to Sensitive Data Protection, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  import 
  
 google.cloud.dlp 
 def 
  
 get_dlp_job 
 ( 
 project 
 : 
 str 
 , 
 job_name 
 : 
 str 
 ) 
 - 
> None 
 : 
  
 """Uses the Data Loss Prevention API to retrieve a DLP job. 
 Args: 
 project: The project id to use as a parent resource. 
 job_name: The name of the DlpJob resource to be retrieved. 
 """ 
 # Instantiate a client. 
 dlp 
 = 
 google 
 . 
 cloud 
 . 
  dlp_v2 
 
 . 
  DlpServiceClient 
 
 () 
 # Convert the project id and job name into a full resource id. 
 job_name 
 = 
 f 
 "projects/ 
 { 
 project 
 } 
 /locations/global/dlpJobs/ 
 { 
 job_name 
 } 
 " 
 # Call the API 
 response 
 = 
 dlp 
 . 
 get_dlp_job 
 ( 
 request 
 = 
 { 
 "name" 
 : 
 job_name 
 }) 
 print 
 ( 
 f 
 "Job: 
 { 
 response 
 . 
 name 
 } 
 Status: 
 { 
 response 
 . 
 state 
 } 
 " 
 ) 
 

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser .

Create a Mobile Website
View Site in Mobile | Classic
Share by: