OpenAPI integration examples (SDK)
This topic describes how to use an SDK to call operations to query a list of sensitive data detection rules.
View the API documentation
Read the API overview to select an OpenAPI for querying the list of instances in a specified region, such as List of detection rules. Refer to the API documentation for the parameters and permissions required to call the API.
Create a RAM user and grant permissions to the RAM user
Identities
You can use an Alibaba Cloud account, a Resource Access Management (RAM) user, or a RAM role to call this operation. For more information about the differences between these identities, see Identity, credential, and authorization. This topic uses a RAM user as an example. Log on to the Resource Access Management (RAM) console, create a RAM user that is only allowed to make API calls, and record the AccessKey information. For more information, see Create a RAM user.
Authorization
On the Users page in the RAM console, find the RAM user that you want to manage and click Add Permissions in the Actions column.
In the Access Policy section, enter the keyword
sddpin the search box and select a policy as needed.NoteAliyunYundunSDDPFullAccess: the permissions to manage Data Security Center (DSC).
AliyunYundunSDDPReadOnlyAccess: the read-only permission on DSC.
AliyunYundunSDDPDataManager: the permissions to manage data domains in DSC.
For more information about how to create a custom policy, see RAM authorization.
Click Confirm Authorization to complete the authorization.
Credentials
By default, an AccessKey pair is generated when you create a RAM user. You can also create an AccessKey pair by performing the following steps: Go to the details page of the RAM user. On the Authentication tab, click Create AccessKey. For more information, see Create an AccessKey pair.
Call OpenAPI
This topic provides an example that uses the Java SDK. For more information about Alibaba Cloud SDKs, see QuickStart.
Configure environment variables
You can configure the AccessKey pair in environment variables. This way, the AccessKey pair is not hard-coded in the code, and your service is not exposed to risks.
For more information about how to set the AccessKey information in environment variables on Linux or macOS system, see Set an Alibaba Cloud AccessKey in environment variables on Linux and macOS.
For more information about how to set the AccessKey information in environment variables on a Windows system, see Set the Alibaba Cloud AccessKey in environment variables on a Windows system.
Download the sample code
Call the DescribeRules operation.
On the Parameters tab of the page, configure required parameters.
On the SDK Sample Code tab of the page, select V2.0 for SDK Version and Java for Languages. Then, click Download Project to download the sample code package.
Decompress the sample code package on your computer and access the sample directory.
Open and run the project
Use IntelliJ IDEA to load the project. After the relevant dependencies are loaded, open the src/main/java/com/aliyun/sample/Sample.java file. Add the code that is used to print the returned values based on the comments in the code.
In the upper-right corner of the IDE, click Run to view the output logs. In this example, the following content is returned:
{
"TotalCount": 568,
"RequestId": "B62E33DC-368B-52E8-A401-1DFFEB0D4DD8",
"PageSize": 2,
"CurrentPage": 1,
"Items": [
{
"Status": 1,
"CustomType": 1,
"LoginName": "sddp_test",
"Category": 5,
"GmtModified": 1693215690000,
"Name": "delete_test",
"HitTotalCount": 0,
"GroupId": "",
"GmtCreate": 1693215690000,
"MatchType": 1,
"Content": "[{\"rule\":[{\"target\":\"content\"}],\"ruleRelation\":\"AND\"}]",
"DisplayName": "User01",
"SupportForm": 1,
"CategoryName": "Keyword",
"Id": 9950553,
"ContentCategory": 108
},
{
"Status": 1,
"CustomType": 1,
"LoginName": "sddp_test",
"Category": 5,
"GmtModified": 1692950931000,
"Name": "OCR-test",
"HitTotalCount": 0,
"GroupId": "",
"GmtCreate": 1692950931000,
"MatchType": 1,
"Content": "[{\"rule\":[{\"operator\":\"contains\",\"target\":\"fileName\",\"value\":\"Orc\"}],\"ruleRelation\":\"AND\"}]",
"DisplayName": "User01",
"SupportForm": 2,
"CategoryName": "User01",
"Id": 9950551,
"ContentCategory": 108
}
]
}