@@ -21,6 +21,8 @@ def submit_uri(project_id: str, uri: str) -> Submission:
21
21
"""Submits a URI suspected of containing malicious content to be reviewed.
22
22
23
23
Returns a google.longrunning.Operation which, once the review is complete, is updated with its result.
24
+ You can use the [Pub/Sub API] (https://cloud.google.com/pubsub) to receive notifications for the
25
+ returned Operation.
24
26
If the result verifies the existence of malicious content, the site will be added to the
25
27
Google's Social Engineering lists in order to protect users that could get exposed to this
26
28
threat in the future. Only allow-listed projects can use this method during Early Access.
@@ -35,14 +37,49 @@ def submit_uri(project_id: str, uri: str) -> Submission:
35
37
"""
36
38
webrisk_client = webrisk_v1 .WebRiskServiceClient ()
37
39
40
+ # Set the URI to be submitted.
38
41
submission = webrisk_v1 .Submission ()
39
42
submission .uri = uri
40
43
41
- request = webrisk_v1 .CreateSubmissionRequest ()
42
- request .parent = f"projects/{ project_id } "
43
- request .submission = submission
44
+ # Confidence that a URI is unsafe.
45
+ threat_confidence = webrisk_v1 .ThreatInfo .Confidence (
46
+ level = webrisk_v1 .ThreatInfo .Confidence .ConfidenceLevel .MEDIUM
47
+ )
44
48
45
- response = webrisk_client .create_submission (request )
49
+ # Context about why the URI is unsafe.
50
+ threat_justification = webrisk_v1 .ThreatInfo .ThreatJustification (
51
+ # Labels that explain how the URI was classified.
52
+ labels = [webrisk_v1 .ThreatInfo .ThreatJustification .JustificationLabel .AUTOMATED_REPORT ],
53
+ # Free-form context on why this URI is unsafe.
54
+ comments = ["Testing submission" ]
55
+ )
56
+
57
+ # Set the context about the submission including the type of abuse found on the URI and
58
+ # supporting details.
59
+ threat_info = webrisk_v1 .ThreatInfo (
60
+ # The abuse type found on the URI.
61
+ abuse_type = webrisk_v1 .types .ThreatType .SOCIAL_ENGINEERING ,
62
+ threat_confidence = threat_confidence ,
63
+ threat_justification = threat_justification
64
+ )
65
+
66
+ # Set the details about how the threat was discovered.
67
+ threat_discovery = webrisk_v1 .ThreatDiscovery (
68
+ # Platform on which the threat was discovered.
69
+ platform = webrisk_v1 .ThreatDiscovery .Platform .MACOS ,
70
+ # CLDR region code of the countries/regions the URI poses a threat ordered
71
+ # from most impact to least impact. Example: "US" for United States.
72
+ region_codes = ["US" ]
73
+ )
74
+
75
+ request = webrisk_v1 .SubmitUriRequest (
76
+ parent = f"projects/{ project_id } " ,
77
+ submission = submission ,
78
+ threat_info = threat_info ,
79
+ threat_discovery = threat_discovery
80
+ )
81
+
82
+ response = webrisk_client .submit_uri (request ).result (timeout = 30 )
46
83
return response
47
84
48
85
0 commit comments