Skip to content

Commit

Permalink
Feat/waf (#2160)
Browse files Browse the repository at this point in the history
* feat/waf

* feat/waf

* feat/waf

* feat/waf

* add

* feat/waf

* feat/waf

* feat/waf

* feat/waf

* feat/waf

* feat/waf

* feat/waf

* feat/waf

* feat/waf

* feat/waf

* add

* add

* feat/waf

* feat/waf
  • Loading branch information
SevenEarth authored Sep 28, 2023
1 parent 04b6fe6 commit 980b431
Show file tree
Hide file tree
Showing 26 changed files with 1,956 additions and 192 deletions.
15 changes: 15 additions & 0 deletions .changelog/2160.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```release-note:new-resource
tencentcloud_waf_anti_fake
```

```release-note:new-resource
tencentcloud_waf_anti_info_leak
```

```release-note:new-data-source
tencentcloud_waf_instance_qps_limit
```

```release-note:enhancement
resource/tencentcloud_waf_clb_domain: alb_type support apisix, tsegw
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ require (
gopkg.in/yaml.v2 v2.4.0
)

require github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.754
require github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.759

require (
4d63.com/gocheckcompilerdirectives v1.2.1 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,10 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.755 h1:3u79chv
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.755/go.mod h1:sOWUQj3GQHdkTqZc1b+mAFqWmhUv2Pg4EZoOjqDprzY=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.754 h1:QjRYFbhUfH4xlwJZf1dRiz8hhQxxbfGTm8F5zC0XYXk=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.754/go.mod h1:Xz3W12eATXJq8EULnYz8/7EY/w2GLCgCWb9Dw36SWKM=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.757 h1:0068GFkgwRJHzFRsS3pUhzqD96v0DkFusmBG8U5XvWc=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.757/go.mod h1:i906Da8ZhGtegDaZyFHTGbjnlzSI1f7hxGxC/eIBWtY=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.759 h1:elaQECRbdePWEJXh3EMRWUkd5GIu5C+u9HrQZRML/3A=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.759/go.mod h1:MDjcWvTd6A+6JFVbyw1jsLfq2tNDTkbiVKvgb7wb5uE=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wedata v1.0.725 h1:ETqP+erlPnDK1zafCmyDYNkZLcY+dAG3143Ihk5vFHk=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wedata v1.0.725/go.mod h1:YPB08jHrJ3GJJ09ZTEBLnMvI+lqQEtu17jJjyfq8+sU=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wss v1.0.199 h1:hMBLtiJPnZ9GvA677cTB6ELBR6B68wCR2QY1sNoGQc4=
Expand Down
153 changes: 153 additions & 0 deletions tencentcloud/data_source_tc_waf_instance_qps_limit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
Use this data source to query detailed information of waf instance_qps_limit
Example Usage
```hcl
data "tencentcloud_waf_instance_qps_limit" "example" {
instance_id = "waf_2kxtlbky00b3b4qz"
}
```
*/
package tencentcloud

import (
"context"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
waf "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf/v20180125"
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
)

func dataSourceTencentCloudWafInstanceQpsLimit() *schema.Resource {
return &schema.Resource{
Read: dataSourceTencentCloudWafInstanceQpsLimitRead,
Schema: map[string]*schema.Schema{
"instance_id": {
Required: true,
Type: schema.TypeString,
Description: "Unique ID of Instance.",
},
"type": {
Optional: true,
Type: schema.TypeString,
Description: "Instance type.",
},
"qps_data": {
Computed: true,
Type: schema.TypeList,
Description: "Qps info.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"elastic_billing_default": {
Type: schema.TypeInt,
Computed: true,
Description: "Elastic qps default value.",
},
"elastic_billing_min": {
Type: schema.TypeInt,
Computed: true,
Description: "Minimum elastic qps.",
},
"elastic_billing_max": {
Type: schema.TypeInt,
Computed: true,
Description: "Maximum elastic qps.",
},
"qps_extend_max": {
Type: schema.TypeInt,
Computed: true,
Description: "Maximum qps of extend package.",
},
"qps_extend_intl_max": {
Type: schema.TypeInt,
Computed: true,
Description: "Maximum qps of extend package for overseas.",
},
},
},
},
"result_output_file": {
Type: schema.TypeString,
Optional: true,
Description: "Used to save results.",
},
},
}
}

func dataSourceTencentCloudWafInstanceQpsLimitRead(d *schema.ResourceData, meta interface{}) error {
defer logElapsed("data_source.tencentcloud_waf_instance_qps_limit.read")()
defer inconsistentCheck(d, meta)()

var (
logId = getLogId(contextNil)
ctx = context.WithValue(context.TODO(), logIdKey, logId)
service = WafService{client: meta.(*TencentCloudClient).apiV3Conn}
qpsData *waf.QpsData
instanceId string
)

paramMap := make(map[string]interface{})
if v, ok := d.GetOk("instance_id"); ok {
paramMap["InstanceId"] = helper.String(v.(string))
instanceId = v.(string)
}

if v, ok := d.GetOk("type"); ok {
paramMap["Type"] = helper.String(v.(string))
}

err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
result, e := service.DescribeWafInstanceQpsLimitByFilter(ctx, paramMap)
if e != nil {
return retryError(e)
}

qpsData = result
return nil
})

if err != nil {
return err
}

if qpsData != nil {
tmqList := []interface{}{}
qpsDataMap := map[string]interface{}{}

if qpsData.ElasticBillingDefault != nil {
qpsDataMap["elastic_billing_default"] = qpsData.ElasticBillingDefault
}

if qpsData.ElasticBillingMin != nil {
qpsDataMap["elastic_billing_min"] = qpsData.ElasticBillingMin
}

if qpsData.ElasticBillingMax != nil {
qpsDataMap["elastic_billing_max"] = qpsData.ElasticBillingMax
}

if qpsData.QPSExtendMax != nil {
qpsDataMap["qps_extend_max"] = qpsData.QPSExtendMax
}

if qpsData.QPSExtendIntlMax != nil {
qpsDataMap["qps_extend_intl_max"] = qpsData.QPSExtendIntlMax
}

tmqList = append(tmqList, qpsDataMap)
_ = d.Set("qps_data", tmqList)
}

d.SetId(instanceId)
output, ok := d.GetOk("result_output_file")
if ok && output.(string) != "" {
if e := writeToFile(output.(string), d); e != nil {
return e
}
}

return nil
}
32 changes: 32 additions & 0 deletions tencentcloud/data_source_tc_waf_instance_qps_limit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package tencentcloud

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

// go test -i; go test -test.run TestAccTencentCloudWafInstanceQpsLimitDataSource_basic -v
func TestAccTencentCloudWafInstanceQpsLimitDataSource_basic(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccWafInstanceQpsLimitDataSource,
Check: resource.ComposeTestCheckFunc(
testAccCheckTencentCloudDataSourceID("data.tencentcloud_waf_instance_qps_limit.example"),
),
},
},
})
}

const testAccWafInstanceQpsLimitDataSource = `
data "tencentcloud_waf_instance_qps_limit" "example" {
instance_id = "waf_2kxtlbky00b3b4qz"
}
`
58 changes: 57 additions & 1 deletion tencentcloud/extension_waf.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,15 @@ const (
)

const (
ALB_TYPE_CLB = "clb"
ALB_TYPE_CLB = "clb"
ALB_TYPE_APISIX = "apisix"
ALB_TYPE_TSEGW = "tsegw"
)

var ALB_TYPES = []string{
ALB_TYPE_CLB,
ALB_TYPE_APISIX,
ALB_TYPE_TSEGW,
}

const (
Expand Down Expand Up @@ -592,3 +596,55 @@ var MetricNameList = []string{
var (
STATE_0 = 0
)

const (
ANTI_FAKE_URL_STATUS_0 = 0
ANTI_FAKE_URL_STATUS_1 = 1
ANTI_FAKE_URL_STATUS_2 = 2
ANTI_FAKE_URL_STATUS_3 = 3
)

var ANTI_FAKE_URL_STATUS = []int{
ANTI_FAKE_URL_STATUS_0,
ANTI_FAKE_URL_STATUS_1,
ANTI_FAKE_URL_STATUS_2,
ANTI_FAKE_URL_STATUS_3,
}

const (
ANTI_INFO_LEAK_ACTION_TYPE_0 = 0
ANTI_INFO_LEAK_ACTION_TYPE_1 = 1
ANTI_INFO_LEAK_ACTION_TYPE_2 = 2
ANTI_INFO_LEAK_ACTION_TYPE_3 = 3
ANTI_INFO_LEAK_ACTION_TYPE_4 = 4
)

var ANTI_INFO_LEAK_ACTION_TYPE = []int{
ANTI_INFO_LEAK_ACTION_TYPE_0,
ANTI_INFO_LEAK_ACTION_TYPE_1,
ANTI_INFO_LEAK_ACTION_TYPE_2,
ANTI_INFO_LEAK_ACTION_TYPE_3,
ANTI_INFO_LEAK_ACTION_TYPE_4,
}

const (
STRATEGIES_FIELD_RETURNCODE = "returncode"
STRATEGIES_FIELD_KEYWORDS = "keywords"
STRATEGIES_FIELD_INFORMATION = "information"
)

var STRATEGIES_FIELD = []string{
STRATEGIES_FIELD_RETURNCODE,
STRATEGIES_FIELD_KEYWORDS,
STRATEGIES_FIELD_INFORMATION,
}

const (
ANTI_INFO_LEAK_RULE_STATUS_0 = 0
ANTI_INFO_LEAK_RULE_STATUS_1 = 1
)

var ANTI_INFO_LEAK_RULE_STATUS = []int{
ANTI_INFO_LEAK_RULE_STATUS_0,
ANTI_INFO_LEAK_RULE_STATUS_1,
}
6 changes: 6 additions & 0 deletions tencentcloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,7 @@ Waf
tencentcloud_waf_attack_overview
tencentcloud_waf_attack_total_count
tencentcloud_waf_peak_points
tencentcloud_waf_instance_qps_limit
Resource
tencentcloud_waf_custom_rule
Expand All @@ -1684,6 +1685,8 @@ Waf
tencentcloud_waf_saas_domain
tencentcloud_waf_clb_instance
tencentcloud_waf_saas_instance
tencentcloud_waf_anti_fake
tencentcloud_waf_anti_info_leak
*/
package tencentcloud

Expand Down Expand Up @@ -2344,6 +2347,7 @@ func Provider() *schema.Provider {
"tencentcloud_waf_attack_overview": dataSourceTencentCloudWafAttackOverview(),
"tencentcloud_waf_attack_total_count": dataSourceTencentCloudWafAttackTotalCount(),
"tencentcloud_waf_peak_points": dataSourceTencentCloudWafPeakPoints(),
"tencentcloud_waf_instance_qps_limit": dataSourceTencentCloudWafInstanceQpsLimit(),
"tencentcloud_ses_receivers": dataSourceTencentCloudSesReceivers(),
"tencentcloud_ses_send_tasks": dataSourceTencentCloudSesSendTasks(),
"tencentcloud_ses_email_identities": dataSourceTencentCloudSesEmailIdentities(),
Expand Down Expand Up @@ -3107,6 +3111,8 @@ func Provider() *schema.Provider {
"tencentcloud_waf_saas_domain": resourceTencentCloudWafSaasDomain(),
"tencentcloud_waf_clb_instance": resourceTencentCloudWafClbInstance(),
"tencentcloud_waf_saas_instance": resourceTencentCloudWafSaasInstance(),
"tencentcloud_waf_anti_fake": resourceTencentCloudWafAntiFake(),
"tencentcloud_waf_anti_info_leak": resourceTencentCloudWafAntiInfoLeak(),
},

ConfigureFunc: providerConfigure,
Expand Down
Loading

0 comments on commit 980b431

Please sign in to comment.