更新规则
功能介绍
更新规则
调用方法
请参见如何调用API。
URI
PUT /v2/{domain_id}/rules/{rule_id}/update
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
domain_id |
是 |
String |
参数解释: 租户ID。 约束限制: 不涉及。 取值范围: 32位字符,由数字和字母组成。 默认取值: 不涉及。 |
rule_id |
是 |
String |
参数解释: 规则ID,规则的唯一标识,通过分页获取规则列表接口获取,data.id即为规则ID。 约束限制: 不涉及。 取值范围: 32位字符,由数字和字母组成。 默认取值: 不涉及。 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
参数解释: 用户Token。通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
type |
是 |
String |
参数解释: 规则类型。 约束限制: 不涉及。 取值范围:
默认取值: 不涉及。 |
name |
是 |
String |
参数解释: 规则名称。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
plugin_id |
否 |
String |
参数解释: 扩展插件唯一ID。可以通过查询插件版本详情接口,获取响应参数中unique_id。 约束限制: 不涉及。 取值范围: 32位字符,由数字和字母组成。 默认取值: 不涉及。 |
plugin_name |
否 |
String |
参数解释: 扩展插件名称。 约束限制: 仅支持输入大小写英文字母、数字、'-'、'_'。 取值范围: 1到50位字符。 默认取值: 不涉及。 |
plugin_version |
否 |
String |
参数解释: 扩展插件版本号。 约束限制: 仅支持输入大小写英文字母、数字、'-'、'_'。 取值范围: 1到50位字符。 默认取值: 不涉及。 |
content |
是 |
Array of RuleContent objects |
参数解释: 规则详细属性。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
group_name |
是 |
String |
参数解释: 分组名称。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
can_modify_when_inherit |
否 |
Boolean |
参数解释: 继承后的子策略是否可以修改阈值。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
properties |
是 |
Array of RuleProperty objects |
参数解释: 规则属性列表。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
key |
是 |
String |
参数解释: 属性键。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
type |
是 |
String |
参数解释: 类型。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
name |
是 |
String |
参数解释: 展示名称。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
operator |
否 |
String |
参数解释: 比较运算符。 约束限制: 不涉及。 取值范围:
默认取值: 不涉及。 |
value |
是 |
String |
参数解释: 属性值。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
value_type |
是 |
String |
参数解释: 数据类型。 约束限制: 不涉及。 取值范围:
默认取值: 不涉及。 |
is_valid |
否 |
Boolean |
参数解释: 属性是否启用。 约束限制: 不涉及。 取值范围:
默认取值: false。 |
响应参数
状态码:200
参数 |
参数类型 |
描述 |
---|---|---|
status |
Boolean |
参数解释: 是否调用成功。 取值范围:
|
rule_id |
String |
参数解释: 规则ID,规则的唯一标识,通过分页获取规则列表接口获取,data.id即为规则ID。 约束限制: 不涉及。 取值范围: 32位字符,由数字和字母组成。 默认取值: 不涉及。 |
状态码:400
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
String |
参数解释: 错误码。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
error_msg |
String |
参数解释: 错误描述。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
状态码:401
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
String |
参数解释: 错误码。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
error_msg |
String |
参数解释: 错误描述。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
状态码:403
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
String |
参数解释: 错误码。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
error_msg |
String |
参数解释: 错误描述。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
状态码:404
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
String |
参数解释: 错误码。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
error_msg |
String |
参数解释: 错误描述。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
请求示例
PUT https://{endpoint}/v2/ce8df55870164338a72d7e828a966a2a/rules/425eba0deaf04596a74cf7967d7fc04d/update { "name" : "新建规则-20230919104204", "type" : "Test", "plugin_id" : "official_devcloud_apiTest", "plugin_name" : "official_devcloud_apiTest", "plugin_version" : "0.0.12", "layout_content" : "layout_content", "content" : [ { "group_name" : "API测试通过率门禁", "properties" : [ { "key" : "pass_ratio", "name" : "api测试通过率", "type" : "judge", "operator" : "=", "value_type" : "float", "value" : "0.5" } ] } ] }
响应示例
状态码:200
请求成功
{ "status" : true, "rule_id" : "425eba0deaf04596a74cf7967d7fc04d" }
SDK代码示例
SDK代码示例如下。
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 |
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.codeartspipeline.v2.region.CodeArtsPipelineRegion; import com.huaweicloud.sdk.codeartspipeline.v2.*; import com.huaweicloud.sdk.codeartspipeline.v2.model.*; import java.util.List; import java.util.ArrayList; public class UpdateRuleSolution { 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"); ICredential auth = new BasicCredentials() .withAk(ak) .withSk(sk); CodeArtsPipelineClient client = CodeArtsPipelineClient.newBuilder() .withCredential(auth) .withRegion(CodeArtsPipelineRegion.valueOf("<YOUR REGION>")) .build(); UpdateRuleRequest request = new UpdateRuleRequest(); request.withDomainId("{domain_id}"); request.withRuleId("{rule_id}"); UpdateRuleReq body = new UpdateRuleReq(); List<RuleProperty> listContentProperties = new ArrayList<>(); listContentProperties.add( new RuleProperty() .withKey("pass_ratio") .withType("judge") .withName("api测试通过率") .withOperator("=") .withValue("0.5") .withValueType("float") ); List<RuleContent> listbodyContent = new ArrayList<>(); listbodyContent.add( new RuleContent() .withGroupName("API测试通过率门禁") .withProperties(listContentProperties) ); body.withContent(listbodyContent); body.withPluginVersion("0.0.12"); body.withPluginName("official_devcloud_apiTest"); body.withPluginId("official_devcloud_apiTest"); body.withLayoutContent("layout_content"); body.withName("新建规则-20230919104204"); body.withType("Test"); request.withBody(body); try { UpdateRuleResponse response = client.updateRule(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 |
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcodeartspipeline.v2.region.codeartspipeline_region import CodeArtsPipelineRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkcodeartspipeline.v2 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"] credentials = BasicCredentials(ak, sk) client = CodeArtsPipelineClient.new_builder() \ .with_credentials(credentials) \ .with_region(CodeArtsPipelineRegion.value_of("<YOUR REGION>")) \ .build() try: request = UpdateRuleRequest() request.domain_id = "{domain_id}" request.rule_id = "{rule_id}" listPropertiesContent = [ RuleProperty( key="pass_ratio", type="judge", name="api测试通过率", operator="=", value="0.5", value_type="float" ) ] listContentbody = [ RuleContent( group_name="API测试通过率门禁", properties=listPropertiesContent ) ] request.body = UpdateRuleReq( content=listContentbody, plugin_version="0.0.12", plugin_name="official_devcloud_apiTest", plugin_id="official_devcloud_apiTest", layout_content="layout_content", name="新建规则-20230919104204", type="Test" ) response = client.update_rule(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 |
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" codeartspipeline "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/codeartspipeline/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/codeartspipeline/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/codeartspipeline/v2/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") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := codeartspipeline.NewCodeArtsPipelineClient( codeartspipeline.CodeArtsPipelineClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.UpdateRuleRequest{} request.DomainId = "{domain_id}" request.RuleId = "{rule_id}" operatorProperties:= "=" var listPropertiesContent = []model.RuleProperty{ { Key: "pass_ratio", Type: "judge", Name: "api测试通过率", Operator: &operatorProperties, Value: "0.5", ValueType: "float", }, } var listContentbody = []model.RuleContent{ { GroupName: "API测试通过率门禁", Properties: listPropertiesContent, }, } pluginVersionUpdateRuleReq:= "0.0.12" pluginNameUpdateRuleReq:= "official_devcloud_apiTest" pluginIdUpdateRuleReq:= "official_devcloud_apiTest" request.Body = &model.UpdateRuleReq{ Content: listContentbody, PluginVersion: &pluginVersionUpdateRuleReq, PluginName: &pluginNameUpdateRuleReq, PluginId: &pluginIdUpdateRuleReq, LayoutContent: "layout_content", Name: "新建规则-20230919104204", Type: "Test", } response, err := client.UpdateRule(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
请求成功 |
400 |
请求失败 |
401 |
认证失败 |
403 |
无权限 |
404 |
资源不存在 |
错误码
请参见错误码。