Creating a Retry Emergency Policy
Function
This API is used to create a retry emergency policy.
Calling Method
For details, see Calling APIs.
URI
POST /v1/{project_id}/workspaces/{workspace_id}/soc/policys
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
project_id |
Yes |
String |
Definition Project ID, which is used to specify the project that a resource belongs to. You can query the resources of a project by project ID. You can obtain the project ID from the API or console. Obtaining the Project ID Constraints N/A Range N/A Default Value N/A |
|
workspace_id |
Yes |
String |
Definition Workspace ID. Constraints N/A Range N/A Default Value N/A |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
action_type |
Yes |
String |
Operation type. The value can be create or retry. |
Request Parameters
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
X-Auth-Token |
Yes |
String |
Definition User token. You can obtain it by calling the IAM API for obtaining a user token. The user token is the value of X-Subject-Token in the response header. Obtaining a User Token Constraints N/A Range N/A Default Value N/A |
|
Content-Type |
Yes |
String |
Definition Content type. Constraints N/A Range Default Value N/A |
|
X-Secmaster-Version |
Yes |
String |
Service version, for example, 25.5.0. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
data_object |
No |
data_object object |
Policy entity information. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
retry_list |
No |
Array of strings |
Retry policy ID. |
|
block_age |
Yes |
block_age object |
Block aging. |
|
block_target |
Yes |
String |
Policy object. |
|
defense_policy_list |
Yes |
Array of defense_policy_list objects |
List of policies corresponding to the operation connection. |
|
description |
No |
String |
Description. |
|
labels |
No |
String |
Tag. |
|
policy_category |
Yes |
String |
Type. The value can be WHITE or BLOCK. WHITE: Objects such as IP addresses will be added to the whitelist. BLOCK: The objects such as IP addresses will be added to the blacklist. |
|
policy_type |
Yes |
policy_type object |
Block type. |
|
region_id |
Yes |
String |
Region ID. |
|
policy_direction |
No |
String |
Inbound or outbound. |
|
account_scope |
No |
String |
Account scope. |
|
eps_scope |
No |
String |
Enterprise project scope. |
|
region_scope |
No |
String |
Region range. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
is_block_ageing |
Yes |
Boolean |
Whether to block aging. |
|
block_ageing |
No |
String |
Aging time. The value is a timestamp, in ms. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
defense_connection_id |
Yes |
String |
Operation connection ID. |
|
defense_connection_name |
Yes |
String |
Operation connection name. |
|
defense_connection_region_id |
Yes |
String |
Region ID for the defense layer policy. |
|
defense_connection_region_name |
Yes |
String |
Region for the defense layer policy. |
|
defense_type |
Yes |
String |
Defense layer service. |
|
target_enterprise_id |
Yes |
String |
Enterprise project ID. |
|
target_enterprise_name |
Yes |
String |
Enterprise project name. |
|
target_project_id |
Yes |
String |
Project ID for the defense layer policy. |
|
target_project_name |
Yes |
String |
Project ID for the defense layer policy. |
Response Parameters
Status code: 200
|
Parameter |
Type |
Description |
|---|---|---|
|
code |
String |
Status code. |
|
data |
String |
Delivered task ID. |
|
message |
String |
Status Information. |
|
request_id |
String |
Request ID. |
|
success |
Boolean |
Request status. |
Status code: 400
|
Parameter |
Type |
Description |
|---|---|---|
|
code |
String |
Definition Error code. Range N/A |
|
message |
String |
Definition Error description. Range N/A |
Example Requests
https://{endpoint}/v1/{project_id}/workspaces/{workspace_id}/soc/policys?action_type=create
{
"data_object" : {
"region_id" : "RegionId",
"block_target" : "1.2.3.4",
"policy_category" : "BLOCK",
"description" : "",
"labels" : "",
"block_age" : {
"is_block_ageing" : false,
"block_ageing" : null
},
"policy_type" : {
"policy_type" : "Source Ip"
},
"defense_policy_list" : [ {
"defense_connection_id" : "84b273d3-47a8-3aba-bd00-7bdd1431d635",
"defense_connection_name" : "CFW",
"defense_type" : "CFW",
"target_enterprise_id" : "0",
"target_enterprise_name" : "default",
"target_project_id" : "3bb27e024693436da46b5f5aaf499060",
"target_project_name" : "RegionName",
"defense_connection_region_id" : "RegionId",
"defense_connection_region_name" : "RegionName"
} ]
}
}
Example Responses
Status code: 200
Response body for creating an emergency policy.
{
"code" : "00000000",
"data" : "b724da59-81db-4dc9-b059-d519869e9a41",
"message" : "",
"request_id" : "",
"success" : true
}
SDK Sample Code
The SDK sample code is as follows.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.secmaster.v1.region.SecMasterRegion; import com.huaweicloud.sdk.secmaster.v1.*; import com.huaweicloud.sdk.secmaster.v1.model.*; import java.util.List; import java.util.ArrayList; public class CreateRetryPolicySolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); SecMasterClient client = SecMasterClient.newBuilder() .withCredential(auth) .withRegion(SecMasterRegion.valueOf("<YOUR REGION>")) .build(); CreateRetryPolicyRequest request = new CreateRetryPolicyRequest(); request.withWorkspaceId("{workspace_id}"); CreateRetryPolicyRequestBody body = new CreateRetryPolicyRequestBody(); CreateRetryPolicyRequestBodyDataObjectPolicyType policyTypeDataObject = new CreateRetryPolicyRequestBodyDataObjectPolicyType(); policyTypeDataObject.withPolicyType(CreateRetryPolicyRequestBodyDataObjectPolicyType.PolicyTypeEnum.fromValue("Source Ip")); List<CreateRetryPolicyRequestBodyDataObjectDefensePolicyList> listDataObjectDefensePolicyList = new ArrayList<>(); listDataObjectDefensePolicyList.add( new CreateRetryPolicyRequestBodyDataObjectDefensePolicyList() .withDefenseConnectionId("84b273d3-47a8-3aba-bd00-7bdd1431d635") .withDefenseConnectionName("CFW") .withDefenseConnectionRegionId("RegionId") .withDefenseConnectionRegionName("RegionName") .withDefenseType("CFW") .withTargetEnterpriseId("0") .withTargetEnterpriseName("default") .withTargetProjectId("3bb27e024693436da46b5f5aaf499060") .withTargetProjectName("RegionName") ); CreateRetryPolicyRequestBodyDataObjectBlockAge blockAgeDataObject = new CreateRetryPolicyRequestBodyDataObjectBlockAge(); blockAgeDataObject.withIsBlockAgeing(false); CreateRetryPolicyRequestBodyDataObject dataObjectbody = new CreateRetryPolicyRequestBodyDataObject(); dataObjectbody.withBlockAge(blockAgeDataObject) .withBlockTarget("1.2.3.4") .withDefensePolicyList(listDataObjectDefensePolicyList) .withDescription("") .withLabels("") .withPolicyCategory(CreateRetryPolicyRequestBodyDataObject.PolicyCategoryEnum.fromValue("BLOCK")) .withPolicyType(policyTypeDataObject) .withRegionId("RegionId"); body.withDataObject(dataObjectbody); request.withBody(body); try { CreateRetryPolicyResponse response = client.createRetryPolicy(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdksecmaster.v1.region.secmaster_region import SecMasterRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdksecmaster.v1 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = SecMasterClient.new_builder() \ .with_credentials(credentials) \ .with_region(SecMasterRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreateRetryPolicyRequest() request.workspace_id = "{workspace_id}" policyTypeDataObject = CreateRetryPolicyRequestBodyDataObjectPolicyType( policy_type="Source Ip" ) listDefensePolicyListDataObject = [ CreateRetryPolicyRequestBodyDataObjectDefensePolicyList( defense_connection_id="84b273d3-47a8-3aba-bd00-7bdd1431d635", defense_connection_name="CFW", defense_connection_region_id="RegionId", defense_connection_region_name="RegionName", defense_type="CFW", target_enterprise_id="0", target_enterprise_name="default", target_project_id="3bb27e024693436da46b5f5aaf499060", target_project_name="RegionName" ) ] blockAgeDataObject = CreateRetryPolicyRequestBodyDataObjectBlockAge( is_block_ageing=False ) dataObjectbody = CreateRetryPolicyRequestBodyDataObject( block_age=blockAgeDataObject, block_target="1.2.3.4", defense_policy_list=listDefensePolicyListDataObject, description="", labels="", policy_category="BLOCK", policy_type=policyTypeDataObject, region_id="RegionId" ) request.body = CreateRetryPolicyRequestBody( data_object=dataObjectbody ) response = client.create_retry_policy(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" secmaster "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/secmaster/v1" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/secmaster/v1/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/secmaster/v1/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := secmaster.NewSecMasterClient( secmaster.SecMasterClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CreateRetryPolicyRequest{} request.WorkspaceId = "{workspace_id}" policyTypeDataObject := &model.CreateRetryPolicyRequestBodyDataObjectPolicyType{ PolicyType: model.GetCreateRetryPolicyRequestBodyDataObjectPolicyTypePolicyTypeEnum().SOURCE_IP, } var listDefensePolicyListDataObject = []model.CreateRetryPolicyRequestBodyDataObjectDefensePolicyList{ { DefenseConnectionId: "84b273d3-47a8-3aba-bd00-7bdd1431d635", DefenseConnectionName: "CFW", DefenseConnectionRegionId: "RegionId", DefenseConnectionRegionName: "RegionName", DefenseType: "CFW", TargetEnterpriseId: "0", TargetEnterpriseName: "default", TargetProjectId: "3bb27e024693436da46b5f5aaf499060", TargetProjectName: "RegionName", }, } blockAgeDataObject := &model.CreateRetryPolicyRequestBodyDataObjectBlockAge{ IsBlockAgeing: false, } descriptionDataObject:= "" labelsDataObject:= "" dataObjectbody := &model.CreateRetryPolicyRequestBodyDataObject{ BlockAge: blockAgeDataObject, BlockTarget: "1.2.3.4", DefensePolicyList: listDefensePolicyListDataObject, Description: &descriptionDataObject, Labels: &labelsDataObject, PolicyCategory: model.GetCreateRetryPolicyRequestBodyDataObjectPolicyCategoryEnum().BLOCK, PolicyType: policyTypeDataObject, RegionId: "RegionId", } request.Body = &model.CreateRetryPolicyRequestBody{ DataObject: dataObjectbody, } response, err := client.CreateRetryPolicy(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.
Status Codes
|
Status Code |
Description |
|---|---|
|
200 |
Response body for creating an emergency policy. |
|
400 |
Response body for an emergency policy creation error. |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot