Review Single-piece Content
Introduces how to call the interface to review a single piece of content in the WebService application channel.
Request method
Interface URL
/skg/v1/dlp/channel/webserviceapp/<WebService Application ID>/<Request Mode>
Request Parameters
The following table introduces the parameters in the interface URL.Parameter Name | Parameter Location | Required | Description |
---|---|---|---|
<WebService Application ID> | URL Parameter | Yes | The ID of the WebService application. Log in to Unified Content Secure Server
(UCSS), and go to the page Note: The WebService ID needs to be bound to the Data Loss Prevention (DLP) policy to take effect. The specific binding steps are as follows:
|
. Look for the corresponding WebService ID in the ID column of the page list.
<Request Mode> | URL Parameter | Yes | Specify the request mode as synchronous or asynchronous. The specific parameter values include:
|
The following table introduces the parameters in the request header.
Metadata Parameters
Definition of metadata parameters
Parameter Name | Type | Applicable Status | Description |
---|---|---|---|
user | String (Required) | Synchronous and Asynchronous | The username that generates the event - supports domain users, in the format domain\username. |
customAttribute | String (Optional) | Synchronous and Asynchronous | Supports user-defined parameter names. |
filename | String (Optional) | Synchronous and Asynchronous | The file name - can be used for policy matching based on the file name. Note: If you are using product version 3.3, then filename is a required option. |
encoding | String (Optional) | Synchronous and Asynchronous | File encoding |
queryID | String (Required) | Synchronous and Asynchronous | The event query ID associated with this request, must be unique. If the request does not generate an event, the event details cannot be queried. Note: The value of queryid corresponds to the traffic UUID in the third-party cloud service. |
redaction | Dict (Optional) | Synchronous and Asynchronous | Related to redaction functionality. Whether to enable redaction. For specific redaction settings, please refer to the sendBack parameter.
|
sendBack | Dict (Optional) | Synchronous and Asynchronous | Related to redaction functionality. Handling of redacted content. Note: To use the redaction feature, set the value of the redaction parameter to true. This field requires an input of a required type attribute, indicating the way the file is returned. The Type attribute supports the following options: response: Return the redacted content to the current path httpUpload: Send the redacted content to the specified URL s3: Upload the redacted content to Amazon S3 storage space Note: This step also applies to storage in Swift, COS, OSS, etc. For specific related configuration parameters, please refer to the chapter objectinfo Parameters for Reviewing Cloud Service Stored Content in Asynchronous Mode.
|
md5 | String (Optional) | Synchronous and Asynchronous | The MD5 value of the file, used for recording and cache acceleration. Supports sending MD5 together with the document for inspection, as well as sending only MD5 for inspection.
|
operation | int (Optional) | Synchronous and Asynchronous | Operation ID. Defined when creating the WebService application, and the operation name corresponding to the operation ID will be displayed in the Webservice Operation field of the API traffic log. There are four defaults, and users can also define their own:
|
antivirus | Bool (Optional) | Synchronous and Asynchronous | Whether to perform virus scanning, default is False. |
md5 | String (Optional) | Synchronous and Asynchronous | The MD5 value of the file, only used for recording. |
callback_url | String (Optional) | Asynchronous | Only for asynchronous mode, the listening address for callback |
uploadtype | String (Required) | Asynchronous | Only for asynchronous. Supports AWS S3, Alibaba Cloud OSS, Tencent Cloud COS, Swift, as well as local files and download URLs.
|
objectInfo | Dict (Optional) | Asynchronous | Only for asynchronous mode and when using object storage. Asynchronous mode supports reviewing objects stored in Amazon S3, Swfit, Alibaba Cloud OSS, Tencent Cloud COS, and other cloud services. For specific setting parameters, refer to the chapter: objectinfo Parameters for Reviewing Cloud Service Stored Content in Asynchronous Mode |
Return Parameters
Including the following:
Name | Description |
---|---|
result | Indicates whether the request was successful. 0 for success, 1 for failure. |
actionCode | When the request is successful, the user can choose to perform a default action on the content that meets the request conditions. Default actions include 1 - Allow data transfer and 2 - Block data transfer. |
errorCode | The error code returned when the request fails. |
message | The error message returned when the request fails. |
Python Request Example - WebService Channel (Synchronous Mode)
The following example shows how to use Python code to call the interface to perform content security review of files in the WebService channel in synchronous mode.
# -*- coding: utf-8 -*- from requests.packages.urllib3.exceptions import InsecureRequestWarning from ucwi_config import UCWIConfig from ucwi_auth import get_headers import requests import json import os import uuid requests.packages.urllib3.disable_warnings(InsecureRequestWarning) app_id = "caafb22a-9f6d-4a06-a0e4-b12c170afdf5" api = "/skg/v1/dlp/channel/webserviceapp/{}/sync".format(app_id) url = "{0}{1}".format(UCWIConfig.base_url, api) file_path = "test.txt" metadata = { "user": "ucwitestuser", } headers = get_headers() data = {"metadata": json.dumps(metadata)} fd = open(file_path) files = { "request": fd } response = requests.post(url, headers=headers, data=data, files=files, verify=False) fd.close() if response.status_code != 200: print("Bad request, response code:", response.status_code) print(response.text) else: result = response.json() # print(json.dumps(result, indent=4).decode('raw_unicode_escape')) if result["responseCode"] != 200: print("Bad request, response code:", result["responseCode"]) print(result["message"]) else: hint = "# 1: Allow; 2: Block; 3: Confirm; 4: Delete Attachment; 5: Email Encryption; 6: Email Quarantine; 7: Terminal System Encryption; 8: Email Content Encryption; 9: Terminal Personal Key Encryption" print("action:{} {}".format(result["actionCode"], hint)) if len(result["incident_info"]) == 0: print("not matched.") else: print("matched policy:") for policy in result["incident_info"]["matchedPolicies"]: print(json.dumps(policy, indent=2).encode('utf-8').decode('raw_unicode_escape'))
Python Request Example - WebService Channel (Asynchronous Mode)
The following example shows how to use Python code to call the interface to upload files in the WebService channel in asynchronous mode for content security review.
# -*- coding: utf-8 -*- from requests.packages.urllib3.exceptions import InsecureRequestWarning from ucwi_config import UCWIConfig from ucwi_auth import get_headers import requests import json import os import uuid requests.packages.urllib3.disable_warnings(InsecureRequestWarning) # Get the WebServiceapp id from UCSS app_id = "caafb22a-9f6d-4a06-a0e4-b12c170afdf5" api = "/skg/v1/dlp/channel/webserviceapp/{}/async".format(app_id) url = "{0}{1}".format(UCWIConfig.base_url, api) file_path = "test.txt" metadata = { # The user who sent the data, used for policy matching during inspection and final event display "user": "ucwitestuser", # The filename of the uploaded file, used for policy matching during inspection "filename": "test.txt", "queryID": str(uuid.uuid4()), # Optional parameter, file encoding method, default is UTF-8 "encoding": "UTF-8", # Optional parameter, whether to perform antivirus operation, default is False "antivirus": False, # Optional parameter, default is an empty string, used for final event display "md5": "09e066b382d4225de7f3c0594aa89b5f", "uploadtype": "file", "callback_url": UCWIConfig.callback_url + "/webserviceapp" } headers = get_headers() data = {"metadata": json.dumps(metadata)} fd = open(file_path) files = { "request": fd } response = requests.post(url, headers=headers, data=data, files=files, verify=False) fd.close() if response.status_code != 200: print("Bad request, response code:", response.status_code) print(response.text) else: result = response.json() print(result["message"])
cURL Request Example - WebService Application Channel (Asynchronous Mode)
The following example shows how to use cURL code to call the interface to upload files in the WebService channel in asynchronous mode for content security review.
- With callback:
curl -F 'metadata={"uploadtype": "s3", "callback_url": "http://172.22.113.12:9999/post/webserviceapp ", "queryID": "000864b0-4b2c-11e7-81f7-9ef3ee527981", "user": "hwshtest1\\hwsh0410user1", "filename": "DLPencrypt.rar"}' -F 'request=http://172.22.78.91:8070/test-webserviceapp/home/test/testfile4/DLPencrypt.rar ' https://172.22.78.107:5443/skg/v1/dlp/channel/webserviceapp/e4dbd0d7-2fc6-4034-b4d8-3807af66bf91/async
- Without callback:
curl -F 'metadata={"uploadtype": "s3", "queryID": "000864b0-4b2c-11e7-81f7-9ef3ee527981", "user": "hwshtest1\\hwsh0410user1", "filename": "DLPencrypt.rar"}' -F 'request=http://172.22.78.91:8070/test-webserviceapp/home/test/testfile4/DLPencrypt.rar ' https://172.22.78.107:5443/skg/v1/dlp/channel/webserviceapp/e4dbd0d7-2fc6-4034-b4d8-3807af66bf91/async
- With callback:
curl -F 'metadata={"uploadtype": "localhost", "callback_url": "http://172.22.113.12:9999/post/webserviceapp ", "queryID": "44130fdc-4b2e-11e7-81f7-9ef3ee527981", "user": "hwshtest1\\hwsh0410user1", "filename": "DLPencrypt.rar"}' -F 'request=@/home/test/testfile4/DLPencrypt.rar' https://172.22.78.107:5443/skg/v1/dlp/channel/webserviceapp/e4dbd0d7-2fc6-4034-b4d8-3807af66bf91/async
- Without callback:
curl -F 'metadata={"uploadtype": "localhost","queryID": "44130fdc-4b2e-11e7-81f7-9ef3ee527981", "user": "hwshtest1\\hwsh0601user1", "filename": "DLPencrypt.rar"}' -F 'request=@/home/test/testfile4/DLPencrypt.rar' https://172.22.78.107:5443/skg/v1/dlp/channel/webserviceapp/e4dbd0d7-2fc6-4034-b4d8-3807af66bf91/async
Example for return code
Full Name | Description |
---|---|
result | Whether the request is successful, 0 means success, and 1 means failure. |
actionCode | When the request is successful, the user can choose a remediation action on the detected content. The default operations include 1-allow data transmission and 2-block data transmission. |
errorCode | Error code returned when the request failed |
message | Error Message returned when the request failed |
The response to the Content inspection request is as follows.
- Request successfully
{ "result" : 0, "actionCode" : 1/2 } actionCode: 1 - allow, 2 - block
Note: If the policy is matched and the violation content is found, the system returns the policy matching information. Refer to The return value for policy match. - Request failed
{ "result" : 1, "errorCode" : 500, "message" : "Invalid parameter" }