github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/waf-premium/v1/rules/ChangeRuleStatus.go (about) 1 package rules 2 3 import ( 4 "github.com/opentelekomcloud/gophertelekomcloud" 5 "github.com/opentelekomcloud/gophertelekomcloud/internal/build" 6 "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" 7 ) 8 9 type ChangeStatusOpts struct { 10 // Rule status. The value can be: 11 // 0: The rule is disabled. 12 // 1: The rule is enabled. 13 Status int `json:"status" required:"true"` 14 } 15 16 // ChangeRuleStatus is used to change the status of a policy rule. 17 func ChangeRuleStatus(client *golangsdk.ServiceClient, PolicyId, Ruletype, RuleId string, opts ChangeStatusOpts) (*RuleStatus, error) { 18 b, err := build.RequestBody(opts, "") 19 if err != nil { 20 return nil, err 21 } 22 23 // PUT /v1/{project_id}/waf/policy/{policy_id}/{ruletype}/{rule_id}/status} 24 url := client.ServiceURL("waf", "policy", PolicyId, Ruletype, RuleId, "status") 25 raw, err := client.Put(url, b, nil, &golangsdk.RequestOpts{ 26 OkCodes: []int{200}, 27 MoreHeaders: map[string]string{"Content-Type": "application/json;charset=utf8"}, 28 }) 29 if err != nil { 30 return nil, err 31 } 32 33 var res RuleStatus 34 return &res, extract.Into(raw.Body, &res) 35 } 36 37 type RuleStatus struct { 38 // Rule ID. 39 Id string `json:"id"` 40 // Policy ID. 41 PolicyId string `json:"policyid"` 42 // Time when the rule was created. 43 CreatedAt int64 `json:"timestamp"` 44 // Rule Description. 45 Description string `json:"description"` 46 // Status. The options are 0 and 1. 0: Disabled. 1: Enabled. 47 Status int `json:"status"` 48 }