File tree Expand file tree Collapse file tree 3 files changed +13
-25
lines changed
Filter options
Expand file tree Collapse file tree 3 files changed +13
-25
lines changed
Original file line number Diff line number Diff line change @@ -27,10 +27,9 @@ def inspect_image_file(project_id='YOUR_PROJECT_ID',
27
27
with open (filepath , mode = 'rb' ) as f :
28
28
file_bytes = f .read ()
29
29
30
- # Construct the item
30
+ # Construct request
31
+ parent = dlp .project_path (project_id )
31
32
item = {'byte_item' : {'type' : 'IMAGE' , 'data' : file_bytes }}
32
-
33
- # Construct the configuration
34
33
inspect_config = {
35
34
# The infoTypes of information to match
36
35
'info_types' : [
@@ -42,13 +41,10 @@ def inspect_image_file(project_id='YOUR_PROJECT_ID',
42
41
'include_quote' : True ,
43
42
}
44
43
45
- # Convert the project id into a full resource id
46
- parent = dlp .project_path (project_id )
47
-
48
- # Call the API
44
+ # Run request
49
45
response = dlp .inspect_content (parent , inspect_config , item )
50
46
51
- # Print out the results
47
+ # Print the results
52
48
if response .result .findings :
53
49
for finding in response .result .findings :
54
50
print ('Quote: {}' .format (finding .quote ))
Original file line number Diff line number Diff line change @@ -22,7 +22,9 @@ def inspect_string(project_id='YOUR_PROJECT_ID'):
22
22
# Instantiate a client
23
23
dlp = google .cloud .dlp .DlpServiceClient ()
24
24
25
- # Construct the configuration
25
+ # Construct request
26
+ parent = dlp .project_path (project_id )
27
+ item = {'value' : 'My name is Gary Smith and my email is gary@example.com' }
26
28
inspect_config = {
27
29
# The infoTypes of information to match
28
30
'info_types' : [
@@ -34,16 +36,10 @@ def inspect_string(project_id='YOUR_PROJECT_ID'):
34
36
'include_quote' : True ,
35
37
}
36
38
37
- # Construct the `item`
38
- item = {'value' : 'My name is Gary Smith and my email is gary@example.com' }
39
-
40
- # Convert the project id into a full resource id
41
- parent = dlp .project_path (project_id )
42
-
43
- # Call the API
39
+ # Run request
44
40
response = dlp .inspect_content (parent , inspect_config , item )
45
41
46
- # Print out the results
42
+ # Print the results
47
43
if response .result .findings :
48
44
for finding in response .result .findings :
49
45
print ('Quote: {}' .format (finding .quote ))
Original file line number Diff line number Diff line change @@ -27,10 +27,9 @@ def inspect_text_file(project_id='YOUR_PROJECT_ID',
27
27
with open (filepath , mode = 'rb' ) as f :
28
28
file_bytes = f .read ()
29
29
30
- # Construct the item
30
+ # Construct request
31
+ parent = dlp .project_path (project_id )
31
32
item = {'byte_item' : {'type' : 'TEXT_UTF8' , 'data' : file_bytes }}
32
-
33
- # Construct the configuration
34
33
inspect_config = {
35
34
# The infoTypes of information to match
36
35
'info_types' : [
@@ -42,13 +41,10 @@ def inspect_text_file(project_id='YOUR_PROJECT_ID',
42
41
'include_quote' : True ,
43
42
}
44
43
45
- # Convert the project id into a full resource id
46
- parent = dlp .project_path (project_id )
47
-
48
- # Call the API
44
+ # Run request
49
45
response = dlp .inspect_content (parent , inspect_config , item )
50
46
51
- # Print out the results
47
+ # Print the results
52
48
if response .result .findings :
53
49
for finding in response .result .findings :
54
50
print ('Quote: {}' .format (finding .quote ))
You can’t perform that action at this time.
0 commit comments