diff --git a/go.mod b/go.mod index 21a0ff348c..2ad3bfb772 100644 --- a/go.mod +++ b/go.mod @@ -33,7 +33,7 @@ require ( github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.445 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.199 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.412 - github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.480 + github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.486 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.445 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.359 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dayu v1.0.335 @@ -60,6 +60,7 @@ require ( github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr v1.0.267 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdmq v1.0.268 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.472 + github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.486 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.480 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod v1.0.199 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.479 diff --git a/go.sum b/go.sum index 0b93383598..d14135471e 100644 --- a/go.sum +++ b/go.sum @@ -489,11 +489,16 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.413/go.mod github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.414/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.443/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.445/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.463/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.466/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.472/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.479/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.480 h1:Dwnfdrk3KXpYRH9Kwrk9sHpZSOmrE7P9LBoNsYUJKR4= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.480/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.484 h1:x37ASMnNHHh7X0JpEhJmUz4OQL9DCIoXB0wv8u1TKic= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.484/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.486 h1:MUO3Gp/jo/t0NBJ2TLH2sDjy+b/eJUCGgBT+7BfN2yE= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.486/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.445 h1:Bh7XD0ypNMHYyBOM8hhKsSu+y0VVKUnJVS+YKKhfpGg= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.445/go.mod h1:jMDD351efCFpT1+KVFbcpu6SbmP4TYmp4qkoCfr63nQ= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.359 h1:cNKqelPgUxrJkLY0Azd2QHr/UMYOPPnmqs88clt2akk= @@ -547,6 +552,14 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdmq v1.0.268 h1:ez5lvK github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdmq v1.0.268/go.mod h1:fchXZhmqaYaG2c4wTCBTdnW6TFAtxl3D/P/yuuuLMfA= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.472 h1:9Jzrgx78+5XnZ8myNYjCYZn5ZF+tbSIpF6KWGgWr0uY= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.472/go.mod h1:ayIL2FNqk7HH5fPQrkWtYjgU4jL7if63f7x+yRwb4a0= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.463 h1:QA9uGf9PjzitWIRFtf/NjsB4HjeuJdFi43RvTXNJQ5M= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.463/go.mod h1:D8kkDqqTJQe/qYhXsQkwD3ACxXPoAXwNR4JWe1rOQIs= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.480 h1:sP9z+Q7acbqElkzRfWbESLWycmpQHFKM+qIbeFyW24I= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.480/go.mod h1:XC6UD5UnzncR6O48Ya/FsIdkiPJT/jSKlUjolzpfayg= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.484 h1:7+1ltleuaAz/jI3NIapvOsl7wzu8UcJYjnh+d4UWAtc= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.484/go.mod h1:o3AyKFiYfjK7U/DsDzz1XmTRmXrTsemx/gx/630d+DE= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.486 h1:JRtQYtJB9sErV9tXY6xbrC3RmXNepBKd7aV3inxkUPs= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.486/go.mod h1:wtPJIKxQUR3KoL2KWAt/Qi8KMR4ayKHiOeVJ6sTSC4U= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.480 h1:oZptW2Fo1pW8fKz/dv+RJLr2q8UC1qkqDqWs3rDgvQ8= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.480/go.mod h1:rs+BUoY53xfiE5sRsVk2RpsjgzODtq52xiBTc6WTWWM= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod v1.0.199 h1:6Yt74l4pA5QtzhwMNIEUt0spXdSBKH744DDqTHJOCP0= diff --git a/tencentcloud/connectivity/client.go b/tencentcloud/connectivity/client.go index a64faf2c5f..ba9ea80d91 100644 --- a/tencentcloud/connectivity/client.go +++ b/tencentcloud/connectivity/client.go @@ -56,6 +56,7 @@ import ( tcr "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr/v20190924" tdmq "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdmq/v20200217" tem "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem/v20210701" + teo "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220106" tke "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke/v20180525" vod "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod/v20180717" vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312" @@ -119,6 +120,7 @@ type TencentCloudClient struct { domainConn *domain.Client lighthouseConn *lighthouse.Client temConn *tem.Client + teoConn *teo.Client } // NewClientProfile returns a new ClientProfile @@ -746,6 +748,19 @@ func (me *TencentCloudClient) UseTemClient() *tem.Client { return me.temConn } +// UseTeoClient returns teo client for service +func (me *TencentCloudClient) UseTeoClient() *teo.Client { + if me.teoConn != nil { + return me.teoConn + } + + cpf := me.NewClientProfile(300) + me.teoConn, _ = teo.NewClient(me.Credential, me.Region, cpf) + me.teoConn.WithHttpTransport(&LogRoundTripper{}) + + return me.teoConn +} + func getEnvDefault(key string, defVal int) int { val, ex := os.LookupEnv(key) if !ex { diff --git a/tencentcloud/data_source_tc_teo_zone_available_plans.go b/tencentcloud/data_source_tc_teo_zone_available_plans.go new file mode 100644 index 0000000000..f92156e0e1 --- /dev/null +++ b/tencentcloud/data_source_tc_teo_zone_available_plans.go @@ -0,0 +1,130 @@ +/* +Use this data source to query zone available plans. + +Example Usage + +```hcl +data "tencentcloud_teo_zone_available_plans" "available_plans" {} +``` +*/ +package tencentcloud + +import ( + "context" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + teo "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220106" +) + +func dataSourceTencentCloudTeoZoneAvailablePlans() *schema.Resource { + return &schema.Resource{ + Read: dataSourceTencentCloudTeoZoneAvailablePlansRead, + + Schema: map[string]*schema.Schema{ + "plan_info_list": { + Type: schema.TypeList, + Computed: true, + Description: "Available plans for a zone.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "plan_type": { + Type: schema.TypeString, + Computed: true, + Description: "Plan type.", + }, + "currency": { + Type: schema.TypeString, + Computed: true, + Description: "Currency type. Valid values: `CNY`, `USD`.", + }, + "flux": { + Type: schema.TypeInt, + Computed: true, + Description: "The number of fluxes included in the zone plan. Unit: Byte.", + }, + "frequency": { + Type: schema.TypeString, + Computed: true, + Description: "Billing cycle. Valid values: `y`: Billed by the year; `m`: Billed by the month; `h`: Billed by the hour; `M`: Billed by the minute; `s`: Billed by the second.", + }, + "price": { + Type: schema.TypeInt, + Computed: true, + Description: "Price of the plan. Unit: cent.", + }, + "request": { + Type: schema.TypeInt, + Computed: true, + Description: "The number of requests included in the zone plan.", + }, + "site_number": { + Type: schema.TypeInt, + Computed: true, + Description: "The number of zones this zone plan can bind.", + }, + }, + }, + }, + "result_output_file": { + Type: schema.TypeString, + Optional: true, + Description: "Used for save results.", + }, + }, + } +} + +func dataSourceTencentCloudTeoZoneAvailablePlansRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("data_source.tencentcloud_teo_zone_available_plans.read")() + + var ( + logId = getLogId(contextNil) + ctx = context.WithValue(context.TODO(), logIdKey, logId) + service = TeoService{client: meta.(*TencentCloudClient).apiV3Conn} + availablePlans *teo.DescribeAvailablePlansResponseParams + err error + ) + + var outErr, inErr error + availablePlans, outErr = service.DescribeAvailablePlans(ctx) + if outErr != nil { + outErr = resource.Retry(readRetryTimeout, func() *resource.RetryError { + availablePlans, inErr = service.DescribeAvailablePlans(ctx) + if inErr != nil { + return retryError(inErr) + } + return nil + }) + } + + planInfos := availablePlans.PlanInfoList + planInfoList := make([]map[string]interface{}, 0, len(planInfos)) + for _, v := range planInfos { + planInfo := map[string]interface{}{ + "plan_type": v.PlanType, + "currency": v.Currency, + "flux": v.Flux, + "frequency": v.Frequency, + "price": v.Price, + "request": v.Request, + "site_number": v.SiteNumber, + } + planInfoList = append(planInfoList, planInfo) + } + if err = d.Set("plan_info_list", planInfoList); err != nil { + log.Printf("[CRITAL]%s provider set list fail, reason:%s", logId, err.Error()) + return err + } + + d.SetId("zone_available_plans") + + output, ok := d.GetOk("result_output_file") + if ok && output.(string) != "" { + if e := writeToFile(output.(string), planInfoList); e != nil { + return e + } + } + return nil +} diff --git a/tencentcloud/data_source_tc_teo_zone_ddos_policy.go b/tencentcloud/data_source_tc_teo_zone_ddos_policy.go new file mode 100644 index 0000000000..2444e27ad2 --- /dev/null +++ b/tencentcloud/data_source_tc_teo_zone_ddos_policy.go @@ -0,0 +1,243 @@ +/* +Use this data source to query zone ddos policy. + +Example Usage + +```hcl +data "tencentcloud_teo_zone_ddos_policy" "example" { + zone_id = "" +} +``` +*/ +package tencentcloud + +import ( + "context" + "log" + "strconv" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + teo "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220106" +) + +func dataSourceTencentCloudTeoZoneDdosPolicy() *schema.Resource { + return &schema.Resource{ + Read: dataSourceTencentCloudTeoZoneDdosPolicyRead, + + Schema: map[string]*schema.Schema{ + "zone_id": { + Type: schema.TypeString, + Optional: true, + Description: "Site ID.", + }, + "app_id": { + Type: schema.TypeString, + Computed: true, + Description: "App ID.", + }, + "shield_areas": { + Type: schema.TypeList, + Computed: true, + Description: "Shield areas of the zone.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "zone_id": { + Type: schema.TypeString, + Computed: true, + Description: "Site ID.", + }, + "policy_id": { + Type: schema.TypeInt, + Computed: true, + Description: "Policy ID.", + }, + "type": { + Type: schema.TypeString, + Computed: true, + Description: "Valid values: `domain`, `application`.", + }, + "entity": { + Type: schema.TypeString, + Computed: true, + Description: "When `Type` is `domain`, this field is `ZoneId`. When `Type` is `application`, this field is `ProxyId`. Note: This field may return null, indicating that no valid value can be obtained.", + }, + "entity_name": { + Type: schema.TypeString, + Computed: true, + Description: "When `Type` is `domain`, this field is `ZoneName`. When `Type` is `application`, this field is `ProxyName`. Note: This field may return null, indicating that no valid value can be obtained.", + }, + "tcp_num": { + Type: schema.TypeInt, + Computed: true, + Description: "TCP forwarding rule number of layer 4 application.", + }, + "udp_num": { + Type: schema.TypeInt, + Computed: true, + Description: "UDP forwarding rule number of layer 4 application.", + }, + "share": { + Type: schema.TypeBool, + Computed: true, + Description: "Whether the resource is shared.", + }, + "application": { + Type: schema.TypeList, + Computed: true, + Description: "Layer 7 Domain Name Parameters.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "host": { + Type: schema.TypeString, + Computed: true, + Description: "Subdomain.", + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "Status of the subdomain. Note: This field may return null, indicating that no valid value can be obtained, init: waiting to config NS; offline: waiting to enable site accelerating; process: config deployment processing; online: normal status.", + }, + "accelerate_type": { + Type: schema.TypeString, + Computed: true, + Description: "on: Enable; off: Disable.", + }, + "security_type": { + Type: schema.TypeString, + Computed: true, + Description: "on: Enable; off: Disable.", + }, + }, + }, + }, + }, + }, + }, + "domains": { + Type: schema.TypeList, + Computed: true, + Description: "All subdomain info. Note: This field may return null, indicating that no valid value can be obtained.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "host": { + Type: schema.TypeString, + Computed: true, + Description: "Subdomain.", + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "Status of the subdomain. Note: This field may return null, indicating that no valid value can be obtained, init: waiting to config NS; offline: waiting to enable site accelerating; process: config deployment processing; online: normal status.", + }, + "accelerate_type": { + Type: schema.TypeString, + Computed: true, + Description: "on: Enable; off: Disable.", + }, + "security_type": { + Type: schema.TypeString, + Computed: true, + Description: "on: Enable; off: Disable.", + }, + }, + }, + }, + "result_output_file": { + Type: schema.TypeString, + Optional: true, + Description: "Used for save results.", + }, + }, + } +} + +func dataSourceTencentCloudTeoZoneDdosPolicyRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("data_source.tencentcloud_teo_zone_ddos_policy.read")() + + var ( + logId = getLogId(contextNil) + ctx = context.WithValue(context.TODO(), logIdKey, logId) + service = TeoService{client: meta.(*TencentCloudClient).apiV3Conn} + zoneId = d.Get("zone_id").(string) + ddosPolicy *teo.DescribeZoneDDoSPolicyResponseParams + err error + ) + + if err = resource.Retry(readRetryTimeout, func() *resource.RetryError { + ddosPolicy, err = service.DescribeZoneDDoSPolicy(ctx, zoneId) + if err != nil { + return retryError(err, InternalError) + } + return nil + }); err != nil { + return err + } + + appId := strconv.FormatInt(*ddosPolicy.AppId, 10) + + shieldAreasList := make([]map[string]interface{}, 0, len(ddosPolicy.ShieldAreas)) + shieldAreas := ddosPolicy.ShieldAreas + for _, v := range shieldAreas { + applications := make([]map[string]interface{}, 0, len(v.Application)) + for _, vv := range v.Application { + application := map[string]interface{}{ + "host": vv.Host, + "status": vv.Status, + "accelerate_type": vv.AccelerateType, + "security_type": vv.SecurityType, + } + applications = append(applications, application) + } + shieldArea := map[string]interface{}{ + "zone_id": v.ZoneId, + "policy_id": v.PolicyId, + "type": v.Type, + "entity_name": v.EntityName, + "application": applications, + "tcp_num": v.TcpNum, + "udp_num": v.UdpNum, + "entity": v.Entity, + "share": v.Share, + } + shieldAreasList = append(shieldAreasList, shieldArea) + } + if err = d.Set("shield_areas", shieldAreasList); err != nil { + log.Printf("[CRITAL]%s provider set list fail, reason:%s", logId, err.Error()) + return err + } + + domainsList := make([]map[string]interface{}, 0, len(ddosPolicy.Domains)) + for _, v := range ddosPolicy.Domains { + application := map[string]interface{}{ + "host": v.Host, + "status": v.Status, + "accelerate_type": v.AccelerateType, + "security_type": v.SecurityType, + } + domainsList = append(domainsList, application) + } + if err = d.Set("domains", domainsList); err != nil { + log.Printf("[CRITAL]%s provider set list fail, reason:%s", logId, err.Error()) + return err + } + + if err = d.Set("app_id", appId); err != nil { + log.Printf("[CRITAL]%s provider set list fail, reason:%s", logId, err.Error()) + return err + } + + d.SetId(appId) + + output, ok := d.GetOk("result_output_file") + if ok && output.(string) != "" { + if e := writeToFile(output.(string), map[string]interface{}{ + "app_id": appId, + "Shield_areas": shieldAreasList, + "domains": domainsList, + }); e != nil { + return e + } + } + return nil +} diff --git a/tencentcloud/provider.go b/tencentcloud/provider.go index 88636e9e55..e9a6eb537e 100644 --- a/tencentcloud/provider.go +++ b/tencentcloud/provider.go @@ -661,6 +661,22 @@ TEM tencentcloud_tem_scale_rule tencentcloud_tem_gateway +Teo + Data Source + tencentcloud_teo_zone_available_plans + + Resource + tencentcloud_teo_zone + tencentcloud_teo_zone_setting + tencentcloud_teo_dns_record + tencentcloud_teo_dns_sec + tencentcloud_teo_load_balancing + tencentcloud_teo_origin_group + tencentcloud_teo_rule_engine + tencentcloud_teo_application_proxy + tencentcloud_teo_application_proxy_rule + tencentcloud_teo_host_certificate + tencentcloud_teo_default_certificate */ package tencentcloud @@ -948,6 +964,8 @@ func Provider() terraform.ResourceProvider { "tencentcloud_ssm_secret_versions": dataSourceTencentCloudSsmSecretVersions(), "tencentcloud_cdh_instances": dataSourceTencentCloudCdhInstances(), "tencentcloud_dayu_eip": dataSourceTencentCloudDayuEip(), + "tencentcloud_teo_zone_ddos_policy": dataSourceTencentCloudTeoZoneDdosPolicy(), + "tencentcloud_teo_zone_available_plans": dataSourceTencentCloudTeoZoneAvailablePlans(), }, ResourcesMap: map[string]*schema.Resource{ @@ -1185,6 +1203,19 @@ func Provider() terraform.ResourceProvider { "tencentcloud_tem_log_config": resourceTencentCloudTemLogConfig(), "tencentcloud_tem_scale_rule": resourceTencentCloudTemScaleRule(), "tencentcloud_tem_gateway": resourceTencentCloudTemGateway(), + "tencentcloud_teo_zone": resourceTencentCloudTeoZone(), + "tencentcloud_teo_zone_setting": resourceTencentCloudTeoZoneSetting(), + "tencentcloud_teo_dns_record": resourceTencentCloudTeoDnsRecord(), + "tencentcloud_teo_dns_sec": resourceTencentCloudTeoDnsSec(), + "tencentcloud_teo_load_balancing": resourceTencentCloudTeoLoadBalancing(), + "tencentcloud_teo_origin_group": resourceTencentCloudTeoOriginGroup(), + "tencentcloud_teo_rule_engine": resourceTencentCloudTeoRuleEngine(), + "tencentcloud_teo_application_proxy": resourceTencentCloudTeoApplicationProxy(), + "tencentcloud_teo_application_proxy_rule": resourceTencentCloudTeoApplicationProxyRule(), + "tencentcloud_teo_security_policy": resourceTencentCloudTeoSecurityPolicy(), + "tencentcloud_teo_host_certificate": resourceTencentCloudTeoHostCertificate(), + "tencentcloud_teo_default_certificate": resourceTencentCloudTeoDefaultCertificate(), + "tencentcloud_teo_ddos_policy": resourceTencentCloudTeoDdosPolicy(), }, ConfigureFunc: providerConfigure, diff --git a/tencentcloud/resource_tc_mysql_instance.go b/tencentcloud/resource_tc_mysql_instance.go index a102c311eb..67cf1606e2 100644 --- a/tencentcloud/resource_tc_mysql_instance.go +++ b/tencentcloud/resource_tc_mysql_instance.go @@ -654,6 +654,15 @@ func resourceTencentCloudMysqlInstanceCreate(d *schema.ResourceData, meta interf mysqlID := d.Id() + if tags := helper.GetTags(d, "tags"); len(tags) > 0 { + tcClient := meta.(*TencentCloudClient).apiV3Conn + tagService := &TagService{client: tcClient} + resourceName := BuildTagResourceName("cdb", "instanceId", tcClient.Region, d.Id()) + if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil { + return err + } + } + err := resource.Retry(7*readRetryTimeout, func() *resource.RetryError { mysqlInfo, err := mysqlService.DescribeDBInstanceById(ctx, mysqlID) if err != nil { @@ -767,15 +776,6 @@ func resourceTencentCloudMysqlInstanceCreate(d *schema.ResourceData, meta interf } } - if tags := helper.GetTags(d, "tags"); len(tags) > 0 { - tcClient := meta.(*TencentCloudClient).apiV3Conn - tagService := &TagService{client: tcClient} - resourceName := BuildTagResourceName("cdb", "instanceId", tcClient.Region, d.Id()) - if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil { - return err - } - } - return resourceTencentCloudMysqlInstanceRead(d, meta) } diff --git a/tencentcloud/resource_tc_teo_application_proxy.go b/tencentcloud/resource_tc_teo_application_proxy.go new file mode 100644 index 0000000000..69454162e9 --- /dev/null +++ b/tencentcloud/resource_tc_teo_application_proxy.go @@ -0,0 +1,376 @@ +/* +Provides a resource to create a teo application_proxy + +Example Usage + +```hcl +resource "tencentcloud_teo_application_proxy" "application_proxy" { + zone_id = tencentcloud_teo_zone.zone.id + zone_name = "sfurnace.work" + + accelerate_type = 1 + security_type = 1 + plat_type = "domain" + proxy_name = "www.sfurnace.work" + proxy_type = "hostname" + session_persist_time = 2400 +} + +``` +Import + +teo application_proxy can be imported using the id, e.g. +``` +$ terraform import tencentcloud_teo_application_proxy.application_proxy zoneId#proxyId +``` +*/ +package tencentcloud + +import ( + "context" + "fmt" + "log" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + teo "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220106" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func resourceTencentCloudTeoApplicationProxy() *schema.Resource { + return &schema.Resource{ + Read: resourceTencentCloudTeoApplicationProxyRead, + Create: resourceTencentCloudTeoApplicationProxyCreate, + Update: resourceTencentCloudTeoApplicationProxyUpdate, + Delete: resourceTencentCloudTeoApplicationProxyDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ + "zone_id": { + Type: schema.TypeString, + Required: true, + Description: "Site ID.", + }, + + "zone_name": { + Type: schema.TypeString, + Required: true, + Description: "Site name.", + }, + + "proxy_name": { + Type: schema.TypeString, + Required: true, + Description: "Layer-4 proxy name.", + }, + + "plat_type": { + Type: schema.TypeString, + Required: true, + Description: "Scheduling mode.- ip: Anycast IP.- domain: CNAME.", + }, + + "security_type": { + Type: schema.TypeInt, + Required: true, + Description: "- 0: Disable security protection.- 1: Enable security protection.", + }, + + "accelerate_type": { + Type: schema.TypeInt, + Required: true, + Description: "- 0: Disable acceleration.- 1: Enable acceleration.", + }, + + "session_persist_time": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "Session persistence duration. Value range: 30-3600 (in seconds).", + }, + + "proxy_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "Specifies how a layer-4 proxy is created.- hostname: Subdomain name.- instance: Instance.", + }, + + "proxy_id": { + Type: schema.TypeString, + Computed: true, + Description: "Proxy ID.", + }, + + "schedule_value": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Computed: true, + Description: "Scheduling information.", + }, + + "update_time": { + Type: schema.TypeString, + Computed: true, + Description: "Last modification date.", + }, + + "host_id": { + Type: schema.TypeString, + Computed: true, + Description: "ID of the layer-7 domain name.", + }, + }, + } +} + +func resourceTencentCloudTeoApplicationProxyCreate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_application_proxy.create")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + + var ( + request = teo.NewCreateApplicationProxyRequest() + response *teo.CreateApplicationProxyResponse + zoneId string + proxyId string + ) + + request.ForwardClientIp = helper.String("") + request.SessionPersist = helper.Bool(true) + + if v, ok := d.GetOk("zone_id"); ok { + zoneId = v.(string) + request.ZoneId = helper.String(v.(string)) + } + + if v, ok := d.GetOk("zone_name"); ok { + request.ZoneName = helper.String(v.(string)) + } + + if v, ok := d.GetOk("proxy_name"); ok { + request.ProxyName = helper.String(v.(string)) + } + + if v, ok := d.GetOk("plat_type"); ok { + request.PlatType = helper.String(v.(string)) + } + + if v, ok := d.GetOk("security_type"); ok { + request.SecurityType = helper.IntInt64(v.(int)) + } + + if v, ok := d.GetOk("accelerate_type"); ok { + request.AccelerateType = helper.IntInt64(v.(int)) + } + + if v, ok := d.GetOk("session_persist_time"); ok { + request.SessionPersistTime = helper.IntUint64(v.(int)) + } + + if v, ok := d.GetOk("proxy_type"); ok { + request.ProxyType = helper.String(v.(string)) + } + + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseTeoClient().CreateApplicationProxy(request) + if e != nil { + return retryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + response = result + return nil + }) + + if err != nil { + log.Printf("[CRITAL]%s create teo applicationProxy failed, reason:%+v", logId, err) + return err + } + + proxyId = *response.Response.ProxyId + + d.SetId(zoneId + FILED_SP + proxyId) + return resourceTencentCloudTeoApplicationProxyRead(d, meta) +} + +func resourceTencentCloudTeoApplicationProxyRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_application_proxy.read")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + service := TeoService{client: meta.(*TencentCloudClient).apiV3Conn} + + idSplit := strings.Split(d.Id(), FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + zoneId := idSplit[0] + proxyId := idSplit[1] + + applicationProxy, err := service.DescribeTeoApplicationProxy(ctx, zoneId, proxyId) + + if err != nil { + return err + } + + if applicationProxy == nil { + d.SetId("") + return fmt.Errorf("resource `applicationProxy` %s does not exist", proxyId) + } + + if applicationProxy.ZoneId != nil { + _ = d.Set("zone_id", applicationProxy.ZoneId) + } + + if applicationProxy.ZoneName != nil { + _ = d.Set("zone_name", applicationProxy.ZoneName) + } + + if applicationProxy.ProxyName != nil { + _ = d.Set("proxy_name", applicationProxy.ProxyName) + } + + if applicationProxy.PlatType != nil { + _ = d.Set("plat_type", applicationProxy.PlatType) + } + + if applicationProxy.SecurityType != nil { + _ = d.Set("security_type", applicationProxy.SecurityType) + } + + if applicationProxy.AccelerateType != nil { + _ = d.Set("accelerate_type", applicationProxy.AccelerateType) + } + + if applicationProxy.SessionPersistTime != nil { + _ = d.Set("session_persist_time", applicationProxy.SessionPersistTime) + } + + if applicationProxy.ProxyType != nil { + _ = d.Set("proxy_type", applicationProxy.ProxyType) + } + + if applicationProxy.ProxyId != nil { + _ = d.Set("proxy_id", applicationProxy.ProxyId) + } + + if applicationProxy.ScheduleValue != nil { + _ = d.Set("schedule_value", applicationProxy.ScheduleValue) + } + + if applicationProxy.UpdateTime != nil { + _ = d.Set("update_time", applicationProxy.UpdateTime) + } + + if applicationProxy.HostId != nil { + _ = d.Set("host_id", applicationProxy.HostId) + } + + return nil +} + +func resourceTencentCloudTeoApplicationProxyUpdate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_application_proxy.update")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + + request := teo.NewModifyApplicationProxyRequest() + + idSplit := strings.Split(d.Id(), FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + zoneId := idSplit[0] + proxyId := idSplit[1] + + request.ZoneId = &zoneId + request.ProxyId = &proxyId + request.ForwardClientIp = helper.String("") + request.SessionPersist = helper.Bool(true) + + if v, ok := d.GetOk("proxy_name"); ok { + request.ProxyName = helper.String(v.(string)) + } + + if d.HasChange("zone_id") { + return fmt.Errorf("`zone_id` do not support change now.") + } + + if d.HasChange("zone_name") { + return fmt.Errorf("`zone_name` do not support change now.") + } + + if d.HasChange("plat_type") { + return fmt.Errorf("`plat_type` do not support change now.") + } + + if d.HasChange("security_type") { + return fmt.Errorf("`security_type` do not support change now.") + } + + if d.HasChange("accelerate_type") { + return fmt.Errorf("`accelerate_type` do not support change now.") + } + + if d.HasChange("session_persist_time") { + if v, ok := d.GetOk("session_persist_time"); ok { + request.SessionPersistTime = helper.IntUint64(v.(int)) + } + } + + if d.HasChange("proxy_type") { + if v, ok := d.GetOk("proxy_type"); ok { + request.ProxyType = helper.String(v.(string)) + } + } + + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseTeoClient().ModifyApplicationProxy(request) + if e != nil { + return retryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + return nil + }) + + if err != nil { + return err + } + + return resourceTencentCloudTeoApplicationProxyRead(d, meta) +} + +func resourceTencentCloudTeoApplicationProxyDelete(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_application_proxy.delete")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + service := TeoService{client: meta.(*TencentCloudClient).apiV3Conn} + + idSplit := strings.Split(d.Id(), FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + zoneId := idSplit[0] + proxyId := idSplit[1] + + if err := service.DeleteTeoApplicationProxyById(ctx, zoneId, proxyId); err != nil { + return err + } + + return nil +} diff --git a/tencentcloud/resource_tc_teo_application_proxy_rule.go b/tencentcloud/resource_tc_teo_application_proxy_rule.go new file mode 100644 index 0000000000..ae6ca3f467 --- /dev/null +++ b/tencentcloud/resource_tc_teo_application_proxy_rule.go @@ -0,0 +1,364 @@ +/* +Provides a resource to create a teo application_proxy_rule + +Example Usage + +```hcl +resource "tencentcloud_teo_application_proxy_rule" "application_proxy_rule" { + zone_id = tencentcloud_teo_zone.zone.id + proxy_id = tencentcloud_teo_application_proxy.application_proxy_rule.proxy_id + + forward_client_ip = "TOA" + origin_type = "custom" + origin_value = [ + "1.1.1.1:80", + ] + port = [ + "80", + ] + proto = "TCP" + session_persist = false +} + +``` +Import + +teo application_proxy_rule can be imported using the id, e.g. +``` +$ terraform import tencentcloud_teo_application_proxy_rule.application_proxy_rule zoneId#proxyId#ruleId +``` +*/ +package tencentcloud + +import ( + "context" + "fmt" + "log" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + teo "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220106" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func resourceTencentCloudTeoApplicationProxyRule() *schema.Resource { + return &schema.Resource{ + Read: resourceTencentCloudTeoApplicationProxyRuleRead, + Create: resourceTencentCloudTeoApplicationProxyRuleCreate, + Update: resourceTencentCloudTeoApplicationProxyRuleUpdate, + Delete: resourceTencentCloudTeoApplicationProxyRuleDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ + "zone_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Site ID.", + }, + + "proxy_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Proxy ID.", + }, + + "rule_id": { + Type: schema.TypeString, + Computed: true, + Description: "Rule ID.", + }, + + "proto": { + Type: schema.TypeString, + Required: true, + Description: "Protocol. Valid values: `TCP`, `UDP`.", + }, + + "port": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Required: true, + Description: "Valid values:- port number: `80` means port 80.- port range: `81-90` means port range 81-90.", + }, + + "origin_type": { + Type: schema.TypeString, + Required: true, + Description: "Origin server type.- custom: Specified origins.- origins: An origin group.- load_balancing: A load balancer.", + }, + + "origin_value": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Required: true, + Description: "Origin server information.When OriginType is custom, this field value indicates multiple origin servers in either of the following formats:- IP:Port- Domain name:Port.When OriginType is origins, it indicates the origin group ID.", + }, + + "forward_client_ip": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "Passes the client IP.When Proto is TCP, valid values:- TOA: Pass the client IP via TOA.- PPV1: Pass the client IP via Proxy Protocol V1.- PPV2: Pass the client IP via Proxy Protocol V2.- OFF: Do not pass the client IP.When Proto=UDP, valid values:- PPV2: Pass the client IP via Proxy Protocol V2.- OFF: Do not pass the client IP.", + }, + + "session_persist": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + Description: "Specifies whether to enable session persistence.", + }, + }, + } +} + +func resourceTencentCloudTeoApplicationProxyRuleCreate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_application_proxy_rule.create")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + + var ( + request = teo.NewCreateApplicationProxyRuleRequest() + response *teo.CreateApplicationProxyRuleResponse + zoneId string + proxyId string + ruleId string + ) + + if v, ok := d.GetOk("zone_id"); ok { + zoneId = v.(string) + request.ZoneId = helper.String(v.(string)) + } + + if v, ok := d.GetOk("proxy_id"); ok { + proxyId = v.(string) + request.ProxyId = helper.String(v.(string)) + } + + if v, ok := d.GetOk("proto"); ok { + request.Proto = helper.String(v.(string)) + } + + if v, ok := d.GetOk("port"); ok { + portSet := v.(*schema.Set).List() + for i := range portSet { + port := portSet[i].(string) + request.Port = append(request.Port, &port) + } + } + + if v, ok := d.GetOk("origin_type"); ok { + request.OriginType = helper.String(v.(string)) + } + + if v, ok := d.GetOk("origin_value"); ok { + originValueSet := v.(*schema.Set).List() + for i := range originValueSet { + originValue := originValueSet[i].(string) + request.OriginValue = append(request.OriginValue, &originValue) + } + } + + if v, ok := d.GetOk("forward_client_ip"); ok { + request.ForwardClientIp = helper.String(v.(string)) + } + + if v, ok := d.GetOk("session_persist"); ok { + request.SessionPersist = helper.Bool(v.(bool)) + } + + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseTeoClient().CreateApplicationProxyRule(request) + if e != nil { + return retryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + response = result + return nil + }) + + if err != nil { + log.Printf("[CRITAL]%s create teo applicationProxyRule failed, reason:%+v", logId, err) + return err + } + + ruleId = *response.Response.RuleId + + d.SetId(zoneId + FILED_SP + proxyId + FILED_SP + ruleId) + return resourceTencentCloudTeoApplicationProxyRuleRead(d, meta) +} + +func resourceTencentCloudTeoApplicationProxyRuleRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_application_proxy_rule.read")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + service := TeoService{client: meta.(*TencentCloudClient).apiV3Conn} + + idSplit := strings.Split(d.Id(), FILED_SP) + if len(idSplit) != 3 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + zoneId := idSplit[0] + proxyId := idSplit[1] + ruleId := idSplit[2] + + applicationProxyRule, err := service.DescribeTeoApplicationProxyRule(ctx, zoneId, proxyId, ruleId) + + if err != nil { + return err + } + + if applicationProxyRule == nil { + d.SetId("") + return fmt.Errorf("resource `applicationProxyRule` %s does not exist", ruleId) + } + + if applicationProxyRule.RuleId != nil { + _ = d.Set("rule_id", applicationProxyRule.RuleId) + } + + if applicationProxyRule.Proto != nil { + _ = d.Set("proto", applicationProxyRule.Proto) + } + + if applicationProxyRule.Port != nil { + _ = d.Set("port", applicationProxyRule.Port) + } + + if applicationProxyRule.OriginType != nil { + _ = d.Set("origin_type", applicationProxyRule.OriginType) + } + + if applicationProxyRule.OriginValue != nil { + _ = d.Set("origin_value", applicationProxyRule.OriginValue) + } + + if applicationProxyRule.ForwardClientIp != nil { + _ = d.Set("forward_client_ip", applicationProxyRule.ForwardClientIp) + } + + if applicationProxyRule.SessionPersist != nil { + _ = d.Set("session_persist", applicationProxyRule.SessionPersist) + } + + return nil +} + +func resourceTencentCloudTeoApplicationProxyRuleUpdate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_application_proxy_rule.update")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + + request := teo.NewModifyApplicationProxyRuleRequest() + + idSplit := strings.Split(d.Id(), FILED_SP) + if len(idSplit) != 3 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + zoneId := idSplit[0] + proxyId := idSplit[1] + ruleId := idSplit[2] + + request.ZoneId = &zoneId + request.ProxyId = &proxyId + request.RuleId = &ruleId + + if d.HasChange("zone_id") { + return fmt.Errorf("`zone_id` do not support change now.") + } + + if d.HasChange("proxy_id") { + return fmt.Errorf("`proxy_id` do not support change now.") + } + + if v, ok := d.GetOk("proto"); ok { + request.Proto = helper.String(v.(string)) + } + + if v, ok := d.GetOk("port"); ok { + portSet := v.(*schema.Set).List() + for i := range portSet { + port := portSet[i].(string) + request.Port = append(request.Port, &port) + } + } + + if v, ok := d.GetOk("origin_type"); ok { + request.OriginType = helper.String(v.(string)) + } + + if v, ok := d.GetOk("origin_value"); ok { + originValueSet := v.(*schema.Set).List() + for i := range originValueSet { + originValue := originValueSet[i].(string) + request.OriginValue = append(request.OriginValue, &originValue) + } + } + + if d.HasChange("forward_client_ip") { + if v, ok := d.GetOk("forward_client_ip"); ok { + request.ForwardClientIp = helper.String(v.(string)) + } + } + + if d.HasChange("session_persist") { + if v, ok := d.GetOk("session_persist"); ok { + request.SessionPersist = helper.Bool(v.(bool)) + } + } + + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseTeoClient().ModifyApplicationProxyRule(request) + if e != nil { + return retryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + return nil + }) + + if err != nil { + return err + } + + return resourceTencentCloudTeoApplicationProxyRuleRead(d, meta) +} + +func resourceTencentCloudTeoApplicationProxyRuleDelete(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_application_proxy_rule.delete")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + service := TeoService{client: meta.(*TencentCloudClient).apiV3Conn} + + idSplit := strings.Split(d.Id(), FILED_SP) + if len(idSplit) != 3 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + zoneId := idSplit[0] + proxyId := idSplit[1] + ruleId := idSplit[2] + + if err := service.DeleteTeoApplicationProxyRuleById(ctx, zoneId, proxyId, ruleId); err != nil { + return err + } + + return nil +} diff --git a/tencentcloud/resource_tc_teo_application_proxy_rule_test.go b/tencentcloud/resource_tc_teo_application_proxy_rule_test.go new file mode 100644 index 0000000000..21f905db3e --- /dev/null +++ b/tencentcloud/resource_tc_teo_application_proxy_rule_test.go @@ -0,0 +1,49 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" +) + +func TestAccTencentCloudNeedFixTeoApplicationProxyRule_basic(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccTeoApplicationProxyRule, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_teo_application_proxy_rule.application_proxy_rule", "id"), + ), + }, + { + ResourceName: "tencentcloud_teo_application_proxy_rule.application_proxy_rule", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccTeoApplicationProxyRule = ` + +resource "tencentcloud_teo_application_proxy_rule" "application_proxy_rule" { + zone_id = tencentcloud_teo_zone.zone.id + proxy_id = tencentcloud_teo_application_proxy.application_proxy_rule.proxy_id + + forward_client_ip = "TOA" + origin_type = "custom" + origin_value = [ + "1.1.1.1:80", + ] + port = [ + "80", + ] + proto = "TCP" + session_persist = false +} + +` diff --git a/tencentcloud/resource_tc_teo_application_proxy_test.go b/tencentcloud/resource_tc_teo_application_proxy_test.go new file mode 100644 index 0000000000..14ff2b6159 --- /dev/null +++ b/tencentcloud/resource_tc_teo_application_proxy_test.go @@ -0,0 +1,45 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" +) + +func TestAccTencentCloudNeedFixTeoApplicationProxy_basic(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccTeoApplicationProxy, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_teo_application_proxy.application_proxy", "id"), + ), + }, + { + ResourceName: "tencentcloud_teo_application_proxy.application_proxy", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccTeoApplicationProxy = ` + +resource "tencentcloud_teo_application_proxy" "application_proxy" { + zone_id = tencentcloud_teo_zone.zone.id + zone_name = "sfurnace.work" + + accelerate_type = 1 + security_type = 1 + plat_type = "domain" + proxy_name = "www.sfurnace.work" + proxy_type = "hostname" + session_persist_time = 2400 +} + +` diff --git a/tencentcloud/resource_tc_teo_ddos_policy.go b/tencentcloud/resource_tc_teo_ddos_policy.go new file mode 100644 index 0000000000..52f357bbcf --- /dev/null +++ b/tencentcloud/resource_tc_teo_ddos_policy.go @@ -0,0 +1,1346 @@ +/* +Provides a resource to create a teo ddosPolicy + +Example Usage + +```hcl +resource "tencentcloud_teo_ddos_policy" "ddosPolicy" { + zone_id = "" + policy_id = "" + ddos_rule { + switch = "" + udp_shard_open = "" + ddos_status_info { + ply_level = "" + } + ddos_geo_ip { + region_id = "" + switch = "" + } + ddos_allow_block { + switch = "" + user_allow_block_ip { + ip = "" + mask = "" + type = "" + ip2 = "" + mask2 = "" + } + } + ddos_anti_ply { + drop_tcp = "" + drop_udp = "" + drop_icmp = "" + drop_other = "" + source_create_limit = "" + source_connect_limit = "" + destination_create_limit = "" + destination_connect_limit = "" + abnormal_connect_num = "" + abnormal_syn_ratio = "" + abnormal_syn_num = "" + connect_timeout = "" + empty_connect_protect = "" + udp_shard = "" + } + ddos_packet_filter { + switch = "" + packet_filter { + action = "" + protocol = "" + dport_start = "" + dport_end = "" + packet_min = "" + packet_max = "" + sport_start = "" + sport_end = "" + match_type = "" + is_not = "" + offset = "" + depth = "" + match_begin = "" + str = "" + match_type2 = "" + is_not2 = "" + offset2 = "" + depth2 = "" + match_begin2 = "" + str2 = "" + match_logic = "" + } + } + ddos_acl { + switch = "" + acl { + dport_end = "" + dport_start = "" + sport_end = "" + sport_start = "" + protocol = "" + action = "" + default = "" + } + } + + } +} + +``` +Import + +teo ddosPolicy can be imported using the id, e.g. +``` +$ terraform import tencentcloud_teo_ddos_policy.ddosPolicy ddosPolicy_id +``` +*/ +package tencentcloud + +import ( + "context" + "fmt" + "log" + "strconv" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + teo "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220106" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func resourceTencentCloudTeoDdosPolicy() *schema.Resource { + return &schema.Resource{ + Read: resourceTencentCloudTeoDdosPolicyRead, + Create: resourceTencentCloudTeoDdosPolicyCreate, + Update: resourceTencentCloudTeoDdosPolicyUpdate, + Delete: resourceTencentCloudTeoDdosPolicyDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ + "zone_id": { + Type: schema.TypeString, + Required: true, + Description: "Site ID.", + }, + + "policy_id": { + Type: schema.TypeInt, + Required: true, + Description: "Policy ID.", + }, + + "ddos_rule": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Description: "DDoS Configuration of the zone.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "switch": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "DDoS protection switch. Valid values:- on: Enable.- off: Disable.", + }, + "udp_shard_open": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "UDP shard switch. Valid values:- on: Enable.- off: Disable.", + }, + "ddos_status_info": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Description: "DDoS protection level.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ply_level": { + Type: schema.TypeString, + Required: true, + Description: "Policy level. Valid values:- low: loose.- middle: moderate.- high: strict.", + }, + }, + }, + }, + "ddos_geo_ip": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Description: "DDoS Protection by Geo Info.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "region_id": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + Optional: true, + Computed: true, + Description: "Region ID. See details in data source `security_policy_regions`.", + }, + "switch": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "- on: Enable.- off: Disable.", + }, + }, + }, + }, + "ddos_allow_block": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Description: "DDoS black-white list.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "switch": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "- on: Enable. `UserAllowBlockIp` parameter is required.- off: Disable.", + }, + "user_allow_block_ip": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Description: "DDoS black-white list detail.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ip": { + Type: schema.TypeString, + Optional: true, + Description: "Client IP.", + }, + "mask": { + Type: schema.TypeInt, + Optional: true, + Description: "IP Mask.", + }, + "type": { + Type: schema.TypeString, + Required: true, + Description: "Valid values: `block`, `allow`.", + }, + "update_time": { + Type: schema.TypeInt, + Computed: true, + Description: "Last modification date.", + }, + "ip2": { + Type: schema.TypeString, + Optional: true, + Description: "End of the IP address when setting an IP range.", + }, + "mask2": { + Type: schema.TypeInt, + Optional: true, + Description: "IP mask of the end IP address.", + }, + }, + }, + }, + }, + }, + }, + "ddos_anti_ply": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Description: "DDoS protocol and connection protection.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "drop_tcp": { + Type: schema.TypeString, + Required: true, + Description: "Block TCP protocol. Valid values: `on`, `off`.", + }, + "drop_udp": { + Type: schema.TypeString, + Required: true, + Description: "Block UDP protocol. Valid values: `on`, `off`.", + }, + "drop_icmp": { + Type: schema.TypeString, + Required: true, + Description: "Block ICMP protocol. Valid values: `on`, `off`.", + }, + "drop_other": { + Type: schema.TypeString, + Required: true, + Description: "Block other protocols. Valid values: `on`, `off`.", + }, + "source_create_limit": { + Type: schema.TypeInt, + Required: true, + Description: "Limitation of new connection to origin website per second. Valid value range: 0-4294967295.", + }, + "source_connect_limit": { + Type: schema.TypeInt, + Required: true, + Description: "Limitation of connections to origin website. Valid value range: 0-4294967295.", + }, + "destination_create_limit": { + Type: schema.TypeInt, + Required: true, + Description: "Limitation of new connection to dest port per second. Valid value range: 0-4294967295.", + }, + "destination_connect_limit": { + Type: schema.TypeInt, + Required: true, + Description: "Limitation of connections to dest port. Valid value range: 0-4294967295.", + }, + "abnormal_connect_num": { + Type: schema.TypeInt, + Required: true, + Description: "Abnormal connections threshold. Valid value range: 0-4294967295.", + }, + "abnormal_syn_ratio": { + Type: schema.TypeInt, + Required: true, + Description: "Abnormal syn packet ratio threshold. Valid value range: 0-100.", + }, + "abnormal_syn_num": { + Type: schema.TypeInt, + Required: true, + Description: "Abnormal syn packet number threshold. Valid value range: 0-65535.", + }, + "connect_timeout": { + Type: schema.TypeInt, + Required: true, + Description: "Connection timeout detection per second. Valid value range: 0-65535.", + }, + "empty_connect_protect": { + Type: schema.TypeString, + Required: true, + Description: "Empty connection protection switch. Valid values: `on`, `off`.", + }, + "udp_shard": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "UDP shard protection switch. Valid values: `on`, `off`.", + }, + }, + }, + }, + "ddos_packet_filter": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Description: "DDoS feature filtering configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "switch": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "- on: Enable. `ModifyDDoSPolicy` parameter is required.- off: Disable.", + }, + "packet_filter": { + Type: schema.TypeList, + Optional: true, + Description: "DDoS feature filtering configuration detail.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "action": { + Type: schema.TypeString, + Optional: true, + Description: "Action to take. Valid values: `drop`, `transmit`, `drop_block`, `forward`.", + }, + "protocol": { + Type: schema.TypeString, + Optional: true, + Description: "Valid value: `tcp`, `udp`, `icmp`, `all`.", + }, + "dport_start": { + Type: schema.TypeInt, + Optional: true, + Description: "Start of the dest port range. Valid value range: 0-65535.", + }, + "dport_end": { + Type: schema.TypeInt, + Optional: true, + Description: "End of the dest port range. Valid value range: 0-65535.", + }, + "packet_min": { + Type: schema.TypeInt, + Optional: true, + Description: "Min packet size. Valid value range: 0-1500.", + }, + "packet_max": { + Type: schema.TypeInt, + Optional: true, + Description: "Max packet size. Valid value range: 0-1500.", + }, + "sport_start": { + Type: schema.TypeInt, + Optional: true, + Description: "Start of the source port range. Valid value range: 0-65535.", + }, + "sport_end": { + Type: schema.TypeInt, + Optional: true, + Description: "End of the source port range. Valid value range: 0-65535.", + }, + "match_type": { + Type: schema.TypeString, + Optional: true, + Description: "Match type of feature 1. Valid values:- pcre: regex expression.- sunday: string match.", + }, + "is_not": { + Type: schema.TypeInt, + Optional: true, + Description: "Negate the match condition of feature 1. Valid values:- 0: match.- 1: not match.", + }, + "offset": { + Type: schema.TypeInt, + Optional: true, + Description: "Offset of feature 1. Valid value range: 1-1500.", + }, + "depth": { + Type: schema.TypeInt, + Optional: true, + Description: "Packet character depth to check of feature 1. Valid value range: 1-1500.", + }, + "match_begin": { + Type: schema.TypeString, + Optional: true, + Description: "Packet layer for matching begin of feature 1. Valid values:- begin_l5: matching from packet payload.- begin_l4: matching from TCP/UDP header.- begin_l3: matching from IP header.", + }, + "str": { + Type: schema.TypeString, + Optional: true, + Description: "Regex expression or string to match.", + }, + "match_type2": { + Type: schema.TypeString, + Optional: true, + Description: "Match type of feature 2. Valid values:- pcre: regex expression.- sunday: string match.", + }, + "is_not2": { + Type: schema.TypeInt, + Optional: true, + Description: "Negate the match condition of feature 2. Valid values:- 0: match.- 1: not match.", + }, + "offset2": { + Type: schema.TypeInt, + Optional: true, + Description: "Offset of feature 2. Valid value range: 1-1500.", + }, + "depth2": { + Type: schema.TypeInt, + Optional: true, + Description: "Packet character depth to check of feature 2. Valid value range: 1-1500.", + }, + "match_begin2": { + Type: schema.TypeString, + Optional: true, + Description: "Packet layer for matching begin of feature 2. Valid values:- begin_l5: matching from packet payload.- begin_l4: matching from TCP/UDP header.- begin_l3: matching from IP header.", + }, + "str2": { + Type: schema.TypeString, + Optional: true, + Description: "Regex expression or string to match.", + }, + "match_logic": { + Type: schema.TypeString, + Optional: true, + Description: "Relation between multi features. Valid values: `and`, `or`, `none` (only feature 1 is used).", + }, + }, + }, + }, + }, + }, + }, + "ddos_acl": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Description: "DDoS ACL rule configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "switch": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "- on: Enable. `Acl` parameter is require.- off: Disable.", + }, + "acl": { + Type: schema.TypeList, + Optional: true, + Description: "DDoS ACL rule configuration detail.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "dport_end": { + Type: schema.TypeInt, + Optional: true, + Description: "End of the dest port range. Valid value range: 0-65535.", + }, + "dport_start": { + Type: schema.TypeInt, + Optional: true, + Description: "Start of the dest port range. Valid value range: 0-65535.", + }, + "sport_end": { + Type: schema.TypeInt, + Optional: true, + Description: "End of the source port range. Valid value range: 0-65535.", + }, + "sport_start": { + Type: schema.TypeInt, + Optional: true, + Description: "Start of the source port range. Valid value range: 0-65535.", + }, + "protocol": { + Type: schema.TypeString, + Optional: true, + Description: "Valid values: `tcp`, `udp`, `all`.", + }, + "action": { + Type: schema.TypeString, + Optional: true, + Description: "Action to take. Valid values: `drop`, `transmit`, `forward`.", + }, + "default": { + Type: schema.TypeInt, + Optional: true, + Description: "Whether it is default configuration. Valid value:- 0: custom configuration.- 1: default configuration.", + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + } +} + +func resourceTencentCloudTeoDdosPolicyCreate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_ddos_policy.create")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + + var ( + request = teo.NewModifyDDoSPolicyRequest() + response *teo.ModifyDDoSPolicyResponse + zoneId string + ) + + if v, ok := d.GetOk("zone_id"); ok { + zoneId = v.(string) + request.ZoneId = helper.String(v.(string)) + } + + if v, ok := d.GetOk("policy_id"); ok { + request.PolicyId = helper.IntInt64(v.(int)) + } + + if dMap, ok := helper.InterfacesHeadMap(d, "ddos_rule"); ok { + ddosRule := teo.DdosRule{} + if v, ok := dMap["switch"]; ok { + ddosRule.Switch = helper.String(v.(string)) + } + if v, ok := dMap["udp_shard_open"]; ok { + ddosRule.UdpShardOpen = helper.String(v.(string)) + } + if DdosStatusInfoMap, ok := helper.InterfaceToMap(dMap, "ddos_status_info"); ok { + dDoSStatusInfo := teo.DDoSStatusInfo{} + if v, ok := DdosStatusInfoMap["ply_level"]; ok { + dDoSStatusInfo.PlyLevel = helper.String(v.(string)) + } + ddosRule.DdosStatusInfo = &dDoSStatusInfo + } + if DdosGeoIpMap, ok := helper.InterfaceToMap(dMap, "ddos_geo_ip"); ok { + dDoSGeoIp := teo.DDoSGeoIp{} + if v, ok := DdosGeoIpMap["region_id"]; ok { + regionIdSet := v.(*schema.Set).List() + for i := range regionIdSet { + regionId := regionIdSet[i].(int) + dDoSGeoIp.RegionId = append(dDoSGeoIp.RegionId, helper.IntInt64(regionId)) + } + } + if v, ok := DdosGeoIpMap["switch"]; ok { + dDoSGeoIp.Switch = helper.String(v.(string)) + } + ddosRule.DdosGeoIp = &dDoSGeoIp + } + if DdosAllowBlockMap, ok := helper.InterfaceToMap(dMap, "ddos_allow_block"); ok { + ddosAllowBlock := teo.DdosAllowBlock{} + if v, ok := DdosAllowBlockMap["switch"]; ok { + ddosAllowBlock.Switch = helper.String(v.(string)) + } + if v, ok := DdosAllowBlockMap["user_allow_block_ip"]; ok { + for _, item := range v.([]interface{}) { + UserAllowBlockIpMap := item.(map[string]interface{}) + dDoSUserAllowBlockIP := teo.DDoSUserAllowBlockIP{} + if v, ok := UserAllowBlockIpMap["ip"]; ok { + dDoSUserAllowBlockIP.Ip = helper.String(v.(string)) + } + if v, ok := UserAllowBlockIpMap["mask"]; ok { + dDoSUserAllowBlockIP.Mask = helper.IntInt64(v.(int)) + } + if v, ok := UserAllowBlockIpMap["type"]; ok { + dDoSUserAllowBlockIP.Type = helper.String(v.(string)) + } + if v, ok := UserAllowBlockIpMap["ip2"]; ok { + dDoSUserAllowBlockIP.Ip2 = helper.String(v.(string)) + } + if v, ok := UserAllowBlockIpMap["mask2"]; ok { + dDoSUserAllowBlockIP.Mask2 = helper.IntInt64(v.(int)) + } + ddosAllowBlock.UserAllowBlockIp = append(ddosAllowBlock.UserAllowBlockIp, &dDoSUserAllowBlockIP) + } + } + ddosRule.DdosAllowBlock = &ddosAllowBlock + } + if DdosAntiPlyMap, ok := helper.InterfaceToMap(dMap, "ddos_anti_ply"); ok { + dDoSAntiPly := teo.DDoSAntiPly{} + if v, ok := DdosAntiPlyMap["drop_tcp"]; ok { + dDoSAntiPly.DropTcp = helper.String(v.(string)) + } + if v, ok := DdosAntiPlyMap["drop_udp"]; ok { + dDoSAntiPly.DropUdp = helper.String(v.(string)) + } + if v, ok := DdosAntiPlyMap["drop_icmp"]; ok { + dDoSAntiPly.DropIcmp = helper.String(v.(string)) + } + if v, ok := DdosAntiPlyMap["drop_other"]; ok { + dDoSAntiPly.DropOther = helper.String(v.(string)) + } + if v, ok := DdosAntiPlyMap["source_create_limit"]; ok { + dDoSAntiPly.SourceCreateLimit = helper.IntInt64(v.(int)) + } + if v, ok := DdosAntiPlyMap["source_connect_limit"]; ok { + dDoSAntiPly.SourceConnectLimit = helper.IntInt64(v.(int)) + } + if v, ok := DdosAntiPlyMap["destination_create_limit"]; ok { + dDoSAntiPly.DestinationCreateLimit = helper.IntInt64(v.(int)) + } + if v, ok := DdosAntiPlyMap["destination_connect_limit"]; ok { + dDoSAntiPly.DestinationConnectLimit = helper.IntInt64(v.(int)) + } + if v, ok := DdosAntiPlyMap["abnormal_connect_num"]; ok { + dDoSAntiPly.AbnormalConnectNum = helper.IntInt64(v.(int)) + } + if v, ok := DdosAntiPlyMap["abnormal_syn_ratio"]; ok { + dDoSAntiPly.AbnormalSynRatio = helper.IntInt64(v.(int)) + } + if v, ok := DdosAntiPlyMap["abnormal_syn_num"]; ok { + dDoSAntiPly.AbnormalSynNum = helper.IntInt64(v.(int)) + } + if v, ok := DdosAntiPlyMap["connect_timeout"]; ok { + dDoSAntiPly.ConnectTimeout = helper.IntInt64(v.(int)) + } + if v, ok := DdosAntiPlyMap["empty_connect_protect"]; ok { + dDoSAntiPly.EmptyConnectProtect = helper.String(v.(string)) + } + if v, ok := DdosAntiPlyMap["udp_shard"]; ok { + dDoSAntiPly.UdpShard = helper.String(v.(string)) + } + ddosRule.DdosAntiPly = &dDoSAntiPly + } + if DdosPacketFilterMap, ok := helper.InterfaceToMap(dMap, "ddos_packet_filter"); ok { + ddosPacketFilter := teo.DdosPacketFilter{} + if v, ok := DdosPacketFilterMap["switch"]; ok { + ddosPacketFilter.Switch = helper.String(v.(string)) + } + if v, ok := DdosPacketFilterMap["packet_filter"]; ok { + for _, item := range v.([]interface{}) { + PacketFilterMap := item.(map[string]interface{}) + dDoSFeaturesFilter := teo.DDoSFeaturesFilter{} + if v, ok := PacketFilterMap["action"]; ok { + dDoSFeaturesFilter.Action = helper.String(v.(string)) + } + if v, ok := PacketFilterMap["protocol"]; ok { + dDoSFeaturesFilter.Protocol = helper.String(v.(string)) + } + if v, ok := PacketFilterMap["dport_start"]; ok { + dDoSFeaturesFilter.DportStart = helper.IntInt64(v.(int)) + } + if v, ok := PacketFilterMap["dport_end"]; ok { + dDoSFeaturesFilter.DportEnd = helper.IntInt64(v.(int)) + } + if v, ok := PacketFilterMap["packet_min"]; ok { + dDoSFeaturesFilter.PacketMin = helper.IntInt64(v.(int)) + } + if v, ok := PacketFilterMap["packet_max"]; ok { + dDoSFeaturesFilter.PacketMax = helper.IntInt64(v.(int)) + } + if v, ok := PacketFilterMap["sport_start"]; ok { + dDoSFeaturesFilter.SportStart = helper.IntInt64(v.(int)) + } + if v, ok := PacketFilterMap["sport_end"]; ok { + dDoSFeaturesFilter.SportEnd = helper.IntInt64(v.(int)) + } + if v, ok := PacketFilterMap["match_type"]; ok { + dDoSFeaturesFilter.MatchType = helper.String(v.(string)) + } + if v, ok := PacketFilterMap["is_not"]; ok { + dDoSFeaturesFilter.IsNot = helper.IntInt64(v.(int)) + } + if v, ok := PacketFilterMap["offset"]; ok { + dDoSFeaturesFilter.Offset = helper.IntInt64(v.(int)) + } + if v, ok := PacketFilterMap["depth"]; ok { + dDoSFeaturesFilter.Depth = helper.IntInt64(v.(int)) + } + if v, ok := PacketFilterMap["match_begin"]; ok { + dDoSFeaturesFilter.MatchBegin = helper.String(v.(string)) + } + if v, ok := PacketFilterMap["str"]; ok { + dDoSFeaturesFilter.Str = helper.String(v.(string)) + } + if v, ok := PacketFilterMap["match_type2"]; ok { + dDoSFeaturesFilter.MatchType2 = helper.String(v.(string)) + } + if v, ok := PacketFilterMap["is_not2"]; ok { + dDoSFeaturesFilter.IsNot2 = helper.IntInt64(v.(int)) + } + if v, ok := PacketFilterMap["offset2"]; ok { + dDoSFeaturesFilter.Offset2 = helper.IntInt64(v.(int)) + } + if v, ok := PacketFilterMap["depth2"]; ok { + dDoSFeaturesFilter.Depth2 = helper.IntInt64(v.(int)) + } + if v, ok := PacketFilterMap["match_begin2"]; ok { + dDoSFeaturesFilter.MatchBegin2 = helper.String(v.(string)) + } + if v, ok := PacketFilterMap["str2"]; ok { + dDoSFeaturesFilter.Str2 = helper.String(v.(string)) + } + if v, ok := PacketFilterMap["match_logic"]; ok { + dDoSFeaturesFilter.MatchLogic = helper.String(v.(string)) + } + ddosPacketFilter.PacketFilter = append(ddosPacketFilter.PacketFilter, &dDoSFeaturesFilter) + } + } + ddosRule.DdosPacketFilter = &ddosPacketFilter + } + if DdosAclMap, ok := helper.InterfaceToMap(dMap, "ddos_acl"); ok { + ddosAcls := teo.DdosAcls{} + if v, ok := DdosAclMap["switch"]; ok { + ddosAcls.Switch = helper.String(v.(string)) + } + if v, ok := DdosAclMap["acl"]; ok { + for _, item := range v.([]interface{}) { + AclMap := item.(map[string]interface{}) + dDoSAcl := teo.DDoSAcl{} + if v, ok := AclMap["dport_end"]; ok { + dDoSAcl.DportEnd = helper.IntInt64(v.(int)) + } + if v, ok := AclMap["dport_start"]; ok { + dDoSAcl.DportStart = helper.IntInt64(v.(int)) + } + if v, ok := AclMap["sport_end"]; ok { + dDoSAcl.SportEnd = helper.IntInt64(v.(int)) + } + if v, ok := AclMap["sport_start"]; ok { + dDoSAcl.SportStart = helper.IntInt64(v.(int)) + } + if v, ok := AclMap["protocol"]; ok { + dDoSAcl.Protocol = helper.String(v.(string)) + } + if v, ok := AclMap["action"]; ok { + dDoSAcl.Action = helper.String(v.(string)) + } + if v, ok := AclMap["default"]; ok { + dDoSAcl.Default = helper.IntInt64(v.(int)) + } + ddosAcls.Acl = append(ddosAcls.Acl, &dDoSAcl) + } + } + ddosRule.DdosAcl = &ddosAcls + } + + request.DdosRule = &ddosRule + } + + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseTeoClient().ModifyDDoSPolicy(request) + if e != nil { + return retryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + response = result + return nil + }) + + if err != nil { + log.Printf("[CRITAL]%s create teo ddosPolicy failed, reason:%+v", logId, err) + return err + } + + ddosPolicyId := strconv.FormatInt(*response.Response.PolicyId, 10) + + d.SetId(zoneId + FILED_SP + ddosPolicyId) + return resourceTencentCloudTeoDdosPolicyRead(d, meta) +} + +func resourceTencentCloudTeoDdosPolicyRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_ddos_policy.read")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + service := TeoService{client: meta.(*TencentCloudClient).apiV3Conn} + + idSplit := strings.Split(d.Id(), FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + zoneId := idSplit[0] + policyId := idSplit[1] + + ddosPolicy, err := service.DescribeTeoDdosPolicy(ctx, zoneId, policyId) + + if err != nil { + return err + } + + if ddosPolicy == nil { + d.SetId("") + return fmt.Errorf("resource `ddosPolicy` %s does not exist", policyId) + } + + _ = d.Set("zone_id", zoneId) + _ = d.Set("policy_id", policyId) + + if ddosPolicy.DdosRule != nil { + ddosRuleMap := map[string]interface{}{} + if ddosPolicy.DdosRule.Switch != nil { + ddosRuleMap["switch"] = ddosPolicy.DdosRule.Switch + } + if ddosPolicy.DdosRule.UdpShardOpen != nil { + ddosRuleMap["udp_shard_open"] = ddosPolicy.DdosRule.UdpShardOpen + } + if ddosPolicy.DdosRule.DdosStatusInfo != nil { + ddosStatusInfoMap := map[string]interface{}{} + if ddosPolicy.DdosRule.DdosStatusInfo.PlyLevel != nil { + ddosStatusInfoMap["ply_level"] = ddosPolicy.DdosRule.DdosStatusInfo.PlyLevel + } + + ddosRuleMap["ddos_status_info"] = []interface{}{ddosStatusInfoMap} + } + if ddosPolicy.DdosRule.DdosGeoIp != nil { + ddosGeoIpMap := map[string]interface{}{} + if ddosPolicy.DdosRule.DdosGeoIp.RegionId != nil { + ddosGeoIpMap["region_id"] = ddosPolicy.DdosRule.DdosGeoIp.RegionId + } + if ddosPolicy.DdosRule.DdosGeoIp.Switch != nil { + ddosGeoIpMap["switch"] = ddosPolicy.DdosRule.DdosGeoIp.Switch + } + + ddosRuleMap["ddos_geo_ip"] = []interface{}{ddosGeoIpMap} + } + if ddosPolicy.DdosRule.DdosAllowBlock != nil { + ddosAllowBlockMap := map[string]interface{}{} + if ddosPolicy.DdosRule.DdosAllowBlock.Switch != nil { + ddosAllowBlockMap["switch"] = ddosPolicy.DdosRule.DdosAllowBlock.Switch + } + if ddosPolicy.DdosRule.DdosAllowBlock.UserAllowBlockIp != nil { + userAllowBlockIpList := []interface{}{} + for _, userAllowBlockIp := range ddosPolicy.DdosRule.DdosAllowBlock.UserAllowBlockIp { + userAllowBlockIpMap := map[string]interface{}{} + if userAllowBlockIp.Ip != nil { + userAllowBlockIpMap["ip"] = userAllowBlockIp.Ip + } + if userAllowBlockIp.Mask != nil { + userAllowBlockIpMap["mask"] = userAllowBlockIp.Mask + } + if userAllowBlockIp.Type != nil { + userAllowBlockIpMap["type"] = userAllowBlockIp.Type + } + if userAllowBlockIp.UpdateTime != nil { + userAllowBlockIpMap["update_time"] = userAllowBlockIp.UpdateTime + } + if userAllowBlockIp.Ip2 != nil { + userAllowBlockIpMap["ip2"] = userAllowBlockIp.Ip2 + } + if userAllowBlockIp.Mask2 != nil { + userAllowBlockIpMap["mask2"] = userAllowBlockIp.Mask2 + } + + userAllowBlockIpList = append(userAllowBlockIpList, userAllowBlockIpMap) + } + ddosAllowBlockMap["user_allow_block_ip"] = userAllowBlockIpList + } + + ddosRuleMap["ddos_allow_block"] = []interface{}{ddosAllowBlockMap} + } + if ddosPolicy.DdosRule.DdosAntiPly != nil { + ddosAntiPlyMap := map[string]interface{}{} + if ddosPolicy.DdosRule.DdosAntiPly.DropTcp != nil { + ddosAntiPlyMap["drop_tcp"] = ddosPolicy.DdosRule.DdosAntiPly.DropTcp + } + if ddosPolicy.DdosRule.DdosAntiPly.DropUdp != nil { + ddosAntiPlyMap["drop_udp"] = ddosPolicy.DdosRule.DdosAntiPly.DropUdp + } + if ddosPolicy.DdosRule.DdosAntiPly.DropIcmp != nil { + ddosAntiPlyMap["drop_icmp"] = ddosPolicy.DdosRule.DdosAntiPly.DropIcmp + } + if ddosPolicy.DdosRule.DdosAntiPly.DropOther != nil { + ddosAntiPlyMap["drop_other"] = ddosPolicy.DdosRule.DdosAntiPly.DropOther + } + if ddosPolicy.DdosRule.DdosAntiPly.SourceCreateLimit != nil { + ddosAntiPlyMap["source_create_limit"] = ddosPolicy.DdosRule.DdosAntiPly.SourceCreateLimit + } + if ddosPolicy.DdosRule.DdosAntiPly.SourceConnectLimit != nil { + ddosAntiPlyMap["source_connect_limit"] = ddosPolicy.DdosRule.DdosAntiPly.SourceConnectLimit + } + if ddosPolicy.DdosRule.DdosAntiPly.DestinationCreateLimit != nil { + ddosAntiPlyMap["destination_create_limit"] = ddosPolicy.DdosRule.DdosAntiPly.DestinationCreateLimit + } + if ddosPolicy.DdosRule.DdosAntiPly.DestinationConnectLimit != nil { + ddosAntiPlyMap["destination_connect_limit"] = ddosPolicy.DdosRule.DdosAntiPly.DestinationConnectLimit + } + if ddosPolicy.DdosRule.DdosAntiPly.AbnormalConnectNum != nil { + ddosAntiPlyMap["abnormal_connect_num"] = ddosPolicy.DdosRule.DdosAntiPly.AbnormalConnectNum + } + if ddosPolicy.DdosRule.DdosAntiPly.AbnormalSynRatio != nil { + ddosAntiPlyMap["abnormal_syn_ratio"] = ddosPolicy.DdosRule.DdosAntiPly.AbnormalSynRatio + } + if ddosPolicy.DdosRule.DdosAntiPly.AbnormalSynNum != nil { + ddosAntiPlyMap["abnormal_syn_num"] = ddosPolicy.DdosRule.DdosAntiPly.AbnormalSynNum + } + if ddosPolicy.DdosRule.DdosAntiPly.ConnectTimeout != nil { + ddosAntiPlyMap["connect_timeout"] = ddosPolicy.DdosRule.DdosAntiPly.ConnectTimeout + } + if ddosPolicy.DdosRule.DdosAntiPly.EmptyConnectProtect != nil { + ddosAntiPlyMap["empty_connect_protect"] = ddosPolicy.DdosRule.DdosAntiPly.EmptyConnectProtect + } + if ddosPolicy.DdosRule.DdosAntiPly.UdpShard != nil { + ddosAntiPlyMap["udp_shard"] = ddosPolicy.DdosRule.DdosAntiPly.UdpShard + } + + ddosRuleMap["ddos_anti_ply"] = []interface{}{ddosAntiPlyMap} + } + if ddosPolicy.DdosRule.DdosPacketFilter != nil { + ddosPacketFilterMap := map[string]interface{}{} + if ddosPolicy.DdosRule.DdosPacketFilter.Switch != nil { + ddosPacketFilterMap["switch"] = ddosPolicy.DdosRule.DdosPacketFilter.Switch + } + if ddosPolicy.DdosRule.DdosPacketFilter.PacketFilter != nil { + packetFilterList := []interface{}{} + for _, packetFilter := range ddosPolicy.DdosRule.DdosPacketFilter.PacketFilter { + packetFilterMap := map[string]interface{}{} + if packetFilter.Action != nil { + packetFilterMap["action"] = packetFilter.Action + } + if packetFilter.Protocol != nil { + packetFilterMap["protocol"] = packetFilter.Protocol + } + if packetFilter.DportStart != nil { + packetFilterMap["dport_start"] = packetFilter.DportStart + } + if packetFilter.DportEnd != nil { + packetFilterMap["dport_end"] = packetFilter.DportEnd + } + if packetFilter.PacketMin != nil { + packetFilterMap["packet_min"] = packetFilter.PacketMin + } + if packetFilter.PacketMax != nil { + packetFilterMap["packet_max"] = packetFilter.PacketMax + } + if packetFilter.SportStart != nil { + packetFilterMap["sport_start"] = packetFilter.SportStart + } + if packetFilter.SportEnd != nil { + packetFilterMap["sport_end"] = packetFilter.SportEnd + } + if packetFilter.MatchType != nil { + packetFilterMap["match_type"] = packetFilter.MatchType + } + if packetFilter.IsNot != nil { + packetFilterMap["is_not"] = packetFilter.IsNot + } + if packetFilter.Offset != nil { + packetFilterMap["offset"] = packetFilter.Offset + } + if packetFilter.Depth != nil { + packetFilterMap["depth"] = packetFilter.Depth + } + if packetFilter.MatchBegin != nil { + packetFilterMap["match_begin"] = packetFilter.MatchBegin + } + if packetFilter.Str != nil { + packetFilterMap["str"] = packetFilter.Str + } + if packetFilter.MatchType2 != nil { + packetFilterMap["match_type2"] = packetFilter.MatchType2 + } + if packetFilter.IsNot2 != nil { + packetFilterMap["is_not2"] = packetFilter.IsNot2 + } + if packetFilter.Offset2 != nil { + packetFilterMap["offset2"] = packetFilter.Offset2 + } + if packetFilter.Depth2 != nil { + packetFilterMap["depth2"] = packetFilter.Depth2 + } + if packetFilter.MatchBegin2 != nil { + packetFilterMap["match_begin2"] = packetFilter.MatchBegin2 + } + if packetFilter.Str2 != nil { + packetFilterMap["str2"] = packetFilter.Str2 + } + if packetFilter.MatchLogic != nil { + packetFilterMap["match_logic"] = packetFilter.MatchLogic + } + + packetFilterList = append(packetFilterList, packetFilterMap) + } + ddosPacketFilterMap["packet_filter"] = packetFilterList + } + + ddosRuleMap["ddos_packet_filter"] = []interface{}{ddosPacketFilterMap} + } + if ddosPolicy.DdosRule.DdosAcl != nil { + ddosAclMap := map[string]interface{}{} + if ddosPolicy.DdosRule.DdosAcl.Switch != nil { + ddosAclMap["switch"] = ddosPolicy.DdosRule.DdosAcl.Switch + } + if ddosPolicy.DdosRule.DdosAcl.Acl != nil { + aclList := []interface{}{} + for _, acl := range ddosPolicy.DdosRule.DdosAcl.Acl { + aclMap := map[string]interface{}{} + if acl.DportEnd != nil { + aclMap["dport_end"] = acl.DportEnd + } + if acl.DportStart != nil { + aclMap["dport_start"] = acl.DportStart + } + if acl.SportEnd != nil { + aclMap["sport_end"] = acl.SportEnd + } + if acl.SportStart != nil { + aclMap["sport_start"] = acl.SportStart + } + if acl.Protocol != nil { + aclMap["protocol"] = acl.Protocol + } + if acl.Action != nil { + aclMap["action"] = acl.Action + } + if acl.Default != nil { + aclMap["default"] = acl.Default + } + + aclList = append(aclList, aclMap) + } + ddosAclMap["acl"] = aclList + } + + ddosRuleMap["ddos_acl"] = []interface{}{ddosAclMap} + } + + _ = d.Set("ddos_rule", []interface{}{ddosRuleMap}) + } + + return nil +} + +func resourceTencentCloudTeoDdosPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_ddos_policy.update")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + request := teo.NewModifyDDoSPolicyRequest() + + idSplit := strings.Split(d.Id(), FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + zoneId := idSplit[0] + policyId := idSplit[1] + + policyId64, errRet := strconv.ParseInt(policyId, 10, 64) + if errRet != nil { + return fmt.Errorf("Type conversion failed, [%s] conversion int64 failed\n", policyId) + } + + request.ZoneId = &zoneId + request.PolicyId = &policyId64 + + if d.HasChange("zone_id") { + return fmt.Errorf("`zone_id` do not support change now.") + } + + if d.HasChange("policy_id") { + return fmt.Errorf("`policy_id` do not support change now.") + } + + if d.HasChange("ddos_rule") { + if dMap, ok := helper.InterfacesHeadMap(d, "ddos_rule"); ok { + ddosRule := teo.DdosRule{} + if v, ok := dMap["switch"]; ok { + ddosRule.Switch = helper.String(v.(string)) + } + if v, ok := dMap["udp_shard_open"]; ok { + ddosRule.UdpShardOpen = helper.String(v.(string)) + } + if DdosStatusInfoMap, ok := helper.InterfaceToMap(dMap, "ddos_status_info"); ok { + dDoSStatusInfo := teo.DDoSStatusInfo{} + if v, ok := DdosStatusInfoMap["ply_level"]; ok { + dDoSStatusInfo.PlyLevel = helper.String(v.(string)) + } + ddosRule.DdosStatusInfo = &dDoSStatusInfo + } + if DdosGeoIpMap, ok := helper.InterfaceToMap(dMap, "ddos_geo_ip"); ok { + dDoSGeoIp := teo.DDoSGeoIp{} + if v, ok := DdosGeoIpMap["region_id"]; ok { + regionIdSet := v.(*schema.Set).List() + for i := range regionIdSet { + regionId := regionIdSet[i].(int) + dDoSGeoIp.RegionId = append(dDoSGeoIp.RegionId, helper.IntInt64(regionId)) + } + } + if v, ok := DdosGeoIpMap["switch"]; ok { + dDoSGeoIp.Switch = helper.String(v.(string)) + } + ddosRule.DdosGeoIp = &dDoSGeoIp + } + if DdosAllowBlockMap, ok := helper.InterfaceToMap(dMap, "ddos_allow_block"); ok { + ddosAllowBlock := teo.DdosAllowBlock{} + if v, ok := DdosAllowBlockMap["switch"]; ok { + ddosAllowBlock.Switch = helper.String(v.(string)) + } + if v, ok := DdosAllowBlockMap["user_allow_block_ip"]; ok { + for _, item := range v.([]interface{}) { + UserAllowBlockIpMap := item.(map[string]interface{}) + dDoSUserAllowBlockIP := teo.DDoSUserAllowBlockIP{} + if v, ok := UserAllowBlockIpMap["ip"]; ok { + dDoSUserAllowBlockIP.Ip = helper.String(v.(string)) + } + if v, ok := UserAllowBlockIpMap["mask"]; ok { + dDoSUserAllowBlockIP.Mask = helper.IntInt64(v.(int)) + } + if v, ok := UserAllowBlockIpMap["type"]; ok { + dDoSUserAllowBlockIP.Type = helper.String(v.(string)) + } + if v, ok := UserAllowBlockIpMap["ip2"]; ok { + dDoSUserAllowBlockIP.Ip2 = helper.String(v.(string)) + } + if v, ok := UserAllowBlockIpMap["mask2"]; ok { + dDoSUserAllowBlockIP.Mask2 = helper.IntInt64(v.(int)) + } + ddosAllowBlock.UserAllowBlockIp = append(ddosAllowBlock.UserAllowBlockIp, &dDoSUserAllowBlockIP) + } + } + ddosRule.DdosAllowBlock = &ddosAllowBlock + } + if DdosAntiPlyMap, ok := helper.InterfaceToMap(dMap, "ddos_anti_ply"); ok { + dDoSAntiPly := teo.DDoSAntiPly{} + if v, ok := DdosAntiPlyMap["drop_tcp"]; ok { + dDoSAntiPly.DropTcp = helper.String(v.(string)) + } + if v, ok := DdosAntiPlyMap["drop_udp"]; ok { + dDoSAntiPly.DropUdp = helper.String(v.(string)) + } + if v, ok := DdosAntiPlyMap["drop_icmp"]; ok { + dDoSAntiPly.DropIcmp = helper.String(v.(string)) + } + if v, ok := DdosAntiPlyMap["drop_other"]; ok { + dDoSAntiPly.DropOther = helper.String(v.(string)) + } + if v, ok := DdosAntiPlyMap["source_create_limit"]; ok { + dDoSAntiPly.SourceCreateLimit = helper.IntInt64(v.(int)) + } + if v, ok := DdosAntiPlyMap["source_connect_limit"]; ok { + dDoSAntiPly.SourceConnectLimit = helper.IntInt64(v.(int)) + } + if v, ok := DdosAntiPlyMap["destination_create_limit"]; ok { + dDoSAntiPly.DestinationCreateLimit = helper.IntInt64(v.(int)) + } + if v, ok := DdosAntiPlyMap["destination_connect_limit"]; ok { + dDoSAntiPly.DestinationConnectLimit = helper.IntInt64(v.(int)) + } + if v, ok := DdosAntiPlyMap["abnormal_connect_num"]; ok { + dDoSAntiPly.AbnormalConnectNum = helper.IntInt64(v.(int)) + } + if v, ok := DdosAntiPlyMap["abnormal_syn_ratio"]; ok { + dDoSAntiPly.AbnormalSynRatio = helper.IntInt64(v.(int)) + } + if v, ok := DdosAntiPlyMap["abnormal_syn_num"]; ok { + dDoSAntiPly.AbnormalSynNum = helper.IntInt64(v.(int)) + } + if v, ok := DdosAntiPlyMap["connect_timeout"]; ok { + dDoSAntiPly.ConnectTimeout = helper.IntInt64(v.(int)) + } + if v, ok := DdosAntiPlyMap["empty_connect_protect"]; ok { + dDoSAntiPly.EmptyConnectProtect = helper.String(v.(string)) + } + if v, ok := DdosAntiPlyMap["udp_shard"]; ok { + dDoSAntiPly.UdpShard = helper.String(v.(string)) + } + ddosRule.DdosAntiPly = &dDoSAntiPly + } + if DdosPacketFilterMap, ok := helper.InterfaceToMap(dMap, "ddos_packet_filter"); ok { + ddosPacketFilter := teo.DdosPacketFilter{} + if v, ok := DdosPacketFilterMap["switch"]; ok { + ddosPacketFilter.Switch = helper.String(v.(string)) + } + if v, ok := DdosPacketFilterMap["packet_filter"]; ok { + for _, item := range v.([]interface{}) { + PacketFilterMap := item.(map[string]interface{}) + dDoSFeaturesFilter := teo.DDoSFeaturesFilter{} + if v, ok := PacketFilterMap["action"]; ok { + dDoSFeaturesFilter.Action = helper.String(v.(string)) + } + if v, ok := PacketFilterMap["protocol"]; ok { + dDoSFeaturesFilter.Protocol = helper.String(v.(string)) + } + if v, ok := PacketFilterMap["dport_start"]; ok { + dDoSFeaturesFilter.DportStart = helper.IntInt64(v.(int)) + } + if v, ok := PacketFilterMap["dport_end"]; ok { + dDoSFeaturesFilter.DportEnd = helper.IntInt64(v.(int)) + } + if v, ok := PacketFilterMap["packet_min"]; ok { + dDoSFeaturesFilter.PacketMin = helper.IntInt64(v.(int)) + } + if v, ok := PacketFilterMap["packet_max"]; ok { + dDoSFeaturesFilter.PacketMax = helper.IntInt64(v.(int)) + } + if v, ok := PacketFilterMap["sport_start"]; ok { + dDoSFeaturesFilter.SportStart = helper.IntInt64(v.(int)) + } + if v, ok := PacketFilterMap["sport_end"]; ok { + dDoSFeaturesFilter.SportEnd = helper.IntInt64(v.(int)) + } + if v, ok := PacketFilterMap["match_type"]; ok { + dDoSFeaturesFilter.MatchType = helper.String(v.(string)) + } + if v, ok := PacketFilterMap["is_not"]; ok { + dDoSFeaturesFilter.IsNot = helper.IntInt64(v.(int)) + } + if v, ok := PacketFilterMap["offset"]; ok { + dDoSFeaturesFilter.Offset = helper.IntInt64(v.(int)) + } + if v, ok := PacketFilterMap["depth"]; ok { + dDoSFeaturesFilter.Depth = helper.IntInt64(v.(int)) + } + if v, ok := PacketFilterMap["match_begin"]; ok { + dDoSFeaturesFilter.MatchBegin = helper.String(v.(string)) + } + if v, ok := PacketFilterMap["str"]; ok { + dDoSFeaturesFilter.Str = helper.String(v.(string)) + } + if v, ok := PacketFilterMap["match_type2"]; ok { + dDoSFeaturesFilter.MatchType2 = helper.String(v.(string)) + } + if v, ok := PacketFilterMap["is_not2"]; ok { + dDoSFeaturesFilter.IsNot2 = helper.IntInt64(v.(int)) + } + if v, ok := PacketFilterMap["offset2"]; ok { + dDoSFeaturesFilter.Offset2 = helper.IntInt64(v.(int)) + } + if v, ok := PacketFilterMap["depth2"]; ok { + dDoSFeaturesFilter.Depth2 = helper.IntInt64(v.(int)) + } + if v, ok := PacketFilterMap["match_begin2"]; ok { + dDoSFeaturesFilter.MatchBegin2 = helper.String(v.(string)) + } + if v, ok := PacketFilterMap["str2"]; ok { + dDoSFeaturesFilter.Str2 = helper.String(v.(string)) + } + if v, ok := PacketFilterMap["match_logic"]; ok { + dDoSFeaturesFilter.MatchLogic = helper.String(v.(string)) + } + ddosPacketFilter.PacketFilter = append(ddosPacketFilter.PacketFilter, &dDoSFeaturesFilter) + } + } + ddosRule.DdosPacketFilter = &ddosPacketFilter + } + if DdosAclMap, ok := helper.InterfaceToMap(dMap, "ddos_acl"); ok { + ddosAcls := teo.DdosAcls{} + if v, ok := DdosAclMap["switch"]; ok { + ddosAcls.Switch = helper.String(v.(string)) + } + if v, ok := DdosAclMap["acl"]; ok { + for _, item := range v.([]interface{}) { + AclMap := item.(map[string]interface{}) + dDoSAcl := teo.DDoSAcl{} + if v, ok := AclMap["dport_end"]; ok { + dDoSAcl.DportEnd = helper.IntInt64(v.(int)) + } + if v, ok := AclMap["dport_start"]; ok { + dDoSAcl.DportStart = helper.IntInt64(v.(int)) + } + if v, ok := AclMap["sport_end"]; ok { + dDoSAcl.SportEnd = helper.IntInt64(v.(int)) + } + if v, ok := AclMap["sport_start"]; ok { + dDoSAcl.SportStart = helper.IntInt64(v.(int)) + } + if v, ok := AclMap["protocol"]; ok { + dDoSAcl.Protocol = helper.String(v.(string)) + } + if v, ok := AclMap["action"]; ok { + dDoSAcl.Action = helper.String(v.(string)) + } + if v, ok := AclMap["default"]; ok { + dDoSAcl.Default = helper.IntInt64(v.(int)) + } + ddosAcls.Acl = append(ddosAcls.Acl, &dDoSAcl) + } + } + ddosRule.DdosAcl = &ddosAcls + } + + request.DdosRule = &ddosRule + } + } + + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseTeoClient().ModifyDDoSPolicy(request) + if e != nil { + return retryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + return nil + }) + + if err != nil { + return err + } + + return resourceTencentCloudTeoDdosPolicyRead(d, meta) +} + +func resourceTencentCloudTeoDdosPolicyDelete(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_ddos_policy.delete")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + service := TeoService{client: meta.(*TencentCloudClient).apiV3Conn} + + idSplit := strings.Split(d.Id(), FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + zoneId := idSplit[0] + policyId := idSplit[1] + + if err := service.DeleteTeoDdosPolicyById(ctx, zoneId, policyId); err != nil { + return err + } + + return nil +} diff --git a/tencentcloud/resource_tc_teo_ddos_policy_test.go b/tencentcloud/resource_tc_teo_ddos_policy_test.go new file mode 100644 index 0000000000..e4f2cc7ece --- /dev/null +++ b/tencentcloud/resource_tc_teo_ddos_policy_test.go @@ -0,0 +1,108 @@ +package tencentcloud + +//func TestAccTencentCloudTeoDdosPolicy_basic(t *testing.T) { +// t.Parallel() +// +// resource.Test(t, resource.TestCase{ +// PreCheck: func() { testAccPreCheck(t) }, +// Providers: testAccProviders, +// Steps: []resource.TestStep{ +// { +// Config: testAccTeoDdosPolicy, +// Check: resource.ComposeTestCheckFunc( +// resource.TestCheckResourceAttrSet("tencentcloud_teo_ddos_policy.ddosPolicy", "id"), +// ), +// }, +// { +// ResourceName: "tencentcloud_teo_ddos_policy.ddosPolicy", +// ImportState: true, +// ImportStateVerify: true, +// }, +// }, +// }) +//} + +const testAccTeoDdosPolicy = ` + +resource "tencentcloud_teo_ddos_policy" "ddosPolicy" { + zone_id = "" + policy_id = "" + ddos_rule { + switch = "" + udp_shard_open = "" + ddos_status_info { + ply_level = "" + } + ddos_geo_ip { + region_id = "" + switch = "" + } + ddos_allow_block { + switch = "" + user_allow_block_ip { + ip = "" + mask = "" + type = "" + ip2 = "" + mask2 = "" + } + } + ddos_anti_ply { + drop_tcp = "" + drop_udp = "" + drop_icmp = "" + drop_other = "" + source_create_limit = "" + source_connect_limit = "" + destination_create_limit = "" + destination_connect_limit = "" + abnormal_connect_num = "" + abnormal_syn_ratio = "" + abnormal_syn_num = "" + connect_timeout = "" + empty_connect_protect = "" + udp_shard = "" + } + ddos_packet_filter { + switch = "" + packet_filter { + action = "" + protocol = "" + dport_start = "" + dport_end = "" + packet_min = "" + packet_max = "" + sport_start = "" + sport_end = "" + match_type = "" + is_not = "" + offset = "" + depth = "" + match_begin = "" + str = "" + match_type2 = "" + is_not2 = "" + offset2 = "" + depth2 = "" + match_begin2 = "" + str2 = "" + match_logic = "" + } + } + ddos_acl { + switch = "" + acl { + dport_end = "" + dport_start = "" + sport_end = "" + sport_start = "" + protocol = "" + action = "" + default = "" + } + } + + } +} + +` diff --git a/tencentcloud/resource_tc_teo_default_certificate.go b/tencentcloud/resource_tc_teo_default_certificate.go new file mode 100644 index 0000000000..0c769b3d39 --- /dev/null +++ b/tencentcloud/resource_tc_teo_default_certificate.go @@ -0,0 +1,262 @@ +/* +Provides a resource to create a teo defaultCertificate + +Example Usage + +```hcl +resource "tencentcloud_teo_default_certificate" "default_certificate" { + zone_id = tencentcloud_teo_zone.zone.id + + cert_info { + cert_id = "teo-28i46c1gtmkl" + status = "deployed" + } +} + +``` +Import + +teo default_certificate can be imported using the id, e.g. +``` +$ terraform import tencentcloud_teo_default_certificate.default_certificate zoneId +``` +*/ +package tencentcloud + +import ( + "context" + "fmt" + "log" + + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + teo "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220106" +) + +func resourceTencentCloudTeoDefaultCertificate() *schema.Resource { + return &schema.Resource{ + Read: resourceTencentCloudTeoDefaultCertificateRead, + Create: resourceTencentCloudTeoDefaultCertificateCreate, + Update: resourceTencentCloudTeoDefaultCertificateUpdate, + Delete: resourceTencentCloudTeoDefaultCertificateDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ + "zone_id": { + Type: schema.TypeString, + Required: true, + Description: "Site ID.", + }, + + "cert_info": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Description: "List of default certificates. Note: This field may return null, indicating that no valid value can be obtained.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cert_id": { + Type: schema.TypeString, + Required: true, + Description: "Server certificate ID, which is the ID of the default certificate. If you choose to upload an external certificate for SSL certificate management, a certificate ID will be generated.", + }, + "alias": { + Type: schema.TypeString, + Computed: true, + Description: "Certificate alias. Note: This field may return null, indicating that no valid value can be obtained.", + }, + "type": { + Type: schema.TypeString, + Computed: true, + Description: "Certificate type.- default: Default certificate.- upload: External certificate.- managed: Tencent Cloud managed certificate.Note: This field may return null, indicating that no valid value can be obtained.", + }, + "expire_time": { + Type: schema.TypeString, + Computed: true, + Description: "Time when the certificate expires. Note: This field may return null, indicating that no valid value can be obtained.", + }, + "effective_time": { + Type: schema.TypeString, + Computed: true, + Description: "Time when the certificate takes effect. Note: This field may return null, indicating that no valid value can be obtained.", + }, + "common_name": { + Type: schema.TypeString, + Computed: true, + Description: "Certificate common name. Note: This field may return null, indicating that no valid value can be obtained.", + }, + "subject_alt_name": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Computed: true, + Description: "Domain names added to the SAN certificate. Note: This field may return null, indicating that no valid value can be obtained.", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "Certificate status.- applying: Application in progress.- failed: Application failed.- processing: Deploying certificate.- deployed: Certificate deployed.- disabled: Certificate disabled.Note: This field may return null, indicating that no valid value can be obtained.", + }, + "message": { + Type: schema.TypeString, + Computed: true, + Description: "Returns a message to display failure causes when `Status` is failed.Note: This field may return null, indicating that no valid value can be obtained.", + }, + }, + }, + }, + }, + } +} + +func resourceTencentCloudTeoDefaultCertificateCreate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_default_certificate.create")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + + var ( + zoneId string + ) + + if v, ok := d.GetOk("zone_id"); ok { + zoneId = v.(string) + } + + service := TeoService{client: meta.(*TencentCloudClient).apiV3Conn} + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + err := resource.Retry(60*readRetryTimeout, func() *resource.RetryError { + instance, errRet := service.DescribeTeoDefaultCertificate(ctx, zoneId) + if errRet != nil { + return retryError(errRet, InternalError) + } + if *instance.Status == "deployed" { + return nil + } + if *instance.Status == "disabled" { + return resource.NonRetryableError(fmt.Errorf("defaultCertificate status is %v, operate failed.", *instance.Status)) + } + return resource.RetryableError(fmt.Errorf("defaultCertificate status is %v, retry...", *instance.Status)) + }) + if err != nil { + return err + } + + d.SetId(zoneId) + return resourceTencentCloudTeoDefaultCertificateUpdate(d, meta) +} + +func resourceTencentCloudTeoDefaultCertificateRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_default_certificate.read")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + service := TeoService{client: meta.(*TencentCloudClient).apiV3Conn} + + zoneId := d.Id() + + defaultCertificate, err := service.DescribeTeoDefaultCertificate(ctx, zoneId) + + if err != nil { + return err + } + + if defaultCertificate == nil { + d.SetId("") + return fmt.Errorf("resource `defaultCertificate` %s does not exist", zoneId) + } + + if defaultCertificate != nil { + certInfoMap := map[string]interface{}{} + if defaultCertificate.CertId != nil { + certInfoMap["cert_id"] = defaultCertificate.CertId + } + if defaultCertificate.Alias != nil { + certInfoMap["alias"] = defaultCertificate.Alias + } + if defaultCertificate.Type != nil { + certInfoMap["type"] = defaultCertificate.Type + } + if defaultCertificate.ExpireTime != nil { + certInfoMap["expire_time"] = defaultCertificate.ExpireTime + } + if defaultCertificate.EffectiveTime != nil { + certInfoMap["effective_time"] = defaultCertificate.EffectiveTime + } + if defaultCertificate.CommonName != nil { + certInfoMap["common_name"] = defaultCertificate.CommonName + } + if defaultCertificate.SubjectAltName != nil { + certInfoMap["subject_alt_name"] = defaultCertificate.SubjectAltName + } + if defaultCertificate.Status != nil { + certInfoMap["status"] = defaultCertificate.Status + } + if defaultCertificate.Message != nil { + certInfoMap["message"] = defaultCertificate.Message + } + + _ = d.Set("cert_info", []interface{}{certInfoMap}) + } + + return nil +} + +func resourceTencentCloudTeoDefaultCertificateUpdate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_default_certificate.update")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + + request := teo.NewModifyDefaultCertificateRequest() + + zoneId := d.Id() + + request.ZoneId = &zoneId + if certInfo, ok := d.GetOk("cert_info"); ok { + if defaultCertList := certInfo.([]interface{}); len(defaultCertList) > 0 { + if cert := defaultCertList[0].(map[string]interface{}); cert != nil { + if v := cert["cert_id"]; v != nil { + request.CertId = helper.String(v.(string)) + } + if v := cert["status"]; v != nil { + request.Status = helper.String(v.(string)) + } + } + } + } + + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseTeoClient().ModifyDefaultCertificate(request) + if e != nil { + return retryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + + return nil + }) + + if err != nil { + log.Printf("[CRITAL]%s create teo defaultCertificate failed, reason:%+v", logId, err) + return err + } + + return resourceTencentCloudTeoDefaultCertificateRead(d, meta) +} + +func resourceTencentCloudTeoDefaultCertificateDelete(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_default_certificate.delete")() + defer inconsistentCheck(d, meta)() + + return nil +} diff --git a/tencentcloud/resource_tc_teo_default_certificate_test.go b/tencentcloud/resource_tc_teo_default_certificate_test.go new file mode 100644 index 0000000000..0bd69da533 --- /dev/null +++ b/tencentcloud/resource_tc_teo_default_certificate_test.go @@ -0,0 +1,42 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" +) + +func TestAccTencentCloudNeedFixTeoDefaultCertificate_basic(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccTeoDefaultCertificate, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_teo_default_certificate.default_certificate", "id"), + ), + }, + { + ResourceName: "tencentcloud_teo_default_certificate.defaultCertificate", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccTeoDefaultCertificate = ` + +resource "tencentcloud_teo_default_certificate" "default_certificate" { + zone_id = tencentcloud_teo_zone.zone.id + + cert_info { + cert_id = "teo-28i46c1gtmkl" + status = "deployed" + } +} + +` diff --git a/tencentcloud/resource_tc_teo_dns_record.go b/tencentcloud/resource_tc_teo_dns_record.go new file mode 100644 index 0000000000..64f8b50c45 --- /dev/null +++ b/tencentcloud/resource_tc_teo_dns_record.go @@ -0,0 +1,427 @@ +/* +Provides a resource to create a teo dnsRecord + +Example Usage + +```hcl +resource "tencentcloud_teo_dns_record" "dns_record" { + zone_id = tencentcloud_teo_zone.zone.id + record_type = "A" + name = "sfurnace.work" + mode = "proxied" + content = "2.2.2.2" + ttl = 80 +} + +``` +Import + +teo dns_record can be imported using the id, e.g. +``` +$ terraform import tencentcloud_teo_dns_record.dnsRecord zoneId#dnsRecordId#name +``` +*/ +package tencentcloud + +import ( + "context" + "fmt" + "log" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + teo "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220106" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func resourceTencentCloudTeoDnsRecord() *schema.Resource { + return &schema.Resource{ + Read: resourceTencentCloudTeoDnsRecordRead, + Create: resourceTencentCloudTeoDnsRecordCreate, + Update: resourceTencentCloudTeoDnsRecordUpdate, + Delete: resourceTencentCloudTeoDnsRecordDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ + "record_type": { + Type: schema.TypeString, + Required: true, + Description: "DNS Record Type.", + }, + + "name": { + Type: schema.TypeString, + Required: true, + Description: "DNS Record Name.", + }, + + "content": { + Type: schema.TypeString, + Required: true, + Description: "DNS Record Content.", + }, + + "mode": { + Type: schema.TypeString, + Required: true, + Description: "Proxy mode. Valid values: dns_only, cdn_only, and secure_cdn.", + }, + + "ttl": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "TTL, the range is 1-604800, and the minimum value of different levels of domain names is different.", + }, + + "priority": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "Priority.", + }, + + "created_on": { + Type: schema.TypeString, + Computed: true, + Description: "Creation time.", + }, + + "modified_on": { + Type: schema.TypeString, + Computed: true, + Description: "Modification time.", + }, + + "locked": { + Type: schema.TypeBool, + Computed: true, + Description: "Whether the DNS record is locked.", + }, + + "zone_id": { + Type: schema.TypeString, + Required: true, + Description: "Site ID.", + }, + + "zone_name": { + Type: schema.TypeString, + Computed: true, + Description: "Site Name.", + }, + + "status": { + Type: schema.TypeString, + Computed: true, + Description: "Resolution status.", + }, + + "cname": { + Type: schema.TypeString, + Computed: true, + Description: "CNAME address.", + }, + + "domain_status": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Computed: true, + Description: ".", + }, + + "tags": { + Type: schema.TypeMap, + Optional: true, + Description: "Tag description list.", + }, + }, + } +} + +func resourceTencentCloudTeoDnsRecordCreate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_dns_record.create")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + + var ( + request = teo.NewCreateDnsRecordRequest() + response *teo.CreateDnsRecordResponse + ) + + if v, ok := d.GetOk("record_type"); ok { + request.Type = helper.String(v.(string)) + } + + if v, ok := d.GetOk("name"); ok { + request.Name = helper.String(v.(string)) + } + + if v, ok := d.GetOk("content"); ok { + request.Content = helper.String(v.(string)) + } + + if v, ok := d.GetOk("mode"); ok { + request.Mode = helper.String(v.(string)) + } + + if v, ok := d.GetOk("ttl"); ok { + request.Ttl = helper.IntInt64(v.(int)) + } + + if v, ok := d.GetOk("priority"); ok { + request.Priority = helper.IntInt64(v.(int)) + } + + if v, ok := d.GetOk("zone_id"); ok { + request.ZoneId = helper.String(v.(string)) + } + + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseTeoClient().CreateDnsRecord(request) + if e != nil { + return retryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + response = result + return nil + }) + + if err != nil { + log.Printf("[CRITAL]%s create teo dnsRecord failed, reason:%+v", logId, err) + return err + } + + dnsRecordId := *response.Response.Id + + ctx := context.WithValue(context.TODO(), logIdKey, logId) + if tags := helper.GetTags(d, "tags"); len(tags) > 0 { + tagService := TagService{client: meta.(*TencentCloudClient).apiV3Conn} + region := meta.(*TencentCloudClient).apiV3Conn.Region + resourceName := fmt.Sprintf("qcs::teo:%s:uin/:zone/%s", region, dnsRecordId) + if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil { + return err + } + } + + zoneId := *response.Response.ZoneId + name := *response.Response.Name + d.SetId(strings.Join([]string{zoneId, dnsRecordId, name}, FILED_SP)) + return resourceTencentCloudTeoDnsRecordRead(d, meta) +} + +func resourceTencentCloudTeoDnsRecordRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_dnsRecord.read")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + service := TeoService{client: meta.(*TencentCloudClient).apiV3Conn} + + ids := strings.Split(d.Id(), FILED_SP) + if len(ids) != 3 { + return fmt.Errorf("id is broken, id is %s", d.Id()) + } + + zoneId := ids[0] + //dnsRecordId := ids[1] + name := ids[2] + + dnsRecord, err := service.DescribeTeoDnsRecord(ctx, zoneId, name) + + if err != nil { + return err + } + + if dnsRecord == nil { + d.SetId("") + return fmt.Errorf("resource `dnsRecord` %s does not exist", name) + } + + _ = d.Set("id", dnsRecord.Id) + + if dnsRecord.Type != nil { + _ = d.Set("record_type", dnsRecord.Type) + } + + if dnsRecord.Name != nil { + _ = d.Set("name", dnsRecord.Name) + } + + if dnsRecord.Content != nil { + _ = d.Set("content", dnsRecord.Content) + } + + if dnsRecord.Mode != nil { + _ = d.Set("mode", dnsRecord.Mode) + } + + if dnsRecord.Ttl != nil { + _ = d.Set("ttl", dnsRecord.Ttl) + } + + if dnsRecord.Priority != nil { + _ = d.Set("priority", dnsRecord.Priority) + } + + if dnsRecord.CreatedOn != nil { + _ = d.Set("created_on", dnsRecord.CreatedOn) + } + + if dnsRecord.ModifiedOn != nil { + _ = d.Set("modified_on", dnsRecord.ModifiedOn) + } + + if dnsRecord.Locked != nil { + _ = d.Set("locked", dnsRecord.Locked) + } + + if dnsRecord.ZoneId != nil { + _ = d.Set("zone_id", dnsRecord.ZoneId) + } + + if dnsRecord.ZoneName != nil { + _ = d.Set("zone_name", dnsRecord.ZoneName) + } + + if dnsRecord.Status != nil { + _ = d.Set("status", dnsRecord.Status) + } + + if dnsRecord.Cname != nil { + _ = d.Set("cname", dnsRecord.Cname) + } + + if dnsRecord.DomainStatus != nil { + _ = d.Set("domain_status", dnsRecord.DomainStatus) + } + + tcClient := meta.(*TencentCloudClient).apiV3Conn + tagService := &TagService{client: tcClient} + tags, err := tagService.DescribeResourceTags(ctx, "teo", "zone", tcClient.Region, d.Id()) + if err != nil { + return err + } + _ = d.Set("tags", tags) + + return nil +} + +func resourceTencentCloudTeoDnsRecordUpdate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_dns_record.update")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + request := teo.NewModifyDnsRecordRequest() + + ids := strings.Split(d.Id(), FILED_SP) + if len(ids) != 3 { + return fmt.Errorf("id is broken, id is %s", d.Id()) + } + + zoneId := ids[0] + dnsRecordId := ids[1] + //name := ids[2] + + request.ZoneId = &zoneId + request.Id = &dnsRecordId + + if d.HasChange("record_type") { + if v, ok := d.GetOk("record_type"); ok { + request.Type = helper.String(v.(string)) + } + } + + if d.HasChange("name") { + if v, ok := d.GetOk("name"); ok { + request.Name = helper.String(v.(string)) + } + } + + if d.HasChange("content") { + if v, ok := d.GetOk("content"); ok { + request.Content = helper.String(v.(string)) + } + } + + if d.HasChange("mode") { + if v, ok := d.GetOk("mode"); ok { + request.Mode = helper.String(v.(string)) + } + } + + if d.HasChange("ttl") { + if v, ok := d.GetOk("ttl"); ok { + request.Ttl = helper.IntInt64(v.(int)) + } + } + + if d.HasChange("priority") { + if v, ok := d.GetOk("priority"); ok { + request.Priority = helper.IntInt64(v.(int)) + } + } + + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseTeoClient().ModifyDnsRecord(request) + if e != nil { + return retryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + return nil + }) + + if err != nil { + return err + } + + if d.HasChange("tags") { + tcClient := meta.(*TencentCloudClient).apiV3Conn + tagService := &TagService{client: tcClient} + oldTags, newTags := d.GetChange("tags") + replaceTags, deleteTags := diffTags(oldTags.(map[string]interface{}), newTags.(map[string]interface{})) + resourceName := BuildTagResourceName("teo", "zone", tcClient.Region, d.Id()) + if err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags); err != nil { + return err + } + } + + return resourceTencentCloudTeoDnsRecordRead(d, meta) +} + +func resourceTencentCloudTeoDnsRecordDelete(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_dns_record.delete")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + service := TeoService{client: meta.(*TencentCloudClient).apiV3Conn} + + ids := strings.Split(d.Id(), FILED_SP) + if len(ids) != 3 { + return fmt.Errorf("id is broken, id is %s", d.Id()) + } + + zoneId := ids[0] + dnsRecordId := ids[1] + //name := ids[2] + + if err := service.DeleteTeoDnsRecordById(ctx, zoneId, dnsRecordId); err != nil { + return err + } + + return nil +} diff --git a/tencentcloud/resource_tc_teo_dns_sec.go b/tencentcloud/resource_tc_teo_dns_sec.go new file mode 100644 index 0000000000..a0bc817388 --- /dev/null +++ b/tencentcloud/resource_tc_teo_dns_sec.go @@ -0,0 +1,274 @@ +/* +Provides a resource to create a teo dnsSec + +Example Usage + +```hcl +resource "tencentcloud_teo_dns_sec" "dns_sec" { + zone_id = tencentcloud_teo_zone.zone.id + status = "disabled" +} + +``` +Import + +teo dns_sec can be imported using the id, e.g. +``` +$ terraform import tencentcloud_teo_dns_sec.dns_sec zoneId +``` +*/ +package tencentcloud + +import ( + "context" + "fmt" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + teo "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220106" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func resourceTencentCloudTeoDnsSec() *schema.Resource { + return &schema.Resource{ + Read: resourceTencentCloudTeoDnsSecRead, + Create: resourceTencentCloudTeoDnsSecCreate, + Update: resourceTencentCloudTeoDnsSecUpdate, + Delete: resourceTencentCloudTeoDnsSecDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ + "zone_id": { + Type: schema.TypeString, + Required: true, + Description: "Site ID.", + }, + + "zone_name": { + Type: schema.TypeString, + Computed: true, + Description: "Site Name.", + }, + + "status": { + Type: schema.TypeString, + Required: true, + Description: "DNSSEC status. Valid values: `enabled`, `disabled`.", + }, + + "dnssec": { + Type: schema.TypeList, + MaxItems: 1, + Computed: true, + Description: "DNSSEC infos.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "flags": { + Type: schema.TypeInt, + Computed: true, + Description: "Flag.", + }, + "algorithm": { + Type: schema.TypeString, + Computed: true, + Description: "Encryption algorithm.", + }, + "key_type": { + Type: schema.TypeString, + Computed: true, + Description: "Encryption type.", + }, + "digest_type": { + Type: schema.TypeString, + Computed: true, + Description: "Digest type.", + }, + "digest_algorithm": { + Type: schema.TypeString, + Computed: true, + Description: "Digest algorithm.", + }, + "digest": { + Type: schema.TypeString, + Computed: true, + Description: "Digest message.", + }, + "d_s": { + Type: schema.TypeString, + Computed: true, + Description: "DS record value.", + }, + "key_tag": { + Type: schema.TypeInt, + Computed: true, + Description: "Key tag.", + }, + "public_key": { + Type: schema.TypeString, + Computed: true, + Description: "Public key.", + }, + }, + }, + }, + + "modified_on": { + Type: schema.TypeString, + Computed: true, + Description: "Last modification date.", + }, + }, + } +} + +func resourceTencentCloudTeoDnsSecCreate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_dns_sec.create")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + + var ( + request = teo.NewModifyDnssecRequest() + zoneId string + ) + + if v, ok := d.GetOk("zone_id"); ok { + zoneId = v.(string) + request.Id = helper.String(v.(string)) + } + + if v, ok := d.GetOk("status"); ok { + request.Status = helper.String(v.(string)) + } + + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseTeoClient().ModifyDnssec(request) + if e != nil { + return retryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + return nil + }) + + if err != nil { + log.Printf("[CRITAL]%s create teo dnsSec failed, reason:%+v", logId, err) + return err + } + + d.SetId(zoneId) + return resourceTencentCloudTeoDnsSecRead(d, meta) +} + +func resourceTencentCloudTeoDnsSecRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_dns_sec.read")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + service := TeoService{client: meta.(*TencentCloudClient).apiV3Conn} + + zoneId := d.Id() + + dnsSec, err := service.DescribeTeoDnsSec(ctx, zoneId) + + if err != nil { + return err + } + + if dnsSec == nil { + d.SetId("") + return fmt.Errorf("resource `dnsSec` %s does not exist", zoneId) + } + + if dnsSec.Name != nil { + _ = d.Set("zone_name", dnsSec.Name) + } + + if dnsSec.Status != nil { + _ = d.Set("status", dnsSec.Status) + } + + if dnsSec.Dnssec != nil { + dnssecMap := map[string]interface{}{} + if dnsSec.Dnssec.Flags != nil { + dnssecMap["flags"] = dnsSec.Dnssec.Flags + } + if dnsSec.Dnssec.Algorithm != nil { + dnssecMap["algorithm"] = dnsSec.Dnssec.Algorithm + } + if dnsSec.Dnssec.KeyType != nil { + dnssecMap["key_type"] = dnsSec.Dnssec.KeyType + } + if dnsSec.Dnssec.DigestType != nil { + dnssecMap["digest_type"] = dnsSec.Dnssec.DigestType + } + if dnsSec.Dnssec.DigestAlgorithm != nil { + dnssecMap["digest_algorithm"] = dnsSec.Dnssec.DigestAlgorithm + } + if dnsSec.Dnssec.Digest != nil { + dnssecMap["digest"] = dnsSec.Dnssec.Digest + } + if dnsSec.Dnssec.DS != nil { + dnssecMap["d_s"] = dnsSec.Dnssec.DS + } + if dnsSec.Dnssec.KeyTag != nil { + dnssecMap["key_tag"] = dnsSec.Dnssec.KeyTag + } + if dnsSec.Dnssec.PublicKey != nil { + dnssecMap["public_key"] = dnsSec.Dnssec.PublicKey + } + + _ = d.Set("dnssec", []interface{}{dnssecMap}) + } + + if dnsSec.ModifiedOn != nil { + _ = d.Set("modified_on", dnsSec.ModifiedOn) + } + + return nil +} + +func resourceTencentCloudTeoDnsSecUpdate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_dns_sec.update")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + request := teo.NewModifyDnssecRequest() + + zoneId := d.Id() + request.Id = &zoneId + + if v, ok := d.GetOk("status"); ok { + request.Status = helper.String(v.(string)) + } + + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseTeoClient().ModifyDnssec(request) + if e != nil { + return retryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + return nil + }) + + if err != nil { + log.Printf("[CRITAL]%s create teo dnsSec failed, reason:%+v", logId, err) + return err + } + + return resourceTencentCloudTeoDnsSecRead(d, meta) +} + +func resourceTencentCloudTeoDnsSecDelete(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_dns_sec.delete")() + defer inconsistentCheck(d, meta)() + + return nil +} diff --git a/tencentcloud/resource_tc_teo_dns_sec_test.go b/tencentcloud/resource_tc_teo_dns_sec_test.go new file mode 100644 index 0000000000..f6acc31a3c --- /dev/null +++ b/tencentcloud/resource_tc_teo_dns_sec_test.go @@ -0,0 +1,37 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" +) + +func TestAccTencentCloudNeedFixTeoDnsSec_basic(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccTeoDnsSec, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_teo_dns_sec.dns_sec", "id"), + ), + }, + { + ResourceName: "tencentcloud_teo_dns_sec.dns_sec", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccTeoDnsSec = ` + +resource "tencentcloud_teo_dns_sec" "dns_sec" { + zone_id = tencentcloud_teo_zone.zone.id + status = "disabled" +} +` diff --git a/tencentcloud/resource_tc_teo_host_certificate.go b/tencentcloud/resource_tc_teo_host_certificate.go new file mode 100644 index 0000000000..1546754dab --- /dev/null +++ b/tencentcloud/resource_tc_teo_host_certificate.go @@ -0,0 +1,237 @@ +/* +Provides a resource to create a teo hostCertificate + +Example Usage + +```hcl +resource "tencentcloud_teo_host_certificate" "host_certificate" { + zone_id = tencentcloud_teo_zone.zone.id + host = tencentcloud_teo_dns_record.dns_record.name + + cert_info { + cert_id = "yqWPPbs7" + status = "deployed" + } +} + +``` +Import + +teo hostCertificate can be imported using the id, e.g. +``` +$ terraform import tencentcloud_teo_host_certificate.host_certificate zoneId#host +``` +*/ +package tencentcloud + +import ( + "context" + "fmt" + "log" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + teo "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220106" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func resourceTencentCloudTeoHostCertificate() *schema.Resource { + return &schema.Resource{ + Read: resourceTencentCloudTeoHostCertificateRead, + Create: resourceTencentCloudTeoHostCertificateCreate, + Update: resourceTencentCloudTeoHostCertificateUpdate, + Delete: resourceTencentCloudTeoHostCertificateDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ + "zone_id": { + Type: schema.TypeString, + Required: true, + Description: "Site ID.", + }, + + "host": { + Type: schema.TypeString, + Required: true, + Description: "Domain name.", + }, + + "cert_info": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Description: "Server certificate configuration.Note: This field may return null, indicating that no valid value can be obtained.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cert_id": { + Type: schema.TypeString, + Required: true, + Description: "Server certificate ID, which is the ID of the default certificate. If you choose to upload an external certificate for SSL certificate management, a certificate ID will be generated.", + }, + "alias": { + Type: schema.TypeString, + Computed: true, + Description: "Alias of the certificate.Note: This field may return null, indicating that no valid value can be obtained.", + }, + "type": { + Type: schema.TypeString, + Computed: true, + Description: "Certificate type.- default: Default certificate.- upload: External certificate.- managed: Tencent Cloud managed certificate.Note: This field may return null, indicating that no valid value can be obtained.", + }, + "expire_time": { + Type: schema.TypeString, + Computed: true, + Description: "Time when the certificate expires.Note: This field may return null, indicating that no valid value can be obtained.", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "Certificate deployment status.- processing: Deploying- deployed: DeployedNote: This field may return null, indicating that no valid value can be obtained.", + }, + }, + }, + }, + }, + } +} + +func resourceTencentCloudTeoHostCertificateCreate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_host_certificate.create")() + defer inconsistentCheck(d, meta)() + + var ( + zoneId string + host string + ) + + if v, ok := d.GetOk("zone_id"); ok { + zoneId = v.(string) + } + + if v, ok := d.GetOk("host"); ok { + host = v.(string) + } + d.SetId(zoneId + FILED_SP + host) + return resourceTencentCloudTeoHostCertificateUpdate(d, meta) +} + +func resourceTencentCloudTeoHostCertificateRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_host_certificate.read")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + service := TeoService{client: meta.(*TencentCloudClient).apiV3Conn} + + idSplit := strings.Split(d.Id(), FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + zoneId := idSplit[0] + host := idSplit[1] + + hostCertificate, err := service.DescribeTeoHostCertificate(ctx, zoneId, host) + + if err != nil { + return err + } + + if hostCertificate == nil { + d.SetId("") + return fmt.Errorf("resource `hostCertificate` %s does not exist", d.Id()) + } + + if hostCertificate.Host != nil { + _ = d.Set("host", hostCertificate.Host) + } + + if hostCertificate.CertInfo != nil { + certInfoList := []interface{}{} + for _, certInfo := range hostCertificate.CertInfo { + certInfoMap := map[string]interface{}{} + if certInfo.CertId != nil { + certInfoMap["cert_id"] = certInfo.CertId + } + if certInfo.Alias != nil { + certInfoMap["alias"] = certInfo.Alias + } + if certInfo.Type != nil { + certInfoMap["type"] = certInfo.Type + } + if certInfo.ExpireTime != nil { + certInfoMap["expire_time"] = certInfo.ExpireTime + } + if certInfo.Status != nil { + certInfoMap["status"] = certInfo.Status + } + + certInfoList = append(certInfoList, certInfoMap) + } + _ = d.Set("cert_info", certInfoList) + } + + return nil +} + +func resourceTencentCloudTeoHostCertificateUpdate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_host_certificate.update")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + + request := teo.NewModifyHostsCertificateRequest() + + idSplit := strings.Split(d.Id(), FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + zoneId := idSplit[0] + host := idSplit[1] + + request.ZoneId = helper.String(zoneId) + request.Hosts = []*string{helper.String(host)} + + if v, ok := d.GetOk("cert_info"); ok { + for _, item := range v.([]interface{}) { + dMap := item.(map[string]interface{}) + serverCertInfo := teo.ServerCertInfo{} + if v, ok := dMap["cert_id"]; ok { + serverCertInfo.CertId = helper.String(v.(string)) + } + if v, ok := dMap["status"]; ok { + serverCertInfo.Status = helper.String(v.(string)) + } + + request.CertInfo = append(request.CertInfo, &serverCertInfo) + } + } + + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseTeoClient().ModifyHostsCertificate(request) + if e != nil { + return retryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + return nil + }) + + if err != nil { + log.Printf("[CRITAL]%s create teo hostCertificate failed, reason:%+v", logId, err) + return err + } + + return resourceTencentCloudTeoHostCertificateRead(d, meta) +} + +func resourceTencentCloudTeoHostCertificateDelete(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_host_certificate.delete")() + defer inconsistentCheck(d, meta)() + + return nil +} diff --git a/tencentcloud/resource_tc_teo_host_certificate_test.go b/tencentcloud/resource_tc_teo_host_certificate_test.go new file mode 100644 index 0000000000..5a08d83f29 --- /dev/null +++ b/tencentcloud/resource_tc_teo_host_certificate_test.go @@ -0,0 +1,43 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" +) + +func TestAccTencentCloudNeedFixTeoHostCertificate_basic(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccTeoHostCertificate, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_teo_host_certificate.host_certificate", "id"), + ), + }, + { + ResourceName: "tencentcloud_teo_host_certificate.host_certificate", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccTeoHostCertificate = ` + +resource "tencentcloud_teo_host_certificate" "host_certificate" { + zone_id = tencentcloud_teo_zone.zone.id + host = tencentcloud_teo_dns_record.dns_record.name + + cert_info { + cert_id = "yqWPPbs7" + status = "deployed" + } +} + +` diff --git a/tencentcloud/resource_tc_teo_load_balancing.go b/tencentcloud/resource_tc_teo_load_balancing.go new file mode 100644 index 0000000000..f1d71701bb --- /dev/null +++ b/tencentcloud/resource_tc_teo_load_balancing.go @@ -0,0 +1,302 @@ +/* +Provides a resource to create a teo loadBalancing + +Example Usage + +```hcl +resource "tencentcloud_teo_load_balancing" "load_balancing" { + zone_id = tencentcloud_teo_zone.zone.id + + host = "sfurnace.work" + origin_id = [ + split("#", tencentcloud_teo_origin_group.group0.id)[1] + ] + ttl = 600 + type = "proxied" +} + +``` +Import + +teo loadBalancing can be imported using the id, e.g. +``` +$ terraform import tencentcloud_teo_load_balancing.loadBalancing loadBalancing_id +``` +*/ +package tencentcloud + +import ( + "context" + "fmt" + "log" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + teo "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220106" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func resourceTencentCloudTeoLoadBalancing() *schema.Resource { + return &schema.Resource{ + Read: resourceTencentCloudTeoLoadBalancingRead, + Create: resourceTencentCloudTeoLoadBalancingCreate, + Update: resourceTencentCloudTeoLoadBalancingUpdate, + Delete: resourceTencentCloudTeoLoadBalancingDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ + "load_balancing_id": { + Type: schema.TypeString, + Computed: true, + Description: "CLB instance ID.", + }, + + "zone_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Site ID.", + }, + + "host": { + Type: schema.TypeString, + Required: true, + Description: "Subdomain name. You can use @ to represent the root domain.", + }, + + "type": { + Type: schema.TypeString, + Required: true, + Description: "Proxy mode. Valid values: dns_only: Only DNS, proxied: Enable proxy.", + }, + + "ttl": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "Indicates DNS TTL time when Type=dns_only.", + }, + + "origin_id": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Required: true, + Description: "ID of the origin group used.", + }, + + "update_time": { + Type: schema.TypeString, + Computed: true, + Description: "Update time.", + }, + + "cname": { + Type: schema.TypeString, + Computed: true, + Description: "Schedules domain names, Note: This field may return null, indicating that no valid value can be obtained.", + }, + }, + } +} + +func resourceTencentCloudTeoLoadBalancingCreate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_load_balancing.create")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + + var ( + request = teo.NewCreateLoadBalancingRequest() + response *teo.CreateLoadBalancingResponse + zoneId string + ) + + if v, ok := d.GetOk("zone_id"); ok { + zoneId = v.(string) + request.ZoneId = helper.String(zoneId) + } + + if v, ok := d.GetOk("host"); ok { + request.Host = helper.String(v.(string)) + } + + if v, ok := d.GetOk("type"); ok { + request.Type = helper.String(v.(string)) + } + + if v, ok := d.GetOk("ttl"); ok { + request.TTL = helper.IntUint64(v.(int)) + } + + if v, ok := d.GetOk("origin_id"); ok { + originIdSet := v.(*schema.Set).List() + for i := range originIdSet { + originId := originIdSet[i].(string) + request.OriginId = append(request.OriginId, &originId) + } + } + + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseTeoClient().CreateLoadBalancing(request) + if e != nil { + return retryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + response = result + return nil + }) + + if err != nil { + log.Printf("[CRITAL]%s create teo loadBalancing failed, reason:%+v", logId, err) + return err + } + + loadBalancingId := *response.Response.LoadBalancingId + + d.SetId(zoneId + "#" + loadBalancingId) + return resourceTencentCloudTeoLoadBalancingRead(d, meta) +} + +func resourceTencentCloudTeoLoadBalancingRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_loadBalancing.read")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + service := TeoService{client: meta.(*TencentCloudClient).apiV3Conn} + + idSplit := strings.Split(d.Id(), FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + zoneId := idSplit[0] + loadBalancingId := idSplit[1] + + loadBalancing, err := service.DescribeTeoLoadBalancing(ctx, zoneId, loadBalancingId) + + if err != nil { + return err + } + + if loadBalancing == nil { + d.SetId("") + return fmt.Errorf("resource `loadBalancing` %s does not exist", loadBalancingId) + } + + if loadBalancing.LoadBalancingId != nil { + _ = d.Set("load_balancing_id", loadBalancing.LoadBalancingId) + } + + if loadBalancing.ZoneId != nil { + _ = d.Set("zone_id", loadBalancing.ZoneId) + } + + if loadBalancing.Host != nil { + _ = d.Set("host", loadBalancing.Host) + } + + if loadBalancing.Type != nil { + _ = d.Set("type", loadBalancing.Type) + } + + if loadBalancing.TTL != nil { + _ = d.Set("ttl", loadBalancing.TTL) + } + + if loadBalancing.OriginId != nil { + _ = d.Set("origin_id", loadBalancing.OriginId) + } + + if loadBalancing.UpdateTime != nil { + _ = d.Set("update_time", loadBalancing.UpdateTime) + } + + if loadBalancing.Cname != nil { + _ = d.Set("cname", loadBalancing.Cname) + } + + return nil +} + +func resourceTencentCloudTeoLoadBalancingUpdate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_load_balancing.update")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + + request := teo.NewModifyLoadBalancingRequest() + + request.ZoneId = helper.String(d.Id()) + + if d.HasChange("host") { + return fmt.Errorf("`host` do not support change now.") + } + + if d.HasChange("type") { + if v, ok := d.GetOk("type"); ok { + request.Type = helper.String(v.(string)) + } + } + + if d.HasChange("ttl") { + if v, ok := d.GetOk("ttl"); ok { + request.TTL = helper.IntUint64(v.(int)) + } + } + + if d.HasChange("origin_id") { + if v, ok := d.GetOk("origin_id"); ok { + originIdSet := v.(*schema.Set).List() + for i := range originIdSet { + originId := originIdSet[i].(string) + request.OriginId = append(request.OriginId, &originId) + } + } + } + + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseTeoClient().ModifyLoadBalancing(request) + if e != nil { + return retryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + return nil + }) + + if err != nil { + return err + } + + return resourceTencentCloudTeoLoadBalancingRead(d, meta) +} + +func resourceTencentCloudTeoLoadBalancingDelete(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_load_balancing.delete")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + service := TeoService{client: meta.(*TencentCloudClient).apiV3Conn} + idSplit := strings.Split(d.Id(), FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + zoneId := idSplit[0] + loadBalancingId := idSplit[1] + + if err := service.DeleteTeoLoadBalancingById(ctx, zoneId, loadBalancingId); err != nil { + return err + } + + return nil +} diff --git a/tencentcloud/resource_tc_teo_origin_group.go b/tencentcloud/resource_tc_teo_origin_group.go new file mode 100644 index 0000000000..0c4726e00c --- /dev/null +++ b/tencentcloud/resource_tc_teo_origin_group.go @@ -0,0 +1,480 @@ +/* +Provides a resource to create a teo originGroup + +Example Usage + +```hcl +locals { + group0 = [ + { + "record" = "1.1.1.1" + "port" = 80 + "weight" = 30 + }, { + "record" = "2.2.2.2" + "port" = 443 + "weight" = 70 + } + ] +} + +resource "tencentcloud_teo_origin_group" "origin_group" { + zone_id = tencentcloud_teo_zone.zone.id + origin_name = "group0" + origin_type = "self" + type = "weight" + + dynamic "record" { + for_each = local.group0 + content { + record = record.value["record"] + port = record.value["port"] + weight = record.value["weight"] + area = [] + } + } +} + +``` +Import + +teo origin_group can be imported using the id, e.g. +``` +$ terraform import tencentcloud_teo_origin_group.origin_group zoneId#originId +``` +*/ +package tencentcloud + +import ( + "context" + "fmt" + "log" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + teo "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220106" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func resourceTencentCloudTeoOriginGroup() *schema.Resource { + return &schema.Resource{ + Read: resourceTencentCloudTeoOriginGroupRead, + Create: resourceTencentCloudTeoOriginGroupCreate, + Update: resourceTencentCloudTeoOriginGroupUpdate, + Delete: resourceTencentCloudTeoOriginGroupDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ + "origin_name": { + Type: schema.TypeString, + Required: true, + Description: "OriginGroup Name.", + }, + + "type": { + Type: schema.TypeString, + Required: true, + Description: "Type of the origin group, this field is required only when `OriginType` is `self`. Valid values:- area: select an origin by using Geo info of the client IP and `Area` field in Records.- weight: weighted select an origin by using `Weight` field in Records.", + }, + + "record": { + Type: schema.TypeList, + Required: true, + Description: "Origin website records.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "record": { + Type: schema.TypeString, + Required: true, + Description: "Record Value.", + }, + "area": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Required: true, + Description: "Indicating origin website's area when `Type` field is `area`. An empty List indicate the default area.", + }, + "weight": { + Type: schema.TypeInt, + Required: true, + Description: "Indicating origin website's weight when `Type` field is `weight`. Valid value range: 1-100. Sum of all weights should be 100.", + }, + "port": { + Type: schema.TypeInt, + Required: true, + Description: "Port of the origin website.", + }, + "private": { + Type: schema.TypeBool, + Optional: true, + Description: "Whether origin website is using private authentication. Only valid when `OriginType` is `third_party`.", + }, + "private_parameter": { + Type: schema.TypeList, + Optional: true, + Description: "Parameters for private authentication. Only valid when `Private` is `true`.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + Description: "Parameter Name. Valid values:- AccessKeyId: Access Key ID.- SecretAccessKey: Secret Access Key.", + }, + "value": { + Type: schema.TypeString, + Required: true, + Description: "Parameter value.", + }, + }, + }, + }, + "record_id": { + Type: schema.TypeString, + Computed: true, + Description: "Record Id.", + }, + }, + }, + }, + + "zone_id": { + Type: schema.TypeString, + Required: true, + Description: "Site ID.", + }, + + "origin_type": { + Type: schema.TypeString, + Optional: true, + Description: "Type of the origin website. Valid values:- self: self-build website.- cos: tencent cos.- third_party: third party cos.", + }, + + "zone_name": { + Type: schema.TypeString, + Computed: true, + Description: "Site Name.", + }, + + "update_time": { + Type: schema.TypeString, + Computed: true, + Description: "Last modification date.", + }, + }, + } +} + +func resourceTencentCloudTeoOriginGroupCreate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_origin_group.create")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + + var ( + request = teo.NewCreateOriginGroupRequest() + response *teo.CreateOriginGroupResponse + zoneId string + originId string + ) + + if v, ok := d.GetOk("origin_name"); ok { + request.OriginName = helper.String(v.(string)) + } + + if v, ok := d.GetOk("type"); ok { + request.Type = helper.String(v.(string)) + } + + if v, ok := d.GetOk("record"); ok { + for _, item := range v.([]interface{}) { + dMap := item.(map[string]interface{}) + originRecord := teo.OriginRecord{} + if v, ok := dMap["record"]; ok { + originRecord.Record = helper.String(v.(string)) + } + if v, ok := dMap["area"]; ok { + areaSet := v.(*schema.Set).List() + for i := range areaSet { + area := areaSet[i].(string) + originRecord.Area = append(originRecord.Area, &area) + } + } + if v, ok := dMap["weight"]; ok { + originRecord.Weight = helper.IntUint64(v.(int)) + } + if v, ok := dMap["port"]; ok { + originRecord.Port = helper.IntUint64(v.(int)) + } + if v, ok := dMap["private"]; ok { + originRecord.Private = helper.Bool(v.(bool)) + } + if v, ok := dMap["private_parameter"]; ok { + for _, item := range v.([]interface{}) { + PrivateParameterMap := item.(map[string]interface{}) + originRecordPrivateParameter := teo.OriginRecordPrivateParameter{} + if v, ok := PrivateParameterMap["name"]; ok { + originRecordPrivateParameter.Name = helper.String(v.(string)) + } + if v, ok := PrivateParameterMap["value"]; ok { + originRecordPrivateParameter.Value = helper.String(v.(string)) + } + originRecord.PrivateParameter = append(originRecord.PrivateParameter, &originRecordPrivateParameter) + } + } + + request.Record = append(request.Record, &originRecord) + } + } + + if v, ok := d.GetOk("zone_id"); ok { + zoneId = v.(string) + request.ZoneId = helper.String(v.(string)) + } + + if v, ok := d.GetOk("origin_type"); ok { + request.OriginType = helper.String(v.(string)) + } + + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseTeoClient().CreateOriginGroup(request) + if e != nil { + return retryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + response = result + return nil + }) + + if err != nil { + log.Printf("[CRITAL]%s create teo originGroup failed, reason:%+v", logId, err) + return err + } + + originId = *response.Response.OriginId + + d.SetId(zoneId + FILED_SP + originId) + return resourceTencentCloudTeoOriginGroupRead(d, meta) +} + +func resourceTencentCloudTeoOriginGroupRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_origin_group.read")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + service := TeoService{client: meta.(*TencentCloudClient).apiV3Conn} + + idSplit := strings.Split(d.Id(), FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + zoneId := idSplit[0] + originId := idSplit[1] + + originGroup, err := service.DescribeTeoOriginGroup(ctx, zoneId, originId) + + if err != nil { + return err + } + + if originGroup == nil { + d.SetId("") + return fmt.Errorf("resource `originGroup` %s does not exist", originId) + } + + if originGroup.OriginName != nil { + _ = d.Set("origin_name", originGroup.OriginName) + } + + if originGroup.Type != nil { + _ = d.Set("type", originGroup.Type) + } + + if originGroup.Record != nil { + recordList := []interface{}{} + for _, record := range originGroup.Record { + recordMap := map[string]interface{}{} + if record.Record != nil { + recordMap["record"] = record.Record + } + if record.Area != nil { + recordMap["area"] = record.Area + } + if record.Weight != nil { + recordMap["weight"] = record.Weight + } + if record.Port != nil { + recordMap["port"] = record.Port + } + if record.Private != nil { + recordMap["private"] = record.Private + } + if record.PrivateParameter != nil { + privateParameterList := []interface{}{} + for _, privateParameter := range record.PrivateParameter { + privateParameterMap := map[string]interface{}{} + if privateParameter.Name != nil { + privateParameterMap["name"] = privateParameter.Name + } + if privateParameter.Value != nil { + privateParameterMap["value"] = privateParameter.Value + } + + privateParameterList = append(privateParameterList, privateParameterMap) + } + recordMap["private_parameter"] = privateParameterList + } + if record.RecordId != nil { + recordMap["record_id"] = record.RecordId + } + + recordList = append(recordList, recordMap) + } + _ = d.Set("record", recordList) + } + + if originGroup.ZoneId != nil { + _ = d.Set("zone_id", originGroup.ZoneId) + } + + if originGroup.OriginType != nil { + _ = d.Set("origin_type", originGroup.OriginType) + } + + if originGroup.ZoneName != nil { + _ = d.Set("zone_name", originGroup.ZoneName) + } + + if originGroup.UpdateTime != nil { + _ = d.Set("update_time", originGroup.UpdateTime) + } + + return nil +} + +func resourceTencentCloudTeoOriginGroupUpdate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_origin_group.update")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + + request := teo.NewModifyOriginGroupRequest() + + idSplit := strings.Split(d.Id(), FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + zoneId := idSplit[0] + originId := idSplit[1] + + request.ZoneId = &zoneId + request.OriginId = &originId + + if v, ok := d.GetOk("origin_name"); ok { + request.OriginName = helper.String(v.(string)) + } + + if v, ok := d.GetOk("type"); ok { + request.Type = helper.String(v.(string)) + } + + if v, ok := d.GetOk("origin_type"); ok { + request.OriginType = helper.String(v.(string)) + } + + if d.HasChange("record") { + if v, ok := d.GetOk("record"); ok { + for _, item := range v.([]interface{}) { + dMap := item.(map[string]interface{}) + originRecord := teo.OriginRecord{} + if v, ok := dMap["record"]; ok { + originRecord.Record = helper.String(v.(string)) + } + if v, ok := dMap["area"]; ok { + areaSet := v.(*schema.Set).List() + for i := range areaSet { + area := areaSet[i].(string) + originRecord.Area = append(originRecord.Area, &area) + } + } + if v, ok := dMap["weight"]; ok { + originRecord.Weight = helper.IntUint64(v.(int)) + } + if v, ok := dMap["port"]; ok { + originRecord.Port = helper.IntUint64(v.(int)) + } + if v, ok := dMap["private"]; ok { + originRecord.Private = helper.Bool(v.(bool)) + } + if v, ok := dMap["private_parameter"]; ok { + for _, item := range v.([]interface{}) { + PrivateParameterMap := item.(map[string]interface{}) + originRecordPrivateParameter := teo.OriginRecordPrivateParameter{} + if v, ok := PrivateParameterMap["name"]; ok { + originRecordPrivateParameter.Name = helper.String(v.(string)) + } + if v, ok := PrivateParameterMap["value"]; ok { + originRecordPrivateParameter.Value = helper.String(v.(string)) + } + originRecord.PrivateParameter = append(originRecord.PrivateParameter, &originRecordPrivateParameter) + } + } + + request.Record = append(request.Record, &originRecord) + } + } + } + + if d.HasChange("zone_id") { + if v, ok := d.GetOk("zone_id"); ok { + request.ZoneId = helper.String(v.(string)) + } + } + + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseTeoClient().ModifyOriginGroup(request) + if e != nil { + return retryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + return nil + }) + + if err != nil { + return err + } + + return resourceTencentCloudTeoOriginGroupRead(d, meta) +} + +func resourceTencentCloudTeoOriginGroupDelete(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_origin_group.delete")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + service := TeoService{client: meta.(*TencentCloudClient).apiV3Conn} + + idSplit := strings.Split(d.Id(), FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + zoneId := idSplit[0] + originId := idSplit[1] + + if err := service.DeleteTeoOriginGroupById(ctx, zoneId, originId); err != nil { + return err + } + + return nil +} diff --git a/tencentcloud/resource_tc_teo_origin_group_test.go b/tencentcloud/resource_tc_teo_origin_group_test.go new file mode 100644 index 0000000000..6ac8914bf3 --- /dev/null +++ b/tencentcloud/resource_tc_teo_origin_group_test.go @@ -0,0 +1,64 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" +) + +func TestAccTencentCloudNeedFixTeoOriginGroup_basic(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccTeoOriginGroup, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_teo_origin_group.originGroup", "id"), + ), + }, + { + ResourceName: "tencentcloud_teo_origin_group.originGroup", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccTeoOriginGroup = ` + +locals { + group0 = [ + { + "record" = "1.1.1.1" + "port" = 80 + "weight" = 30 + }, { + "record" = "2.2.2.2" + "port" = 443 + "weight" = 70 + } + ] +} + +resource "tencentcloud_teo_origin_group" "origin_group" { + zone_id = tencentcloud_teo_zone.zone.id + origin_name = "group0" + origin_type = "self" + type = "weight" + + dynamic "record" { + for_each = local.group0 + content { + record = record.value["record"] + port = record.value["port"] + weight = record.value["weight"] + area = [] + } + } +} + +` diff --git a/tencentcloud/resource_tc_teo_rule_engine.go b/tencentcloud/resource_tc_teo_rule_engine.go new file mode 100644 index 0000000000..6de283d8d4 --- /dev/null +++ b/tencentcloud/resource_tc_teo_rule_engine.go @@ -0,0 +1,795 @@ +/* +Provides a resource to create a teo ruleEngine + +Example Usage + +```hcl +resource "tencentcloud_teo_rule_engine" "rule_engine" { + zone_id = tencentcloud_teo_zone.zone.id + rule_name = "rule0" + status = "enable" + + rules { + conditions { + conditions { + operator = "equal" + target = "host" + values = [ + "www.sfurnace.work", + ] + } + } + + actions { + normal_action { + action = "MaxAge" + + parameters { + name = "FollowOrigin" + values = [ + "on", + ] + } + parameters { + name = "MaxAgeTime" + values = [ + "0", + ] + } + } + } + } +} + +``` +Import + +teo ruleEngine can be imported using the id, e.g. +``` +$ terraform import tencentcloud_teo_rule_engine.rule_engine zoneId#ruleId +``` +*/ +package tencentcloud + +import ( + "context" + "fmt" + "log" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + teo "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220106" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func resourceTencentCloudTeoRuleEngine() *schema.Resource { + return &schema.Resource{ + Read: resourceTencentCloudTeoRuleEngineRead, + Create: resourceTencentCloudTeoRuleEngineCreate, + Update: resourceTencentCloudTeoRuleEngineUpdate, + Delete: resourceTencentCloudTeoRuleEngineDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ + "zone_id": { + Type: schema.TypeString, + Required: true, + Description: "Site ID.", + }, + + "rule_name": { + Type: schema.TypeString, + Optional: true, + Description: "Rule name.", + }, + + "status": { + Type: schema.TypeString, + Required: true, + Description: "Status of the rule, valid value can be `enable` or `disable`.", + }, + + "rules": { + Type: schema.TypeList, + Required: true, + Description: "Rule items list.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "conditions": { + Type: schema.TypeList, + Required: true, + Description: "OR Conditions list of the rule. Rule would be triggered if any of the condition is true.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "conditions": { + Type: schema.TypeList, + Required: true, + Description: "AND Conditions list of the rule. Rule would be triggered if all conditions are true.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "operator": { + Type: schema.TypeString, + Required: true, + Description: "Condition operator. Valid values are `equal`, `notequal`.", + }, + "target": { + Type: schema.TypeString, + Required: true, + Description: "Condition target. Valid values:- host: Host of the URL.- filename: filename of the URL.- extension: file extension of the URL.- full_url: full url.- url: path of the URL.", + }, + "values": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Required: true, + Description: "Condition Value.", + }, + }, + }, + }, + }, + }, + }, + "actions": { + Type: schema.TypeList, + Required: true, + Description: "Actions list of the rule. See details in data source `rule_engine_setting`.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "normal_action": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Description: "Define a normal action.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "action": { + Type: schema.TypeString, + Required: true, + Description: "Action name.", + }, + "parameters": { + Type: schema.TypeList, + Required: true, + Description: "Action parameters.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + Description: "Parameter Name.", + }, + "values": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Required: true, + Description: "Parameter Values.", + }, + }, + }, + }, + }, + }, + }, + "rewrite_action": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Description: "Define a rewrite action.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "action": { + Type: schema.TypeString, + Required: true, + Description: "Action name.", + }, + "parameters": { + Type: schema.TypeList, + Required: true, + Description: "Action parameters.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "action": { + Type: schema.TypeString, + Required: true, + Description: "Action to take on the HEADER.", + }, + "name": { + Type: schema.TypeString, + Required: true, + Description: "Target HEADER name.", + }, + "values": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Required: true, + Description: "Parameter Value.", + }, + }, + }, + }, + }, + }, + }, + "code_action": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Description: "Define a code action.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "action": { + Type: schema.TypeString, + Required: true, + Description: "Action name.", + }, + "parameters": { + Type: schema.TypeList, + Required: true, + Description: "Action parameters.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + Description: "Parameter Name.", + }, + "values": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Required: true, + Description: "Parameter Values.", + }, + "status_code": { + Type: schema.TypeInt, + Required: true, + Description: "HTTP status code to use.", + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + + "rule_id": { + Type: schema.TypeString, + Computed: true, + Description: "Rule ID.", + }, + }, + } +} + +func resourceTencentCloudTeoRuleEngineCreate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_rule_engine.create")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + + var ( + request = teo.NewCreateRuleRequest() + response *teo.CreateRuleResponse + zoneId string + ruleId string + ) + + if v, ok := d.GetOk("zone_id"); ok { + zoneId = v.(string) + request.ZoneId = helper.String(v.(string)) + } + + if v, ok := d.GetOk("rule_name"); ok { + request.RuleName = helper.String(v.(string)) + } + + if v, ok := d.GetOk("status"); ok { + request.Status = helper.String(v.(string)) + } + + if v, ok := d.GetOk("rules"); ok { + for _, item := range v.([]interface{}) { + dMap := item.(map[string]interface{}) + ruleItem := teo.RuleItem{} + if v, ok := dMap["conditions"]; ok { + for _, item := range v.([]interface{}) { + ConditionsMap := item.(map[string]interface{}) + ruleAndConditions := teo.RuleAndConditions{} + if v, ok := ConditionsMap["conditions"]; ok { + for _, item := range v.([]interface{}) { + ConditionsMap := item.(map[string]interface{}) + ruleCondition := teo.RuleCondition{} + if v, ok := ConditionsMap["operator"]; ok { + ruleCondition.Operator = helper.String(v.(string)) + } + if v, ok := ConditionsMap["target"]; ok { + ruleCondition.Target = helper.String(v.(string)) + } + if v, ok := ConditionsMap["values"]; ok { + valuesSet := v.(*schema.Set).List() + for i := range valuesSet { + values := valuesSet[i].(string) + ruleCondition.Values = append(ruleCondition.Values, &values) + } + } + ruleAndConditions.Conditions = append(ruleAndConditions.Conditions, &ruleCondition) + } + } + ruleItem.Conditions = append(ruleItem.Conditions, &ruleAndConditions) + } + } + if v, ok := dMap["actions"]; ok { + for _, item := range v.([]interface{}) { + ActionsMap := item.(map[string]interface{}) + ruleAction := teo.RuleAction{} + if NormalActionMap, ok := helper.InterfaceToMap(ActionsMap, "normal_action"); ok { + ruleNormalAction := teo.RuleNormalAction{} + if v, ok := NormalActionMap["action"]; ok { + ruleNormalAction.Action = helper.String(v.(string)) + } + if v, ok := NormalActionMap["parameters"]; ok { + for _, item := range v.([]interface{}) { + ParametersMap := item.(map[string]interface{}) + ruleNormalActionParams := teo.RuleNormalActionParams{} + if v, ok := ParametersMap["name"]; ok { + ruleNormalActionParams.Name = helper.String(v.(string)) + } + if v, ok := ParametersMap["values"]; ok { + valuesSet := v.(*schema.Set).List() + for i := range valuesSet { + values := valuesSet[i].(string) + ruleNormalActionParams.Values = append(ruleNormalActionParams.Values, &values) + } + } + ruleNormalAction.Parameters = append(ruleNormalAction.Parameters, &ruleNormalActionParams) + } + } + ruleAction.NormalAction = &ruleNormalAction + } + if RewriteActionMap, ok := helper.InterfaceToMap(ActionsMap, "rewrite_action"); ok { + ruleRewriteAction := teo.RuleRewriteAction{} + if v, ok := RewriteActionMap["action"]; ok { + ruleRewriteAction.Action = helper.String(v.(string)) + } + if v, ok := RewriteActionMap["parameters"]; ok { + for _, item := range v.([]interface{}) { + ParametersMap := item.(map[string]interface{}) + ruleRewriteActionParams := teo.RuleRewriteActionParams{} + if v, ok := ParametersMap["action"]; ok { + ruleRewriteActionParams.Action = helper.String(v.(string)) + } + if v, ok := ParametersMap["name"]; ok { + ruleRewriteActionParams.Name = helper.String(v.(string)) + } + if v, ok := ParametersMap["values"]; ok { + valuesSet := v.(*schema.Set).List() + for i := range valuesSet { + values := valuesSet[i].(string) + ruleRewriteActionParams.Values = append(ruleRewriteActionParams.Values, &values) + } + } + ruleRewriteAction.Parameters = append(ruleRewriteAction.Parameters, &ruleRewriteActionParams) + } + } + ruleAction.RewriteAction = &ruleRewriteAction + } + if CodeActionMap, ok := helper.InterfaceToMap(ActionsMap, "code_action"); ok { + ruleCodeAction := teo.RuleCodeAction{} + if v, ok := CodeActionMap["action"]; ok { + ruleCodeAction.Action = helper.String(v.(string)) + } + if v, ok := CodeActionMap["parameters"]; ok { + for _, item := range v.([]interface{}) { + ParametersMap := item.(map[string]interface{}) + ruleCodeActionParams := teo.RuleCodeActionParams{} + if v, ok := ParametersMap["name"]; ok { + ruleCodeActionParams.Name = helper.String(v.(string)) + } + if v, ok := ParametersMap["values"]; ok { + valuesSet := v.(*schema.Set).List() + for i := range valuesSet { + values := valuesSet[i].(string) + ruleCodeActionParams.Values = append(ruleCodeActionParams.Values, &values) + } + } + if v, ok := ParametersMap["status_code"]; ok { + ruleCodeActionParams.StatusCode = helper.IntInt64(v.(int)) + } + ruleCodeAction.Parameters = append(ruleCodeAction.Parameters, &ruleCodeActionParams) + } + } + ruleAction.CodeAction = &ruleCodeAction + } + ruleItem.Actions = append(ruleItem.Actions, &ruleAction) + } + } + + request.Rules = append(request.Rules, &ruleItem) + } + } + + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseTeoClient().CreateRule(request) + if e != nil { + return retryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + response = result + return nil + }) + + if err != nil { + log.Printf("[CRITAL]%s create teo ruleEngine failed, reason:%+v", logId, err) + return err + } + + ruleId = *response.Response.RuleId + + d.SetId(zoneId + FILED_SP + ruleId) + return resourceTencentCloudTeoRuleEngineRead(d, meta) +} + +func resourceTencentCloudTeoRuleEngineRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_rule_engine.read")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + service := TeoService{client: meta.(*TencentCloudClient).apiV3Conn} + + idSplit := strings.Split(d.Id(), FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + zoneId := idSplit[0] + ruleId := idSplit[1] + + ruleEngine, err := service.DescribeTeoRuleEngine(ctx, zoneId, ruleId) + + if err != nil { + return err + } + + if ruleEngine == nil { + d.SetId("") + return fmt.Errorf("resource `ruleEngine` %s does not exist", ruleId) + } + + if ruleEngine.RuleName != nil { + _ = d.Set("rule_name", ruleEngine.RuleName) + } + + if ruleEngine.Status != nil { + _ = d.Set("status", ruleEngine.Status) + } + + if ruleEngine.Rules != nil { + rulesList := []interface{}{} + for _, rules := range ruleEngine.Rules { + rulesMap := map[string]interface{}{} + if rules.Conditions != nil { + conditionsList := []interface{}{} + for _, conditions := range rules.Conditions { + conditionsMap := map[string]interface{}{} + if conditions.Conditions != nil { + conditionsList := []interface{}{} + for _, conditions := range conditions.Conditions { + conditionsMap := map[string]interface{}{} + if conditions.Operator != nil { + conditionsMap["operator"] = conditions.Operator + } + if conditions.Target != nil { + conditionsMap["target"] = conditions.Target + } + if conditions.Values != nil { + conditionsMap["values"] = conditions.Values + } + + conditionsList = append(conditionsList, conditionsMap) + } + conditionsMap["conditions"] = conditionsList + } + + conditionsList = append(conditionsList, conditionsMap) + } + rulesMap["conditions"] = conditionsList + } + if rules.Actions != nil { + actionsList := []interface{}{} + for _, actions := range rules.Actions { + actionsMap := map[string]interface{}{} + if actions.NormalAction != nil { + normalActionMap := map[string]interface{}{} + if actions.NormalAction.Action != nil { + normalActionMap["action"] = actions.NormalAction.Action + } + if actions.NormalAction.Parameters != nil { + parametersList := []interface{}{} + for _, parameters := range actions.NormalAction.Parameters { + parametersMap := map[string]interface{}{} + if parameters.Name != nil { + parametersMap["name"] = parameters.Name + } + if parameters.Values != nil { + parametersMap["values"] = parameters.Values + } + + parametersList = append(parametersList, parametersMap) + } + normalActionMap["parameters"] = parametersList + } + + actionsMap["normal_action"] = []interface{}{normalActionMap} + } + if actions.RewriteAction != nil { + rewriteActionMap := map[string]interface{}{} + if actions.RewriteAction.Action != nil { + rewriteActionMap["action"] = actions.RewriteAction.Action + } + if actions.RewriteAction.Parameters != nil { + parametersList := []interface{}{} + for _, parameters := range actions.RewriteAction.Parameters { + parametersMap := map[string]interface{}{} + if parameters.Action != nil { + parametersMap["action"] = parameters.Action + } + if parameters.Name != nil { + parametersMap["name"] = parameters.Name + } + if parameters.Values != nil { + parametersMap["values"] = parameters.Values + } + + parametersList = append(parametersList, parametersMap) + } + rewriteActionMap["parameters"] = parametersList + } + + actionsMap["rewrite_action"] = []interface{}{rewriteActionMap} + } + if actions.CodeAction != nil { + codeActionMap := map[string]interface{}{} + if actions.CodeAction.Action != nil { + codeActionMap["action"] = actions.CodeAction.Action + } + if actions.CodeAction.Parameters != nil { + parametersList := []interface{}{} + for _, parameters := range actions.CodeAction.Parameters { + parametersMap := map[string]interface{}{} + if parameters.Name != nil { + parametersMap["name"] = parameters.Name + } + if parameters.Values != nil { + parametersMap["values"] = parameters.Values + } + if parameters.StatusCode != nil { + parametersMap["status_code"] = parameters.StatusCode + } + + parametersList = append(parametersList, parametersMap) + } + codeActionMap["parameters"] = parametersList + } + + actionsMap["code_action"] = []interface{}{codeActionMap} + } + + actionsList = append(actionsList, actionsMap) + } + rulesMap["actions"] = actionsList + } + + rulesList = append(rulesList, rulesMap) + } + _ = d.Set("rules", rulesList) + } + + if ruleEngine.RuleId != nil { + _ = d.Set("rule_id", ruleEngine.RuleId) + } + + return nil +} + +func resourceTencentCloudTeoRuleEngineUpdate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_rule_engine.update")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + + request := teo.NewModifyRuleRequest() + + idSplit := strings.Split(d.Id(), FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + zoneId := idSplit[0] + ruleId := idSplit[1] + + request.ZoneId = &zoneId + request.RuleId = &ruleId + if v, ok := d.GetOk("rule_name"); ok { + request.RuleName = helper.String(v.(string)) + } + if v, ok := d.GetOk("status"); ok { + request.Status = helper.String(v.(string)) + } + if v, ok := d.GetOk("rules"); ok { + for _, item := range v.([]interface{}) { + dMap := item.(map[string]interface{}) + ruleItem := teo.RuleItem{} + if v, ok := dMap["conditions"]; ok { + for _, item := range v.([]interface{}) { + ConditionsMap := item.(map[string]interface{}) + ruleAndConditions := teo.RuleAndConditions{} + if v, ok := ConditionsMap["conditions"]; ok { + for _, item := range v.([]interface{}) { + ConditionsMap := item.(map[string]interface{}) + ruleCondition := teo.RuleCondition{} + if v, ok := ConditionsMap["operator"]; ok { + ruleCondition.Operator = helper.String(v.(string)) + } + if v, ok := ConditionsMap["target"]; ok { + ruleCondition.Target = helper.String(v.(string)) + } + if v, ok := ConditionsMap["values"]; ok { + valuesSet := v.(*schema.Set).List() + for i := range valuesSet { + values := valuesSet[i].(string) + ruleCondition.Values = append(ruleCondition.Values, &values) + } + } + ruleAndConditions.Conditions = append(ruleAndConditions.Conditions, &ruleCondition) + } + } + ruleItem.Conditions = append(ruleItem.Conditions, &ruleAndConditions) + } + } + if v, ok := dMap["actions"]; ok { + for _, item := range v.([]interface{}) { + ActionsMap := item.(map[string]interface{}) + ruleAction := teo.RuleAction{} + if NormalActionMap, ok := helper.InterfaceToMap(ActionsMap, "normal_action"); ok { + ruleNormalAction := teo.RuleNormalAction{} + if v, ok := NormalActionMap["action"]; ok { + ruleNormalAction.Action = helper.String(v.(string)) + } + if v, ok := NormalActionMap["parameters"]; ok { + for _, item := range v.([]interface{}) { + ParametersMap := item.(map[string]interface{}) + ruleNormalActionParams := teo.RuleNormalActionParams{} + if v, ok := ParametersMap["name"]; ok { + ruleNormalActionParams.Name = helper.String(v.(string)) + } + if v, ok := ParametersMap["values"]; ok { + valuesSet := v.(*schema.Set).List() + for i := range valuesSet { + values := valuesSet[i].(string) + ruleNormalActionParams.Values = append(ruleNormalActionParams.Values, &values) + } + } + ruleNormalAction.Parameters = append(ruleNormalAction.Parameters, &ruleNormalActionParams) + } + } + ruleAction.NormalAction = &ruleNormalAction + } + if RewriteActionMap, ok := helper.InterfaceToMap(ActionsMap, "rewrite_action"); ok { + ruleRewriteAction := teo.RuleRewriteAction{} + if v, ok := RewriteActionMap["action"]; ok { + ruleRewriteAction.Action = helper.String(v.(string)) + } + if v, ok := RewriteActionMap["parameters"]; ok { + for _, item := range v.([]interface{}) { + ParametersMap := item.(map[string]interface{}) + ruleRewriteActionParams := teo.RuleRewriteActionParams{} + if v, ok := ParametersMap["action"]; ok { + ruleRewriteActionParams.Action = helper.String(v.(string)) + } + if v, ok := ParametersMap["name"]; ok { + ruleRewriteActionParams.Name = helper.String(v.(string)) + } + if v, ok := ParametersMap["values"]; ok { + valuesSet := v.(*schema.Set).List() + for i := range valuesSet { + values := valuesSet[i].(string) + ruleRewriteActionParams.Values = append(ruleRewriteActionParams.Values, &values) + } + } + ruleRewriteAction.Parameters = append(ruleRewriteAction.Parameters, &ruleRewriteActionParams) + } + } + ruleAction.RewriteAction = &ruleRewriteAction + } + if CodeActionMap, ok := helper.InterfaceToMap(ActionsMap, "code_action"); ok { + ruleCodeAction := teo.RuleCodeAction{} + if v, ok := CodeActionMap["action"]; ok { + ruleCodeAction.Action = helper.String(v.(string)) + } + if v, ok := CodeActionMap["parameters"]; ok { + for _, item := range v.([]interface{}) { + ParametersMap := item.(map[string]interface{}) + ruleCodeActionParams := teo.RuleCodeActionParams{} + if v, ok := ParametersMap["name"]; ok { + ruleCodeActionParams.Name = helper.String(v.(string)) + } + if v, ok := ParametersMap["values"]; ok { + valuesSet := v.(*schema.Set).List() + for i := range valuesSet { + values := valuesSet[i].(string) + ruleCodeActionParams.Values = append(ruleCodeActionParams.Values, &values) + } + } + if v, ok := ParametersMap["status_code"]; ok { + ruleCodeActionParams.StatusCode = helper.IntInt64(v.(int)) + } + ruleCodeAction.Parameters = append(ruleCodeAction.Parameters, &ruleCodeActionParams) + } + } + ruleAction.CodeAction = &ruleCodeAction + } + ruleItem.Actions = append(ruleItem.Actions, &ruleAction) + } + } + + request.Rules = append(request.Rules, &ruleItem) + } + } + + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseTeoClient().ModifyRule(request) + if e != nil { + return retryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + return nil + }) + + if err != nil { + return err + } + + return resourceTencentCloudTeoRuleEngineRead(d, meta) +} + +func resourceTencentCloudTeoRuleEngineDelete(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_rule_engine.delete")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + service := TeoService{client: meta.(*TencentCloudClient).apiV3Conn} + + idSplit := strings.Split(d.Id(), FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + zoneId := idSplit[0] + ruleId := idSplit[1] + + if err := service.DeleteTeoRuleEngineById(ctx, zoneId, ruleId); err != nil { + return err + } + + return nil +} diff --git a/tencentcloud/resource_tc_teo_rule_engine_test.go b/tencentcloud/resource_tc_teo_rule_engine_test.go new file mode 100644 index 0000000000..08a2648472 --- /dev/null +++ b/tencentcloud/resource_tc_teo_rule_engine_test.go @@ -0,0 +1,71 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" +) + +func TestAccTencentCloudNeedFixTeoRuleEngine_basic(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccTeoRuleEngine, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_teo_rule_engine.rule_engine", "id"), + ), + }, + { + ResourceName: "tencentcloud_teo_rule_engine.rule_engine", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccTeoRuleEngine = ` + +resource "tencentcloud_teo_rule_engine" "rule_engine" { + zone_id = tencentcloud_teo_zone.zone.id + rule_name = "rule0" + status = "enable" + + rules { + conditions { + conditions { + operator = "equal" + target = "host" + values = [ + "www.sfurnace.work", + ] + } + } + + actions { + normal_action { + action = "MaxAge" + + parameters { + name = "FollowOrigin" + values = [ + "on", + ] + } + parameters { + name = "MaxAgeTime" + values = [ + "0", + ] + } + } + } + } +} + + +` diff --git a/tencentcloud/resource_tc_teo_security_policy.go b/tencentcloud/resource_tc_teo_security_policy.go new file mode 100644 index 0000000000..c4ac609be2 --- /dev/null +++ b/tencentcloud/resource_tc_teo_security_policy.go @@ -0,0 +1,1663 @@ +/* +Provides a resource to create a teo securityPolicy + +Example Usage + +```hcl +resource "tencentcloud_teo_security_policy" "securityPolicy" { + zone_id = "" + entity = "" + config { + waf_config { + switch = "" + level = "" + mode = "" + waf_rules { + switch = "" + block_rule_ids = "" + observe_rule_ids = "" + } + ai_rule { + mode = "" + } + } + rate_limit_config { + switch = "" + user_rules { + rule_name = "" + threshold = "" + period = "" + action = "" + punish_time = "" + punish_time_unit = "" + rule_status = "" + freq_fields = "" + conditions { + match_from = "" + match_param = "" + operator = "" + match_content = "" + } + rule_priority = "" + } + template { + mode = "" + detail { + mode = "" + id = "" + action = "" + punish_time = "" + threshold = "" + period = "" + } + } + intelligence { + switch = "" + action = "" + } + } + acl_config { + switch = "" + user_rules { + rule_name = "" + action = "" + rule_status = "" + conditions { + match_from = "" + match_param = "" + operator = "" + match_content = "" + } + rule_priority = "" + punish_time = "" + punish_time_unit = "" + name = "" + page_id = "" + redirect_url = "" + response_code = "" + } + } + bot_config { + switch = "" + managed_rule { + rule_id = "" + action = "" + punish_time = "" + punish_time_unit = "" + name = "" + page_id = "" + redirect_url = "" + response_code = "" + trans_managed_ids = "" + alg_managed_ids = "" + cap_managed_ids = "" + mon_managed_ids = "" + drop_managed_ids = "" + } + portrait_rule { + rule_id = "" + alg_managed_ids = "" + cap_managed_ids = "" + mon_managed_ids = "" + drop_managed_ids = "" + switch = "" + } + intelligence_rule { + switch = "" + items { + label = "" + action = "" + } + } + } + switch_config { + web_switch = "" + } + ip_table_config { + switch = "" + rules { + action = "" + match_from = "" + match_content = "" + rule_id = "" + } + } + + } +} + +``` +Import + +teo securityPolicy can be imported using the id, e.g. +``` +$ terraform import tencentcloud_teo_security_policy.securityPolicy securityPolicy_id#entity +``` +*/ +package tencentcloud + +import ( + "context" + "fmt" + "log" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + teo "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220106" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func resourceTencentCloudTeoSecurityPolicy() *schema.Resource { + return &schema.Resource{ + Read: resourceTencentCloudTeoSecurityPolicyRead, + Create: resourceTencentCloudTeoSecurityPolicyCreate, + Update: resourceTencentCloudTeoSecurityPolicyUpdate, + Delete: resourceTencentCloudTeoSecurityPolicyDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ + "zone_id": { + Type: schema.TypeString, + Required: true, + Description: "Site ID.", + }, + + "entity": { + Type: schema.TypeString, + Required: true, + Description: "Subdomain.", + }, + + "config": { + Type: schema.TypeList, + MaxItems: 1, + Required: true, + Description: "Security policy configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "waf_config": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Description: "WAF (Web Application Firewall) Configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "switch": { + Type: schema.TypeString, + Required: true, + Description: "Whether to enable WAF rules. Valid values:- on: Enable.- off: Disable.", + }, + "level": { + Type: schema.TypeString, + Required: true, + Description: "Protection level. Valid values: `loose`, `normal`, `strict`, `stricter`, `custom`.", + }, + "mode": { + Type: schema.TypeString, + Required: true, + Description: "Protection mode. Valid values:- block: use block mode globally, you still can set a group of rules to use observe mode.- observe: use observe mode globally.", + }, + "waf_rules": { + Type: schema.TypeList, + MaxItems: 1, + Required: true, + Description: "WAF Rules Configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "switch": { + Type: schema.TypeString, + Required: true, + Description: "Whether to host the rules' configuration.- on: Enable.- off: Disable.", + }, + "block_rule_ids": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + Required: true, + Description: "Block mode rules list. See details in data source `waf_managed_rules`.", + }, + "observe_rule_ids": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + Optional: true, + Computed: true, + Description: "Observe rules list. See details in data source `waf_managed_rules`.", + }, + }, + }, + }, + "ai_rule": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Description: "AI based rules configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "mode": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "Valid values:- smart_status_close: disabled.- smart_status_open: blocked.- smart_status_observe: observed.", + }, + }, + }, + }, + }, + }, + }, + "rate_limit_config": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Description: "RateLimit Configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "switch": { + Type: schema.TypeString, + Required: true, + Description: "- on: Enable.- off: Disable.", + }, + "user_rules": { + Type: schema.TypeList, + Required: true, + Description: "Custom configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "rule_id": { + Type: schema.TypeInt, + Computed: true, + Description: "Rule ID.", + }, + "rule_name": { + Type: schema.TypeString, + Required: true, + Description: "Rule Name.", + }, + "threshold": { + Type: schema.TypeInt, + Required: true, + Description: "Threshold of the rate limit. Valid value range: 0-4294967294.", + }, + "period": { + Type: schema.TypeInt, + Required: true, + Description: "Period of the rate limit. Valid values: 10, 20, 30, 40, 50, 60 (in seconds).", + }, + "action": { + Type: schema.TypeString, + Required: true, + Description: "Valid values: `monitor`, `drop`.", + }, + "punish_time": { + Type: schema.TypeInt, + Required: true, + Description: "Punish time, Valid value range: 0-2 days.", + }, + "punish_time_unit": { + Type: schema.TypeString, + Required: true, + Description: "Time unit of the punish time. Valid values: `second`,`minutes`,`hour`.", + }, + "rule_status": { + Type: schema.TypeString, + Required: true, + Description: "Status of the rule.", + }, + "freq_fields": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Optional: true, + Description: "Filter words.", + }, + "conditions": { + Type: schema.TypeList, + Required: true, + Description: "Conditions of the rule.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "match_from": { + Type: schema.TypeString, + Required: true, + Description: "Matching field.", + }, + "match_param": { + Type: schema.TypeString, + Required: true, + Description: "Matching string.", + }, + "operator": { + Type: schema.TypeString, + Required: true, + Description: "Matching operator.", + }, + "match_content": { + Type: schema.TypeString, + Required: true, + Description: "Matching content.", + }, + }, + }, + }, + "rule_priority": { + Type: schema.TypeInt, + Required: true, + Description: "Priority of the rule.", + }, + "update_time": { + Type: schema.TypeString, + Computed: true, + Description: "Last modification date.", + }, + }, + }, + }, + "template": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Description: "Default Template.Note: This field may return null, indicating that no valid value can be obtained.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "mode": { + Type: schema.TypeString, + Optional: true, + Description: "Template Name.Note: This field may return null, indicating that no valid value can be obtained.", + }, + "detail": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Description: "Detail of the template.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "mode": { + Type: schema.TypeString, + Optional: true, + Description: "Template Name.Note: This field may return null, indicating that no valid value can be obtained.", + }, + "id": { + Type: schema.TypeInt, + Optional: true, + Description: "Template ID.Note: This field may return null, indicating that no valid value can be obtained.", + }, + "action": { + Type: schema.TypeString, + Optional: true, + Description: "Action to take.", + }, + "punish_time": { + Type: schema.TypeInt, + Optional: true, + Description: "Punish time.", + }, + "threshold": { + Type: schema.TypeInt, + Optional: true, + Description: "Threshold.", + }, + "period": { + Type: schema.TypeInt, + Optional: true, + Description: "Period.", + }, + }, + }, + }, + }, + }, + }, + "intelligence": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Description: "Intelligent client filter.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "switch": { + Type: schema.TypeString, + Optional: true, + Description: "- on: Enable.- off: Disable.", + }, + "action": { + Type: schema.TypeString, + Optional: true, + Description: "Action to take. Valid values: `monitor`, `alg`.", + }, + }, + }, + }, + }, + }, + }, + "acl_config": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Description: "ACL configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "switch": { + Type: schema.TypeString, + Required: true, + Description: "- on: Enable.- off: Disable.", + }, + "user_rules": { + Type: schema.TypeList, + Required: true, + Description: "Custom configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "rule_id": { + Type: schema.TypeInt, + Computed: true, + Description: "Rule ID.", + }, + "rule_name": { + Type: schema.TypeString, + Required: true, + Description: "Rule name.", + }, + "action": { + Type: schema.TypeString, + Required: true, + Description: "Action to take. Valid values: `trans`, `drop`, `monitor`, `ban`, `redirect`, `page`, `alg`.", + }, + "rule_status": { + Type: schema.TypeString, + Required: true, + Description: "Status of the rule.", + }, + "conditions": { + Type: schema.TypeList, + Required: true, + Description: "Conditions of the rule.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "match_from": { + Type: schema.TypeString, + Required: true, + Description: "Matching field.", + }, + "match_param": { + Type: schema.TypeString, + Required: true, + Description: "Matching string.", + }, + "operator": { + Type: schema.TypeString, + Required: true, + Description: "Matching operator.", + }, + "match_content": { + Type: schema.TypeString, + Required: true, + Description: "Matching content.", + }, + }, + }, + }, + "rule_priority": { + Type: schema.TypeInt, + Required: true, + Description: "Priority of the rule. Valid value range: 0-100.", + }, + "update_time": { + Type: schema.TypeString, + Computed: true, + Description: "Last modification date.", + }, + "punish_time": { + Type: schema.TypeInt, + Optional: true, + Description: "Punish time, Valid value range: 0-2 days.", + }, + "punish_time_unit": { + Type: schema.TypeString, + Optional: true, + Description: "Time unit of the punish time. Valid values: `second`, `minutes`, `hour`.", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Name of the custom response page.", + }, + "page_id": { + Type: schema.TypeInt, + Optional: true, + Description: "ID of the custom response page.", + }, + "redirect_url": { + Type: schema.TypeString, + Optional: true, + Description: "Redirect target URL, must be an sub-domain from one of the account's site.", + }, + "response_code": { + Type: schema.TypeInt, + Optional: true, + Description: "Response code to use when redirecting.", + }, + }, + }, + }, + }, + }, + }, + "bot_config": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Description: "Bot Configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "switch": { + Type: schema.TypeString, + Optional: true, + Description: "- on: Enable.- off: Disable.", + }, + "managed_rule": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Description: "Preset rules.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "rule_id": { + Type: schema.TypeInt, + Required: true, + Description: "Rule ID.", + }, + "action": { + Type: schema.TypeString, + Optional: true, + Description: "Action to take. Valid values: `drop`, `trans`, `monitor`, `alg`.", + }, + "punish_time": { + Type: schema.TypeInt, + Optional: true, + Description: "Punish time.", + }, + "punish_time_unit": { + Type: schema.TypeString, + Optional: true, + Description: "Time unit of the punish time.", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Name of the custom response page.", + }, + "page_id": { + Type: schema.TypeInt, + Optional: true, + Description: "ID of the custom response page.", + }, + "redirect_url": { + Type: schema.TypeString, + Optional: true, + Description: "Redirect target URL, must be an sub-domain from one of the account's site.", + }, + "response_code": { + Type: schema.TypeInt, + Optional: true, + Description: "Response code to use when redirecting.", + }, + "trans_managed_ids": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + Optional: true, + Description: "Rules to enable when action is `trans`. See details in data source `bot_managed_rules`.", + }, + "alg_managed_ids": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + Optional: true, + Description: "Rules to enable when action is `alg`. See details in data source `bot_managed_rules`.", + }, + "cap_managed_ids": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + Optional: true, + Description: "Rules to enable when action is `captcha`. See details in data source `bot_managed_rules`.", + }, + "mon_managed_ids": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + Optional: true, + Description: "Rules to enable when action is `monitor`. See details in data source `bot_managed_rules`.", + }, + "drop_managed_ids": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + Optional: true, + Description: "Rules to enable when action is `drop`. See details in data source `bot_managed_rules`.", + }, + }, + }, + }, + "portrait_rule": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Description: "Portrait rule.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "rule_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Rule ID.", + }, + "alg_managed_ids": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + Optional: true, + Description: "Rules to enable when action is `alg`. See details in data source `bot_portrait_rules`.", + }, + "cap_managed_ids": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + Optional: true, + Description: "Rules to enable when action is `captcha`. See details in data source `bot_portrait_rules`.", + }, + "mon_managed_ids": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + Optional: true, + Description: "Rules to enable when action is `monitor`. See details in data source `bot_portrait_rules`.", + }, + "drop_managed_ids": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + Optional: true, + Description: "Rules to enable when action is `drop`. See details in data source `bot_portrait_rules`.", + }, + "switch": { + Type: schema.TypeString, + Optional: true, + Description: "- on: Enable.- off: Disable.", + }, + }, + }, + }, + "intelligence_rule": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Description: "Bot intelligent rule configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "switch": { + Type: schema.TypeString, + Optional: true, + Description: "- on: Enable.- off: Disable.", + }, + "items": { + Type: schema.TypeList, + Optional: true, + Description: "Configuration detail.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "label": { + Type: schema.TypeString, + Optional: true, + Description: "Bot label, valid values: `evil_bot`, `suspect_bot`, `good_bot`, `normal`.", + }, + "action": { + Type: schema.TypeString, + Optional: true, + Description: "Action to take. Valid values: `trans`, `monitor`, `alg`, `captcha`, `drop`.", + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + "switch_config": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Description: "Main switch of 7-layer security.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "web_switch": { + Type: schema.TypeString, + Optional: true, + Description: "- on: Enable.- off: Disable.", + }, + }, + }, + }, + "ip_table_config": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Description: "Basic access control.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "switch": { + Type: schema.TypeString, + Optional: true, + Description: "- on: Enable.- off: Disable.", + }, + "rules": { + Type: schema.TypeList, + Optional: true, + Description: "Rules list.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "action": { + Type: schema.TypeString, + Optional: true, + Description: "Actions to take. Valid values: `drop`, `trans`, `monitor`.", + }, + "match_from": { + Type: schema.TypeString, + Optional: true, + Description: "Matching type. Valid values: `ip`, `area`.", + }, + "match_content": { + Type: schema.TypeString, + Optional: true, + Description: "Matching content.", + }, + "rule_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Rule ID.", + }, + "update_time": { + Type: schema.TypeString, + Computed: true, + Description: "Last modification date.", + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + } +} + +func resourceTencentCloudTeoSecurityPolicyCreate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_security_policy.create")() + defer inconsistentCheck(d, meta)() + + var ( + zoneId string + entity string + ) + + if v, ok := d.GetOk("zone_id"); ok { + zoneId = v.(string) + } + + if v, ok := d.GetOk("entity"); ok { + entity = v.(string) + } + + d.SetId(zoneId + FILED_SP + entity) + return resourceTencentCloudTeoSecurityPolicyUpdate(d, meta) +} + +func resourceTencentCloudTeoSecurityPolicyRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_security_policy.read")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + service := TeoService{client: meta.(*TencentCloudClient).apiV3Conn} + + idSplit := strings.Split(d.Id(), FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + zoneId := idSplit[0] + entity := idSplit[1] + + securityPolicy, err := service.DescribeTeoSecurityPolicy(ctx, zoneId, entity) + + if err != nil { + return err + } + + if securityPolicy == nil { + d.SetId("") + return fmt.Errorf("resource `securityPolicy` %s does not exist", d.Id()) + } + + if securityPolicy.ZoneId != nil { + _ = d.Set("zone_id", securityPolicy.ZoneId) + } + + if securityPolicy.Entity != nil { + _ = d.Set("entity", securityPolicy.Entity) + } + + if securityPolicy.Config != nil { + configMap := map[string]interface{}{} + if securityPolicy.Config.WafConfig != nil { + wafConfigMap := map[string]interface{}{} + if securityPolicy.Config.WafConfig.Switch != nil { + wafConfigMap["switch"] = securityPolicy.Config.WafConfig.Switch + } + if securityPolicy.Config.WafConfig.Level != nil { + wafConfigMap["level"] = securityPolicy.Config.WafConfig.Level + } + if securityPolicy.Config.WafConfig.Mode != nil { + wafConfigMap["mode"] = securityPolicy.Config.WafConfig.Mode + } + if securityPolicy.Config.WafConfig.WafRules != nil { + wafRulesMap := map[string]interface{}{} + if securityPolicy.Config.WafConfig.WafRules.Switch != nil { + wafRulesMap["switch"] = securityPolicy.Config.WafConfig.WafRules.Switch + } + if securityPolicy.Config.WafConfig.WafRules.BlockRuleIDs != nil { + wafRulesMap["block_rule_ids"] = securityPolicy.Config.WafConfig.WafRules.BlockRuleIDs + } + if securityPolicy.Config.WafConfig.WafRules.ObserveRuleIDs != nil { + wafRulesMap["observe_rule_ids"] = securityPolicy.Config.WafConfig.WafRules.ObserveRuleIDs + } + + wafConfigMap["waf_rules"] = []interface{}{wafRulesMap} + } + if securityPolicy.Config.WafConfig.AiRule != nil { + aiRuleMap := map[string]interface{}{} + if securityPolicy.Config.WafConfig.AiRule.Mode != nil { + aiRuleMap["mode"] = securityPolicy.Config.WafConfig.AiRule.Mode + } + + wafConfigMap["ai_rule"] = []interface{}{aiRuleMap} + } + + configMap["waf_config"] = []interface{}{wafConfigMap} + } + if securityPolicy.Config.RateLimitConfig != nil { + rateLimitConfigMap := map[string]interface{}{} + if securityPolicy.Config.RateLimitConfig.Switch != nil { + rateLimitConfigMap["switch"] = securityPolicy.Config.RateLimitConfig.Switch + } + if securityPolicy.Config.RateLimitConfig.UserRules != nil { + userRulesList := []interface{}{} + for _, userRules := range securityPolicy.Config.RateLimitConfig.UserRules { + userRulesMap := map[string]interface{}{} + if userRules.RuleID != nil { + userRulesMap["rule_id"] = userRules.RuleID + } + if userRules.RuleName != nil { + userRulesMap["rule_name"] = userRules.RuleName + } + if userRules.Threshold != nil { + userRulesMap["threshold"] = userRules.Threshold + } + if userRules.Period != nil { + userRulesMap["period"] = userRules.Period + } + if userRules.Action != nil { + userRulesMap["action"] = userRules.Action + } + if userRules.PunishTime != nil { + userRulesMap["punish_time"] = userRules.PunishTime + } + if userRules.PunishTimeUnit != nil { + userRulesMap["punish_time_unit"] = userRules.PunishTimeUnit + } + if userRules.RuleStatus != nil { + userRulesMap["rule_status"] = userRules.RuleStatus + } + if userRules.FreqFields != nil { + userRulesMap["freq_fields"] = userRules.FreqFields + } + if userRules.Conditions != nil { + conditionsList := []interface{}{} + for _, conditions := range userRules.Conditions { + conditionsMap := map[string]interface{}{} + if conditions.MatchFrom != nil { + conditionsMap["match_from"] = conditions.MatchFrom + } + if conditions.MatchParam != nil { + conditionsMap["match_param"] = conditions.MatchParam + } + if conditions.Operator != nil { + conditionsMap["operator"] = conditions.Operator + } + if conditions.MatchContent != nil { + conditionsMap["match_content"] = conditions.MatchContent + } + + conditionsList = append(conditionsList, conditionsMap) + } + userRulesMap["conditions"] = conditionsList + } + if userRules.RulePriority != nil { + userRulesMap["rule_priority"] = userRules.RulePriority + } + if userRules.UpdateTime != nil { + userRulesMap["update_time"] = userRules.UpdateTime + } + + userRulesList = append(userRulesList, userRulesMap) + } + rateLimitConfigMap["user_rules"] = userRulesList + } + if securityPolicy.Config.RateLimitConfig.Template != nil { + templateMap := map[string]interface{}{} + if securityPolicy.Config.RateLimitConfig.Template.Mode != nil { + templateMap["mode"] = securityPolicy.Config.RateLimitConfig.Template.Mode + } + if securityPolicy.Config.RateLimitConfig.Template.Detail != nil { + detailMap := map[string]interface{}{} + if securityPolicy.Config.RateLimitConfig.Template.Detail.Mode != nil { + detailMap["mode"] = securityPolicy.Config.RateLimitConfig.Template.Detail.Mode + } + if securityPolicy.Config.RateLimitConfig.Template.Detail.ID != nil { + detailMap["id"] = securityPolicy.Config.RateLimitConfig.Template.Detail.ID + } + if securityPolicy.Config.RateLimitConfig.Template.Detail.Action != nil { + detailMap["action"] = securityPolicy.Config.RateLimitConfig.Template.Detail.Action + } + if securityPolicy.Config.RateLimitConfig.Template.Detail.PunishTime != nil { + detailMap["punish_time"] = securityPolicy.Config.RateLimitConfig.Template.Detail.PunishTime + } + if securityPolicy.Config.RateLimitConfig.Template.Detail.Threshold != nil { + detailMap["threshold"] = securityPolicy.Config.RateLimitConfig.Template.Detail.Threshold + } + if securityPolicy.Config.RateLimitConfig.Template.Detail.Period != nil { + detailMap["period"] = securityPolicy.Config.RateLimitConfig.Template.Detail.Period + } + + templateMap["detail"] = []interface{}{detailMap} + } + + rateLimitConfigMap["template"] = []interface{}{templateMap} + } + if securityPolicy.Config.RateLimitConfig.Intelligence != nil { + intelligenceMap := map[string]interface{}{} + if securityPolicy.Config.RateLimitConfig.Intelligence.Switch != nil { + intelligenceMap["switch"] = securityPolicy.Config.RateLimitConfig.Intelligence.Switch + } + if securityPolicy.Config.RateLimitConfig.Intelligence.Action != nil { + intelligenceMap["action"] = securityPolicy.Config.RateLimitConfig.Intelligence.Action + } + + rateLimitConfigMap["intelligence"] = []interface{}{intelligenceMap} + } + + configMap["rate_limit_config"] = []interface{}{rateLimitConfigMap} + } + if securityPolicy.Config.AclConfig != nil { + aclConfigMap := map[string]interface{}{} + if securityPolicy.Config.AclConfig.Switch != nil { + aclConfigMap["switch"] = securityPolicy.Config.AclConfig.Switch + } + if securityPolicy.Config.AclConfig.UserRules != nil { + userRulesList := []interface{}{} + for _, userRules := range securityPolicy.Config.AclConfig.UserRules { + userRulesMap := map[string]interface{}{} + if userRules.RuleID != nil { + userRulesMap["rule_id"] = userRules.RuleID + } + if userRules.RuleName != nil { + userRulesMap["rule_name"] = userRules.RuleName + } + if userRules.Action != nil { + userRulesMap["action"] = userRules.Action + } + if userRules.RuleStatus != nil { + userRulesMap["rule_status"] = userRules.RuleStatus + } + if userRules.Conditions != nil { + conditionsList := []interface{}{} + for _, conditions := range userRules.Conditions { + conditionsMap := map[string]interface{}{} + if conditions.MatchFrom != nil { + conditionsMap["match_from"] = conditions.MatchFrom + } + if conditions.MatchParam != nil { + conditionsMap["match_param"] = conditions.MatchParam + } + if conditions.Operator != nil { + conditionsMap["operator"] = conditions.Operator + } + if conditions.MatchContent != nil { + conditionsMap["match_content"] = conditions.MatchContent + } + + conditionsList = append(conditionsList, conditionsMap) + } + userRulesMap["conditions"] = conditionsList + } + if userRules.RulePriority != nil { + userRulesMap["rule_priority"] = userRules.RulePriority + } + if userRules.UpdateTime != nil { + userRulesMap["update_time"] = userRules.UpdateTime + } + if userRules.PunishTime != nil { + userRulesMap["punish_time"] = userRules.PunishTime + } + if userRules.PunishTimeUnit != nil { + userRulesMap["punish_time_unit"] = userRules.PunishTimeUnit + } + if userRules.Name != nil { + userRulesMap["name"] = userRules.Name + } + if userRules.PageId != nil { + userRulesMap["page_id"] = userRules.PageId + } + if userRules.RedirectUrl != nil { + userRulesMap["redirect_url"] = userRules.RedirectUrl + } + if userRules.ResponseCode != nil { + userRulesMap["response_code"] = userRules.ResponseCode + } + + userRulesList = append(userRulesList, userRulesMap) + } + aclConfigMap["user_rules"] = userRulesList + } + + configMap["acl_config"] = []interface{}{aclConfigMap} + } + if securityPolicy.Config.BotConfig != nil { + botConfigMap := map[string]interface{}{} + if securityPolicy.Config.BotConfig.Switch != nil { + botConfigMap["switch"] = securityPolicy.Config.BotConfig.Switch + } + if securityPolicy.Config.BotConfig.ManagedRule != nil { + managedRuleMap := map[string]interface{}{} + if securityPolicy.Config.BotConfig.ManagedRule.RuleID != nil { + managedRuleMap["rule_id"] = securityPolicy.Config.BotConfig.ManagedRule.RuleID + } + if securityPolicy.Config.BotConfig.ManagedRule.Action != nil { + managedRuleMap["action"] = securityPolicy.Config.BotConfig.ManagedRule.Action + } + if securityPolicy.Config.BotConfig.ManagedRule.PunishTime != nil { + managedRuleMap["punish_time"] = securityPolicy.Config.BotConfig.ManagedRule.PunishTime + } + if securityPolicy.Config.BotConfig.ManagedRule.PunishTimeUnit != nil { + managedRuleMap["punish_time_unit"] = securityPolicy.Config.BotConfig.ManagedRule.PunishTimeUnit + } + if securityPolicy.Config.BotConfig.ManagedRule.Name != nil { + managedRuleMap["name"] = securityPolicy.Config.BotConfig.ManagedRule.Name + } + if securityPolicy.Config.BotConfig.ManagedRule.PageId != nil { + managedRuleMap["page_id"] = securityPolicy.Config.BotConfig.ManagedRule.PageId + } + if securityPolicy.Config.BotConfig.ManagedRule.RedirectUrl != nil { + managedRuleMap["redirect_url"] = securityPolicy.Config.BotConfig.ManagedRule.RedirectUrl + } + if securityPolicy.Config.BotConfig.ManagedRule.ResponseCode != nil { + managedRuleMap["response_code"] = securityPolicy.Config.BotConfig.ManagedRule.ResponseCode + } + if securityPolicy.Config.BotConfig.ManagedRule.TransManagedIds != nil { + managedRuleMap["trans_managed_ids"] = securityPolicy.Config.BotConfig.ManagedRule.TransManagedIds + } + if securityPolicy.Config.BotConfig.ManagedRule.AlgManagedIds != nil { + managedRuleMap["alg_managed_ids"] = securityPolicy.Config.BotConfig.ManagedRule.AlgManagedIds + } + if securityPolicy.Config.BotConfig.ManagedRule.CapManagedIds != nil { + managedRuleMap["cap_managed_ids"] = securityPolicy.Config.BotConfig.ManagedRule.CapManagedIds + } + if securityPolicy.Config.BotConfig.ManagedRule.MonManagedIds != nil { + managedRuleMap["mon_managed_ids"] = securityPolicy.Config.BotConfig.ManagedRule.MonManagedIds + } + if securityPolicy.Config.BotConfig.ManagedRule.DropManagedIds != nil { + managedRuleMap["drop_managed_ids"] = securityPolicy.Config.BotConfig.ManagedRule.DropManagedIds + } + + botConfigMap["managed_rule"] = []interface{}{managedRuleMap} + } + if securityPolicy.Config.BotConfig.PortraitRule != nil { + portraitRuleMap := map[string]interface{}{} + if securityPolicy.Config.BotConfig.PortraitRule.RuleID != nil { + portraitRuleMap["rule_id"] = securityPolicy.Config.BotConfig.PortraitRule.RuleID + } + if securityPolicy.Config.BotConfig.PortraitRule.AlgManagedIds != nil { + portraitRuleMap["alg_managed_ids"] = securityPolicy.Config.BotConfig.PortraitRule.AlgManagedIds + } + if securityPolicy.Config.BotConfig.PortraitRule.CapManagedIds != nil { + portraitRuleMap["cap_managed_ids"] = securityPolicy.Config.BotConfig.PortraitRule.CapManagedIds + } + if securityPolicy.Config.BotConfig.PortraitRule.MonManagedIds != nil { + portraitRuleMap["mon_managed_ids"] = securityPolicy.Config.BotConfig.PortraitRule.MonManagedIds + } + if securityPolicy.Config.BotConfig.PortraitRule.DropManagedIds != nil { + portraitRuleMap["drop_managed_ids"] = securityPolicy.Config.BotConfig.PortraitRule.DropManagedIds + } + if securityPolicy.Config.BotConfig.PortraitRule.Switch != nil { + portraitRuleMap["switch"] = securityPolicy.Config.BotConfig.PortraitRule.Switch + } + + botConfigMap["portrait_rule"] = []interface{}{portraitRuleMap} + } + if securityPolicy.Config.BotConfig.IntelligenceRule != nil { + intelligenceRuleMap := map[string]interface{}{} + if securityPolicy.Config.BotConfig.IntelligenceRule.Switch != nil { + intelligenceRuleMap["switch"] = securityPolicy.Config.BotConfig.IntelligenceRule.Switch + } + if securityPolicy.Config.BotConfig.IntelligenceRule.Items != nil { + itemsList := []interface{}{} + for _, items := range securityPolicy.Config.BotConfig.IntelligenceRule.Items { + itemsMap := map[string]interface{}{} + if items.Label != nil { + itemsMap["label"] = items.Label + } + if items.Action != nil { + itemsMap["action"] = items.Action + } + + itemsList = append(itemsList, itemsMap) + } + intelligenceRuleMap["items"] = itemsList + } + + botConfigMap["intelligence_rule"] = []interface{}{intelligenceRuleMap} + } + + configMap["bot_config"] = []interface{}{botConfigMap} + } + if securityPolicy.Config.SwitchConfig != nil { + switchConfigMap := map[string]interface{}{} + if securityPolicy.Config.SwitchConfig.WebSwitch != nil { + switchConfigMap["web_switch"] = securityPolicy.Config.SwitchConfig.WebSwitch + } + + configMap["switch_config"] = []interface{}{switchConfigMap} + } + if securityPolicy.Config.IpTableConfig != nil { + ipTableConfigMap := map[string]interface{}{} + if securityPolicy.Config.IpTableConfig.Switch != nil { + ipTableConfigMap["switch"] = securityPolicy.Config.IpTableConfig.Switch + } + if securityPolicy.Config.IpTableConfig.Rules != nil { + rulesList := []interface{}{} + for _, rules := range securityPolicy.Config.IpTableConfig.Rules { + rulesMap := map[string]interface{}{} + if rules.Action != nil { + rulesMap["action"] = rules.Action + } + if rules.MatchFrom != nil { + rulesMap["match_from"] = rules.MatchFrom + } + if rules.MatchContent != nil { + rulesMap["match_content"] = rules.MatchContent + } + if rules.RuleID != nil { + rulesMap["rule_id"] = rules.RuleID + } + if rules.UpdateTime != nil { + rulesMap["update_time"] = rules.UpdateTime + } + + rulesList = append(rulesList, rulesMap) + } + ipTableConfigMap["rules"] = rulesList + } + + configMap["ip_table_config"] = []interface{}{ipTableConfigMap} + } + + _ = d.Set("config", []interface{}{configMap}) + } + + return nil +} + +func resourceTencentCloudTeoSecurityPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_security_policy.update")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + + request := teo.NewModifySecurityPolicyRequest() + + idSplit := strings.Split(d.Id(), FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + zoneId := idSplit[0] + entity := idSplit[1] + + request.ZoneId = &zoneId + request.Entity = &entity + + if dMap, ok := helper.InterfacesHeadMap(d, "config"); ok { + securityConfig := teo.SecurityConfig{} + if WafConfigMap, ok := helper.InterfaceToMap(dMap, "waf_config"); ok { + wafConfig := teo.WafConfig{} + if v, ok := WafConfigMap["switch"]; ok { + wafConfig.Switch = helper.String(v.(string)) + } + if v, ok := WafConfigMap["level"]; ok { + wafConfig.Level = helper.String(v.(string)) + } + if v, ok := WafConfigMap["mode"]; ok { + wafConfig.Mode = helper.String(v.(string)) + } + if WafRulesMap, ok := helper.InterfaceToMap(WafConfigMap, "waf_rules"); ok { + wafRule := teo.WafRule{} + if v, ok := WafRulesMap["switch"]; ok { + wafRule.Switch = helper.String(v.(string)) + } + if v, ok := WafRulesMap["block_rule_ids"]; ok { + blockRuleIDsSet := v.(*schema.Set).List() + for i := range blockRuleIDsSet { + blockRuleIDs := blockRuleIDsSet[i].(int) + wafRule.BlockRuleIDs = append(wafRule.BlockRuleIDs, helper.IntInt64(blockRuleIDs)) + } + } + if v, ok := WafRulesMap["observe_rule_ids"]; ok { + observeRuleIDsSet := v.(*schema.Set).List() + for i := range observeRuleIDsSet { + observeRuleIDs := observeRuleIDsSet[i].(int) + wafRule.ObserveRuleIDs = append(wafRule.ObserveRuleIDs, helper.IntInt64(observeRuleIDs)) + } + } + wafConfig.WafRules = &wafRule + } + if AiRuleMap, ok := helper.InterfaceToMap(WafConfigMap, "ai_rule"); ok { + aiRule := teo.AiRule{} + if v, ok := AiRuleMap["mode"]; ok { + aiRule.Mode = helper.String(v.(string)) + } + wafConfig.AiRule = &aiRule + } + securityConfig.WafConfig = &wafConfig + } + if RateLimitConfigMap, ok := helper.InterfaceToMap(dMap, "rate_limit_config"); ok { + rateLimitConfig := teo.RateLimitConfig{} + if v, ok := RateLimitConfigMap["switch"]; ok { + rateLimitConfig.Switch = helper.String(v.(string)) + } + if v, ok := RateLimitConfigMap["user_rules"]; ok { + for _, item := range v.([]interface{}) { + UserRulesMap := item.(map[string]interface{}) + rateLimitUserRule := teo.RateLimitUserRule{} + if v, ok := UserRulesMap["rule_name"]; ok { + rateLimitUserRule.RuleName = helper.String(v.(string)) + } + if v, ok := UserRulesMap["threshold"]; ok { + rateLimitUserRule.Threshold = helper.IntInt64(v.(int)) + } + if v, ok := UserRulesMap["period"]; ok { + rateLimitUserRule.Period = helper.IntInt64(v.(int)) + } + if v, ok := UserRulesMap["action"]; ok { + rateLimitUserRule.Action = helper.String(v.(string)) + } + if v, ok := UserRulesMap["punish_time"]; ok { + rateLimitUserRule.PunishTime = helper.IntInt64(v.(int)) + } + if v, ok := UserRulesMap["punish_time_unit"]; ok { + rateLimitUserRule.PunishTimeUnit = helper.String(v.(string)) + } + if v, ok := UserRulesMap["rule_status"]; ok { + rateLimitUserRule.RuleStatus = helper.String(v.(string)) + } + if v, ok := UserRulesMap["freq_fields"]; ok { + freqFieldsSet := v.(*schema.Set).List() + for i := range freqFieldsSet { + freqFields := freqFieldsSet[i].(string) + rateLimitUserRule.FreqFields = append(rateLimitUserRule.FreqFields, &freqFields) + } + } + if v, ok := UserRulesMap["conditions"]; ok { + for _, item := range v.([]interface{}) { + ConditionsMap := item.(map[string]interface{}) + aCLCondition := teo.ACLCondition{} + if v, ok := ConditionsMap["match_from"]; ok { + aCLCondition.MatchFrom = helper.String(v.(string)) + } + if v, ok := ConditionsMap["match_param"]; ok { + aCLCondition.MatchParam = helper.String(v.(string)) + } + if v, ok := ConditionsMap["operator"]; ok { + aCLCondition.Operator = helper.String(v.(string)) + } + if v, ok := ConditionsMap["match_content"]; ok { + aCLCondition.MatchContent = helper.String(v.(string)) + } + rateLimitUserRule.Conditions = append(rateLimitUserRule.Conditions, &aCLCondition) + } + } + if v, ok := UserRulesMap["rule_priority"]; ok { + rateLimitUserRule.RulePriority = helper.IntInt64(v.(int)) + } + rateLimitConfig.UserRules = append(rateLimitConfig.UserRules, &rateLimitUserRule) + } + } + if TemplateMap, ok := helper.InterfaceToMap(RateLimitConfigMap, "template"); ok { + rateLimitTemplate := teo.RateLimitTemplate{} + if v, ok := TemplateMap["mode"]; ok { + rateLimitTemplate.Mode = helper.String(v.(string)) + } + if DetailMap, ok := helper.InterfaceToMap(TemplateMap, "detail"); ok { + rateLimitTemplateDetail := teo.RateLimitTemplateDetail{} + if v, ok := DetailMap["mode"]; ok { + rateLimitTemplateDetail.Mode = helper.String(v.(string)) + } + if v, ok := DetailMap["id"]; ok { + rateLimitTemplateDetail.ID = helper.IntInt64(v.(int)) + } + if v, ok := DetailMap["action"]; ok { + rateLimitTemplateDetail.Action = helper.String(v.(string)) + } + if v, ok := DetailMap["punish_time"]; ok { + rateLimitTemplateDetail.PunishTime = helper.IntInt64(v.(int)) + } + if v, ok := DetailMap["threshold"]; ok { + rateLimitTemplateDetail.Threshold = helper.IntInt64(v.(int)) + } + if v, ok := DetailMap["period"]; ok { + rateLimitTemplateDetail.Period = helper.IntInt64(v.(int)) + } + rateLimitTemplate.Detail = &rateLimitTemplateDetail + } + rateLimitConfig.Template = &rateLimitTemplate + } + if IntelligenceMap, ok := helper.InterfaceToMap(RateLimitConfigMap, "intelligence"); ok { + rateLimitIntelligence := teo.RateLimitIntelligence{} + if v, ok := IntelligenceMap["switch"]; ok { + rateLimitIntelligence.Switch = helper.String(v.(string)) + } + if v, ok := IntelligenceMap["action"]; ok { + rateLimitIntelligence.Action = helper.String(v.(string)) + } + rateLimitConfig.Intelligence = &rateLimitIntelligence + } + securityConfig.RateLimitConfig = &rateLimitConfig + } + if AclConfigMap, ok := helper.InterfaceToMap(dMap, "acl_config"); ok { + aclConfig := teo.AclConfig{} + if v, ok := AclConfigMap["switch"]; ok { + aclConfig.Switch = helper.String(v.(string)) + } + if v, ok := AclConfigMap["user_rules"]; ok { + for _, item := range v.([]interface{}) { + UserRulesMap := item.(map[string]interface{}) + aCLUserRule := teo.ACLUserRule{} + if v, ok := UserRulesMap["rule_name"]; ok { + aCLUserRule.RuleName = helper.String(v.(string)) + } + if v, ok := UserRulesMap["action"]; ok { + aCLUserRule.Action = helper.String(v.(string)) + } + if v, ok := UserRulesMap["rule_status"]; ok { + aCLUserRule.RuleStatus = helper.String(v.(string)) + } + if v, ok := UserRulesMap["conditions"]; ok { + for _, item := range v.([]interface{}) { + ConditionsMap := item.(map[string]interface{}) + aCLCondition := teo.ACLCondition{} + if v, ok := ConditionsMap["match_from"]; ok { + aCLCondition.MatchFrom = helper.String(v.(string)) + } + if v, ok := ConditionsMap["match_param"]; ok { + aCLCondition.MatchParam = helper.String(v.(string)) + } + if v, ok := ConditionsMap["operator"]; ok { + aCLCondition.Operator = helper.String(v.(string)) + } + if v, ok := ConditionsMap["match_content"]; ok { + aCLCondition.MatchContent = helper.String(v.(string)) + } + aCLUserRule.Conditions = append(aCLUserRule.Conditions, &aCLCondition) + } + } + if v, ok := UserRulesMap["rule_priority"]; ok { + aCLUserRule.RulePriority = helper.IntInt64(v.(int)) + } + if v, ok := UserRulesMap["punish_time"]; ok { + aCLUserRule.PunishTime = helper.IntInt64(v.(int)) + } + if v, ok := UserRulesMap["punish_time_unit"]; ok { + aCLUserRule.PunishTimeUnit = helper.String(v.(string)) + } + if v, ok := UserRulesMap["name"]; ok { + aCLUserRule.Name = helper.String(v.(string)) + } + if v, ok := UserRulesMap["page_id"]; ok { + aCLUserRule.PageId = helper.IntInt64(v.(int)) + } + if v, ok := UserRulesMap["redirect_url"]; ok { + aCLUserRule.RedirectUrl = helper.String(v.(string)) + } + if v, ok := UserRulesMap["response_code"]; ok { + aCLUserRule.ResponseCode = helper.IntInt64(v.(int)) + } + aclConfig.UserRules = append(aclConfig.UserRules, &aCLUserRule) + } + } + securityConfig.AclConfig = &aclConfig + } + if BotConfigMap, ok := helper.InterfaceToMap(dMap, "bot_config"); ok { + botConfig := teo.BotConfig{} + if v, ok := BotConfigMap["switch"]; ok { + botConfig.Switch = helper.String(v.(string)) + } + if ManagedRuleMap, ok := helper.InterfaceToMap(BotConfigMap, "managed_rule"); ok { + botManagedRule := teo.BotManagedRule{} + if v, ok := ManagedRuleMap["rule_id"]; ok { + botManagedRule.RuleID = helper.IntInt64(v.(int)) + } + if v, ok := ManagedRuleMap["action"]; ok { + botManagedRule.Action = helper.String(v.(string)) + } + if v, ok := ManagedRuleMap["punish_time"]; ok { + botManagedRule.PunishTime = helper.IntInt64(v.(int)) + } + if v, ok := ManagedRuleMap["punish_time_unit"]; ok { + botManagedRule.PunishTimeUnit = helper.String(v.(string)) + } + if v, ok := ManagedRuleMap["name"]; ok { + botManagedRule.Name = helper.String(v.(string)) + } + if v, ok := ManagedRuleMap["page_id"]; ok { + botManagedRule.PageId = helper.IntInt64(v.(int)) + } + if v, ok := ManagedRuleMap["redirect_url"]; ok { + botManagedRule.RedirectUrl = helper.String(v.(string)) + } + if v, ok := ManagedRuleMap["response_code"]; ok { + botManagedRule.ResponseCode = helper.IntInt64(v.(int)) + } + if v, ok := ManagedRuleMap["trans_managed_ids"]; ok { + transManagedIdsSet := v.(*schema.Set).List() + for i := range transManagedIdsSet { + transManagedIds := transManagedIdsSet[i].(int) + botManagedRule.TransManagedIds = append(botManagedRule.TransManagedIds, helper.IntInt64(transManagedIds)) + } + } + if v, ok := ManagedRuleMap["alg_managed_ids"]; ok { + algManagedIdsSet := v.(*schema.Set).List() + for i := range algManagedIdsSet { + algManagedIds := algManagedIdsSet[i].(int) + botManagedRule.AlgManagedIds = append(botManagedRule.AlgManagedIds, helper.IntInt64(algManagedIds)) + } + } + if v, ok := ManagedRuleMap["cap_managed_ids"]; ok { + capManagedIdsSet := v.(*schema.Set).List() + for i := range capManagedIdsSet { + capManagedIds := capManagedIdsSet[i].(int) + botManagedRule.CapManagedIds = append(botManagedRule.CapManagedIds, helper.IntInt64(capManagedIds)) + } + } + if v, ok := ManagedRuleMap["mon_managed_ids"]; ok { + monManagedIdsSet := v.(*schema.Set).List() + for i := range monManagedIdsSet { + monManagedIds := monManagedIdsSet[i].(int) + botManagedRule.MonManagedIds = append(botManagedRule.MonManagedIds, helper.IntInt64(monManagedIds)) + } + } + if v, ok := ManagedRuleMap["drop_managed_ids"]; ok { + dropManagedIdsSet := v.(*schema.Set).List() + for i := range dropManagedIdsSet { + dropManagedIds := dropManagedIdsSet[i].(int) + botManagedRule.DropManagedIds = append(botManagedRule.DropManagedIds, helper.IntInt64(dropManagedIds)) + } + } + botConfig.ManagedRule = &botManagedRule + } + if PortraitRuleMap, ok := helper.InterfaceToMap(BotConfigMap, "portrait_rule"); ok { + botPortraitRule := teo.BotPortraitRule{} + if v, ok := PortraitRuleMap["rule_id"]; ok { + botPortraitRule.RuleID = helper.IntInt64(v.(int)) + } + if v, ok := PortraitRuleMap["alg_managed_ids"]; ok { + algManagedIdsSet := v.(*schema.Set).List() + for i := range algManagedIdsSet { + algManagedIds := algManagedIdsSet[i].(int) + botPortraitRule.AlgManagedIds = append(botPortraitRule.AlgManagedIds, helper.IntInt64(algManagedIds)) + } + } + if v, ok := PortraitRuleMap["cap_managed_ids"]; ok { + capManagedIdsSet := v.(*schema.Set).List() + for i := range capManagedIdsSet { + capManagedIds := capManagedIdsSet[i].(int) + botPortraitRule.CapManagedIds = append(botPortraitRule.CapManagedIds, helper.IntInt64(capManagedIds)) + } + } + if v, ok := PortraitRuleMap["mon_managed_ids"]; ok { + monManagedIdsSet := v.(*schema.Set).List() + for i := range monManagedIdsSet { + monManagedIds := monManagedIdsSet[i].(int) + botPortraitRule.MonManagedIds = append(botPortraitRule.MonManagedIds, helper.IntInt64(monManagedIds)) + } + } + if v, ok := PortraitRuleMap["drop_managed_ids"]; ok { + dropManagedIdsSet := v.(*schema.Set).List() + for i := range dropManagedIdsSet { + dropManagedIds := dropManagedIdsSet[i].(int) + botPortraitRule.DropManagedIds = append(botPortraitRule.DropManagedIds, helper.IntInt64(dropManagedIds)) + } + } + if v, ok := PortraitRuleMap["switch"]; ok { + botPortraitRule.Switch = helper.String(v.(string)) + } + botConfig.PortraitRule = &botPortraitRule + } + if IntelligenceRuleMap, ok := helper.InterfaceToMap(BotConfigMap, "intelligence_rule"); ok { + intelligenceRule := teo.IntelligenceRule{} + if v, ok := IntelligenceRuleMap["switch"]; ok { + intelligenceRule.Switch = helper.String(v.(string)) + } + if v, ok := IntelligenceRuleMap["items"]; ok { + for _, item := range v.([]interface{}) { + ItemsMap := item.(map[string]interface{}) + intelligenceRuleItem := teo.IntelligenceRuleItem{} + if v, ok := ItemsMap["label"]; ok { + intelligenceRuleItem.Label = helper.String(v.(string)) + } + if v, ok := ItemsMap["action"]; ok { + intelligenceRuleItem.Action = helper.String(v.(string)) + } + intelligenceRule.Items = append(intelligenceRule.Items, &intelligenceRuleItem) + } + } + botConfig.IntelligenceRule = &intelligenceRule + } + securityConfig.BotConfig = &botConfig + } + if SwitchConfigMap, ok := helper.InterfaceToMap(dMap, "switch_config"); ok { + switchConfig := teo.SwitchConfig{} + if v, ok := SwitchConfigMap["web_switch"]; ok { + switchConfig.WebSwitch = helper.String(v.(string)) + } + securityConfig.SwitchConfig = &switchConfig + } + if IpTableConfigMap, ok := helper.InterfaceToMap(dMap, "ip_table_config"); ok { + ipTableConfig := teo.IpTableConfig{} + if v, ok := IpTableConfigMap["switch"]; ok { + ipTableConfig.Switch = helper.String(v.(string)) + } + if v, ok := IpTableConfigMap["rules"]; ok { + for _, item := range v.([]interface{}) { + RulesMap := item.(map[string]interface{}) + ipTableRule := teo.IpTableRule{} + if v, ok := RulesMap["action"]; ok { + ipTableRule.Action = helper.String(v.(string)) + } + if v, ok := RulesMap["match_from"]; ok { + ipTableRule.MatchFrom = helper.String(v.(string)) + } + if v, ok := RulesMap["match_content"]; ok { + ipTableRule.MatchContent = helper.String(v.(string)) + } + if v, ok := RulesMap["rule_id"]; ok { + ipTableRule.RuleID = helper.IntInt64(v.(int)) + } + ipTableConfig.Rules = append(ipTableConfig.Rules, &ipTableRule) + } + } + securityConfig.IpTableConfig = &ipTableConfig + } + + request.Config = &securityConfig + } + + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseTeoClient().ModifySecurityPolicy(request) + if e != nil { + return retryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + return nil + }) + + if err != nil { + log.Printf("[CRITAL]%s create teo securityPolicy failed, reason:%+v", logId, err) + return err + } + + return resourceTencentCloudTeoSecurityPolicyRead(d, meta) +} + +func resourceTencentCloudTeoSecurityPolicyDelete(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_security_policy.delete")() + defer inconsistentCheck(d, meta)() + + return nil +} diff --git a/tencentcloud/resource_tc_teo_security_policy_test.go b/tencentcloud/resource_tc_teo_security_policy_test.go new file mode 100644 index 0000000000..02f4c71d08 --- /dev/null +++ b/tencentcloud/resource_tc_teo_security_policy_test.go @@ -0,0 +1,155 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" +) + +func TestAccTencentCloudNeedFixTeoSecurityPolicy_basic(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccTeoSecurityPolicy, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_teo_security_policy.securityPolicy", "id"), + ), + }, + { + ResourceName: "tencentcloud_teo_security_policy.securityPolicy", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccTeoSecurityPolicy = ` + +resource "tencentcloud_teo_security_policy" "securityPolicy" { + zone_id = "" + entity = "" + config { + waf_config { + switch = "" + level = "" + mode = "" + waf_rules { + switch = "" + block_rule_i_ds = "" + observe_rule_i_ds = "" + } + ai_rule { + mode = "" + } + } + rate_limit_config { + switch = "" + user_rules { + rule_name = "" + threshold = "" + period = "" + action = "" + punish_time = "" + punish_time_unit = "" + rule_status = "" + freq_fields = "" + conditions { + match_from = "" + match_param = "" + operator = "" + match_content = "" + } + rule_priority = "" + } + template { + mode = "" + detail { + mode = "" + i_d = "" + action = "" + punish_time = "" + threshold = "" + period = "" + } + } + intelligence { + switch = "" + action = "" + } + } + acl_config { + switch = "" + user_rules { + rule_name = "" + action = "" + rule_status = "" + conditions { + match_from = "" + match_param = "" + operator = "" + match_content = "" + } + rule_priority = "" + punish_time = "" + punish_time_unit = "" + name = "" + page_id = "" + redirect_url = "" + response_code = "" + } + } + bot_config { + switch = "" + managed_rule { + rule_i_d = "" + action = "" + punish_time = "" + punish_time_unit = "" + name = "" + page_id = "" + redirect_url = "" + response_code = "" + trans_managed_ids = "" + alg_managed_ids = "" + cap_managed_ids = "" + mon_managed_ids = "" + drop_managed_ids = "" + } + portrait_rule { + rule_i_d = "" + alg_managed_ids = "" + cap_managed_ids = "" + mon_managed_ids = "" + drop_managed_ids = "" + switch = "" + } + intelligence_rule { + switch = "" + items { + label = "" + action = "" + } + } + } + switch_config { + web_switch = "" + } + ip_table_config { + switch = "" + rules { + action = "" + match_from = "" + match_content = "" + rule_i_d = "" + } + } + + } +} + +` diff --git a/tencentcloud/resource_tc_teo_zone.go b/tencentcloud/resource_tc_teo_zone.go new file mode 100644 index 0000000000..e8f8a401b8 --- /dev/null +++ b/tencentcloud/resource_tc_teo_zone.go @@ -0,0 +1,496 @@ +/* +Provides a resource to create a teo zone + +Example Usage + +```hcl +resource "tencentcloud_teo_zone" "zone" { + name = "sfurnace.work" + plan_type = "ent_cm_with_bot" + type = "full" + paused = false + cname_speed_up = "enabled" + + # vanity_name_servers { + # switch = "on" + # servers = ["2.2.2.2"] + # } +} +``` +Import + +teo zone can be imported using the id, e.g. +``` +$ terraform import tencentcloud_teo_zone.zone zone_id +``` +*/ +package tencentcloud + +import ( + "context" + "errors" + "fmt" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + teo "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220106" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func resourceTencentCloudTeoZone() *schema.Resource { + return &schema.Resource{ + Read: resourceTencentCloudTeoZoneRead, + Create: resourceTencentCloudTeoZoneCreate, + Update: resourceTencentCloudTeoZoneUpdate, + Delete: resourceTencentCloudTeoZoneDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + Description: "Site name.", + }, + + "plan_type": { + Type: schema.TypeString, + Required: true, + Description: "Plan type of the zone. See details in data source `zone_available_plans`.", + }, + + "original_name_servers": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Computed: true, + Description: "List of name servers used.", + }, + + "name_servers": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Computed: true, + Description: "List of name servers assigned to users by Tencent Cloud.", + }, + + "status": { + Type: schema.TypeString, + Computed: true, + Description: "Site status.", + }, + + "type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "Specifies how the site is connected to EdgeOne.", + }, + + "paused": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + Description: "Indicates whether the site is disabled.", + }, + + "created_on": { + Type: schema.TypeString, + Computed: true, + Description: "Site creation date.", + }, + + "modified_on": { + Type: schema.TypeString, + Computed: true, + Description: "Site modification date.", + }, + + "vanity_name_servers": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Description: "User-defined name server information.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "switch": { + Type: schema.TypeString, + Required: true, + Description: "Whether to enable the custom name server.", + }, + "servers": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Optional: true, + Computed: true, + Description: "List of custom name servers.", + }, + }, + }, + }, + + "vanity_name_servers_ips": { + Type: schema.TypeList, + Computed: true, + Description: "User-defined name server IP information.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + Description: "Name of the custom name server.", + }, + "ipv4": { + Type: schema.TypeString, + Computed: true, + Description: "IPv4 address of the custom name server.", + }, + }, + }, + }, + + "cname_speed_up": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "Specifies whether to enable CNAME acceleration, enabled: Enable; disabled: Disable.", + }, + + "cname_status": { + Type: schema.TypeString, + Computed: true, + Description: "Ownership verification status of the site when it accesses via CNAME.", + }, + + "tags": { + Type: schema.TypeMap, + Optional: true, + Description: "Tag description list.", + }, + "area": { + Type: schema.TypeString, + Computed: true, + Description: "Acceleration area of the zone. Valid values: `mainland`, `overseas`.", + }, + }, + } +} + +func resourceTencentCloudTeoZoneCreate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_zone.create")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + + var ( + request = teo.NewCreateZoneRequest() + response *teo.CreateZoneResponse + ) + + if v, ok := d.GetOk("name"); ok { + request.Name = helper.String(v.(string)) + } + + if v, ok := d.GetOk("type"); ok { + request.Type = helper.String(v.(string)) + } + + if dMap, ok := helper.InterfacesHeadMap(d, "vanity_name_servers"); ok { + vanityNameServers := teo.VanityNameServers{} + if v, ok := dMap["switch"]; ok { + vanityNameServers.Switch = helper.String(v.(string)) + } + if v, ok := dMap["servers"]; ok { + serversSet := v.(*schema.Set).List() + for i := range serversSet { + servers := serversSet[i].(string) + vanityNameServers.Servers = append(vanityNameServers.Servers, &servers) + } + } + } + + result, e := meta.(*TencentCloudClient).apiV3Conn.UseTeoClient().CreateZone(request) + if e != nil { + return e + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + response = result + + if response == nil || response.Response == nil || response.Response.Id == nil { + return errors.New("CreateZone create teo zone failed") + } + + zoneId := *response.Response.Id + + var planRequest = teo.NewCreatePlanForZoneRequest() + planRequest.ZoneId = &zoneId + if v, ok := d.GetOk("plan_type"); ok { + planRequest.PlanType = helper.String(v.(string)) + } + + resultPlan, err := meta.(*TencentCloudClient).apiV3Conn.UseTeoClient().CreatePlanForZone(planRequest) + if e != nil { + log.Printf("[CRITAL]%s create teo zone plan failed, reason:%+v", logId, e) + return err + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), resultPlan.ToJsonString()) + } + + ctx := context.WithValue(context.TODO(), logIdKey, logId) + if tags := helper.GetTags(d, "tags"); len(tags) > 0 { + tagService := TagService{client: meta.(*TencentCloudClient).apiV3Conn} + region := meta.(*TencentCloudClient).apiV3Conn.Region + resourceName := fmt.Sprintf("qcs::teo:%s:uin/:zone/%s", region, zoneId) + if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil { + return err + } + } + d.SetId(zoneId) + return resourceTencentCloudTeoZoneRead(d, meta) +} + +func resourceTencentCloudTeoZoneRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_zone.read")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + service := TeoService{client: meta.(*TencentCloudClient).apiV3Conn} + + zoneId := d.Id() + + zone, err := service.DescribeTeoZone(ctx, zoneId) + + if err != nil { + return err + } + + if zone == nil { + d.SetId("") + return fmt.Errorf("resource `zone` %s does not exist", zoneId) + } + + if zone.Id != nil { + _ = d.Set("id", zone.Id) + } + + if zone.Name != nil { + _ = d.Set("name", zone.Name) + } + + if zone.OriginalNameServers != nil { + _ = d.Set("original_name_servers", zone.OriginalNameServers) + } + + if zone.NameServers != nil { + _ = d.Set("name_servers", zone.NameServers) + } + + if zone.Status != nil { + _ = d.Set("status", zone.Status) + } + + if zone.Type != nil { + _ = d.Set("type", zone.Type) + } + + if zone.Paused != nil { + _ = d.Set("paused", zone.Paused) + } + + if zone.CreatedOn != nil { + _ = d.Set("created_on", zone.CreatedOn) + } + + if zone.ModifiedOn != nil { + _ = d.Set("modified_on", zone.ModifiedOn) + } + + if zone.VanityNameServers != nil { + vanityNameServersMap := map[string]interface{}{} + if zone.VanityNameServers.Switch != nil { + vanityNameServersMap["switch"] = zone.VanityNameServers.Switch + } + if zone.VanityNameServers.Servers != nil { + vanityNameServersMap["servers"] = zone.VanityNameServers.Servers + } + + _ = d.Set("vanity_name_servers", []interface{}{vanityNameServersMap}) + } + + if zone.VanityNameServersIps != nil { + vanityNameServersIpsList := []interface{}{} + for _, vanityNameServersIps := range zone.VanityNameServersIps { + vanityNameServersIpsMap := map[string]interface{}{} + if vanityNameServersIps.Name != nil { + vanityNameServersIpsMap["name"] = vanityNameServersIps.Name + } + if vanityNameServersIps.IPv4 != nil { + vanityNameServersIpsMap["ipv4"] = vanityNameServersIps.IPv4 + } + + vanityNameServersIpsList = append(vanityNameServersIpsList, vanityNameServersIpsMap) + } + _ = d.Set("vanity_name_servers_ips", vanityNameServersIpsList) + } + + if zone.CnameSpeedUp != nil { + _ = d.Set("cname_speed_up", zone.CnameSpeedUp) + } + + if zone.CnameStatus != nil { + _ = d.Set("cname_status", zone.CnameStatus) + } + + tcClient := meta.(*TencentCloudClient).apiV3Conn + tagService := &TagService{client: tcClient} + tags, err := tagService.DescribeResourceTags(ctx, "teo", "zone", tcClient.Region, d.Id()) + if err != nil { + return err + } + _ = d.Set("tags", tags) + + if zone.Area != nil { + _ = d.Set("area", zone.Area) + } + + return nil +} + +func resourceTencentCloudTeoZoneUpdate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_zone.update")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + request := teo.NewModifyZoneRequest() + + request.Id = helper.String(d.Id()) + + if d.HasChange("name") { + return fmt.Errorf("`name` do not support change now.") + } + + if d.HasChange("type") { + if v, ok := d.GetOk("type"); ok { + request.Type = helper.String(v.(string)) + } + } + + if d.HasChange("vanity_name_servers") { + if dMap, ok := helper.InterfacesHeadMap(d, "vanity_name_servers"); ok { + vanityNameServers := teo.VanityNameServers{} + if v, ok := dMap["switch"]; ok { + vanityNameServers.Switch = helper.String(v.(string)) + } + if v, ok := dMap["servers"]; ok { + serversSet := v.(*schema.Set).List() + for i := range serversSet { + servers := serversSet[i].(string) + vanityNameServers.Servers = append(vanityNameServers.Servers, &servers) + } + } + request.VanityNameServers = &vanityNameServers + } + } + + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseTeoClient().ModifyZone(request) + if e != nil { + return retryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + return nil + }) + + if err != nil { + return err + } + + if d.HasChange("tags") { + tcClient := meta.(*TencentCloudClient).apiV3Conn + tagService := &TagService{client: tcClient} + oldTags, newTags := d.GetChange("tags") + replaceTags, deleteTags := diffTags(oldTags.(map[string]interface{}), newTags.(map[string]interface{})) + resourceName := BuildTagResourceName("teo", "zone", tcClient.Region, d.Id()) + if err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags); err != nil { + return err + } + } + + if d.HasChange("cname_speed_up") { + requestCnameSpeedUp := teo.NewModifyZoneCnameSpeedUpRequest() + requestCnameSpeedUp.Id = helper.String(d.Id()) + if v, ok := d.GetOk("cname_speed_up"); ok { + requestCnameSpeedUp.Status = helper.String(v.(string)) + } + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseTeoClient().ModifyZoneCnameSpeedUp(requestCnameSpeedUp) + if e != nil { + return retryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + return nil + }) + + if err != nil { + return err + } + } + + if d.HasChange("paused") { + requestPaused := teo.NewModifyZoneStatusRequest() + requestPaused.Id = helper.String(d.Id()) + v, _ := d.GetOk("paused") + requestPaused.Paused = helper.Bool(v.(bool)) + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseTeoClient().ModifyZoneStatus(requestPaused) + if e != nil { + return retryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + return nil + }) + + if err != nil { + return err + } + } + + return resourceTencentCloudTeoZoneRead(d, meta) +} + +func resourceTencentCloudTeoZoneDelete(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_zone.delete")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + service := TeoService{client: meta.(*TencentCloudClient).apiV3Conn} + zoneId := d.Id() + + if err := service.DeleteTeoZoneById(ctx, zoneId); err != nil { + return err + } + + return nil +} diff --git a/tencentcloud/resource_tc_teo_zone_setting.go b/tencentcloud/resource_tc_teo_zone_setting.go new file mode 100644 index 0000000000..16e71131f5 --- /dev/null +++ b/tencentcloud/resource_tc_teo_zone_setting.go @@ -0,0 +1,1086 @@ +/* +Provides a resource to create a teo zone_setting + +Example Usage + +```hcl +resource "tencentcloud_teo_zone_setting" "zone_setting" { + zone_id = tencentcloud_teo_zone.zone.id + + cache { + follow_origin { + switch = "off" + } + + no_cache { + switch = "off" + } + } + + cache_key { + full_url_cache = "off" + ignore_case = "on" + + query_string { + action = "excludeCustom" + switch = "on" + value = ["test", "apple"] + } + } + + cache_prefresh { + percent = 90 + switch = "off" + } + + client_ip_header { + switch = "off" + } + + compression { + switch = "off" + } + + force_redirect { + redirect_status_code = 302 + switch = "on" + } + + https { + http2 = "on" + ocsp_stapling = "off" + tls_version = [ + "TLSv1.2", + "TLSv1.3", + ] + + hsts { + include_sub_domains = "off" + max_age = 0 + preload = "off" + switch = "off" + } + } + + max_age { + follow_origin = "off" + max_age_time = 600 + } + + offline_cache { + switch = "off" + } + + origin { + origin_pull_protocol = "follow" + } + + post_max_size { + max_size = 524288000 + switch = "on" + } + + quic { + switch = "on" + } + + smart_routing { + switch = "on" + } + + upstream_http2 { + switch = "off" + } + + web_socket { + switch = "off" + timeout = 30 + } +} + +``` +Import + +teo zone_setting can be imported using the id, e.g. +``` +$ terraform import tencentcloud_teo_zone_setting.zone_setting zone_id +``` +*/ +package tencentcloud + +import ( + "context" + "fmt" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + teo "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220106" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func resourceTencentCloudTeoZoneSetting() *schema.Resource { + return &schema.Resource{ + Read: resourceTencentCloudTeoZoneSettingRead, + Create: resourceTencentCloudTeoZoneSettingCreate, + Update: resourceTencentCloudTeoZoneSettingUpdate, + Delete: resourceTencentCloudTeoZoneSettingDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ + "zone_id": { + Type: schema.TypeString, + Required: true, + Description: "Site ID.", + }, + + "cache": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Description: "Cache expiration time configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cache": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Description: "Cache configuration.Note: This field may return null, indicating that no valid value can be obtained.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "switch": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "Cache configuration switch.- on: Enable.- off: Disable.Note: This field may return null, indicating that no valid value can be obtained.", + }, + "cache_time": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "Cache expiration time settings.Unit: second. The maximum value is 365 days.Note: This field may return null, indicating that no valid value can be obtained.", + }, + "ignore_cache_control": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "Specifies whether to enable force cache.- on: Enable.- off: Disable.Note: This field may return null, indicating that no valid value can be obtained.", + }, + }, + }, + }, + "no_cache": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Description: "No-cache configuration.Note: This field may return null, indicating that no valid value can be obtained.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "switch": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "Whether to cache the configuration.- on: Do not cache.- off: Cache.Note: This field may return null, indicating that no valid value can be obtained.", + }, + }, + }, + }, + "follow_origin": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Description: "Follows the origin server configuration.Note: This field may return null, indicating that no valid value can be obtained.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "switch": { + Type: schema.TypeString, + Required: true, + Description: "According to the configuration switch of the origin site, the values are: on: open; off: off.", + }, + }, + }, + }, + }, + }, + }, + + "cache_key": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Description: "Node cache key configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "full_url_cache": { + Type: schema.TypeString, + Optional: true, + Description: "Specifies whether to enable full-path cache.- on: Enable full-path cache (i.e., disable Ignore Query String).- off: Disable full-path cache (i.e., enable Ignore Query String).Note: This field may return null, indicating that no valid value can be obtained.", + }, + "ignore_case": { + Type: schema.TypeString, + Optional: true, + Description: "Specifies whether the cache key is case-sensitive.Note: This field may return null, indicating that no valid value can be obtained.", + }, + "query_string": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Description: "Request parameter contained in CacheKey.Note: This field may return null, indicating that no valid value can be obtained.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "switch": { + Type: schema.TypeString, + Required: true, + Description: "Whether to use QueryString as part of CacheKey.- on: Enable.- off: Disable.Note: This field may return null, indicating that no valid value can be obtained.", + }, + "action": { + Type: schema.TypeString, + Optional: true, + Description: "- includeCustom: Include the specified query strings.- excludeCustom: Exclude the specified query strings.Note: This field may return null, indicating that no valid value can be obtained.", + }, + "value": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Optional: true, + Description: "Array of query strings used/excluded.Note: This field may return null, indicating that no valid value can be obtained.", + }, + }, + }, + }, + }, + }, + }, + + "max_age": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Description: "Browser cache configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "max_age_time": { + Type: schema.TypeInt, + Optional: true, + Description: "Specifies the max age of the cache (in seconds). The maximum value is 365 days.Note: the value 0 means not to cache.Note: This field may return null, indicating that no valid value can be obtained.", + }, + "follow_origin": { + Type: schema.TypeString, + Optional: true, + Description: "Specifies whether to follow the max cache age of the origin server.- on: Enable.- off: Disable.If it's on, MaxAgeTime is ignored.Note: This field may return null, indicating that no valid value can be obtained.", + }, + }, + }, + }, + + "offline_cache": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Description: "Offline cache configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "switch": { + Type: schema.TypeString, + Required: true, + Description: "Whether to enable offline cache.- on: Enable.- off: Disable.Note: This field may return null, indicating that no valid value can be obtained.", + }, + }, + }, + }, + + "quic": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Description: "QUIC access configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "switch": { + Type: schema.TypeString, + Required: true, + Description: "Whether to enable QUIC.- on: Enable.- off: Disable.", + }, + }, + }, + }, + + "post_max_size": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Description: "Maximum size of files transferred over POST request.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "switch": { + Type: schema.TypeString, + Required: true, + Description: "Specifies whether to enable custom setting of the maximum file size.- on: Enable. You can set a custom max size.- off: Disable. In this case, the max size defaults to 32 MB.", + }, + "max_size": { + Type: schema.TypeInt, + Optional: true, + Description: "Maximum size. Value range: 1-500 MB.Note: This field may return null, indicating that no valid value can be obtained.", + }, + }, + }, + }, + + "compression": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Description: "Smart compression configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "switch": { + Type: schema.TypeString, + Required: true, + Description: "Whether to enable Smart compression.- on: Enable.- off: Disable.", + }, + }, + }, + }, + + "upstream_http2": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Description: "HTTP2 origin-pull configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "switch": { + Type: schema.TypeString, + Required: true, + Description: "Whether to enable HTTP2 origin-pull.- on: Enable.- off: Disable.", + }, + }, + }, + }, + + "force_redirect": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Description: "Force HTTPS redirect configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "switch": { + Type: schema.TypeString, + Required: true, + Description: "Whether to enable force redirect.- on: Enable.- off: Disable.", + }, + "redirect_status_code": { + Type: schema.TypeInt, + Optional: true, + Description: "Redirection status code.- 301- 302Note: This field may return null, indicating that no valid value can be obtained.", + }, + }, + }, + }, + + "https": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Description: "HTTPS acceleration configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "http2": { + Type: schema.TypeString, + Optional: true, + Description: "HTTP2 configuration switch.- on: Enable.- off: Disable.Note: This field may return null, indicating that no valid value can be obtained.", + }, + "ocsp_stapling": { + Type: schema.TypeString, + Optional: true, + Description: "OCSP configuration switch.- on: Enable.- off: Disable.It is disabled by default. Note: This field may return null, indicating that no valid value can be obtained.", + }, + "tls_version": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Optional: true, + Description: "TLS version settings. Valid values: `TLSv1`, `TLSV1.1`, `TLSV1.2`, and `TLSv1.3`.Only consecutive versions can be enabled at the same time.Note: This field may return null, indicating that no valid value can be obtained.", + }, + "hsts": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Description: "HSTS Configuration.Note: This field may return null, indicating that no valid value can be obtained.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "switch": { + Type: schema.TypeString, + Required: true, + Description: "- on: Enable.- off: Disable.", + }, + "max_age": { + Type: schema.TypeInt, + Optional: true, + Description: "MaxAge value.Note: This field may return null, indicating that no valid value can be obtained.", + }, + "include_sub_domains": { + Type: schema.TypeString, + Optional: true, + Description: "Specifies whether to include subdomain names. Valid values: `on` and `off`.Note: This field may return null, indicating that no valid value can be obtained.", + }, + "preload": { + Type: schema.TypeString, + Optional: true, + Description: "Specifies whether to preload. Valid values: `on` and `off`.Note: This field may return null, indicating that no valid value can be obtained.", + }, + }, + }, + }, + }, + }, + }, + + "origin": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Description: "Origin server configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "origin_pull_protocol": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "Origin-pull protocol.- http: Switch HTTPS requests to HTTP.- follow: Follow the protocol of the request.- https: Switch HTTP requests to HTTPS. This only supports port 443 on the origin server.Note: This field may return null, indicating that no valid value can be obtained.", + }, + }, + }, + }, + + "smart_routing": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Description: "Smart acceleration configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "switch": { + Type: schema.TypeString, + Required: true, + Description: "Whether to enable smart acceleration.- on: Enable.- off: Disable.", + }, + }, + }, + }, + + "web_socket": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Description: "WebSocket configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "switch": { + Type: schema.TypeString, + Required: true, + Description: "Whether to enable custom WebSocket timeout setting. When it's off: it means to keep the default WebSocket connection timeout period, which is 15 seconds. To change the timeout period, please set it to on.", + }, + "timeout": { + Type: schema.TypeInt, + Optional: true, + Description: "Sets timeout period in seconds. Maximum value: 120.", + }, + }, + }, + }, + + "client_ip_header": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Description: "Origin-pull client IP header configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "switch": { + Type: schema.TypeString, + Required: true, + Description: "Specifies whether to enable client IP header.- on: Enable.- off: Disable.Note: This field may return null, indicating that no valid value can be obtained.", + }, + "header_name": { + Type: schema.TypeString, + Optional: true, + Description: "Name of the origin-pull client IP request header.Note: This field may return null, indicating that no valid value can be obtained.", + }, + }, + }, + }, + + "cache_prefresh": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Description: "Cache pre-refresh configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "switch": { + Type: schema.TypeString, + Required: true, + Description: "Specifies whether to enable cache prefresh.- on: Enable.- off: Disable.", + }, + "percent": { + Type: schema.TypeInt, + Optional: true, + Description: "Percentage of cache time before try to prefresh. Value range: 1-99.", + }, + }, + }, + }, + }, + } +} + +func resourceTencentCloudTeoZoneSettingCreate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_zone_setting.create")() + defer inconsistentCheck(d, meta)() + + var ( + zoneId string + ) + + if v, ok := d.GetOk("zone_id"); ok { + zoneId = v.(string) + } + + d.SetId(zoneId) + return resourceTencentCloudTeoZoneSettingUpdate(d, meta) +} + +func resourceTencentCloudTeoZoneSettingRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_zone_setting.read")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + service := TeoService{client: meta.(*TencentCloudClient).apiV3Conn} + + zoneId := d.Id() + + zoneSetting, err := service.DescribeTeoZoneSetting(ctx, zoneId) + + if err != nil { + return err + } + + if zoneSetting == nil { + d.SetId("") + return fmt.Errorf("resource `zoneSetting` %s does not exist", zoneId) + } + + if zoneSetting.ZoneId != nil { + _ = d.Set("zone_id", zoneSetting.ZoneId) + } + + if zoneSetting.Cache != nil { + cacheMap := map[string]interface{}{} + if zoneSetting.Cache.Cache != nil { + cacheMap := map[string]interface{}{} + if zoneSetting.Cache.Cache.Switch != nil { + cacheMap["switch"] = zoneSetting.Cache.Cache.Switch + } + if zoneSetting.Cache.Cache.CacheTime != nil { + cacheMap["cache_time"] = zoneSetting.Cache.Cache.CacheTime + } + if zoneSetting.Cache.Cache.IgnoreCacheControl != nil { + cacheMap["ignore_cache_control"] = zoneSetting.Cache.Cache.IgnoreCacheControl + } + + cacheMap["cache"] = []interface{}{cacheMap} + } + if zoneSetting.Cache.NoCache != nil { + noCacheMap := map[string]interface{}{} + if zoneSetting.Cache.NoCache.Switch != nil { + noCacheMap["switch"] = zoneSetting.Cache.NoCache.Switch + } + + cacheMap["no_cache"] = []interface{}{noCacheMap} + } + if zoneSetting.Cache.FollowOrigin != nil { + followOriginMap := map[string]interface{}{} + if zoneSetting.Cache.FollowOrigin.Switch != nil { + followOriginMap["switch"] = zoneSetting.Cache.FollowOrigin.Switch + } + + cacheMap["follow_origin"] = []interface{}{followOriginMap} + } + + _ = d.Set("cache", []interface{}{cacheMap}) + } + + if zoneSetting.CacheKey != nil { + cacheKeyMap := map[string]interface{}{} + if zoneSetting.CacheKey.FullUrlCache != nil { + cacheKeyMap["full_url_cache"] = zoneSetting.CacheKey.FullUrlCache + } + if zoneSetting.CacheKey.IgnoreCase != nil { + cacheKeyMap["ignore_case"] = zoneSetting.CacheKey.IgnoreCase + } + if zoneSetting.CacheKey.QueryString != nil { + queryStringMap := map[string]interface{}{} + if zoneSetting.CacheKey.QueryString.Switch != nil { + queryStringMap["switch"] = zoneSetting.CacheKey.QueryString.Switch + } + if zoneSetting.CacheKey.QueryString.Action != nil { + queryStringMap["action"] = zoneSetting.CacheKey.QueryString.Action + } + if zoneSetting.CacheKey.QueryString.Value != nil { + queryStringMap["value"] = zoneSetting.CacheKey.QueryString.Value + } + + cacheKeyMap["query_string"] = []interface{}{queryStringMap} + } + + _ = d.Set("cache_key", []interface{}{cacheKeyMap}) + } + + if zoneSetting.MaxAge != nil { + maxAgeMap := map[string]interface{}{} + if zoneSetting.MaxAge.MaxAgeTime != nil { + maxAgeMap["max_age_time"] = zoneSetting.MaxAge.MaxAgeTime + } + if zoneSetting.MaxAge.FollowOrigin != nil { + maxAgeMap["follow_origin"] = zoneSetting.MaxAge.FollowOrigin + } + + _ = d.Set("max_age", []interface{}{maxAgeMap}) + } + + if zoneSetting.OfflineCache != nil { + offlineCacheMap := map[string]interface{}{} + if zoneSetting.OfflineCache.Switch != nil { + offlineCacheMap["switch"] = zoneSetting.OfflineCache.Switch + } + + _ = d.Set("offline_cache", []interface{}{offlineCacheMap}) + } + + if zoneSetting.Quic != nil { + quicMap := map[string]interface{}{} + if zoneSetting.Quic.Switch != nil { + quicMap["switch"] = zoneSetting.Quic.Switch + } + + _ = d.Set("quic", []interface{}{quicMap}) + } + + if zoneSetting.PostMaxSize != nil { + postMaxSizeMap := map[string]interface{}{} + if zoneSetting.PostMaxSize.Switch != nil { + postMaxSizeMap["switch"] = zoneSetting.PostMaxSize.Switch + } + if zoneSetting.PostMaxSize.MaxSize != nil { + postMaxSizeMap["max_size"] = zoneSetting.PostMaxSize.MaxSize + } + + _ = d.Set("post_max_size", []interface{}{postMaxSizeMap}) + } + + if zoneSetting.Compression != nil { + compressionMap := map[string]interface{}{} + if zoneSetting.Compression.Switch != nil { + compressionMap["switch"] = zoneSetting.Compression.Switch + } + + _ = d.Set("compression", []interface{}{compressionMap}) + } + + if zoneSetting.UpstreamHttp2 != nil { + upstreamHttp2Map := map[string]interface{}{} + if zoneSetting.UpstreamHttp2.Switch != nil { + upstreamHttp2Map["switch"] = zoneSetting.UpstreamHttp2.Switch + } + + _ = d.Set("upstream_http2", []interface{}{upstreamHttp2Map}) + } + + if zoneSetting.ForceRedirect != nil { + forceRedirectMap := map[string]interface{}{} + if zoneSetting.ForceRedirect.Switch != nil { + forceRedirectMap["switch"] = zoneSetting.ForceRedirect.Switch + } + if zoneSetting.ForceRedirect.RedirectStatusCode != nil { + forceRedirectMap["redirect_status_code"] = zoneSetting.ForceRedirect.RedirectStatusCode + } + + _ = d.Set("force_redirect", []interface{}{forceRedirectMap}) + } + + if zoneSetting.Https != nil { + httpsMap := map[string]interface{}{} + if zoneSetting.Https.Http2 != nil { + httpsMap["http2"] = zoneSetting.Https.Http2 + } + if zoneSetting.Https.OcspStapling != nil { + httpsMap["ocsp_stapling"] = zoneSetting.Https.OcspStapling + } + if zoneSetting.Https.TlsVersion != nil { + httpsMap["tls_version"] = zoneSetting.Https.TlsVersion + } + if zoneSetting.Https.Hsts != nil { + hstsMap := map[string]interface{}{} + if zoneSetting.Https.Hsts.Switch != nil { + hstsMap["switch"] = zoneSetting.Https.Hsts.Switch + } + if zoneSetting.Https.Hsts.MaxAge != nil { + hstsMap["max_age"] = zoneSetting.Https.Hsts.MaxAge + } + if zoneSetting.Https.Hsts.IncludeSubDomains != nil { + hstsMap["include_sub_domains"] = zoneSetting.Https.Hsts.IncludeSubDomains + } + if zoneSetting.Https.Hsts.Preload != nil { + hstsMap["preload"] = zoneSetting.Https.Hsts.Preload + } + + httpsMap["hsts"] = []interface{}{hstsMap} + } + + _ = d.Set("https", []interface{}{httpsMap}) + } + + if zoneSetting.Origin != nil { + originMap := map[string]interface{}{} + if zoneSetting.Origin.OriginPullProtocol != nil { + originMap["origin_pull_protocol"] = zoneSetting.Origin.OriginPullProtocol + } + + _ = d.Set("origin", []interface{}{originMap}) + } + + if zoneSetting.SmartRouting != nil { + smartRoutingMap := map[string]interface{}{} + if zoneSetting.SmartRouting.Switch != nil { + smartRoutingMap["switch"] = zoneSetting.SmartRouting.Switch + } + + _ = d.Set("smart_routing", []interface{}{smartRoutingMap}) + } + + if zoneSetting.WebSocket != nil { + webSocketMap := map[string]interface{}{} + if zoneSetting.WebSocket.Switch != nil { + webSocketMap["switch"] = zoneSetting.WebSocket.Switch + } + if zoneSetting.WebSocket.Timeout != nil { + webSocketMap["timeout"] = zoneSetting.WebSocket.Timeout + } + + _ = d.Set("web_socket", []interface{}{webSocketMap}) + } + + if zoneSetting.ClientIpHeader != nil { + clientIpHeaderMap := map[string]interface{}{} + if zoneSetting.ClientIpHeader.Switch != nil { + clientIpHeaderMap["switch"] = zoneSetting.ClientIpHeader.Switch + } + if zoneSetting.ClientIpHeader.HeaderName != nil { + clientIpHeaderMap["header_name"] = zoneSetting.ClientIpHeader.HeaderName + } + + _ = d.Set("client_ip_header", []interface{}{clientIpHeaderMap}) + } + + if zoneSetting.CachePrefresh != nil { + cachePrefreshMap := map[string]interface{}{} + if zoneSetting.CachePrefresh.Switch != nil { + cachePrefreshMap["switch"] = zoneSetting.CachePrefresh.Switch + } + if zoneSetting.CachePrefresh.Percent != nil { + cachePrefreshMap["percent"] = zoneSetting.CachePrefresh.Percent + } + + _ = d.Set("cache_prefresh", []interface{}{cachePrefreshMap}) + } + + return nil +} + +func resourceTencentCloudTeoZoneSettingUpdate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_zone_setting.update")() + defer inconsistentCheck(d, meta)() + + logId := getLogId(contextNil) + + var ( + request = teo.NewModifyZoneSettingRequest() + ) + + if v, ok := d.GetOk("zone_id"); ok { + request.ZoneId = helper.String(v.(string)) + } + + if dMap, ok := helper.InterfacesHeadMap(d, "cache"); ok { + cacheConfig := teo.CacheConfig{} + if CacheMap, ok := helper.InterfaceToMap(dMap, "cache"); ok { + cacheConfigCache := teo.CacheConfigCache{} + if v, ok := CacheMap["switch"]; ok { + cacheConfigCache.Switch = helper.String(v.(string)) + } + if v, ok := CacheMap["cache_time"]; ok { + cacheConfigCache.CacheTime = helper.IntInt64(v.(int)) + } + if v, ok := CacheMap["ignore_cache_control"]; ok { + cacheConfigCache.IgnoreCacheControl = helper.String(v.(string)) + } + cacheConfig.Cache = &cacheConfigCache + } + if NoCacheMap, ok := helper.InterfaceToMap(dMap, "no_cache"); ok { + cacheConfigNoCache := teo.CacheConfigNoCache{} + if v, ok := NoCacheMap["switch"]; ok { + cacheConfigNoCache.Switch = helper.String(v.(string)) + } + cacheConfig.NoCache = &cacheConfigNoCache + } + if FollowOriginMap, ok := helper.InterfaceToMap(dMap, "follow_origin"); ok { + cacheConfigFollowOrigin := teo.CacheConfigFollowOrigin{} + if v, ok := FollowOriginMap["switch"]; ok { + cacheConfigFollowOrigin.Switch = helper.String(v.(string)) + } + cacheConfig.FollowOrigin = &cacheConfigFollowOrigin + } + + request.Cache = &cacheConfig + } + + if dMap, ok := helper.InterfacesHeadMap(d, "cache_key"); ok { + cacheKey := teo.CacheKey{} + if v, ok := dMap["full_url_cache"]; ok { + cacheKey.FullUrlCache = helper.String(v.(string)) + } + if v, ok := dMap["ignore_case"]; ok { + cacheKey.IgnoreCase = helper.String(v.(string)) + } + if QueryStringMap, ok := helper.InterfaceToMap(dMap, "query_string"); ok { + queryString := teo.QueryString{} + if v, ok := QueryStringMap["switch"]; ok { + queryString.Switch = helper.String(v.(string)) + } + if v, ok := QueryStringMap["action"]; ok { + queryString.Action = helper.String(v.(string)) + } + if v, ok := QueryStringMap["value"]; ok { + valueSet := v.(*schema.Set).List() + for i := range valueSet { + value := valueSet[i].(string) + queryString.Value = append(queryString.Value, &value) + } + } + cacheKey.QueryString = &queryString + } + + request.CacheKey = &cacheKey + } + + if dMap, ok := helper.InterfacesHeadMap(d, "max_age"); ok { + maxAge := teo.MaxAge{} + if v, ok := dMap["max_age_time"]; ok { + maxAge.MaxAgeTime = helper.IntInt64(v.(int)) + } + if v, ok := dMap["follow_origin"]; ok { + maxAge.FollowOrigin = helper.String(v.(string)) + } + + request.MaxAge = &maxAge + } + + if dMap, ok := helper.InterfacesHeadMap(d, "offline_cache"); ok { + offlineCache := teo.OfflineCache{} + if v, ok := dMap["switch"]; ok { + offlineCache.Switch = helper.String(v.(string)) + } + + request.OfflineCache = &offlineCache + } + + if dMap, ok := helper.InterfacesHeadMap(d, "quic"); ok { + quic := teo.Quic{} + if v, ok := dMap["switch"]; ok { + quic.Switch = helper.String(v.(string)) + } + + request.Quic = &quic + } + + if dMap, ok := helper.InterfacesHeadMap(d, "post_max_size"); ok { + postMaxSize := teo.PostMaxSize{} + if v, ok := dMap["switch"]; ok { + postMaxSize.Switch = helper.String(v.(string)) + } + if v, ok := dMap["max_size"]; ok { + postMaxSize.MaxSize = helper.IntInt64(v.(int)) + } + + request.PostMaxSize = &postMaxSize + } + + if dMap, ok := helper.InterfacesHeadMap(d, "compression"); ok { + compression := teo.Compression{} + if v, ok := dMap["switch"]; ok { + compression.Switch = helper.String(v.(string)) + } + + request.Compression = &compression + } + + if dMap, ok := helper.InterfacesHeadMap(d, "upstream_http2"); ok { + upstreamHttp2 := teo.UpstreamHttp2{} + if v, ok := dMap["switch"]; ok { + upstreamHttp2.Switch = helper.String(v.(string)) + } + + request.UpstreamHttp2 = &upstreamHttp2 + } + + if dMap, ok := helper.InterfacesHeadMap(d, "force_redirect"); ok { + forceRedirect := teo.ForceRedirect{} + if v, ok := dMap["switch"]; ok { + forceRedirect.Switch = helper.String(v.(string)) + } + if v, ok := dMap["redirect_status_code"]; ok { + forceRedirect.RedirectStatusCode = helper.IntInt64(v.(int)) + } + + request.ForceRedirect = &forceRedirect + } + + if dMap, ok := helper.InterfacesHeadMap(d, "https"); ok { + https := teo.Https{} + if v, ok := dMap["http2"]; ok { + https.Http2 = helper.String(v.(string)) + } + if v, ok := dMap["ocsp_stapling"]; ok { + https.OcspStapling = helper.String(v.(string)) + } + if v, ok := dMap["tls_version"]; ok { + tlsVersionSet := v.(*schema.Set).List() + for i := range tlsVersionSet { + tlsVersion := tlsVersionSet[i].(string) + https.TlsVersion = append(https.TlsVersion, &tlsVersion) + } + } + if HstsMap, ok := helper.InterfaceToMap(dMap, "hsts"); ok { + hsts := teo.Hsts{} + if v, ok := HstsMap["switch"]; ok { + hsts.Switch = helper.String(v.(string)) + } + if v, ok := HstsMap["max_age"]; ok { + hsts.MaxAge = helper.IntInt64(v.(int)) + } + if v, ok := HstsMap["include_sub_domains"]; ok { + hsts.IncludeSubDomains = helper.String(v.(string)) + } + if v, ok := HstsMap["preload"]; ok { + hsts.Preload = helper.String(v.(string)) + } + https.Hsts = &hsts + } + + request.Https = &https + } + + if dMap, ok := helper.InterfacesHeadMap(d, "origin"); ok { + origin := teo.Origin{} + if v, ok := dMap["origin_pull_protocol"]; ok { + origin.OriginPullProtocol = helper.String(v.(string)) + } + + request.Origin = &origin + } + + if dMap, ok := helper.InterfacesHeadMap(d, "smart_routing"); ok { + smartRouting := teo.SmartRouting{} + if v, ok := dMap["switch"]; ok { + smartRouting.Switch = helper.String(v.(string)) + } + + request.SmartRouting = &smartRouting + } + + if dMap, ok := helper.InterfacesHeadMap(d, "web_socket"); ok { + webSocket := teo.WebSocket{} + if v, ok := dMap["switch"]; ok { + webSocket.Switch = helper.String(v.(string)) + } + if v, ok := dMap["timeout"]; ok { + webSocket.Timeout = helper.IntInt64(v.(int)) + } + + request.WebSocket = &webSocket + } + + if dMap, ok := helper.InterfacesHeadMap(d, "client_ip_header"); ok { + clientIp := teo.ClientIp{} + if v, ok := dMap["switch"]; ok { + clientIp.Switch = helper.String(v.(string)) + } + if v, ok := dMap["header_name"]; ok { + clientIp.HeaderName = helper.String(v.(string)) + } + + request.ClientIpHeader = &clientIp + } + + if dMap, ok := helper.InterfacesHeadMap(d, "cache_prefresh"); ok { + cachePrefresh := teo.CachePrefresh{} + if v, ok := dMap["switch"]; ok { + cachePrefresh.Switch = helper.String(v.(string)) + } + if v, ok := dMap["percent"]; ok { + cachePrefresh.Percent = helper.IntInt64(v.(int)) + } + + request.CachePrefresh = &cachePrefresh + } + + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseTeoClient().ModifyZoneSetting(request) + if e != nil { + return retryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + return nil + }) + + if err != nil { + log.Printf("[CRITAL]%s create teo zoneSetting failed, reason:%+v", logId, err) + return err + } + + return resourceTencentCloudTeoZoneSettingRead(d, meta) +} + +func resourceTencentCloudTeoZoneSettingDelete(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_teo_zone_setting.delete")() + defer inconsistentCheck(d, meta)() + + return nil +} diff --git a/tencentcloud/resource_tc_teo_zone_setting_test.go b/tencentcloud/resource_tc_teo_zone_setting_test.go new file mode 100644 index 0000000000..237672d263 --- /dev/null +++ b/tencentcloud/resource_tc_teo_zone_setting_test.go @@ -0,0 +1,127 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" +) + +func TestAccTencentCloudNeedFixTeoZoneSetting_basic(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccTeoZoneSetting, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_teo_zone_setting.zone_setting", "id"), + ), + }, + { + ResourceName: "tencentcloud_teo_zone_setting.zone_setting", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccTeoZoneSetting = ` + +resource "tencentcloud_teo_zone_setting" "zone_setting" { + zone_id = tencentcloud_teo_zone.zone.id + + cache { + follow_origin { + switch = "off" + } + + no_cache { + switch = "off" + } + } + + cache_key { + full_url_cache = "off" + ignore_case = "on" + + query_string { + action = "excludeCustom" + switch = "on" + value = ["test", "apple"] + } + } + + cache_prefresh { + percent = 90 + switch = "off" + } + + client_ip_header { + switch = "off" + } + + compression { + switch = "off" + } + + force_redirect { + redirect_status_code = 302 + switch = "on" + } + + https { + http2 = "on" + ocsp_stapling = "off" + tls_version = [ + "TLSv1.2", + "TLSv1.3", + ] + + hsts { + include_sub_domains = "off" + max_age = 0 + preload = "off" + switch = "off" + } + } + + max_age { + follow_origin = "off" + max_age_time = 600 + } + + offline_cache { + switch = "off" + } + + origin { + origin_pull_protocol = "follow" + } + + post_max_size { + max_size = 524288000 + switch = "on" + } + + quic { + switch = "on" + } + + smart_routing { + switch = "on" + } + + upstream_http2 { + switch = "off" + } + + web_socket { + switch = "off" + timeout = 30 + } +} + +` diff --git a/tencentcloud/resource_tc_teo_zone_test.go b/tencentcloud/resource_tc_teo_zone_test.go new file mode 100644 index 0000000000..0292cbda47 --- /dev/null +++ b/tencentcloud/resource_tc_teo_zone_test.go @@ -0,0 +1,46 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" +) + +func TestAccTencentCloudNeedFixTeoZone_basic(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccTeoZone, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_teo_zone.zone", "id"), + ), + }, + { + ResourceName: "tencentcloud_teo_zone.zone", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccTeoZone = ` + +resource "tencentcloud_teo_zone" "zone" { + name = "sfurnace.work" + plan_type = "ent_cm_with_bot" + type = "full" + paused = false + cname_speed_up = "enabled" + + # vanity_name_servers { + # switch = "on" + # servers = ["2.2.2.2"] + # } +} + +` diff --git a/tencentcloud/service_tencentcloud_teo.go b/tencentcloud/service_tencentcloud_teo.go new file mode 100644 index 0000000000..e224a2ef20 --- /dev/null +++ b/tencentcloud/service_tencentcloud_teo.go @@ -0,0 +1,758 @@ +package tencentcloud + +import ( + "context" + "log" + "strconv" + + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" + + teo "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220106" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/connectivity" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/ratelimit" +) + +type TeoService struct { + client *connectivity.TencentCloudClient +} + +func (me *TeoService) DescribeTeoZone(ctx context.Context, zoneId string) (zone *teo.DescribeZoneDetailsResponseParams, errRet error) { + var ( + logId = getLogId(ctx) + request = teo.NewDescribeZoneDetailsRequest() + ) + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, "query object", request.ToJsonString(), errRet.Error()) + } + }() + request.Id = &zoneId + + response, err := me.client.UseTeoClient().DescribeZoneDetails(request) + if err != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, request.GetAction(), request.ToJsonString(), err.Error()) + errRet = err + return + } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + + zone = response.Response + return +} + +func (me *TeoService) DeleteTeoZoneById(ctx context.Context, zoneId string) (errRet error) { + logId := getLogId(ctx) + + request := teo.NewDeleteZoneRequest() + request.Id = &zoneId + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, "delete object", request.ToJsonString(), errRet.Error()) + } + }() + + ratelimit.Check(request.GetAction()) + response, err := me.client.UseTeoClient().DeleteZone(request) + if err != nil { + errRet = err + return err + } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + + return +} + +func (me *TeoService) DescribeTeoDnsRecord(ctx context.Context, zoneId, name string) (dnsRecord *teo.DnsRecord, errRet error) { + var ( + logId = getLogId(ctx) + request = teo.NewDescribeDnsRecordsRequest() + ) + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, "query object", request.ToJsonString(), errRet.Error()) + } + }() + + request.ZoneId = &zoneId + request.Filters = append( + request.Filters, + &teo.DnsRecordFilter{ + Name: helper.String("name"), + Values: []*string{&name}, + }, + ) + ratelimit.Check(request.GetAction()) + + var offset int64 = 0 + var pageSize int64 = 100 + instances := make([]*teo.DnsRecord, 0) + + for { + request.Offset = &offset + request.Limit = &pageSize + ratelimit.Check(request.GetAction()) + response, err := me.client.UseTeoClient().DescribeDnsRecords(request) + if err != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, request.GetAction(), request.ToJsonString(), err.Error()) + errRet = err + return + } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + + if response == nil || len(response.Response.Records) < 1 { + break + } + instances = append(instances, response.Response.Records...) + if len(response.Response.Records) < int(pageSize) { + break + } + offset += pageSize + } + + if len(instances) < 1 { + return + } + dnsRecord = instances[0] + + return + +} + +func (me *TeoService) DeleteTeoDnsRecordById(ctx context.Context, zoneId, dnsRecordId string) (errRet error) { + logId := getLogId(ctx) + + request := teo.NewDeleteDnsRecordsRequest() + request.Ids = []*string{&dnsRecordId} + request.ZoneId = &zoneId + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, "delete object", request.ToJsonString(), errRet.Error()) + } + }() + + ratelimit.Check(request.GetAction()) + response, err := me.client.UseTeoClient().DeleteDnsRecords(request) + if err != nil { + errRet = err + return err + } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + + return +} + +func (me *TeoService) DescribeTeoLoadBalancing(ctx context.Context, zoneId string, loadBalancingId string) (loadBalancing *teo.DescribeLoadBalancingDetailResponseParams, errRet error) { + var ( + logId = getLogId(ctx) + request = teo.NewDescribeLoadBalancingDetailRequest() + ) + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, "query object", request.ToJsonString(), errRet.Error()) + } + }() + request.ZoneId = &zoneId + request.LoadBalancingId = &loadBalancingId + + response, err := me.client.UseTeoClient().DescribeLoadBalancingDetail(request) + if err != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, request.GetAction(), request.ToJsonString(), err.Error()) + errRet = err + return + } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + + loadBalancing = response.Response + return +} + +func (me *TeoService) DeleteTeoLoadBalancingById(ctx context.Context, zoneId string, loadBalancingId string) (errRet error) { + logId := getLogId(ctx) + + request := teo.NewDeleteLoadBalancingRequest() + request.ZoneId = &zoneId + request.LoadBalancingId = &loadBalancingId + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, "delete object", request.ToJsonString(), errRet.Error()) + } + }() + + ratelimit.Check(request.GetAction()) + response, err := me.client.UseTeoClient().DeleteLoadBalancing(request) + if err != nil { + errRet = err + return err + } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + + return +} + +func (me *TeoService) DescribeTeoOriginGroup(ctx context.Context, zoneId string, originGroupId string) (originGroup *teo.DescribeOriginGroupDetailResponseParams, errRet error) { + var ( + logId = getLogId(ctx) + request = teo.NewDescribeOriginGroupDetailRequest() + ) + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, "query object", request.ToJsonString(), errRet.Error()) + } + }() + request.ZoneId = &zoneId + request.OriginId = &originGroupId + + response, err := me.client.UseTeoClient().DescribeOriginGroupDetail(request) + if err != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, request.GetAction(), request.ToJsonString(), err.Error()) + errRet = err + return + } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + + originGroup = response.Response + return +} + +func (me *TeoService) DeleteTeoOriginGroupById(ctx context.Context, zoneId string, originGroupId string) (errRet error) { + logId := getLogId(ctx) + + request := teo.NewDeleteOriginGroupRequest() + request.ZoneId = &zoneId + request.OriginId = &originGroupId + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, "delete object", request.ToJsonString(), errRet.Error()) + } + }() + + ratelimit.Check(request.GetAction()) + response, err := me.client.UseTeoClient().DeleteOriginGroup(request) + if err != nil { + errRet = err + return err + } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + + return +} + +func (me *TeoService) DescribeTeoRuleEngine(ctx context.Context, zoneId, ruleId string) (ruleEngine *teo.RuleSettingDetail, errRet error) { + var ( + logId = getLogId(ctx) + request = teo.NewDescribeRulesRequest() + ) + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, "query object", request.ToJsonString(), errRet.Error()) + } + }() + + request.ZoneId = &zoneId + request.Filters = append( + request.Filters, + &teo.RuleFilter{ + Name: helper.String("RULE_ID"), + Values: []*string{&ruleId}, + }, + ) + ratelimit.Check(request.GetAction()) + + response, err := me.client.UseTeoClient().DescribeRules(request) + if err != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, request.GetAction(), request.ToJsonString(), err.Error()) + errRet = err + return + } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + + instances := response.Response.RuleList + + if len(instances) < 1 { + return + } + ruleEngine = instances[0] + + return + +} + +func (me *TeoService) DeleteTeoRuleEngineById(ctx context.Context, zoneId, ruleId string) (errRet error) { + logId := getLogId(ctx) + + request := teo.NewDeleteRulesRequest() + + request.ZoneId = &zoneId + request.RuleIds = []*string{&ruleId} + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, "delete object", request.ToJsonString(), errRet.Error()) + } + }() + + ratelimit.Check(request.GetAction()) + response, err := me.client.UseTeoClient().DeleteRules(request) + if err != nil { + errRet = err + return err + } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + + return +} + +func (me *TeoService) DescribeTeoApplicationProxy(ctx context.Context, zoneId, proxyId string) (applicationProxy *teo.DescribeApplicationProxyDetailResponseParams, errRet error) { + var ( + logId = getLogId(ctx) + request = teo.NewDescribeApplicationProxyDetailRequest() + ) + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, "query object", request.ToJsonString(), errRet.Error()) + } + }() + request.ZoneId = &zoneId + request.ProxyId = &proxyId + + response, err := me.client.UseTeoClient().DescribeApplicationProxyDetail(request) + if err != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, request.GetAction(), request.ToJsonString(), err.Error()) + errRet = err + return + } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + applicationProxy = response.Response + return +} + +func (me *TeoService) DeleteTeoApplicationProxyById(ctx context.Context, zoneId, proxyId string) (errRet error) { + logId := getLogId(ctx) + + request := teo.NewDeleteApplicationProxyRequest() + + request.ZoneId = &zoneId + request.ProxyId = &proxyId + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, "delete object", request.ToJsonString(), errRet.Error()) + } + }() + + ratelimit.Check(request.GetAction()) + response, err := me.client.UseTeoClient().DeleteApplicationProxy(request) + if err != nil { + errRet = err + return err + } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + + return +} + +func (me *TeoService) DescribeTeoApplicationProxyRule(ctx context.Context, zoneId, proxyId, ruleId string) (applicationProxyRule *teo.ApplicationProxyRule, errRet error) { + var ( + logId = getLogId(ctx) + request = teo.NewDescribeApplicationProxyDetailRequest() + ) + + rules := make([]*teo.ApplicationProxyRule, 0) + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, "query object", request.ToJsonString(), errRet.Error()) + } + }() + request.ZoneId = &zoneId + request.ProxyId = &proxyId + + response, err := me.client.UseTeoClient().DescribeApplicationProxyDetail(request) + if err != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, request.GetAction(), request.ToJsonString(), err.Error()) + errRet = err + return + } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + rules = response.Response.Rule + for _, rule := range rules { + if *rule.RuleId == ruleId { + applicationProxyRule = rule + return + } + } + return +} + +func (me *TeoService) DeleteTeoApplicationProxyRuleById(ctx context.Context, zoneId, proxyId, ruleId string) (errRet error) { + logId := getLogId(ctx) + + request := teo.NewDeleteApplicationProxyRuleRequest() + + request.ZoneId = &zoneId + request.ProxyId = &proxyId + request.RuleId = &ruleId + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, "delete object", request.ToJsonString(), errRet.Error()) + } + }() + + ratelimit.Check(request.GetAction()) + response, err := me.client.UseTeoClient().DeleteApplicationProxyRule(request) + if err != nil { + errRet = err + return err + } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + + return +} + +func (me *TeoService) DescribeTeoZoneSetting(ctx context.Context, zoneId string) (zoneSetting *teo.DescribeZoneSettingResponseParams, errRet error) { + var ( + logId = getLogId(ctx) + request = teo.NewDescribeZoneSettingRequest() + ) + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, "query object", request.ToJsonString(), errRet.Error()) + } + }() + request.ZoneId = &zoneId + + response, err := me.client.UseTeoClient().DescribeZoneSetting(request) + if err != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, request.GetAction(), request.ToJsonString(), err.Error()) + errRet = err + return + } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + zoneSetting = response.Response + return +} + +func (me *TeoService) DescribeTeoSecurityPolicy(ctx context.Context, zoneId, entity string) (securityPolicy *teo.DescribeSecurityPolicyResponseParams, errRet error) { + var ( + logId = getLogId(ctx) + request = teo.NewDescribeSecurityPolicyRequest() + ) + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, "query object", request.ToJsonString(), errRet.Error()) + } + }() + request.ZoneId = &zoneId + request.Entity = &entity + + response, err := me.client.UseTeoClient().DescribeSecurityPolicy(request) + if err != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, request.GetAction(), request.ToJsonString(), err.Error()) + errRet = err + return + } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + securityPolicy = response.Response + return +} + +func (me *TeoService) DescribeTeoHostCertificate(ctx context.Context, zoneId, host string) (hostCertificate *teo.HostCertSetting, errRet error) { + var ( + logId = getLogId(ctx) + request = teo.NewDescribeHostsCertificateRequest() + ) + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, "query object", request.ToJsonString(), errRet.Error()) + } + }() + + request.ZoneId = &zoneId + + request.Filters = append( + request.Filters, + &teo.CertFilter{ + Name: helper.String("host"), + Values: []*string{&host}, + }, + ) + ratelimit.Check(request.GetAction()) + + var offset int64 = 0 + var pageSize int64 = 100 + instances := make([]*teo.HostCertSetting, 0) + + for { + request.Offset = &offset + request.Limit = &pageSize + ratelimit.Check(request.GetAction()) + response, err := me.client.UseTeoClient().DescribeHostsCertificate(request) + if err != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, request.GetAction(), request.ToJsonString(), err.Error()) + errRet = err + return + } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + + if response == nil || len(response.Response.Hosts) < 1 { + break + } + instances = append(instances, response.Response.Hosts...) + if len(response.Response.Hosts) < int(pageSize) { + break + } + offset += pageSize + } + + if len(instances) < 1 { + return + } + hostCertificate = instances[0] + + return +} + +func (me *TeoService) DescribeTeoDnsSec(ctx context.Context, zoneId string) (dnsSec *teo.DescribeDnssecResponseParams, errRet error) { + var ( + logId = getLogId(ctx) + request = teo.NewDescribeDnssecRequest() + ) + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, "query object", request.ToJsonString(), errRet.Error()) + } + }() + request.Id = &zoneId + + response, err := me.client.UseTeoClient().DescribeDnssec(request) + if err != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, request.GetAction(), request.ToJsonString(), err.Error()) + errRet = err + return + } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + dnsSec = response.Response + return +} + +func (me *TeoService) DescribeTeoDefaultCertificate(ctx context.Context, zoneId string) (defaultCertificate *teo.DefaultServerCertInfo, errRet error) { + var ( + logId = getLogId(ctx) + request = teo.NewDescribeDefaultCertificatesRequest() + ) + + defaultCertificates := make([]*teo.DefaultServerCertInfo, 0) + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, "query object", request.ToJsonString(), errRet.Error()) + } + }() + request.ZoneId = &zoneId + + response, err := me.client.UseTeoClient().DescribeDefaultCertificates(request) + if err != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, request.GetAction(), request.ToJsonString(), err.Error()) + errRet = err + return + } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + defaultCertificates = response.Response.CertInfo + + for _, cert := range defaultCertificates { + if *cert.CertId != "" { + defaultCertificate = cert + return + } + } + return +} + +func (me *TeoService) DescribeTeoDdosPolicy(ctx context.Context, zoneId, policyId string) (ddosPolicy *teo.DescribeDDoSPolicyResponseParams, errRet error) { + var ( + logId = getLogId(ctx) + request = teo.NewDescribeDDoSPolicyRequest() + ) + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, "query object", request.ToJsonString(), errRet.Error()) + } + }() + + policyId64, errRet := strconv.ParseInt(policyId, 10, 64) + if errRet != nil { + log.Printf("[DEBUG]%s api[%s] error, Type conversion failed, [%s] conversion int64 failed\n", + logId, request.GetAction(), policyId) + return nil, errRet + } + + request.ZoneId = &zoneId + request.PolicyId = &policyId64 + + response, err := me.client.UseTeoClient().DescribeDDoSPolicy(request) + if err != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, request.GetAction(), request.ToJsonString(), err.Error()) + errRet = err + return + } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + ddosPolicy = response.Response + return +} + +func (me *TeoService) DescribeZoneDDoSPolicy(ctx context.Context, zoneId string) (ddosPolicy *teo.DescribeZoneDDoSPolicyResponseParams, errRet error) { + var ( + logId = getLogId(ctx) + request = teo.NewDescribeZoneDDoSPolicyRequest() + ) + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, "query object", request.ToJsonString(), errRet.Error()) + } + }() + + if zoneId != "" { + request.ZoneId = &zoneId + } + + response, err := me.client.UseTeoClient().DescribeZoneDDoSPolicy(request) + if err != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, request.GetAction(), request.ToJsonString(), err.Error()) + errRet = err + return + } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + ddosPolicy = response.Response + return +} + +func (me *TeoService) DeleteTeoDdosPolicyById(ctx context.Context, zoneId, policyId string) (errRet error) { + logId := getLogId(ctx) + + request := teo.NewModifyDDoSPolicyRequest() + + policyId64, errRet := strconv.ParseInt(policyId, 10, 64) + if errRet != nil { + log.Printf("[DEBUG]%s api[%s] error, Type conversion failed, [%s] conversion int64 failed\n", + logId, request.GetAction(), policyId) + return errRet + } + + request.ZoneId = &zoneId + request.PolicyId = &policyId64 + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, "delete object", request.ToJsonString(), errRet.Error()) + } + }() + + ratelimit.Check(request.GetAction()) + response, err := me.client.UseTeoClient().ModifyDDoSPolicy(request) + if err != nil { + errRet = err + return err + } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + + return +} + +func (me *TeoService) DescribeAvailablePlans(ctx context.Context) (availablePlans *teo.DescribeAvailablePlansResponseParams, errRet error) { + var ( + logId = getLogId(ctx) + request = teo.NewDescribeAvailablePlansRequest() + ) + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, "query object", request.ToJsonString(), errRet.Error()) + } + }() + + response, err := me.client.UseTeoClient().DescribeAvailablePlans(request) + if err != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, request.GetAction(), request.ToJsonString(), err.Error()) + errRet = err + return + } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + availablePlans = response.Response + return +} diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/client.go b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/client.go index f636d5a44d..c0e8aba3be 100644 --- a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/client.go +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/client.go @@ -121,7 +121,7 @@ func (c *Client) sendWithoutSignature(request tchttp.Request, response tchttp.Re if c.region != "" { headers["X-TC-Region"] = c.region } - if c.credential.GetToken() != "" { + if c.credential != nil && c.credential.GetToken() != "" { headers["X-TC-Token"] = c.credential.GetToken() } if request.GetHttpMethod() == "GET" { diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http/request.go b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http/request.go index 78b619bbf7..6c0b2f976f 100644 --- a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http/request.go +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http/request.go @@ -265,7 +265,7 @@ func CompleteCommonParams(request Request, region string) { params["Action"] = request.GetAction() params["Timestamp"] = strconv.FormatInt(time.Now().Unix(), 10) params["Nonce"] = strconv.Itoa(rand.Int()) - params["RequestClient"] = "SDK_GO_1.0.480" + params["RequestClient"] = "SDK_GO_1.0.486" } func ConstructParams(req Request) (err error) { diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/oidc_role_arn_provider.go b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/oidc_role_arn_provider.go new file mode 100644 index 0000000000..8f42fb6430 --- /dev/null +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/oidc_role_arn_provider.go @@ -0,0 +1,135 @@ +package common + +import ( + "encoding/json" + "errors" + "io/ioutil" + "os" + "strconv" + "time" + + tcerr "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors" + tchttp "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http" + "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile" +) + +type OIDCRoleArnProvider struct { + region string + providerId string + webIdentityToken string + roleArn string + roleSessionName string + durationSeconds int64 +} + +type oidcStsRsp struct { + Response struct { + Credentials struct { + Token string `json:"Token"` + TmpSecretId string `json:"TmpSecretId"` + TmpSecretKey string `json:"TmpSecretKey"` + } `json:"Credentials"` + ExpiredTime int `json:"ExpiredTime"` + Expiration time.Time `json:"Expiration"` + RequestId string `json:"RequestId"` + } `json:"Response"` +} + +func NewOIDCRoleArnProvider(region, providerId, webIdentityToken, roleArn, roleSessionName string, durationSeconds int64) *OIDCRoleArnProvider { + return &OIDCRoleArnProvider{ + region: region, + providerId: providerId, + webIdentityToken: webIdentityToken, + roleArn: roleArn, + roleSessionName: roleSessionName, + durationSeconds: durationSeconds, + } +} + +// DefaultTkeOIDCRoleArnProvider returns a OIDCRoleArnProvider with some default options: +// 1. providerId will be environment var TKE_PROVIDER_ID +// 2. webIdentityToken will be the content of file specified by env TKE_IDENTITY_TOKEN_FILE +// 3. roleArn will be env TKE_ROLE_ARN +// 4. roleSessionName will be "tencentcloud-go-sdk-" + timestamp +// 5. durationSeconds will be 7200s +func DefaultTkeOIDCRoleArnProvider() (*OIDCRoleArnProvider, error) { + reg := os.Getenv("TKE_REGION") + if reg == "" { + return nil, errors.New("env TKE_REGION not exist") + } + + providerId := os.Getenv("TKE_PROVIDER_ID") + if providerId == "" { + return nil, errors.New("env TKE_PROVIDER_ID not exist") + } + + tokenFile := os.Getenv("TKE_IDENTITY_TOKEN_FILE") + if tokenFile == "" { + return nil, errors.New("env TKE_IDENTITY_TOKEN_FILE not exist") + } + tokenBytes, err := ioutil.ReadFile(tokenFile) + if err != nil { + return nil, err + } + + roleArn := os.Getenv("TKE_ROLE_ARN") + if roleArn == "" { + return nil, errors.New("env TKE_ROLE_ARN not exist") + } + + sessionName := defaultSessionName + strconv.FormatInt(time.Now().UnixNano()/1000, 10) + + return NewOIDCRoleArnProvider(reg, providerId, string(tokenBytes), roleArn, sessionName, defaultDurationSeconds), nil +} + +func (r *OIDCRoleArnProvider) GetCredential() (CredentialIface, error) { + const ( + service = "sts" + version = "2018-08-13" + action = "AssumeRoleWithWebIdentity" + ) + if r.durationSeconds > 43200 || r.durationSeconds <= 0 { + return nil, tcerr.NewTencentCloudSDKError(creErr, "AssumeRoleWithWebIdentity durationSeconds should be in the range of 0~43200s", "") + } + cpf := profile.NewClientProfile() + cpf.HttpProfile.Endpoint = endpoint + cpf.HttpProfile.ReqMethod = "POST" + + client := NewCommonClient(nil, r.region, cpf) + request := tchttp.NewCommonRequest(service, version, action) + request.SetSkipSign(true) + + params := map[string]interface{}{ + "ProviderId": r.providerId, + "WebIdentityToken": r.webIdentityToken, + "RoleArn": r.roleArn, + "RoleSessionName": r.roleSessionName, + "DurationSeconds": r.durationSeconds, + } + err := request.SetActionParameters(params) + if err != nil { + return nil, err + } + + response := tchttp.NewCommonResponse() + err = client.Send(request, response) + if err != nil { + return nil, err + } + rspSt := new(oidcStsRsp) + + if err = json.Unmarshal(response.GetBody(), rspSt); err != nil { + return nil, tcerr.NewTencentCloudSDKError(creErr, err.Error(), "") + } + + return &RoleArnCredential{ + roleArn: r.roleArn, + roleSessionName: r.roleSessionName, + durationSeconds: r.durationSeconds, + expiredTime: int64(rspSt.Response.ExpiredTime), + token: rspSt.Response.Credentials.Token, + tmpSecretId: rspSt.Response.Credentials.TmpSecretId, + tmpSecretKey: rspSt.Response.Credentials.TmpSecretKey, + source: r, + }, nil +} diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/role_arn_credential.go b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/role_arn_credential.go index 392c337834..3f71a02171 100644 --- a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/role_arn_credential.go +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/role_arn_credential.go @@ -13,7 +13,7 @@ type RoleArnCredential struct { token string tmpSecretId string tmpSecretKey string - source *RoleArnProvider + source Provider } func (c *RoleArnCredential) GetSecretId() string { diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/LICENSE b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/LICENSE new file mode 100644 index 0000000000..efc75a2253 --- /dev/null +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright (c) 2017-2018 Tencent Ltd. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220106/client.go b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220106/client.go new file mode 100644 index 0000000000..946461b88f --- /dev/null +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220106/client.go @@ -0,0 +1,5002 @@ +// Copyright (c) 2017-2018 THL A29 Limited, a Tencent company. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package v20220106 + +import ( + "context" + "errors" + "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" + tchttp "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http" + "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile" +) + +const APIVersion = "2022-01-06" + +type Client struct { + common.Client +} + +// Deprecated +func NewClientWithSecretId(secretId, secretKey, region string) (client *Client, err error) { + cpf := profile.NewClientProfile() + client = &Client{} + client.Init(region).WithSecretId(secretId, secretKey).WithProfile(cpf) + return +} + +func NewClient(credential common.CredentialIface, region string, clientProfile *profile.ClientProfile) (client *Client, err error) { + client = &Client{} + client.Init(region). + WithCredential(credential). + WithProfile(clientProfile) + return +} + + +func NewCheckCertificateRequest() (request *CheckCertificateRequest) { + request = &CheckCertificateRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "CheckCertificate") + + + return +} + +func NewCheckCertificateResponse() (response *CheckCertificateResponse) { + response = &CheckCertificateResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// CheckCertificate +// 校验证书 +// +// 可能返回的错误码: +// INVALIDPARAMETER_INVALIDCERTINFO = "InvalidParameter.InvalidCertInfo" +// OPERATIONDENIED = "OperationDenied" +func (c *Client) CheckCertificate(request *CheckCertificateRequest) (response *CheckCertificateResponse, err error) { + return c.CheckCertificateWithContext(context.Background(), request) +} + +// CheckCertificate +// 校验证书 +// +// 可能返回的错误码: +// INVALIDPARAMETER_INVALIDCERTINFO = "InvalidParameter.InvalidCertInfo" +// OPERATIONDENIED = "OperationDenied" +func (c *Client) CheckCertificateWithContext(ctx context.Context, request *CheckCertificateRequest) (response *CheckCertificateResponse, err error) { + if request == nil { + request = NewCheckCertificateRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("CheckCertificate require credential") + } + + request.SetContext(ctx) + + response = NewCheckCertificateResponse() + err = c.Send(request, response) + return +} + +func NewCreateApplicationProxyRequest() (request *CreateApplicationProxyRequest) { + request = &CreateApplicationProxyRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "CreateApplicationProxy") + + + return +} + +func NewCreateApplicationProxyResponse() (response *CreateApplicationProxyResponse) { + response = &CreateApplicationProxyResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// CreateApplicationProxy +// 创建应用代理 +// +// 可能返回的错误码: +// INVALIDPARAMETER_PARAMETERERROR = "InvalidParameter.ParameterError" +// LIMITEXCEEDED = "LimitExceeded" +// OPERATIONDENIED = "OperationDenied" +// RESOURCEINSUFFICIENT = "ResourceInsufficient" +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) CreateApplicationProxy(request *CreateApplicationProxyRequest) (response *CreateApplicationProxyResponse, err error) { + return c.CreateApplicationProxyWithContext(context.Background(), request) +} + +// CreateApplicationProxy +// 创建应用代理 +// +// 可能返回的错误码: +// INVALIDPARAMETER_PARAMETERERROR = "InvalidParameter.ParameterError" +// LIMITEXCEEDED = "LimitExceeded" +// OPERATIONDENIED = "OperationDenied" +// RESOURCEINSUFFICIENT = "ResourceInsufficient" +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) CreateApplicationProxyWithContext(ctx context.Context, request *CreateApplicationProxyRequest) (response *CreateApplicationProxyResponse, err error) { + if request == nil { + request = NewCreateApplicationProxyRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("CreateApplicationProxy require credential") + } + + request.SetContext(ctx) + + response = NewCreateApplicationProxyResponse() + err = c.Send(request, response) + return +} + +func NewCreateApplicationProxyRuleRequest() (request *CreateApplicationProxyRuleRequest) { + request = &CreateApplicationProxyRuleRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "CreateApplicationProxyRule") + + + return +} + +func NewCreateApplicationProxyRuleResponse() (response *CreateApplicationProxyRuleResponse) { + response = &CreateApplicationProxyRuleResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// CreateApplicationProxyRule +// 创建应用代理规则 +// +// 可能返回的错误码: +// INVALIDPARAMETER_PARAMETERERROR = "InvalidParameter.ParameterError" +func (c *Client) CreateApplicationProxyRule(request *CreateApplicationProxyRuleRequest) (response *CreateApplicationProxyRuleResponse, err error) { + return c.CreateApplicationProxyRuleWithContext(context.Background(), request) +} + +// CreateApplicationProxyRule +// 创建应用代理规则 +// +// 可能返回的错误码: +// INVALIDPARAMETER_PARAMETERERROR = "InvalidParameter.ParameterError" +func (c *Client) CreateApplicationProxyRuleWithContext(ctx context.Context, request *CreateApplicationProxyRuleRequest) (response *CreateApplicationProxyRuleResponse, err error) { + if request == nil { + request = NewCreateApplicationProxyRuleRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("CreateApplicationProxyRule require credential") + } + + request.SetContext(ctx) + + response = NewCreateApplicationProxyRuleResponse() + err = c.Send(request, response) + return +} + +func NewCreateApplicationProxyRulesRequest() (request *CreateApplicationProxyRulesRequest) { + request = &CreateApplicationProxyRulesRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "CreateApplicationProxyRules") + + + return +} + +func NewCreateApplicationProxyRulesResponse() (response *CreateApplicationProxyRulesResponse) { + response = &CreateApplicationProxyRulesResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// CreateApplicationProxyRules +// 批量创建应用代理规则 +// +// 可能返回的错误码: +// INVALIDPARAMETER_PARAMETERERROR = "InvalidParameter.ParameterError" +func (c *Client) CreateApplicationProxyRules(request *CreateApplicationProxyRulesRequest) (response *CreateApplicationProxyRulesResponse, err error) { + return c.CreateApplicationProxyRulesWithContext(context.Background(), request) +} + +// CreateApplicationProxyRules +// 批量创建应用代理规则 +// +// 可能返回的错误码: +// INVALIDPARAMETER_PARAMETERERROR = "InvalidParameter.ParameterError" +func (c *Client) CreateApplicationProxyRulesWithContext(ctx context.Context, request *CreateApplicationProxyRulesRequest) (response *CreateApplicationProxyRulesResponse, err error) { + if request == nil { + request = NewCreateApplicationProxyRulesRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("CreateApplicationProxyRules require credential") + } + + request.SetContext(ctx) + + response = NewCreateApplicationProxyRulesResponse() + err = c.Send(request, response) + return +} + +func NewCreateCustomErrorPageRequest() (request *CreateCustomErrorPageRequest) { + request = &CreateCustomErrorPageRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "CreateCustomErrorPage") + + + return +} + +func NewCreateCustomErrorPageResponse() (response *CreateCustomErrorPageResponse) { + response = &CreateCustomErrorPageResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// CreateCustomErrorPage +// 创建自定义规则的自定义页 +// +// 可能返回的错误码: +// INVALIDPARAMETER_PARAMETERERROR = "InvalidParameter.ParameterError" +func (c *Client) CreateCustomErrorPage(request *CreateCustomErrorPageRequest) (response *CreateCustomErrorPageResponse, err error) { + return c.CreateCustomErrorPageWithContext(context.Background(), request) +} + +// CreateCustomErrorPage +// 创建自定义规则的自定义页 +// +// 可能返回的错误码: +// INVALIDPARAMETER_PARAMETERERROR = "InvalidParameter.ParameterError" +func (c *Client) CreateCustomErrorPageWithContext(ctx context.Context, request *CreateCustomErrorPageRequest) (response *CreateCustomErrorPageResponse, err error) { + if request == nil { + request = NewCreateCustomErrorPageRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("CreateCustomErrorPage require credential") + } + + request.SetContext(ctx) + + response = NewCreateCustomErrorPageResponse() + err = c.Send(request, response) + return +} + +func NewCreateDnsRecordRequest() (request *CreateDnsRecordRequest) { + request = &CreateDnsRecordRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "CreateDnsRecord") + + + return +} + +func NewCreateDnsRecordResponse() (response *CreateDnsRecordResponse) { + response = &CreateDnsRecordResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// CreateDnsRecord +// 创建 DNS 记录 +// +// 可能返回的错误码: +// INVALIDPARAMETERVALUE_CONFLICTRECORD = "InvalidParameterValue.ConflictRecord" +// INVALIDPARAMETERVALUE_CONFLICTWITHDNSSEC = "InvalidParameterValue.ConflictWithDNSSEC" +// INVALIDPARAMETERVALUE_CONFLICTWITHLBRECORD = "InvalidParameterValue.ConflictWithLBRecord" +// INVALIDPARAMETERVALUE_CONFLICTWITHNSRECORD = "InvalidParameterValue.ConflictWithNSRecord" +// INVALIDPARAMETERVALUE_INVALIDDNSCONTENT = "InvalidParameterValue.InvalidDNSContent" +// INVALIDPARAMETERVALUE_INVALIDDNSNAME = "InvalidParameterValue.InvalidDNSName" +// INVALIDPARAMETERVALUE_INVALIDPROXYNAME = "InvalidParameterValue.InvalidProxyName" +// INVALIDPARAMETERVALUE_INVALIDPROXYORIGIN = "InvalidParameterValue.InvalidProxyOrigin" +// INVALIDPARAMETERVALUE_RECORDALREADYEXISTS = "InvalidParameterValue.RecordAlreadyExists" +// INVALIDPARAMETERVALUE_RECORDNOTALLOWED = "InvalidParameterValue.RecordNotAllowed" +// OPERATIONDENIED = "OperationDenied" +// OPERATIONDENIED_DOMAINNOICP = "OperationDenied.DomainNoICP" +// RESOURCENOTFOUND = "ResourceNotFound" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) CreateDnsRecord(request *CreateDnsRecordRequest) (response *CreateDnsRecordResponse, err error) { + return c.CreateDnsRecordWithContext(context.Background(), request) +} + +// CreateDnsRecord +// 创建 DNS 记录 +// +// 可能返回的错误码: +// INVALIDPARAMETERVALUE_CONFLICTRECORD = "InvalidParameterValue.ConflictRecord" +// INVALIDPARAMETERVALUE_CONFLICTWITHDNSSEC = "InvalidParameterValue.ConflictWithDNSSEC" +// INVALIDPARAMETERVALUE_CONFLICTWITHLBRECORD = "InvalidParameterValue.ConflictWithLBRecord" +// INVALIDPARAMETERVALUE_CONFLICTWITHNSRECORD = "InvalidParameterValue.ConflictWithNSRecord" +// INVALIDPARAMETERVALUE_INVALIDDNSCONTENT = "InvalidParameterValue.InvalidDNSContent" +// INVALIDPARAMETERVALUE_INVALIDDNSNAME = "InvalidParameterValue.InvalidDNSName" +// INVALIDPARAMETERVALUE_INVALIDPROXYNAME = "InvalidParameterValue.InvalidProxyName" +// INVALIDPARAMETERVALUE_INVALIDPROXYORIGIN = "InvalidParameterValue.InvalidProxyOrigin" +// INVALIDPARAMETERVALUE_RECORDALREADYEXISTS = "InvalidParameterValue.RecordAlreadyExists" +// INVALIDPARAMETERVALUE_RECORDNOTALLOWED = "InvalidParameterValue.RecordNotAllowed" +// OPERATIONDENIED = "OperationDenied" +// OPERATIONDENIED_DOMAINNOICP = "OperationDenied.DomainNoICP" +// RESOURCENOTFOUND = "ResourceNotFound" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) CreateDnsRecordWithContext(ctx context.Context, request *CreateDnsRecordRequest) (response *CreateDnsRecordResponse, err error) { + if request == nil { + request = NewCreateDnsRecordRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("CreateDnsRecord require credential") + } + + request.SetContext(ctx) + + response = NewCreateDnsRecordResponse() + err = c.Send(request, response) + return +} + +func NewCreateLoadBalancingRequest() (request *CreateLoadBalancingRequest) { + request = &CreateLoadBalancingRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "CreateLoadBalancing") + + + return +} + +func NewCreateLoadBalancingResponse() (response *CreateLoadBalancingResponse) { + response = &CreateLoadBalancingResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// CreateLoadBalancing +// 创建负载均衡 +// +// 可能返回的错误码: +// LIMITEXCEEDED = "LimitExceeded" +func (c *Client) CreateLoadBalancing(request *CreateLoadBalancingRequest) (response *CreateLoadBalancingResponse, err error) { + return c.CreateLoadBalancingWithContext(context.Background(), request) +} + +// CreateLoadBalancing +// 创建负载均衡 +// +// 可能返回的错误码: +// LIMITEXCEEDED = "LimitExceeded" +func (c *Client) CreateLoadBalancingWithContext(ctx context.Context, request *CreateLoadBalancingRequest) (response *CreateLoadBalancingResponse, err error) { + if request == nil { + request = NewCreateLoadBalancingRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("CreateLoadBalancing require credential") + } + + request.SetContext(ctx) + + response = NewCreateLoadBalancingResponse() + err = c.Send(request, response) + return +} + +func NewCreateOriginGroupRequest() (request *CreateOriginGroupRequest) { + request = &CreateOriginGroupRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "CreateOriginGroup") + + + return +} + +func NewCreateOriginGroupResponse() (response *CreateOriginGroupResponse) { + response = &CreateOriginGroupResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// CreateOriginGroup +// 源站组创建 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +// UNAUTHORIZEDOPERATION_NOPERMISSION = "UnauthorizedOperation.NoPermission" +func (c *Client) CreateOriginGroup(request *CreateOriginGroupRequest) (response *CreateOriginGroupResponse, err error) { + return c.CreateOriginGroupWithContext(context.Background(), request) +} + +// CreateOriginGroup +// 源站组创建 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +// UNAUTHORIZEDOPERATION_NOPERMISSION = "UnauthorizedOperation.NoPermission" +func (c *Client) CreateOriginGroupWithContext(ctx context.Context, request *CreateOriginGroupRequest) (response *CreateOriginGroupResponse, err error) { + if request == nil { + request = NewCreateOriginGroupRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("CreateOriginGroup require credential") + } + + request.SetContext(ctx) + + response = NewCreateOriginGroupResponse() + err = c.Send(request, response) + return +} + +func NewCreatePlanForZoneRequest() (request *CreatePlanForZoneRequest) { + request = &CreatePlanForZoneRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "CreatePlanForZone") + + + return +} + +func NewCreatePlanForZoneResponse() (response *CreatePlanForZoneResponse) { + response = &CreatePlanForZoneResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// CreatePlanForZone +// 为未购买套餐的站点购买套餐 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +// UNAUTHORIZEDOPERATION_NOPERMISSION = "UnauthorizedOperation.NoPermission" +func (c *Client) CreatePlanForZone(request *CreatePlanForZoneRequest) (response *CreatePlanForZoneResponse, err error) { + return c.CreatePlanForZoneWithContext(context.Background(), request) +} + +// CreatePlanForZone +// 为未购买套餐的站点购买套餐 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +// UNAUTHORIZEDOPERATION_NOPERMISSION = "UnauthorizedOperation.NoPermission" +func (c *Client) CreatePlanForZoneWithContext(ctx context.Context, request *CreatePlanForZoneRequest) (response *CreatePlanForZoneResponse, err error) { + if request == nil { + request = NewCreatePlanForZoneRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("CreatePlanForZone require credential") + } + + request.SetContext(ctx) + + response = NewCreatePlanForZoneResponse() + err = c.Send(request, response) + return +} + +func NewCreatePrefetchTaskRequest() (request *CreatePrefetchTaskRequest) { + request = &CreatePrefetchTaskRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "CreatePrefetchTask") + + + return +} + +func NewCreatePrefetchTaskResponse() (response *CreatePrefetchTaskResponse) { + response = &CreatePrefetchTaskResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// CreatePrefetchTask +// 创建预热任务 +// +// 可能返回的错误码: +// INTERNALERROR_BACKENDERROR = "InternalError.BackendError" +// INTERNALERROR_DOMAINCONFIG = "InternalError.DomainConfig" +// INTERNALERROR_FAILEDTOGENERATEURL = "InternalError.FailedToGenerateUrl" +// INTERNALERROR_QUOTASYSTEM = "InternalError.QuotaSystem" +// INVALIDPARAMETER_DOMAINNOTFOUND = "InvalidParameter.DomainNotFound" +// INVALIDPARAMETER_PARAMETERERROR = "InvalidParameter.ParameterError" +// INVALIDPARAMETER_TARGET = "InvalidParameter.Target" +// INVALIDPARAMETER_TASKNOTGENERATED = "InvalidParameter.TaskNotGenerated" +// INVALIDPARAMETER_UPLOADURL = "InvalidParameter.UploadUrl" +// LIMITEXCEEDED_BATCHQUOTA = "LimitExceeded.BatchQuota" +// LIMITEXCEEDED_DAILYQUOTA = "LimitExceeded.DailyQuota" +func (c *Client) CreatePrefetchTask(request *CreatePrefetchTaskRequest) (response *CreatePrefetchTaskResponse, err error) { + return c.CreatePrefetchTaskWithContext(context.Background(), request) +} + +// CreatePrefetchTask +// 创建预热任务 +// +// 可能返回的错误码: +// INTERNALERROR_BACKENDERROR = "InternalError.BackendError" +// INTERNALERROR_DOMAINCONFIG = "InternalError.DomainConfig" +// INTERNALERROR_FAILEDTOGENERATEURL = "InternalError.FailedToGenerateUrl" +// INTERNALERROR_QUOTASYSTEM = "InternalError.QuotaSystem" +// INVALIDPARAMETER_DOMAINNOTFOUND = "InvalidParameter.DomainNotFound" +// INVALIDPARAMETER_PARAMETERERROR = "InvalidParameter.ParameterError" +// INVALIDPARAMETER_TARGET = "InvalidParameter.Target" +// INVALIDPARAMETER_TASKNOTGENERATED = "InvalidParameter.TaskNotGenerated" +// INVALIDPARAMETER_UPLOADURL = "InvalidParameter.UploadUrl" +// LIMITEXCEEDED_BATCHQUOTA = "LimitExceeded.BatchQuota" +// LIMITEXCEEDED_DAILYQUOTA = "LimitExceeded.DailyQuota" +func (c *Client) CreatePrefetchTaskWithContext(ctx context.Context, request *CreatePrefetchTaskRequest) (response *CreatePrefetchTaskResponse, err error) { + if request == nil { + request = NewCreatePrefetchTaskRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("CreatePrefetchTask require credential") + } + + request.SetContext(ctx) + + response = NewCreatePrefetchTaskResponse() + err = c.Send(request, response) + return +} + +func NewCreatePurgeTaskRequest() (request *CreatePurgeTaskRequest) { + request = &CreatePurgeTaskRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "CreatePurgeTask") + + + return +} + +func NewCreatePurgeTaskResponse() (response *CreatePurgeTaskResponse) { + response = &CreatePurgeTaskResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// CreatePurgeTask +// 创建清除缓存任务 +// +// 可能返回的错误码: +// INTERNALERROR_BACKENDERROR = "InternalError.BackendError" +// INTERNALERROR_DOMAINCONFIG = "InternalError.DomainConfig" +// INTERNALERROR_QUOTASYSTEM = "InternalError.QuotaSystem" +// INVALIDPARAMETER_DOMAINNOTFOUND = "InvalidParameter.DomainNotFound" +// INVALIDPARAMETER_PARAMETERERROR = "InvalidParameter.ParameterError" +// INVALIDPARAMETER_TARGET = "InvalidParameter.Target" +// INVALIDPARAMETER_TASKNOTGENERATED = "InvalidParameter.TaskNotGenerated" +// INVALIDPARAMETER_UPLOADURL = "InvalidParameter.UploadUrl" +// LIMITEXCEEDED_BATCHQUOTA = "LimitExceeded.BatchQuota" +// LIMITEXCEEDED_DAILYQUOTA = "LimitExceeded.DailyQuota" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) CreatePurgeTask(request *CreatePurgeTaskRequest) (response *CreatePurgeTaskResponse, err error) { + return c.CreatePurgeTaskWithContext(context.Background(), request) +} + +// CreatePurgeTask +// 创建清除缓存任务 +// +// 可能返回的错误码: +// INTERNALERROR_BACKENDERROR = "InternalError.BackendError" +// INTERNALERROR_DOMAINCONFIG = "InternalError.DomainConfig" +// INTERNALERROR_QUOTASYSTEM = "InternalError.QuotaSystem" +// INVALIDPARAMETER_DOMAINNOTFOUND = "InvalidParameter.DomainNotFound" +// INVALIDPARAMETER_PARAMETERERROR = "InvalidParameter.ParameterError" +// INVALIDPARAMETER_TARGET = "InvalidParameter.Target" +// INVALIDPARAMETER_TASKNOTGENERATED = "InvalidParameter.TaskNotGenerated" +// INVALIDPARAMETER_UPLOADURL = "InvalidParameter.UploadUrl" +// LIMITEXCEEDED_BATCHQUOTA = "LimitExceeded.BatchQuota" +// LIMITEXCEEDED_DAILYQUOTA = "LimitExceeded.DailyQuota" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) CreatePurgeTaskWithContext(ctx context.Context, request *CreatePurgeTaskRequest) (response *CreatePurgeTaskResponse, err error) { + if request == nil { + request = NewCreatePurgeTaskRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("CreatePurgeTask require credential") + } + + request.SetContext(ctx) + + response = NewCreatePurgeTaskResponse() + err = c.Send(request, response) + return +} + +func NewCreateRuleRequest() (request *CreateRuleRequest) { + request = &CreateRuleRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "CreateRule") + + + return +} + +func NewCreateRuleResponse() (response *CreateRuleResponse) { + response = &CreateRuleResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// CreateRule +// 规则引擎创建规则。 +// +// 可能返回的错误码: +// INVALIDPARAMETER_INVALIDRULEENGINETARGET = "InvalidParameter.InvalidRuleEngineTarget" +func (c *Client) CreateRule(request *CreateRuleRequest) (response *CreateRuleResponse, err error) { + return c.CreateRuleWithContext(context.Background(), request) +} + +// CreateRule +// 规则引擎创建规则。 +// +// 可能返回的错误码: +// INVALIDPARAMETER_INVALIDRULEENGINETARGET = "InvalidParameter.InvalidRuleEngineTarget" +func (c *Client) CreateRuleWithContext(ctx context.Context, request *CreateRuleRequest) (response *CreateRuleResponse, err error) { + if request == nil { + request = NewCreateRuleRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("CreateRule require credential") + } + + request.SetContext(ctx) + + response = NewCreateRuleResponse() + err = c.Send(request, response) + return +} + +func NewCreateZoneRequest() (request *CreateZoneRequest) { + request = &CreateZoneRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "CreateZone") + + + return +} + +func NewCreateZoneResponse() (response *CreateZoneResponse) { + response = &CreateZoneResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// CreateZone +// 用于用户接入新的站点 +// +// 可能返回的错误码: +// DRYRUNOPERATION = "DryRunOperation" +// OPERATIONDENIED = "OperationDenied" +// RESOURCEINUSE = "ResourceInUse" +// RESOURCEINUSE_OTHERS = "ResourceInUse.Others" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) CreateZone(request *CreateZoneRequest) (response *CreateZoneResponse, err error) { + return c.CreateZoneWithContext(context.Background(), request) +} + +// CreateZone +// 用于用户接入新的站点 +// +// 可能返回的错误码: +// DRYRUNOPERATION = "DryRunOperation" +// OPERATIONDENIED = "OperationDenied" +// RESOURCEINUSE = "ResourceInUse" +// RESOURCEINUSE_OTHERS = "ResourceInUse.Others" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) CreateZoneWithContext(ctx context.Context, request *CreateZoneRequest) (response *CreateZoneResponse, err error) { + if request == nil { + request = NewCreateZoneRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("CreateZone require credential") + } + + request.SetContext(ctx) + + response = NewCreateZoneResponse() + err = c.Send(request, response) + return +} + +func NewDeleteApplicationProxyRequest() (request *DeleteApplicationProxyRequest) { + request = &DeleteApplicationProxyRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DeleteApplicationProxy") + + + return +} + +func NewDeleteApplicationProxyResponse() (response *DeleteApplicationProxyResponse) { + response = &DeleteApplicationProxyResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DeleteApplicationProxy +// 删除应用代理 +// +// 可能返回的错误码: +// DRYRUNOPERATION = "DryRunOperation" +// OPERATIONDENIED = "OperationDenied" +// RESOURCEINUSE = "ResourceInUse" +// RESOURCEINUSE_OTHERS = "ResourceInUse.Others" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DeleteApplicationProxy(request *DeleteApplicationProxyRequest) (response *DeleteApplicationProxyResponse, err error) { + return c.DeleteApplicationProxyWithContext(context.Background(), request) +} + +// DeleteApplicationProxy +// 删除应用代理 +// +// 可能返回的错误码: +// DRYRUNOPERATION = "DryRunOperation" +// OPERATIONDENIED = "OperationDenied" +// RESOURCEINUSE = "ResourceInUse" +// RESOURCEINUSE_OTHERS = "ResourceInUse.Others" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DeleteApplicationProxyWithContext(ctx context.Context, request *DeleteApplicationProxyRequest) (response *DeleteApplicationProxyResponse, err error) { + if request == nil { + request = NewDeleteApplicationProxyRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DeleteApplicationProxy require credential") + } + + request.SetContext(ctx) + + response = NewDeleteApplicationProxyResponse() + err = c.Send(request, response) + return +} + +func NewDeleteApplicationProxyRuleRequest() (request *DeleteApplicationProxyRuleRequest) { + request = &DeleteApplicationProxyRuleRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DeleteApplicationProxyRule") + + + return +} + +func NewDeleteApplicationProxyRuleResponse() (response *DeleteApplicationProxyRuleResponse) { + response = &DeleteApplicationProxyRuleResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DeleteApplicationProxyRule +// 删除应用代理规则 +// +// 可能返回的错误码: +// DRYRUNOPERATION = "DryRunOperation" +// OPERATIONDENIED = "OperationDenied" +// RESOURCEINUSE = "ResourceInUse" +// RESOURCEINUSE_OTHERS = "ResourceInUse.Others" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DeleteApplicationProxyRule(request *DeleteApplicationProxyRuleRequest) (response *DeleteApplicationProxyRuleResponse, err error) { + return c.DeleteApplicationProxyRuleWithContext(context.Background(), request) +} + +// DeleteApplicationProxyRule +// 删除应用代理规则 +// +// 可能返回的错误码: +// DRYRUNOPERATION = "DryRunOperation" +// OPERATIONDENIED = "OperationDenied" +// RESOURCEINUSE = "ResourceInUse" +// RESOURCEINUSE_OTHERS = "ResourceInUse.Others" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DeleteApplicationProxyRuleWithContext(ctx context.Context, request *DeleteApplicationProxyRuleRequest) (response *DeleteApplicationProxyRuleResponse, err error) { + if request == nil { + request = NewDeleteApplicationProxyRuleRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DeleteApplicationProxyRule require credential") + } + + request.SetContext(ctx) + + response = NewDeleteApplicationProxyRuleResponse() + err = c.Send(request, response) + return +} + +func NewDeleteDnsRecordsRequest() (request *DeleteDnsRecordsRequest) { + request = &DeleteDnsRecordsRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DeleteDnsRecords") + + + return +} + +func NewDeleteDnsRecordsResponse() (response *DeleteDnsRecordsResponse) { + response = &DeleteDnsRecordsResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DeleteDnsRecords +// 批量删除 DNS 记录 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// RESOURCEINUSE = "ResourceInUse" +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DeleteDnsRecords(request *DeleteDnsRecordsRequest) (response *DeleteDnsRecordsResponse, err error) { + return c.DeleteDnsRecordsWithContext(context.Background(), request) +} + +// DeleteDnsRecords +// 批量删除 DNS 记录 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// RESOURCEINUSE = "ResourceInUse" +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DeleteDnsRecordsWithContext(ctx context.Context, request *DeleteDnsRecordsRequest) (response *DeleteDnsRecordsResponse, err error) { + if request == nil { + request = NewDeleteDnsRecordsRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DeleteDnsRecords require credential") + } + + request.SetContext(ctx) + + response = NewDeleteDnsRecordsResponse() + err = c.Send(request, response) + return +} + +func NewDeleteLoadBalancingRequest() (request *DeleteLoadBalancingRequest) { + request = &DeleteLoadBalancingRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DeleteLoadBalancing") + + + return +} + +func NewDeleteLoadBalancingResponse() (response *DeleteLoadBalancingResponse) { + response = &DeleteLoadBalancingResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DeleteLoadBalancing +// 删除负载均衡 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// RESOURCEINUSE = "ResourceInUse" +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DeleteLoadBalancing(request *DeleteLoadBalancingRequest) (response *DeleteLoadBalancingResponse, err error) { + return c.DeleteLoadBalancingWithContext(context.Background(), request) +} + +// DeleteLoadBalancing +// 删除负载均衡 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// RESOURCEINUSE = "ResourceInUse" +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DeleteLoadBalancingWithContext(ctx context.Context, request *DeleteLoadBalancingRequest) (response *DeleteLoadBalancingResponse, err error) { + if request == nil { + request = NewDeleteLoadBalancingRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DeleteLoadBalancing require credential") + } + + request.SetContext(ctx) + + response = NewDeleteLoadBalancingResponse() + err = c.Send(request, response) + return +} + +func NewDeleteOriginGroupRequest() (request *DeleteOriginGroupRequest) { + request = &DeleteOriginGroupRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DeleteOriginGroup") + + + return +} + +func NewDeleteOriginGroupResponse() (response *DeleteOriginGroupResponse) { + response = &DeleteOriginGroupResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DeleteOriginGroup +// 源站组删除 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// RESOURCEINUSE = "ResourceInUse" +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DeleteOriginGroup(request *DeleteOriginGroupRequest) (response *DeleteOriginGroupResponse, err error) { + return c.DeleteOriginGroupWithContext(context.Background(), request) +} + +// DeleteOriginGroup +// 源站组删除 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// RESOURCEINUSE = "ResourceInUse" +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DeleteOriginGroupWithContext(ctx context.Context, request *DeleteOriginGroupRequest) (response *DeleteOriginGroupResponse, err error) { + if request == nil { + request = NewDeleteOriginGroupRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DeleteOriginGroup require credential") + } + + request.SetContext(ctx) + + response = NewDeleteOriginGroupResponse() + err = c.Send(request, response) + return +} + +func NewDeleteRulesRequest() (request *DeleteRulesRequest) { + request = &DeleteRulesRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DeleteRules") + + + return +} + +func NewDeleteRulesResponse() (response *DeleteRulesResponse) { + response = &DeleteRulesResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DeleteRules +// 批量删除规则引擎规则。 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// RESOURCEINUSE = "ResourceInUse" +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DeleteRules(request *DeleteRulesRequest) (response *DeleteRulesResponse, err error) { + return c.DeleteRulesWithContext(context.Background(), request) +} + +// DeleteRules +// 批量删除规则引擎规则。 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// RESOURCEINUSE = "ResourceInUse" +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DeleteRulesWithContext(ctx context.Context, request *DeleteRulesRequest) (response *DeleteRulesResponse, err error) { + if request == nil { + request = NewDeleteRulesRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DeleteRules require credential") + } + + request.SetContext(ctx) + + response = NewDeleteRulesResponse() + err = c.Send(request, response) + return +} + +func NewDeleteZoneRequest() (request *DeleteZoneRequest) { + request = &DeleteZoneRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DeleteZone") + + + return +} + +func NewDeleteZoneResponse() (response *DeleteZoneResponse) { + response = &DeleteZoneResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DeleteZone +// 删除站点 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// RESOURCEINUSE = "ResourceInUse" +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DeleteZone(request *DeleteZoneRequest) (response *DeleteZoneResponse, err error) { + return c.DeleteZoneWithContext(context.Background(), request) +} + +// DeleteZone +// 删除站点 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// RESOURCEINUSE = "ResourceInUse" +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DeleteZoneWithContext(ctx context.Context, request *DeleteZoneRequest) (response *DeleteZoneResponse, err error) { + if request == nil { + request = NewDeleteZoneRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DeleteZone require credential") + } + + request.SetContext(ctx) + + response = NewDeleteZoneResponse() + err = c.Send(request, response) + return +} + +func NewDescribeApplicationProxyRequest() (request *DescribeApplicationProxyRequest) { + request = &DescribeApplicationProxyRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeApplicationProxy") + + + return +} + +func NewDescribeApplicationProxyResponse() (response *DescribeApplicationProxyResponse) { + response = &DescribeApplicationProxyResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeApplicationProxy +// 获取应用代理列表 +// +// 可能返回的错误码: +// INTERNALERROR_PROXYSERVER = "InternalError.ProxyServer" +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeApplicationProxy(request *DescribeApplicationProxyRequest) (response *DescribeApplicationProxyResponse, err error) { + return c.DescribeApplicationProxyWithContext(context.Background(), request) +} + +// DescribeApplicationProxy +// 获取应用代理列表 +// +// 可能返回的错误码: +// INTERNALERROR_PROXYSERVER = "InternalError.ProxyServer" +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeApplicationProxyWithContext(ctx context.Context, request *DescribeApplicationProxyRequest) (response *DescribeApplicationProxyResponse, err error) { + if request == nil { + request = NewDescribeApplicationProxyRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeApplicationProxy require credential") + } + + request.SetContext(ctx) + + response = NewDescribeApplicationProxyResponse() + err = c.Send(request, response) + return +} + +func NewDescribeApplicationProxyDetailRequest() (request *DescribeApplicationProxyDetailRequest) { + request = &DescribeApplicationProxyDetailRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeApplicationProxyDetail") + + + return +} + +func NewDescribeApplicationProxyDetailResponse() (response *DescribeApplicationProxyDetailResponse) { + response = &DescribeApplicationProxyDetailResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeApplicationProxyDetail +// 获取应用代理详细信息 +// +// 可能返回的错误码: +// INTERNALERROR_PROXYSERVER = "InternalError.ProxyServer" +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DescribeApplicationProxyDetail(request *DescribeApplicationProxyDetailRequest) (response *DescribeApplicationProxyDetailResponse, err error) { + return c.DescribeApplicationProxyDetailWithContext(context.Background(), request) +} + +// DescribeApplicationProxyDetail +// 获取应用代理详细信息 +// +// 可能返回的错误码: +// INTERNALERROR_PROXYSERVER = "InternalError.ProxyServer" +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DescribeApplicationProxyDetailWithContext(ctx context.Context, request *DescribeApplicationProxyDetailRequest) (response *DescribeApplicationProxyDetailResponse, err error) { + if request == nil { + request = NewDescribeApplicationProxyDetailRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeApplicationProxyDetail require credential") + } + + request.SetContext(ctx) + + response = NewDescribeApplicationProxyDetailResponse() + err = c.Send(request, response) + return +} + +func NewDescribeAvailablePlansRequest() (request *DescribeAvailablePlansRequest) { + request = &DescribeAvailablePlansRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeAvailablePlans") + + + return +} + +func NewDescribeAvailablePlansResponse() (response *DescribeAvailablePlansResponse) { + response = &DescribeAvailablePlansResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeAvailablePlans +// 查询当前账户可用套餐信息列表 +// +// 可能返回的错误码: +// INTERNALERROR_PROXYSERVER = "InternalError.ProxyServer" +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DescribeAvailablePlans(request *DescribeAvailablePlansRequest) (response *DescribeAvailablePlansResponse, err error) { + return c.DescribeAvailablePlansWithContext(context.Background(), request) +} + +// DescribeAvailablePlans +// 查询当前账户可用套餐信息列表 +// +// 可能返回的错误码: +// INTERNALERROR_PROXYSERVER = "InternalError.ProxyServer" +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DescribeAvailablePlansWithContext(ctx context.Context, request *DescribeAvailablePlansRequest) (response *DescribeAvailablePlansResponse, err error) { + if request == nil { + request = NewDescribeAvailablePlansRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeAvailablePlans require credential") + } + + request.SetContext(ctx) + + response = NewDescribeAvailablePlansResponse() + err = c.Send(request, response) + return +} + +func NewDescribeBotLogRequest() (request *DescribeBotLogRequest) { + request = &DescribeBotLogRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeBotLog") + + + return +} + +func NewDescribeBotLogResponse() (response *DescribeBotLogResponse) { + response = &DescribeBotLogResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeBotLog +// 查询Bot攻击日志 +// +// 可能返回的错误码: +// INTERNALERROR_PROXYSERVER = "InternalError.ProxyServer" +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DescribeBotLog(request *DescribeBotLogRequest) (response *DescribeBotLogResponse, err error) { + return c.DescribeBotLogWithContext(context.Background(), request) +} + +// DescribeBotLog +// 查询Bot攻击日志 +// +// 可能返回的错误码: +// INTERNALERROR_PROXYSERVER = "InternalError.ProxyServer" +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DescribeBotLogWithContext(ctx context.Context, request *DescribeBotLogRequest) (response *DescribeBotLogResponse, err error) { + if request == nil { + request = NewDescribeBotLogRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeBotLog require credential") + } + + request.SetContext(ctx) + + response = NewDescribeBotLogResponse() + err = c.Send(request, response) + return +} + +func NewDescribeBotManagedRulesRequest() (request *DescribeBotManagedRulesRequest) { + request = &DescribeBotManagedRulesRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeBotManagedRules") + + + return +} + +func NewDescribeBotManagedRulesResponse() (response *DescribeBotManagedRulesResponse) { + response = &DescribeBotManagedRulesResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeBotManagedRules +// 分页查询Bot托管规则 +// +// 可能返回的错误码: +// INVALIDPARAMETER_SECURITY = "InvalidParameter.Security" +func (c *Client) DescribeBotManagedRules(request *DescribeBotManagedRulesRequest) (response *DescribeBotManagedRulesResponse, err error) { + return c.DescribeBotManagedRulesWithContext(context.Background(), request) +} + +// DescribeBotManagedRules +// 分页查询Bot托管规则 +// +// 可能返回的错误码: +// INVALIDPARAMETER_SECURITY = "InvalidParameter.Security" +func (c *Client) DescribeBotManagedRulesWithContext(ctx context.Context, request *DescribeBotManagedRulesRequest) (response *DescribeBotManagedRulesResponse, err error) { + if request == nil { + request = NewDescribeBotManagedRulesRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeBotManagedRules require credential") + } + + request.SetContext(ctx) + + response = NewDescribeBotManagedRulesResponse() + err = c.Send(request, response) + return +} + +func NewDescribeCnameStatusRequest() (request *DescribeCnameStatusRequest) { + request = &DescribeCnameStatusRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeCnameStatus") + + + return +} + +func NewDescribeCnameStatusResponse() (response *DescribeCnameStatusResponse) { + response = &DescribeCnameStatusResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeCnameStatus +// 查询域名 CNAME 状态 +// +// 可能返回的错误码: +// INTERNALERROR_PROXYSERVER = "InternalError.ProxyServer" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeCnameStatus(request *DescribeCnameStatusRequest) (response *DescribeCnameStatusResponse, err error) { + return c.DescribeCnameStatusWithContext(context.Background(), request) +} + +// DescribeCnameStatus +// 查询域名 CNAME 状态 +// +// 可能返回的错误码: +// INTERNALERROR_PROXYSERVER = "InternalError.ProxyServer" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeCnameStatusWithContext(ctx context.Context, request *DescribeCnameStatusRequest) (response *DescribeCnameStatusResponse, err error) { + if request == nil { + request = NewDescribeCnameStatusRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeCnameStatus require credential") + } + + request.SetContext(ctx) + + response = NewDescribeCnameStatusResponse() + err = c.Send(request, response) + return +} + +func NewDescribeDDoSPolicyRequest() (request *DescribeDDoSPolicyRequest) { + request = &DescribeDDoSPolicyRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeDDoSPolicy") + + + return +} + +func NewDescribeDDoSPolicyResponse() (response *DescribeDDoSPolicyResponse) { + response = &DescribeDDoSPolicyResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeDDoSPolicy +// 查询DDoS防护配置详情 +// +// 可能返回的错误码: +// INTERNALERROR_PROXYSERVER = "InternalError.ProxyServer" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeDDoSPolicy(request *DescribeDDoSPolicyRequest) (response *DescribeDDoSPolicyResponse, err error) { + return c.DescribeDDoSPolicyWithContext(context.Background(), request) +} + +// DescribeDDoSPolicy +// 查询DDoS防护配置详情 +// +// 可能返回的错误码: +// INTERNALERROR_PROXYSERVER = "InternalError.ProxyServer" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeDDoSPolicyWithContext(ctx context.Context, request *DescribeDDoSPolicyRequest) (response *DescribeDDoSPolicyResponse, err error) { + if request == nil { + request = NewDescribeDDoSPolicyRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeDDoSPolicy require credential") + } + + request.SetContext(ctx) + + response = NewDescribeDDoSPolicyResponse() + err = c.Send(request, response) + return +} + +func NewDescribeDDosAttackDataRequest() (request *DescribeDDosAttackDataRequest) { + request = &DescribeDDosAttackDataRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeDDosAttackData") + + + return +} + +func NewDescribeDDosAttackDataResponse() (response *DescribeDDosAttackDataResponse) { + response = &DescribeDDosAttackDataResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeDDosAttackData +// 查询DDos攻击时序数据 +// +// 可能返回的错误码: +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeDDosAttackData(request *DescribeDDosAttackDataRequest) (response *DescribeDDosAttackDataResponse, err error) { + return c.DescribeDDosAttackDataWithContext(context.Background(), request) +} + +// DescribeDDosAttackData +// 查询DDos攻击时序数据 +// +// 可能返回的错误码: +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeDDosAttackDataWithContext(ctx context.Context, request *DescribeDDosAttackDataRequest) (response *DescribeDDosAttackDataResponse, err error) { + if request == nil { + request = NewDescribeDDosAttackDataRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeDDosAttackData require credential") + } + + request.SetContext(ctx) + + response = NewDescribeDDosAttackDataResponse() + err = c.Send(request, response) + return +} + +func NewDescribeDDosAttackEventRequest() (request *DescribeDDosAttackEventRequest) { + request = &DescribeDDosAttackEventRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeDDosAttackEvent") + + + return +} + +func NewDescribeDDosAttackEventResponse() (response *DescribeDDosAttackEventResponse) { + response = &DescribeDDosAttackEventResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeDDosAttackEvent +// 查询DDos攻击事件 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// RESOURCENOTFOUND = "ResourceNotFound" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeDDosAttackEvent(request *DescribeDDosAttackEventRequest) (response *DescribeDDosAttackEventResponse, err error) { + return c.DescribeDDosAttackEventWithContext(context.Background(), request) +} + +// DescribeDDosAttackEvent +// 查询DDos攻击事件 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// RESOURCENOTFOUND = "ResourceNotFound" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeDDosAttackEventWithContext(ctx context.Context, request *DescribeDDosAttackEventRequest) (response *DescribeDDosAttackEventResponse, err error) { + if request == nil { + request = NewDescribeDDosAttackEventRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeDDosAttackEvent require credential") + } + + request.SetContext(ctx) + + response = NewDescribeDDosAttackEventResponse() + err = c.Send(request, response) + return +} + +func NewDescribeDDosAttackEventDetailRequest() (request *DescribeDDosAttackEventDetailRequest) { + request = &DescribeDDosAttackEventDetailRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeDDosAttackEventDetail") + + + return +} + +func NewDescribeDDosAttackEventDetailResponse() (response *DescribeDDosAttackEventDetailResponse) { + response = &DescribeDDosAttackEventDetailResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeDDosAttackEventDetail +// 查询DDos攻击事件详情 +// +// 可能返回的错误码: +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeDDosAttackEventDetail(request *DescribeDDosAttackEventDetailRequest) (response *DescribeDDosAttackEventDetailResponse, err error) { + return c.DescribeDDosAttackEventDetailWithContext(context.Background(), request) +} + +// DescribeDDosAttackEventDetail +// 查询DDos攻击事件详情 +// +// 可能返回的错误码: +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeDDosAttackEventDetailWithContext(ctx context.Context, request *DescribeDDosAttackEventDetailRequest) (response *DescribeDDosAttackEventDetailResponse, err error) { + if request == nil { + request = NewDescribeDDosAttackEventDetailRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeDDosAttackEventDetail require credential") + } + + request.SetContext(ctx) + + response = NewDescribeDDosAttackEventDetailResponse() + err = c.Send(request, response) + return +} + +func NewDescribeDDosAttackSourceEventRequest() (request *DescribeDDosAttackSourceEventRequest) { + request = &DescribeDDosAttackSourceEventRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeDDosAttackSourceEvent") + + + return +} + +func NewDescribeDDosAttackSourceEventResponse() (response *DescribeDDosAttackSourceEventResponse) { + response = &DescribeDDosAttackSourceEventResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeDDosAttackSourceEvent +// 查询DDos攻击源信息 +// +// 可能返回的错误码: +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeDDosAttackSourceEvent(request *DescribeDDosAttackSourceEventRequest) (response *DescribeDDosAttackSourceEventResponse, err error) { + return c.DescribeDDosAttackSourceEventWithContext(context.Background(), request) +} + +// DescribeDDosAttackSourceEvent +// 查询DDos攻击源信息 +// +// 可能返回的错误码: +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeDDosAttackSourceEventWithContext(ctx context.Context, request *DescribeDDosAttackSourceEventRequest) (response *DescribeDDosAttackSourceEventResponse, err error) { + if request == nil { + request = NewDescribeDDosAttackSourceEventRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeDDosAttackSourceEvent require credential") + } + + request.SetContext(ctx) + + response = NewDescribeDDosAttackSourceEventResponse() + err = c.Send(request, response) + return +} + +func NewDescribeDDosAttackTopDataRequest() (request *DescribeDDosAttackTopDataRequest) { + request = &DescribeDDosAttackTopDataRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeDDosAttackTopData") + + + return +} + +func NewDescribeDDosAttackTopDataResponse() (response *DescribeDDosAttackTopDataResponse) { + response = &DescribeDDosAttackTopDataResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeDDosAttackTopData +// 查询DDos攻击Top数据 +// +// 可能返回的错误码: +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeDDosAttackTopData(request *DescribeDDosAttackTopDataRequest) (response *DescribeDDosAttackTopDataResponse, err error) { + return c.DescribeDDosAttackTopDataWithContext(context.Background(), request) +} + +// DescribeDDosAttackTopData +// 查询DDos攻击Top数据 +// +// 可能返回的错误码: +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeDDosAttackTopDataWithContext(ctx context.Context, request *DescribeDDosAttackTopDataRequest) (response *DescribeDDosAttackTopDataResponse, err error) { + if request == nil { + request = NewDescribeDDosAttackTopDataRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeDDosAttackTopData require credential") + } + + request.SetContext(ctx) + + response = NewDescribeDDosAttackTopDataResponse() + err = c.Send(request, response) + return +} + +func NewDescribeDDosMajorAttackEventRequest() (request *DescribeDDosMajorAttackEventRequest) { + request = &DescribeDDosMajorAttackEventRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeDDosMajorAttackEvent") + + + return +} + +func NewDescribeDDosMajorAttackEventResponse() (response *DescribeDDosMajorAttackEventResponse) { + response = &DescribeDDosMajorAttackEventResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeDDosMajorAttackEvent +// 查询DDos主攻击事件 +// +// 可能返回的错误码: +// FAILEDOPERATION = "FailedOperation" +// LIMITEXCEEDED = "LimitExceeded" +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeDDosMajorAttackEvent(request *DescribeDDosMajorAttackEventRequest) (response *DescribeDDosMajorAttackEventResponse, err error) { + return c.DescribeDDosMajorAttackEventWithContext(context.Background(), request) +} + +// DescribeDDosMajorAttackEvent +// 查询DDos主攻击事件 +// +// 可能返回的错误码: +// FAILEDOPERATION = "FailedOperation" +// LIMITEXCEEDED = "LimitExceeded" +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeDDosMajorAttackEventWithContext(ctx context.Context, request *DescribeDDosMajorAttackEventRequest) (response *DescribeDDosMajorAttackEventResponse, err error) { + if request == nil { + request = NewDescribeDDosMajorAttackEventRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeDDosMajorAttackEvent require credential") + } + + request.SetContext(ctx) + + response = NewDescribeDDosMajorAttackEventResponse() + err = c.Send(request, response) + return +} + +func NewDescribeDefaultCertificatesRequest() (request *DescribeDefaultCertificatesRequest) { + request = &DescribeDefaultCertificatesRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeDefaultCertificates") + + + return +} + +func NewDescribeDefaultCertificatesResponse() (response *DescribeDefaultCertificatesResponse) { + response = &DescribeDefaultCertificatesResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeDefaultCertificates +// 查询默认证书列表 +// +// 可能返回的错误码: +// INTERNALERROR_DBERROR = "InternalError.DBError" +// INTERNALERROR_ROUTEERROR = "InternalError.RouteError" +// OPERATIONDENIED = "OperationDenied" +// RESOURCEUNAVAILABLE_ZONENOTFOUND = "ResourceUnavailable.ZoneNotFound" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +// UNAUTHORIZEDOPERATION_NOPERMISSION = "UnauthorizedOperation.NoPermission" +func (c *Client) DescribeDefaultCertificates(request *DescribeDefaultCertificatesRequest) (response *DescribeDefaultCertificatesResponse, err error) { + return c.DescribeDefaultCertificatesWithContext(context.Background(), request) +} + +// DescribeDefaultCertificates +// 查询默认证书列表 +// +// 可能返回的错误码: +// INTERNALERROR_DBERROR = "InternalError.DBError" +// INTERNALERROR_ROUTEERROR = "InternalError.RouteError" +// OPERATIONDENIED = "OperationDenied" +// RESOURCEUNAVAILABLE_ZONENOTFOUND = "ResourceUnavailable.ZoneNotFound" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +// UNAUTHORIZEDOPERATION_NOPERMISSION = "UnauthorizedOperation.NoPermission" +func (c *Client) DescribeDefaultCertificatesWithContext(ctx context.Context, request *DescribeDefaultCertificatesRequest) (response *DescribeDefaultCertificatesResponse, err error) { + if request == nil { + request = NewDescribeDefaultCertificatesRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeDefaultCertificates require credential") + } + + request.SetContext(ctx) + + response = NewDescribeDefaultCertificatesResponse() + err = c.Send(request, response) + return +} + +func NewDescribeDnsDataRequest() (request *DescribeDnsDataRequest) { + request = &DescribeDnsDataRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeDnsData") + + + return +} + +func NewDescribeDnsDataResponse() (response *DescribeDnsDataResponse) { + response = &DescribeDnsDataResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeDnsData +// 获取DNS请求数统计曲线 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeDnsData(request *DescribeDnsDataRequest) (response *DescribeDnsDataResponse, err error) { + return c.DescribeDnsDataWithContext(context.Background(), request) +} + +// DescribeDnsData +// 获取DNS请求数统计曲线 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeDnsDataWithContext(ctx context.Context, request *DescribeDnsDataRequest) (response *DescribeDnsDataResponse, err error) { + if request == nil { + request = NewDescribeDnsDataRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeDnsData require credential") + } + + request.SetContext(ctx) + + response = NewDescribeDnsDataResponse() + err = c.Send(request, response) + return +} + +func NewDescribeDnsRecordsRequest() (request *DescribeDnsRecordsRequest) { + request = &DescribeDnsRecordsRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeDnsRecords") + + + return +} + +func NewDescribeDnsRecordsResponse() (response *DescribeDnsRecordsResponse) { + response = &DescribeDnsRecordsResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeDnsRecords +// 查询 DNS 记录列表,支持搜索、分页、排序、过滤。 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeDnsRecords(request *DescribeDnsRecordsRequest) (response *DescribeDnsRecordsResponse, err error) { + return c.DescribeDnsRecordsWithContext(context.Background(), request) +} + +// DescribeDnsRecords +// 查询 DNS 记录列表,支持搜索、分页、排序、过滤。 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeDnsRecordsWithContext(ctx context.Context, request *DescribeDnsRecordsRequest) (response *DescribeDnsRecordsResponse, err error) { + if request == nil { + request = NewDescribeDnsRecordsRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeDnsRecords require credential") + } + + request.SetContext(ctx) + + response = NewDescribeDnsRecordsResponse() + err = c.Send(request, response) + return +} + +func NewDescribeDnssecRequest() (request *DescribeDnssecRequest) { + request = &DescribeDnssecRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeDnssec") + + + return +} + +func NewDescribeDnssecResponse() (response *DescribeDnssecResponse) { + response = &DescribeDnssecResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeDnssec +// 用于查询 DNSSEC 相关信息 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeDnssec(request *DescribeDnssecRequest) (response *DescribeDnssecResponse, err error) { + return c.DescribeDnssecWithContext(context.Background(), request) +} + +// DescribeDnssec +// 用于查询 DNSSEC 相关信息 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeDnssecWithContext(ctx context.Context, request *DescribeDnssecRequest) (response *DescribeDnssecResponse, err error) { + if request == nil { + request = NewDescribeDnssecRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeDnssec require credential") + } + + request.SetContext(ctx) + + response = NewDescribeDnssecResponse() + err = c.Send(request, response) + return +} + +func NewDescribeHostsCertificateRequest() (request *DescribeHostsCertificateRequest) { + request = &DescribeHostsCertificateRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeHostsCertificate") + + + return +} + +func NewDescribeHostsCertificateResponse() (response *DescribeHostsCertificateResponse) { + response = &DescribeHostsCertificateResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeHostsCertificate +// 查询域名证书列表,支持搜索、分页、排序、过滤。 +// +// 可能返回的错误码: +// INTERNALERROR_PROXYSERVER = "InternalError.ProxyServer" +// INTERNALERROR_ROUTEERROR = "InternalError.RouteError" +// INTERNALERROR_SYSTEMERROR = "InternalError.SystemError" +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_NOPERMISSION = "UnauthorizedOperation.NoPermission" +func (c *Client) DescribeHostsCertificate(request *DescribeHostsCertificateRequest) (response *DescribeHostsCertificateResponse, err error) { + return c.DescribeHostsCertificateWithContext(context.Background(), request) +} + +// DescribeHostsCertificate +// 查询域名证书列表,支持搜索、分页、排序、过滤。 +// +// 可能返回的错误码: +// INTERNALERROR_PROXYSERVER = "InternalError.ProxyServer" +// INTERNALERROR_ROUTEERROR = "InternalError.RouteError" +// INTERNALERROR_SYSTEMERROR = "InternalError.SystemError" +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_NOPERMISSION = "UnauthorizedOperation.NoPermission" +func (c *Client) DescribeHostsCertificateWithContext(ctx context.Context, request *DescribeHostsCertificateRequest) (response *DescribeHostsCertificateResponse, err error) { + if request == nil { + request = NewDescribeHostsCertificateRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeHostsCertificate require credential") + } + + request.SetContext(ctx) + + response = NewDescribeHostsCertificateResponse() + err = c.Send(request, response) + return +} + +func NewDescribeHostsSettingRequest() (request *DescribeHostsSettingRequest) { + request = &DescribeHostsSettingRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeHostsSetting") + + + return +} + +func NewDescribeHostsSettingResponse() (response *DescribeHostsSettingResponse) { + response = &DescribeHostsSettingResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeHostsSetting +// 用于查询域名配置信息 +// +// 可能返回的错误码: +// INVALIDPARAMETER = "InvalidParameter" +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +// UNAUTHORIZEDOPERATION_NOPERMISSION = "UnauthorizedOperation.NoPermission" +func (c *Client) DescribeHostsSetting(request *DescribeHostsSettingRequest) (response *DescribeHostsSettingResponse, err error) { + return c.DescribeHostsSettingWithContext(context.Background(), request) +} + +// DescribeHostsSetting +// 用于查询域名配置信息 +// +// 可能返回的错误码: +// INVALIDPARAMETER = "InvalidParameter" +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +// UNAUTHORIZEDOPERATION_NOPERMISSION = "UnauthorizedOperation.NoPermission" +func (c *Client) DescribeHostsSettingWithContext(ctx context.Context, request *DescribeHostsSettingRequest) (response *DescribeHostsSettingResponse, err error) { + if request == nil { + request = NewDescribeHostsSettingRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeHostsSetting require credential") + } + + request.SetContext(ctx) + + response = NewDescribeHostsSettingResponse() + err = c.Send(request, response) + return +} + +func NewDescribeIdentificationRequest() (request *DescribeIdentificationRequest) { + request = &DescribeIdentificationRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeIdentification") + + + return +} + +func NewDescribeIdentificationResponse() (response *DescribeIdentificationResponse) { + response = &DescribeIdentificationResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeIdentification +// 查询验证结果 +// +// 可能返回的错误码: +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DescribeIdentification(request *DescribeIdentificationRequest) (response *DescribeIdentificationResponse, err error) { + return c.DescribeIdentificationWithContext(context.Background(), request) +} + +// DescribeIdentification +// 查询验证结果 +// +// 可能返回的错误码: +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DescribeIdentificationWithContext(ctx context.Context, request *DescribeIdentificationRequest) (response *DescribeIdentificationResponse, err error) { + if request == nil { + request = NewDescribeIdentificationRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeIdentification require credential") + } + + request.SetContext(ctx) + + response = NewDescribeIdentificationResponse() + err = c.Send(request, response) + return +} + +func NewDescribeLoadBalancingRequest() (request *DescribeLoadBalancingRequest) { + request = &DescribeLoadBalancingRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeLoadBalancing") + + + return +} + +func NewDescribeLoadBalancingResponse() (response *DescribeLoadBalancingResponse) { + response = &DescribeLoadBalancingResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeLoadBalancing +// 获取负载均衡列表 +// +// 可能返回的错误码: +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +// UNAUTHORIZEDOPERATION_NOPERMISSION = "UnauthorizedOperation.NoPermission" +func (c *Client) DescribeLoadBalancing(request *DescribeLoadBalancingRequest) (response *DescribeLoadBalancingResponse, err error) { + return c.DescribeLoadBalancingWithContext(context.Background(), request) +} + +// DescribeLoadBalancing +// 获取负载均衡列表 +// +// 可能返回的错误码: +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +// UNAUTHORIZEDOPERATION_NOPERMISSION = "UnauthorizedOperation.NoPermission" +func (c *Client) DescribeLoadBalancingWithContext(ctx context.Context, request *DescribeLoadBalancingRequest) (response *DescribeLoadBalancingResponse, err error) { + if request == nil { + request = NewDescribeLoadBalancingRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeLoadBalancing require credential") + } + + request.SetContext(ctx) + + response = NewDescribeLoadBalancingResponse() + err = c.Send(request, response) + return +} + +func NewDescribeLoadBalancingDetailRequest() (request *DescribeLoadBalancingDetailRequest) { + request = &DescribeLoadBalancingDetailRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeLoadBalancingDetail") + + + return +} + +func NewDescribeLoadBalancingDetailResponse() (response *DescribeLoadBalancingDetailResponse) { + response = &DescribeLoadBalancingDetailResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeLoadBalancingDetail +// 获取负载均衡详细信息 +// +// 可能返回的错误码: +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DescribeLoadBalancingDetail(request *DescribeLoadBalancingDetailRequest) (response *DescribeLoadBalancingDetailResponse, err error) { + return c.DescribeLoadBalancingDetailWithContext(context.Background(), request) +} + +// DescribeLoadBalancingDetail +// 获取负载均衡详细信息 +// +// 可能返回的错误码: +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DescribeLoadBalancingDetailWithContext(ctx context.Context, request *DescribeLoadBalancingDetailRequest) (response *DescribeLoadBalancingDetailResponse, err error) { + if request == nil { + request = NewDescribeLoadBalancingDetailRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeLoadBalancingDetail require credential") + } + + request.SetContext(ctx) + + response = NewDescribeLoadBalancingDetailResponse() + err = c.Send(request, response) + return +} + +func NewDescribeOriginGroupRequest() (request *DescribeOriginGroupRequest) { + request = &DescribeOriginGroupRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeOriginGroup") + + + return +} + +func NewDescribeOriginGroupResponse() (response *DescribeOriginGroupResponse) { + response = &DescribeOriginGroupResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeOriginGroup +// 获取源站组信息列表 +// +// 可能返回的错误码: +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DescribeOriginGroup(request *DescribeOriginGroupRequest) (response *DescribeOriginGroupResponse, err error) { + return c.DescribeOriginGroupWithContext(context.Background(), request) +} + +// DescribeOriginGroup +// 获取源站组信息列表 +// +// 可能返回的错误码: +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DescribeOriginGroupWithContext(ctx context.Context, request *DescribeOriginGroupRequest) (response *DescribeOriginGroupResponse, err error) { + if request == nil { + request = NewDescribeOriginGroupRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeOriginGroup require credential") + } + + request.SetContext(ctx) + + response = NewDescribeOriginGroupResponse() + err = c.Send(request, response) + return +} + +func NewDescribeOriginGroupDetailRequest() (request *DescribeOriginGroupDetailRequest) { + request = &DescribeOriginGroupDetailRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeOriginGroupDetail") + + + return +} + +func NewDescribeOriginGroupDetailResponse() (response *DescribeOriginGroupDetailResponse) { + response = &DescribeOriginGroupDetailResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeOriginGroupDetail +// 获取源站组详细信息 +// +// 可能返回的错误码: +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DescribeOriginGroupDetail(request *DescribeOriginGroupDetailRequest) (response *DescribeOriginGroupDetailResponse, err error) { + return c.DescribeOriginGroupDetailWithContext(context.Background(), request) +} + +// DescribeOriginGroupDetail +// 获取源站组详细信息 +// +// 可能返回的错误码: +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DescribeOriginGroupDetailWithContext(ctx context.Context, request *DescribeOriginGroupDetailRequest) (response *DescribeOriginGroupDetailResponse, err error) { + if request == nil { + request = NewDescribeOriginGroupDetailRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeOriginGroupDetail require credential") + } + + request.SetContext(ctx) + + response = NewDescribeOriginGroupDetailResponse() + err = c.Send(request, response) + return +} + +func NewDescribeOverviewL7DataRequest() (request *DescribeOverviewL7DataRequest) { + request = &DescribeOverviewL7DataRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeOverviewL7Data") + + + return +} + +func NewDescribeOverviewL7DataResponse() (response *DescribeOverviewL7DataResponse) { + response = &DescribeOverviewL7DataResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeOverviewL7Data +// 查询七层监控类时序流量数据 +// +// 可能返回的错误码: +// INTERNALERROR_ROUTEERROR = "InternalError.RouteError" +// RESOURCEUNAVAILABLE = "ResourceUnavailable" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeOverviewL7Data(request *DescribeOverviewL7DataRequest) (response *DescribeOverviewL7DataResponse, err error) { + return c.DescribeOverviewL7DataWithContext(context.Background(), request) +} + +// DescribeOverviewL7Data +// 查询七层监控类时序流量数据 +// +// 可能返回的错误码: +// INTERNALERROR_ROUTEERROR = "InternalError.RouteError" +// RESOURCEUNAVAILABLE = "ResourceUnavailable" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeOverviewL7DataWithContext(ctx context.Context, request *DescribeOverviewL7DataRequest) (response *DescribeOverviewL7DataResponse, err error) { + if request == nil { + request = NewDescribeOverviewL7DataRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeOverviewL7Data require credential") + } + + request.SetContext(ctx) + + response = NewDescribeOverviewL7DataResponse() + err = c.Send(request, response) + return +} + +func NewDescribePrefetchTasksRequest() (request *DescribePrefetchTasksRequest) { + request = &DescribePrefetchTasksRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribePrefetchTasks") + + + return +} + +func NewDescribePrefetchTasksResponse() (response *DescribePrefetchTasksResponse) { + response = &DescribePrefetchTasksResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribePrefetchTasks +// 查询预热任务状态 +// +// 可能返回的错误码: +// INTERNALERROR = "InternalError" +// INVALIDPARAMETER_PARAMETERERROR = "InvalidParameter.ParameterError" +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_DOMAINEMPTY = "UnauthorizedOperation.DomainEmpty" +func (c *Client) DescribePrefetchTasks(request *DescribePrefetchTasksRequest) (response *DescribePrefetchTasksResponse, err error) { + return c.DescribePrefetchTasksWithContext(context.Background(), request) +} + +// DescribePrefetchTasks +// 查询预热任务状态 +// +// 可能返回的错误码: +// INTERNALERROR = "InternalError" +// INVALIDPARAMETER_PARAMETERERROR = "InvalidParameter.ParameterError" +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_DOMAINEMPTY = "UnauthorizedOperation.DomainEmpty" +func (c *Client) DescribePrefetchTasksWithContext(ctx context.Context, request *DescribePrefetchTasksRequest) (response *DescribePrefetchTasksResponse, err error) { + if request == nil { + request = NewDescribePrefetchTasksRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribePrefetchTasks require credential") + } + + request.SetContext(ctx) + + response = NewDescribePrefetchTasksResponse() + err = c.Send(request, response) + return +} + +func NewDescribePurgeTasksRequest() (request *DescribePurgeTasksRequest) { + request = &DescribePurgeTasksRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribePurgeTasks") + + + return +} + +func NewDescribePurgeTasksResponse() (response *DescribePurgeTasksResponse) { + response = &DescribePurgeTasksResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribePurgeTasks +// 查询清除缓存历史记录 +// +// 可能返回的错误码: +// INTERNALERROR = "InternalError" +// INVALIDPARAMETER_PARAMETERERROR = "InvalidParameter.ParameterError" +// OPERATIONDENIED = "OperationDenied" +func (c *Client) DescribePurgeTasks(request *DescribePurgeTasksRequest) (response *DescribePurgeTasksResponse, err error) { + return c.DescribePurgeTasksWithContext(context.Background(), request) +} + +// DescribePurgeTasks +// 查询清除缓存历史记录 +// +// 可能返回的错误码: +// INTERNALERROR = "InternalError" +// INVALIDPARAMETER_PARAMETERERROR = "InvalidParameter.ParameterError" +// OPERATIONDENIED = "OperationDenied" +func (c *Client) DescribePurgeTasksWithContext(ctx context.Context, request *DescribePurgeTasksRequest) (response *DescribePurgeTasksResponse, err error) { + if request == nil { + request = NewDescribePurgeTasksRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribePurgeTasks require credential") + } + + request.SetContext(ctx) + + response = NewDescribePurgeTasksResponse() + err = c.Send(request, response) + return +} + +func NewDescribeRulesRequest() (request *DescribeRulesRequest) { + request = &DescribeRulesRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeRules") + + + return +} + +func NewDescribeRulesResponse() (response *DescribeRulesResponse) { + response = &DescribeRulesResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeRules +// 查询规则引擎规则。 +// +// 可能返回的错误码: +// INTERNALERROR = "InternalError" +// INVALIDPARAMETER_PARAMETERERROR = "InvalidParameter.ParameterError" +// OPERATIONDENIED = "OperationDenied" +func (c *Client) DescribeRules(request *DescribeRulesRequest) (response *DescribeRulesResponse, err error) { + return c.DescribeRulesWithContext(context.Background(), request) +} + +// DescribeRules +// 查询规则引擎规则。 +// +// 可能返回的错误码: +// INTERNALERROR = "InternalError" +// INVALIDPARAMETER_PARAMETERERROR = "InvalidParameter.ParameterError" +// OPERATIONDENIED = "OperationDenied" +func (c *Client) DescribeRulesWithContext(ctx context.Context, request *DescribeRulesRequest) (response *DescribeRulesResponse, err error) { + if request == nil { + request = NewDescribeRulesRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeRules require credential") + } + + request.SetContext(ctx) + + response = NewDescribeRulesResponse() + err = c.Send(request, response) + return +} + +func NewDescribeRulesSettingRequest() (request *DescribeRulesSettingRequest) { + request = &DescribeRulesSettingRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeRulesSetting") + + + return +} + +func NewDescribeRulesSettingResponse() (response *DescribeRulesSettingResponse) { + response = &DescribeRulesSettingResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeRulesSetting +// 返回规则引擎可应用匹配请求的设置列表及其详细建议配置信息 +// +// 可能返回的错误码: +// INTERNALERROR = "InternalError" +// INVALIDPARAMETER_PARAMETERERROR = "InvalidParameter.ParameterError" +// OPERATIONDENIED = "OperationDenied" +func (c *Client) DescribeRulesSetting(request *DescribeRulesSettingRequest) (response *DescribeRulesSettingResponse, err error) { + return c.DescribeRulesSettingWithContext(context.Background(), request) +} + +// DescribeRulesSetting +// 返回规则引擎可应用匹配请求的设置列表及其详细建议配置信息 +// +// 可能返回的错误码: +// INTERNALERROR = "InternalError" +// INVALIDPARAMETER_PARAMETERERROR = "InvalidParameter.ParameterError" +// OPERATIONDENIED = "OperationDenied" +func (c *Client) DescribeRulesSettingWithContext(ctx context.Context, request *DescribeRulesSettingRequest) (response *DescribeRulesSettingResponse, err error) { + if request == nil { + request = NewDescribeRulesSettingRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeRulesSetting require credential") + } + + request.SetContext(ctx) + + response = NewDescribeRulesSettingResponse() + err = c.Send(request, response) + return +} + +func NewDescribeSecurityPolicyRequest() (request *DescribeSecurityPolicyRequest) { + request = &DescribeSecurityPolicyRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeSecurityPolicy") + + + return +} + +func NewDescribeSecurityPolicyResponse() (response *DescribeSecurityPolicyResponse) { + response = &DescribeSecurityPolicyResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeSecurityPolicy +// 查询安全防护配置详情 +// +// 可能返回的错误码: +// INTERNALERROR = "InternalError" +// INVALIDPARAMETER_PARAMETERERROR = "InvalidParameter.ParameterError" +// OPERATIONDENIED = "OperationDenied" +func (c *Client) DescribeSecurityPolicy(request *DescribeSecurityPolicyRequest) (response *DescribeSecurityPolicyResponse, err error) { + return c.DescribeSecurityPolicyWithContext(context.Background(), request) +} + +// DescribeSecurityPolicy +// 查询安全防护配置详情 +// +// 可能返回的错误码: +// INTERNALERROR = "InternalError" +// INVALIDPARAMETER_PARAMETERERROR = "InvalidParameter.ParameterError" +// OPERATIONDENIED = "OperationDenied" +func (c *Client) DescribeSecurityPolicyWithContext(ctx context.Context, request *DescribeSecurityPolicyRequest) (response *DescribeSecurityPolicyResponse, err error) { + if request == nil { + request = NewDescribeSecurityPolicyRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeSecurityPolicy require credential") + } + + request.SetContext(ctx) + + response = NewDescribeSecurityPolicyResponse() + err = c.Send(request, response) + return +} + +func NewDescribeSecurityPolicyListRequest() (request *DescribeSecurityPolicyListRequest) { + request = &DescribeSecurityPolicyListRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeSecurityPolicyList") + + + return +} + +func NewDescribeSecurityPolicyListResponse() (response *DescribeSecurityPolicyListResponse) { + response = &DescribeSecurityPolicyListResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeSecurityPolicyList +// 查询全部安全实例 +// +// 可能返回的错误码: +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeSecurityPolicyList(request *DescribeSecurityPolicyListRequest) (response *DescribeSecurityPolicyListResponse, err error) { + return c.DescribeSecurityPolicyListWithContext(context.Background(), request) +} + +// DescribeSecurityPolicyList +// 查询全部安全实例 +// +// 可能返回的错误码: +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeSecurityPolicyListWithContext(ctx context.Context, request *DescribeSecurityPolicyListRequest) (response *DescribeSecurityPolicyListResponse, err error) { + if request == nil { + request = NewDescribeSecurityPolicyListRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeSecurityPolicyList require credential") + } + + request.SetContext(ctx) + + response = NewDescribeSecurityPolicyListResponse() + err = c.Send(request, response) + return +} + +func NewDescribeSecurityPolicyManagedRulesRequest() (request *DescribeSecurityPolicyManagedRulesRequest) { + request = &DescribeSecurityPolicyManagedRulesRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeSecurityPolicyManagedRules") + + + return +} + +func NewDescribeSecurityPolicyManagedRulesResponse() (response *DescribeSecurityPolicyManagedRulesResponse) { + response = &DescribeSecurityPolicyManagedRulesResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeSecurityPolicyManagedRules +// 分页查询门神规则 +// +// 可能返回的错误码: +// INVALIDPARAMETER_SECURITY = "InvalidParameter.Security" +func (c *Client) DescribeSecurityPolicyManagedRules(request *DescribeSecurityPolicyManagedRulesRequest) (response *DescribeSecurityPolicyManagedRulesResponse, err error) { + return c.DescribeSecurityPolicyManagedRulesWithContext(context.Background(), request) +} + +// DescribeSecurityPolicyManagedRules +// 分页查询门神规则 +// +// 可能返回的错误码: +// INVALIDPARAMETER_SECURITY = "InvalidParameter.Security" +func (c *Client) DescribeSecurityPolicyManagedRulesWithContext(ctx context.Context, request *DescribeSecurityPolicyManagedRulesRequest) (response *DescribeSecurityPolicyManagedRulesResponse, err error) { + if request == nil { + request = NewDescribeSecurityPolicyManagedRulesRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeSecurityPolicyManagedRules require credential") + } + + request.SetContext(ctx) + + response = NewDescribeSecurityPolicyManagedRulesResponse() + err = c.Send(request, response) + return +} + +func NewDescribeSecurityPolicyManagedRulesIdRequest() (request *DescribeSecurityPolicyManagedRulesIdRequest) { + request = &DescribeSecurityPolicyManagedRulesIdRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeSecurityPolicyManagedRulesId") + + + return +} + +func NewDescribeSecurityPolicyManagedRulesIdResponse() (response *DescribeSecurityPolicyManagedRulesIdResponse) { + response = &DescribeSecurityPolicyManagedRulesIdResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeSecurityPolicyManagedRulesId +// 规则id查询门神规则详情 +// +// 可能返回的错误码: +// INVALIDPARAMETER_SECURITY = "InvalidParameter.Security" +func (c *Client) DescribeSecurityPolicyManagedRulesId(request *DescribeSecurityPolicyManagedRulesIdRequest) (response *DescribeSecurityPolicyManagedRulesIdResponse, err error) { + return c.DescribeSecurityPolicyManagedRulesIdWithContext(context.Background(), request) +} + +// DescribeSecurityPolicyManagedRulesId +// 规则id查询门神规则详情 +// +// 可能返回的错误码: +// INVALIDPARAMETER_SECURITY = "InvalidParameter.Security" +func (c *Client) DescribeSecurityPolicyManagedRulesIdWithContext(ctx context.Context, request *DescribeSecurityPolicyManagedRulesIdRequest) (response *DescribeSecurityPolicyManagedRulesIdResponse, err error) { + if request == nil { + request = NewDescribeSecurityPolicyManagedRulesIdRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeSecurityPolicyManagedRulesId require credential") + } + + request.SetContext(ctx) + + response = NewDescribeSecurityPolicyManagedRulesIdResponse() + err = c.Send(request, response) + return +} + +func NewDescribeSecurityPolicyRegionsRequest() (request *DescribeSecurityPolicyRegionsRequest) { + request = &DescribeSecurityPolicyRegionsRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeSecurityPolicyRegions") + + + return +} + +func NewDescribeSecurityPolicyRegionsResponse() (response *DescribeSecurityPolicyRegionsResponse) { + response = &DescribeSecurityPolicyRegionsResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeSecurityPolicyRegions +// 查询所有地域信息 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +func (c *Client) DescribeSecurityPolicyRegions(request *DescribeSecurityPolicyRegionsRequest) (response *DescribeSecurityPolicyRegionsResponse, err error) { + return c.DescribeSecurityPolicyRegionsWithContext(context.Background(), request) +} + +// DescribeSecurityPolicyRegions +// 查询所有地域信息 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +func (c *Client) DescribeSecurityPolicyRegionsWithContext(ctx context.Context, request *DescribeSecurityPolicyRegionsRequest) (response *DescribeSecurityPolicyRegionsResponse, err error) { + if request == nil { + request = NewDescribeSecurityPolicyRegionsRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeSecurityPolicyRegions require credential") + } + + request.SetContext(ctx) + + response = NewDescribeSecurityPolicyRegionsResponse() + err = c.Send(request, response) + return +} + +func NewDescribeSecurityPortraitRulesRequest() (request *DescribeSecurityPortraitRulesRequest) { + request = &DescribeSecurityPortraitRulesRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeSecurityPortraitRules") + + + return +} + +func NewDescribeSecurityPortraitRulesResponse() (response *DescribeSecurityPortraitRulesResponse) { + response = &DescribeSecurityPortraitRulesResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeSecurityPortraitRules +// 查询Bot用户画像规则 +// +// 可能返回的错误码: +// INVALIDPARAMETER_SECURITY = "InvalidParameter.Security" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeSecurityPortraitRules(request *DescribeSecurityPortraitRulesRequest) (response *DescribeSecurityPortraitRulesResponse, err error) { + return c.DescribeSecurityPortraitRulesWithContext(context.Background(), request) +} + +// DescribeSecurityPortraitRules +// 查询Bot用户画像规则 +// +// 可能返回的错误码: +// INVALIDPARAMETER_SECURITY = "InvalidParameter.Security" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeSecurityPortraitRulesWithContext(ctx context.Context, request *DescribeSecurityPortraitRulesRequest) (response *DescribeSecurityPortraitRulesResponse, err error) { + if request == nil { + request = NewDescribeSecurityPortraitRulesRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeSecurityPortraitRules require credential") + } + + request.SetContext(ctx) + + response = NewDescribeSecurityPortraitRulesResponse() + err = c.Send(request, response) + return +} + +func NewDescribeTimingL4DataRequest() (request *DescribeTimingL4DataRequest) { + request = &DescribeTimingL4DataRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeTimingL4Data") + + + return +} + +func NewDescribeTimingL4DataResponse() (response *DescribeTimingL4DataResponse) { + response = &DescribeTimingL4DataResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeTimingL4Data +// 四层时序流量数据查询 +// +// 可能返回的错误码: +// FAILEDOPERATION = "FailedOperation" +// INTERNALERROR_PROXYSERVER = "InternalError.ProxyServer" +// INTERNALERROR_ROUTEERROR = "InternalError.RouteError" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeTimingL4Data(request *DescribeTimingL4DataRequest) (response *DescribeTimingL4DataResponse, err error) { + return c.DescribeTimingL4DataWithContext(context.Background(), request) +} + +// DescribeTimingL4Data +// 四层时序流量数据查询 +// +// 可能返回的错误码: +// FAILEDOPERATION = "FailedOperation" +// INTERNALERROR_PROXYSERVER = "InternalError.ProxyServer" +// INTERNALERROR_ROUTEERROR = "InternalError.RouteError" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeTimingL4DataWithContext(ctx context.Context, request *DescribeTimingL4DataRequest) (response *DescribeTimingL4DataResponse, err error) { + if request == nil { + request = NewDescribeTimingL4DataRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeTimingL4Data require credential") + } + + request.SetContext(ctx) + + response = NewDescribeTimingL4DataResponse() + err = c.Send(request, response) + return +} + +func NewDescribeTimingL7AnalysisDataRequest() (request *DescribeTimingL7AnalysisDataRequest) { + request = &DescribeTimingL7AnalysisDataRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeTimingL7AnalysisData") + + + return +} + +func NewDescribeTimingL7AnalysisDataResponse() (response *DescribeTimingL7AnalysisDataResponse) { + response = &DescribeTimingL7AnalysisDataResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeTimingL7AnalysisData +// 查询七层数据分析类时序流量数据 +// +// 可能返回的错误码: +// FAILEDOPERATION = "FailedOperation" +// INTERNALERROR_PROXYSERVER = "InternalError.ProxyServer" +// OPERATIONDENIED = "OperationDenied" +// RESOURCEUNAVAILABLE = "ResourceUnavailable" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeTimingL7AnalysisData(request *DescribeTimingL7AnalysisDataRequest) (response *DescribeTimingL7AnalysisDataResponse, err error) { + return c.DescribeTimingL7AnalysisDataWithContext(context.Background(), request) +} + +// DescribeTimingL7AnalysisData +// 查询七层数据分析类时序流量数据 +// +// 可能返回的错误码: +// FAILEDOPERATION = "FailedOperation" +// INTERNALERROR_PROXYSERVER = "InternalError.ProxyServer" +// OPERATIONDENIED = "OperationDenied" +// RESOURCEUNAVAILABLE = "ResourceUnavailable" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeTimingL7AnalysisDataWithContext(ctx context.Context, request *DescribeTimingL7AnalysisDataRequest) (response *DescribeTimingL7AnalysisDataResponse, err error) { + if request == nil { + request = NewDescribeTimingL7AnalysisDataRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeTimingL7AnalysisData require credential") + } + + request.SetContext(ctx) + + response = NewDescribeTimingL7AnalysisDataResponse() + err = c.Send(request, response) + return +} + +func NewDescribeTimingL7CacheDataRequest() (request *DescribeTimingL7CacheDataRequest) { + request = &DescribeTimingL7CacheDataRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeTimingL7CacheData") + + + return +} + +func NewDescribeTimingL7CacheDataResponse() (response *DescribeTimingL7CacheDataResponse) { + response = &DescribeTimingL7CacheDataResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeTimingL7CacheData +// 七层查询缓存分析时序类流量数据 +// +// 可能返回的错误码: +// RESOURCEUNAVAILABLE = "ResourceUnavailable" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeTimingL7CacheData(request *DescribeTimingL7CacheDataRequest) (response *DescribeTimingL7CacheDataResponse, err error) { + return c.DescribeTimingL7CacheDataWithContext(context.Background(), request) +} + +// DescribeTimingL7CacheData +// 七层查询缓存分析时序类流量数据 +// +// 可能返回的错误码: +// RESOURCEUNAVAILABLE = "ResourceUnavailable" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeTimingL7CacheDataWithContext(ctx context.Context, request *DescribeTimingL7CacheDataRequest) (response *DescribeTimingL7CacheDataResponse, err error) { + if request == nil { + request = NewDescribeTimingL7CacheDataRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeTimingL7CacheData require credential") + } + + request.SetContext(ctx) + + response = NewDescribeTimingL7CacheDataResponse() + err = c.Send(request, response) + return +} + +func NewDescribeTopL7AnalysisDataRequest() (request *DescribeTopL7AnalysisDataRequest) { + request = &DescribeTopL7AnalysisDataRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeTopL7AnalysisData") + + + return +} + +func NewDescribeTopL7AnalysisDataResponse() (response *DescribeTopL7AnalysisDataResponse) { + response = &DescribeTopL7AnalysisDataResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeTopL7AnalysisData +// 查询top类流量数据 +// +// 可能返回的错误码: +// FAILEDOPERATION = "FailedOperation" +// INTERNALERROR_PROXYSERVER = "InternalError.ProxyServer" +// OPERATIONDENIED = "OperationDenied" +// RESOURCEUNAVAILABLE = "ResourceUnavailable" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeTopL7AnalysisData(request *DescribeTopL7AnalysisDataRequest) (response *DescribeTopL7AnalysisDataResponse, err error) { + return c.DescribeTopL7AnalysisDataWithContext(context.Background(), request) +} + +// DescribeTopL7AnalysisData +// 查询top类流量数据 +// +// 可能返回的错误码: +// FAILEDOPERATION = "FailedOperation" +// INTERNALERROR_PROXYSERVER = "InternalError.ProxyServer" +// OPERATIONDENIED = "OperationDenied" +// RESOURCEUNAVAILABLE = "ResourceUnavailable" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeTopL7AnalysisDataWithContext(ctx context.Context, request *DescribeTopL7AnalysisDataRequest) (response *DescribeTopL7AnalysisDataResponse, err error) { + if request == nil { + request = NewDescribeTopL7AnalysisDataRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeTopL7AnalysisData require credential") + } + + request.SetContext(ctx) + + response = NewDescribeTopL7AnalysisDataResponse() + err = c.Send(request, response) + return +} + +func NewDescribeTopL7CacheDataRequest() (request *DescribeTopL7CacheDataRequest) { + request = &DescribeTopL7CacheDataRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeTopL7CacheData") + + + return +} + +func NewDescribeTopL7CacheDataResponse() (response *DescribeTopL7CacheDataResponse) { + response = &DescribeTopL7CacheDataResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeTopL7CacheData +// 七层查询缓存分析top类流量数据 +// +// 可能返回的错误码: +// RESOURCEUNAVAILABLE = "ResourceUnavailable" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeTopL7CacheData(request *DescribeTopL7CacheDataRequest) (response *DescribeTopL7CacheDataResponse, err error) { + return c.DescribeTopL7CacheDataWithContext(context.Background(), request) +} + +// DescribeTopL7CacheData +// 七层查询缓存分析top类流量数据 +// +// 可能返回的错误码: +// RESOURCEUNAVAILABLE = "ResourceUnavailable" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeTopL7CacheDataWithContext(ctx context.Context, request *DescribeTopL7CacheDataRequest) (response *DescribeTopL7CacheDataResponse, err error) { + if request == nil { + request = NewDescribeTopL7CacheDataRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeTopL7CacheData require credential") + } + + request.SetContext(ctx) + + response = NewDescribeTopL7CacheDataResponse() + err = c.Send(request, response) + return +} + +func NewDescribeWebManagedRulesAttackEventsRequest() (request *DescribeWebManagedRulesAttackEventsRequest) { + request = &DescribeWebManagedRulesAttackEventsRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeWebManagedRulesAttackEvents") + + + return +} + +func NewDescribeWebManagedRulesAttackEventsResponse() (response *DescribeWebManagedRulesAttackEventsResponse) { + response = &DescribeWebManagedRulesAttackEventsResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeWebManagedRulesAttackEvents +// 查询Web托管攻击事件 +// +// 可能返回的错误码: +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DescribeWebManagedRulesAttackEvents(request *DescribeWebManagedRulesAttackEventsRequest) (response *DescribeWebManagedRulesAttackEventsResponse, err error) { + return c.DescribeWebManagedRulesAttackEventsWithContext(context.Background(), request) +} + +// DescribeWebManagedRulesAttackEvents +// 查询Web托管攻击事件 +// +// 可能返回的错误码: +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DescribeWebManagedRulesAttackEventsWithContext(ctx context.Context, request *DescribeWebManagedRulesAttackEventsRequest) (response *DescribeWebManagedRulesAttackEventsResponse, err error) { + if request == nil { + request = NewDescribeWebManagedRulesAttackEventsRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeWebManagedRulesAttackEvents require credential") + } + + request.SetContext(ctx) + + response = NewDescribeWebManagedRulesAttackEventsResponse() + err = c.Send(request, response) + return +} + +func NewDescribeWebManagedRulesDataRequest() (request *DescribeWebManagedRulesDataRequest) { + request = &DescribeWebManagedRulesDataRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeWebManagedRulesData") + + + return +} + +func NewDescribeWebManagedRulesDataResponse() (response *DescribeWebManagedRulesDataResponse) { + response = &DescribeWebManagedRulesDataResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeWebManagedRulesData +// 查询waf攻击时序数据 +// +// 可能返回的错误码: +// FAILEDOPERATION = "FailedOperation" +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DescribeWebManagedRulesData(request *DescribeWebManagedRulesDataRequest) (response *DescribeWebManagedRulesDataResponse, err error) { + return c.DescribeWebManagedRulesDataWithContext(context.Background(), request) +} + +// DescribeWebManagedRulesData +// 查询waf攻击时序数据 +// +// 可能返回的错误码: +// FAILEDOPERATION = "FailedOperation" +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DescribeWebManagedRulesDataWithContext(ctx context.Context, request *DescribeWebManagedRulesDataRequest) (response *DescribeWebManagedRulesDataResponse, err error) { + if request == nil { + request = NewDescribeWebManagedRulesDataRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeWebManagedRulesData require credential") + } + + request.SetContext(ctx) + + response = NewDescribeWebManagedRulesDataResponse() + err = c.Send(request, response) + return +} + +func NewDescribeWebManagedRulesLogRequest() (request *DescribeWebManagedRulesLogRequest) { + request = &DescribeWebManagedRulesLogRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeWebManagedRulesLog") + + + return +} + +func NewDescribeWebManagedRulesLogResponse() (response *DescribeWebManagedRulesLogResponse) { + response = &DescribeWebManagedRulesLogResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeWebManagedRulesLog +// 查询waf攻击日志 +// +// 可能返回的错误码: +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeWebManagedRulesLog(request *DescribeWebManagedRulesLogRequest) (response *DescribeWebManagedRulesLogResponse, err error) { + return c.DescribeWebManagedRulesLogWithContext(context.Background(), request) +} + +// DescribeWebManagedRulesLog +// 查询waf攻击日志 +// +// 可能返回的错误码: +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeWebManagedRulesLogWithContext(ctx context.Context, request *DescribeWebManagedRulesLogRequest) (response *DescribeWebManagedRulesLogResponse, err error) { + if request == nil { + request = NewDescribeWebManagedRulesLogRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeWebManagedRulesLog require credential") + } + + request.SetContext(ctx) + + response = NewDescribeWebManagedRulesLogResponse() + err = c.Send(request, response) + return +} + +func NewDescribeWebManagedRulesTopDataRequest() (request *DescribeWebManagedRulesTopDataRequest) { + request = &DescribeWebManagedRulesTopDataRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeWebManagedRulesTopData") + + + return +} + +func NewDescribeWebManagedRulesTopDataResponse() (response *DescribeWebManagedRulesTopDataResponse) { + response = &DescribeWebManagedRulesTopDataResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeWebManagedRulesTopData +// 查询waf攻击top数据 +// +// 可能返回的错误码: +// FAILEDOPERATION = "FailedOperation" +// LIMITEXCEEDED = "LimitExceeded" +// RESOURCENOTFOUND = "ResourceNotFound" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeWebManagedRulesTopData(request *DescribeWebManagedRulesTopDataRequest) (response *DescribeWebManagedRulesTopDataResponse, err error) { + return c.DescribeWebManagedRulesTopDataWithContext(context.Background(), request) +} + +// DescribeWebManagedRulesTopData +// 查询waf攻击top数据 +// +// 可能返回的错误码: +// FAILEDOPERATION = "FailedOperation" +// LIMITEXCEEDED = "LimitExceeded" +// RESOURCENOTFOUND = "ResourceNotFound" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeWebManagedRulesTopDataWithContext(ctx context.Context, request *DescribeWebManagedRulesTopDataRequest) (response *DescribeWebManagedRulesTopDataResponse, err error) { + if request == nil { + request = NewDescribeWebManagedRulesTopDataRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeWebManagedRulesTopData require credential") + } + + request.SetContext(ctx) + + response = NewDescribeWebManagedRulesTopDataResponse() + err = c.Send(request, response) + return +} + +func NewDescribeWebProtectionAttackEventsRequest() (request *DescribeWebProtectionAttackEventsRequest) { + request = &DescribeWebProtectionAttackEventsRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeWebProtectionAttackEvents") + + + return +} + +func NewDescribeWebProtectionAttackEventsResponse() (response *DescribeWebProtectionAttackEventsResponse) { + response = &DescribeWebProtectionAttackEventsResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeWebProtectionAttackEvents +// 查询web防护攻击事件 +// +// 可能返回的错误码: +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DescribeWebProtectionAttackEvents(request *DescribeWebProtectionAttackEventsRequest) (response *DescribeWebProtectionAttackEventsResponse, err error) { + return c.DescribeWebProtectionAttackEventsWithContext(context.Background(), request) +} + +// DescribeWebProtectionAttackEvents +// 查询web防护攻击事件 +// +// 可能返回的错误码: +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DescribeWebProtectionAttackEventsWithContext(ctx context.Context, request *DescribeWebProtectionAttackEventsRequest) (response *DescribeWebProtectionAttackEventsResponse, err error) { + if request == nil { + request = NewDescribeWebProtectionAttackEventsRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeWebProtectionAttackEvents require credential") + } + + request.SetContext(ctx) + + response = NewDescribeWebProtectionAttackEventsResponse() + err = c.Send(request, response) + return +} + +func NewDescribeWebProtectionDataRequest() (request *DescribeWebProtectionDataRequest) { + request = &DescribeWebProtectionDataRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeWebProtectionData") + + + return +} + +func NewDescribeWebProtectionDataResponse() (response *DescribeWebProtectionDataResponse) { + response = &DescribeWebProtectionDataResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeWebProtectionData +// 查询CC防护时序数据 +// +// 可能返回的错误码: +// FAILEDOPERATION = "FailedOperation" +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DescribeWebProtectionData(request *DescribeWebProtectionDataRequest) (response *DescribeWebProtectionDataResponse, err error) { + return c.DescribeWebProtectionDataWithContext(context.Background(), request) +} + +// DescribeWebProtectionData +// 查询CC防护时序数据 +// +// 可能返回的错误码: +// FAILEDOPERATION = "FailedOperation" +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) DescribeWebProtectionDataWithContext(ctx context.Context, request *DescribeWebProtectionDataRequest) (response *DescribeWebProtectionDataResponse, err error) { + if request == nil { + request = NewDescribeWebProtectionDataRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeWebProtectionData require credential") + } + + request.SetContext(ctx) + + response = NewDescribeWebProtectionDataResponse() + err = c.Send(request, response) + return +} + +func NewDescribeWebProtectionLogRequest() (request *DescribeWebProtectionLogRequest) { + request = &DescribeWebProtectionLogRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeWebProtectionLog") + + + return +} + +func NewDescribeWebProtectionLogResponse() (response *DescribeWebProtectionLogResponse) { + response = &DescribeWebProtectionLogResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeWebProtectionLog +// 查询CC防护日志 +// +// 可能返回的错误码: +// RESOURCENOTFOUND = "ResourceNotFound" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeWebProtectionLog(request *DescribeWebProtectionLogRequest) (response *DescribeWebProtectionLogResponse, err error) { + return c.DescribeWebProtectionLogWithContext(context.Background(), request) +} + +// DescribeWebProtectionLog +// 查询CC防护日志 +// +// 可能返回的错误码: +// RESOURCENOTFOUND = "ResourceNotFound" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeWebProtectionLogWithContext(ctx context.Context, request *DescribeWebProtectionLogRequest) (response *DescribeWebProtectionLogResponse, err error) { + if request == nil { + request = NewDescribeWebProtectionLogRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeWebProtectionLog require credential") + } + + request.SetContext(ctx) + + response = NewDescribeWebProtectionLogResponse() + err = c.Send(request, response) + return +} + +func NewDescribeZoneDDoSPolicyRequest() (request *DescribeZoneDDoSPolicyRequest) { + request = &DescribeZoneDDoSPolicyRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeZoneDDoSPolicy") + + + return +} + +func NewDescribeZoneDDoSPolicyResponse() (response *DescribeZoneDDoSPolicyResponse) { + response = &DescribeZoneDDoSPolicyResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeZoneDDoSPolicy +// 查询所有DDoS防护分区 +// +// 可能返回的错误码: +// FAILEDOPERATION = "FailedOperation" +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeZoneDDoSPolicy(request *DescribeZoneDDoSPolicyRequest) (response *DescribeZoneDDoSPolicyResponse, err error) { + return c.DescribeZoneDDoSPolicyWithContext(context.Background(), request) +} + +// DescribeZoneDDoSPolicy +// 查询所有DDoS防护分区 +// +// 可能返回的错误码: +// FAILEDOPERATION = "FailedOperation" +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeZoneDDoSPolicyWithContext(ctx context.Context, request *DescribeZoneDDoSPolicyRequest) (response *DescribeZoneDDoSPolicyResponse, err error) { + if request == nil { + request = NewDescribeZoneDDoSPolicyRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeZoneDDoSPolicy require credential") + } + + request.SetContext(ctx) + + response = NewDescribeZoneDDoSPolicyResponse() + err = c.Send(request, response) + return +} + +func NewDescribeZoneDetailsRequest() (request *DescribeZoneDetailsRequest) { + request = &DescribeZoneDetailsRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeZoneDetails") + + + return +} + +func NewDescribeZoneDetailsResponse() (response *DescribeZoneDetailsResponse) { + response = &DescribeZoneDetailsResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeZoneDetails +// 根据站点 ID 查询站点的详细信息 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// RESOURCENOTFOUND = "ResourceNotFound" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeZoneDetails(request *DescribeZoneDetailsRequest) (response *DescribeZoneDetailsResponse, err error) { + return c.DescribeZoneDetailsWithContext(context.Background(), request) +} + +// DescribeZoneDetails +// 根据站点 ID 查询站点的详细信息 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// RESOURCENOTFOUND = "ResourceNotFound" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DescribeZoneDetailsWithContext(ctx context.Context, request *DescribeZoneDetailsRequest) (response *DescribeZoneDetailsResponse, err error) { + if request == nil { + request = NewDescribeZoneDetailsRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeZoneDetails require credential") + } + + request.SetContext(ctx) + + response = NewDescribeZoneDetailsResponse() + err = c.Send(request, response) + return +} + +func NewDescribeZoneSettingRequest() (request *DescribeZoneSettingRequest) { + request = &DescribeZoneSettingRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeZoneSetting") + + + return +} + +func NewDescribeZoneSettingResponse() (response *DescribeZoneSettingResponse) { + response = &DescribeZoneSettingResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeZoneSetting +// 用于查询站点的所有配置信息。 +// +// 可能返回的错误码: +// INVALIDPARAMETER_SETTINGINVALIDPARAM = "InvalidParameter.SettingInvalidParam" +// INVALIDPARAMETER_ZONENOTFOUND = "InvalidParameter.ZoneNotFound" +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +// UNAUTHORIZEDOPERATION_NOPERMISSION = "UnauthorizedOperation.NoPermission" +func (c *Client) DescribeZoneSetting(request *DescribeZoneSettingRequest) (response *DescribeZoneSettingResponse, err error) { + return c.DescribeZoneSettingWithContext(context.Background(), request) +} + +// DescribeZoneSetting +// 用于查询站点的所有配置信息。 +// +// 可能返回的错误码: +// INVALIDPARAMETER_SETTINGINVALIDPARAM = "InvalidParameter.SettingInvalidParam" +// INVALIDPARAMETER_ZONENOTFOUND = "InvalidParameter.ZoneNotFound" +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +// UNAUTHORIZEDOPERATION_NOPERMISSION = "UnauthorizedOperation.NoPermission" +func (c *Client) DescribeZoneSettingWithContext(ctx context.Context, request *DescribeZoneSettingRequest) (response *DescribeZoneSettingResponse, err error) { + if request == nil { + request = NewDescribeZoneSettingRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeZoneSetting require credential") + } + + request.SetContext(ctx) + + response = NewDescribeZoneSettingResponse() + err = c.Send(request, response) + return +} + +func NewDescribeZonesRequest() (request *DescribeZonesRequest) { + request = &DescribeZonesRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DescribeZones") + + + return +} + +func NewDescribeZonesResponse() (response *DescribeZonesResponse) { + response = &DescribeZonesResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DescribeZones +// 用户查询用户站点信息列表,支持分页 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +// UNAUTHORIZEDOPERATION_NOPERMISSION = "UnauthorizedOperation.NoPermission" +func (c *Client) DescribeZones(request *DescribeZonesRequest) (response *DescribeZonesResponse, err error) { + return c.DescribeZonesWithContext(context.Background(), request) +} + +// DescribeZones +// 用户查询用户站点信息列表,支持分页 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +// UNAUTHORIZEDOPERATION_NOPERMISSION = "UnauthorizedOperation.NoPermission" +func (c *Client) DescribeZonesWithContext(ctx context.Context, request *DescribeZonesRequest) (response *DescribeZonesResponse, err error) { + if request == nil { + request = NewDescribeZonesRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DescribeZones require credential") + } + + request.SetContext(ctx) + + response = NewDescribeZonesResponse() + err = c.Send(request, response) + return +} + +func NewDownloadL7LogsRequest() (request *DownloadL7LogsRequest) { + request = &DownloadL7LogsRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "DownloadL7Logs") + + + return +} + +func NewDownloadL7LogsResponse() (response *DownloadL7LogsResponse) { + response = &DownloadL7LogsResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// DownloadL7Logs +// 查询七层离线日志 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// RESOURCEUNAVAILABLE = "ResourceUnavailable" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DownloadL7Logs(request *DownloadL7LogsRequest) (response *DownloadL7LogsResponse, err error) { + return c.DownloadL7LogsWithContext(context.Background(), request) +} + +// DownloadL7Logs +// 查询七层离线日志 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// RESOURCEUNAVAILABLE = "ResourceUnavailable" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) DownloadL7LogsWithContext(ctx context.Context, request *DownloadL7LogsRequest) (response *DownloadL7LogsResponse, err error) { + if request == nil { + request = NewDownloadL7LogsRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DownloadL7Logs require credential") + } + + request.SetContext(ctx) + + response = NewDownloadL7LogsResponse() + err = c.Send(request, response) + return +} + +func NewIdentifyZoneRequest() (request *IdentifyZoneRequest) { + request = &IdentifyZoneRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "IdentifyZone") + + + return +} + +func NewIdentifyZoneResponse() (response *IdentifyZoneResponse) { + response = &IdentifyZoneResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// IdentifyZone +// 用于验证站点所有权 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) IdentifyZone(request *IdentifyZoneRequest) (response *IdentifyZoneResponse, err error) { + return c.IdentifyZoneWithContext(context.Background(), request) +} + +// IdentifyZone +// 用于验证站点所有权 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) IdentifyZoneWithContext(ctx context.Context, request *IdentifyZoneRequest) (response *IdentifyZoneResponse, err error) { + if request == nil { + request = NewIdentifyZoneRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("IdentifyZone require credential") + } + + request.SetContext(ctx) + + response = NewIdentifyZoneResponse() + err = c.Send(request, response) + return +} + +func NewImportDnsRecordsRequest() (request *ImportDnsRecordsRequest) { + request = &ImportDnsRecordsRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "ImportDnsRecords") + + + return +} + +func NewImportDnsRecordsResponse() (response *ImportDnsRecordsResponse) { + response = &ImportDnsRecordsResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// ImportDnsRecords +// 导入 DNS 记录 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) ImportDnsRecords(request *ImportDnsRecordsRequest) (response *ImportDnsRecordsResponse, err error) { + return c.ImportDnsRecordsWithContext(context.Background(), request) +} + +// ImportDnsRecords +// 导入 DNS 记录 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) ImportDnsRecordsWithContext(ctx context.Context, request *ImportDnsRecordsRequest) (response *ImportDnsRecordsResponse, err error) { + if request == nil { + request = NewImportDnsRecordsRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("ImportDnsRecords require credential") + } + + request.SetContext(ctx) + + response = NewImportDnsRecordsResponse() + err = c.Send(request, response) + return +} + +func NewModifyApplicationProxyRequest() (request *ModifyApplicationProxyRequest) { + request = &ModifyApplicationProxyRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "ModifyApplicationProxy") + + + return +} + +func NewModifyApplicationProxyResponse() (response *ModifyApplicationProxyResponse) { + response = &ModifyApplicationProxyResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// ModifyApplicationProxy +// 修改应用代理 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) ModifyApplicationProxy(request *ModifyApplicationProxyRequest) (response *ModifyApplicationProxyResponse, err error) { + return c.ModifyApplicationProxyWithContext(context.Background(), request) +} + +// ModifyApplicationProxy +// 修改应用代理 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) ModifyApplicationProxyWithContext(ctx context.Context, request *ModifyApplicationProxyRequest) (response *ModifyApplicationProxyResponse, err error) { + if request == nil { + request = NewModifyApplicationProxyRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("ModifyApplicationProxy require credential") + } + + request.SetContext(ctx) + + response = NewModifyApplicationProxyResponse() + err = c.Send(request, response) + return +} + +func NewModifyApplicationProxyRuleRequest() (request *ModifyApplicationProxyRuleRequest) { + request = &ModifyApplicationProxyRuleRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "ModifyApplicationProxyRule") + + + return +} + +func NewModifyApplicationProxyRuleResponse() (response *ModifyApplicationProxyRuleResponse) { + response = &ModifyApplicationProxyRuleResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// ModifyApplicationProxyRule +// 修改应用代理规则 +// +// 可能返回的错误码: +// INVALIDPARAMETER_PARAMETERERROR = "InvalidParameter.ParameterError" +func (c *Client) ModifyApplicationProxyRule(request *ModifyApplicationProxyRuleRequest) (response *ModifyApplicationProxyRuleResponse, err error) { + return c.ModifyApplicationProxyRuleWithContext(context.Background(), request) +} + +// ModifyApplicationProxyRule +// 修改应用代理规则 +// +// 可能返回的错误码: +// INVALIDPARAMETER_PARAMETERERROR = "InvalidParameter.ParameterError" +func (c *Client) ModifyApplicationProxyRuleWithContext(ctx context.Context, request *ModifyApplicationProxyRuleRequest) (response *ModifyApplicationProxyRuleResponse, err error) { + if request == nil { + request = NewModifyApplicationProxyRuleRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("ModifyApplicationProxyRule require credential") + } + + request.SetContext(ctx) + + response = NewModifyApplicationProxyRuleResponse() + err = c.Send(request, response) + return +} + +func NewModifyApplicationProxyRuleStatusRequest() (request *ModifyApplicationProxyRuleStatusRequest) { + request = &ModifyApplicationProxyRuleStatusRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "ModifyApplicationProxyRuleStatus") + + + return +} + +func NewModifyApplicationProxyRuleStatusResponse() (response *ModifyApplicationProxyRuleStatusResponse) { + response = &ModifyApplicationProxyRuleStatusResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// ModifyApplicationProxyRuleStatus +// 修改应用代理规则的状态 +// +// 可能返回的错误码: +// INVALIDPARAMETER_PARAMETERERROR = "InvalidParameter.ParameterError" +func (c *Client) ModifyApplicationProxyRuleStatus(request *ModifyApplicationProxyRuleStatusRequest) (response *ModifyApplicationProxyRuleStatusResponse, err error) { + return c.ModifyApplicationProxyRuleStatusWithContext(context.Background(), request) +} + +// ModifyApplicationProxyRuleStatus +// 修改应用代理规则的状态 +// +// 可能返回的错误码: +// INVALIDPARAMETER_PARAMETERERROR = "InvalidParameter.ParameterError" +func (c *Client) ModifyApplicationProxyRuleStatusWithContext(ctx context.Context, request *ModifyApplicationProxyRuleStatusRequest) (response *ModifyApplicationProxyRuleStatusResponse, err error) { + if request == nil { + request = NewModifyApplicationProxyRuleStatusRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("ModifyApplicationProxyRuleStatus require credential") + } + + request.SetContext(ctx) + + response = NewModifyApplicationProxyRuleStatusResponse() + err = c.Send(request, response) + return +} + +func NewModifyApplicationProxyStatusRequest() (request *ModifyApplicationProxyStatusRequest) { + request = &ModifyApplicationProxyStatusRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "ModifyApplicationProxyStatus") + + + return +} + +func NewModifyApplicationProxyStatusResponse() (response *ModifyApplicationProxyStatusResponse) { + response = &ModifyApplicationProxyStatusResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// ModifyApplicationProxyStatus +// 修改应用代理的状态 +// +// 可能返回的错误码: +// INVALIDPARAMETER_PARAMETERERROR = "InvalidParameter.ParameterError" +func (c *Client) ModifyApplicationProxyStatus(request *ModifyApplicationProxyStatusRequest) (response *ModifyApplicationProxyStatusResponse, err error) { + return c.ModifyApplicationProxyStatusWithContext(context.Background(), request) +} + +// ModifyApplicationProxyStatus +// 修改应用代理的状态 +// +// 可能返回的错误码: +// INVALIDPARAMETER_PARAMETERERROR = "InvalidParameter.ParameterError" +func (c *Client) ModifyApplicationProxyStatusWithContext(ctx context.Context, request *ModifyApplicationProxyStatusRequest) (response *ModifyApplicationProxyStatusResponse, err error) { + if request == nil { + request = NewModifyApplicationProxyStatusRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("ModifyApplicationProxyStatus require credential") + } + + request.SetContext(ctx) + + response = NewModifyApplicationProxyStatusResponse() + err = c.Send(request, response) + return +} + +func NewModifyDDoSPolicyRequest() (request *ModifyDDoSPolicyRequest) { + request = &ModifyDDoSPolicyRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "ModifyDDoSPolicy") + + + return +} + +func NewModifyDDoSPolicyResponse() (response *ModifyDDoSPolicyResponse) { + response = &ModifyDDoSPolicyResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// ModifyDDoSPolicy +// 修改DDoS防护分区配置 +// +// 可能返回的错误码: +// INVALIDPARAMETER_SECURITY = "InvalidParameter.Security" +func (c *Client) ModifyDDoSPolicy(request *ModifyDDoSPolicyRequest) (response *ModifyDDoSPolicyResponse, err error) { + return c.ModifyDDoSPolicyWithContext(context.Background(), request) +} + +// ModifyDDoSPolicy +// 修改DDoS防护分区配置 +// +// 可能返回的错误码: +// INVALIDPARAMETER_SECURITY = "InvalidParameter.Security" +func (c *Client) ModifyDDoSPolicyWithContext(ctx context.Context, request *ModifyDDoSPolicyRequest) (response *ModifyDDoSPolicyResponse, err error) { + if request == nil { + request = NewModifyDDoSPolicyRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("ModifyDDoSPolicy require credential") + } + + request.SetContext(ctx) + + response = NewModifyDDoSPolicyResponse() + err = c.Send(request, response) + return +} + +func NewModifyDDoSPolicyHostRequest() (request *ModifyDDoSPolicyHostRequest) { + request = &ModifyDDoSPolicyHostRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "ModifyDDoSPolicyHost") + + + return +} + +func NewModifyDDoSPolicyHostResponse() (response *ModifyDDoSPolicyHostResponse) { + response = &ModifyDDoSPolicyHostResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// ModifyDDoSPolicyHost +// 域名DDoS高可用开关 +// +// 可能返回的错误码: +// FAILEDOPERATION = "FailedOperation" +func (c *Client) ModifyDDoSPolicyHost(request *ModifyDDoSPolicyHostRequest) (response *ModifyDDoSPolicyHostResponse, err error) { + return c.ModifyDDoSPolicyHostWithContext(context.Background(), request) +} + +// ModifyDDoSPolicyHost +// 域名DDoS高可用开关 +// +// 可能返回的错误码: +// FAILEDOPERATION = "FailedOperation" +func (c *Client) ModifyDDoSPolicyHostWithContext(ctx context.Context, request *ModifyDDoSPolicyHostRequest) (response *ModifyDDoSPolicyHostResponse, err error) { + if request == nil { + request = NewModifyDDoSPolicyHostRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("ModifyDDoSPolicyHost require credential") + } + + request.SetContext(ctx) + + response = NewModifyDDoSPolicyHostResponse() + err = c.Send(request, response) + return +} + +func NewModifyDefaultCertificateRequest() (request *ModifyDefaultCertificateRequest) { + request = &ModifyDefaultCertificateRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "ModifyDefaultCertificate") + + + return +} + +func NewModifyDefaultCertificateResponse() (response *ModifyDefaultCertificateResponse) { + response = &ModifyDefaultCertificateResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// ModifyDefaultCertificate +// 修改默认证书状态 +// +// 可能返回的错误码: +// INTERNALERROR_SYSTEMERROR = "InternalError.SystemError" +// OPERATIONDENIED = "OperationDenied" +// RESOURCEUNAVAILABLE_CERTNOTFOUND = "ResourceUnavailable.CertNotFound" +func (c *Client) ModifyDefaultCertificate(request *ModifyDefaultCertificateRequest) (response *ModifyDefaultCertificateResponse, err error) { + return c.ModifyDefaultCertificateWithContext(context.Background(), request) +} + +// ModifyDefaultCertificate +// 修改默认证书状态 +// +// 可能返回的错误码: +// INTERNALERROR_SYSTEMERROR = "InternalError.SystemError" +// OPERATIONDENIED = "OperationDenied" +// RESOURCEUNAVAILABLE_CERTNOTFOUND = "ResourceUnavailable.CertNotFound" +func (c *Client) ModifyDefaultCertificateWithContext(ctx context.Context, request *ModifyDefaultCertificateRequest) (response *ModifyDefaultCertificateResponse, err error) { + if request == nil { + request = NewModifyDefaultCertificateRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("ModifyDefaultCertificate require credential") + } + + request.SetContext(ctx) + + response = NewModifyDefaultCertificateResponse() + err = c.Send(request, response) + return +} + +func NewModifyDnsRecordRequest() (request *ModifyDnsRecordRequest) { + request = &ModifyDnsRecordRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "ModifyDnsRecord") + + + return +} + +func NewModifyDnsRecordResponse() (response *ModifyDnsRecordResponse) { + response = &ModifyDnsRecordResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// ModifyDnsRecord +// 修改 DNS 记录 +// +// 可能返回的错误码: +// INVALIDPARAMETERVALUE_INVALIDDNSCONTENT = "InvalidParameterValue.InvalidDNSContent" +// INVALIDPARAMETERVALUE_INVALIDDNSNAME = "InvalidParameterValue.InvalidDNSName" +// INVALIDPARAMETERVALUE_RECORDALREADYEXISTS = "InvalidParameterValue.RecordAlreadyExists" +// INVALIDPARAMETERVALUE_RECORDNOTALLOWED = "InvalidParameterValue.RecordNotAllowed" +// OPERATIONDENIED = "OperationDenied" +// RESOURCEINUSE = "ResourceInUse" +// RESOURCENOTFOUND = "ResourceNotFound" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) ModifyDnsRecord(request *ModifyDnsRecordRequest) (response *ModifyDnsRecordResponse, err error) { + return c.ModifyDnsRecordWithContext(context.Background(), request) +} + +// ModifyDnsRecord +// 修改 DNS 记录 +// +// 可能返回的错误码: +// INVALIDPARAMETERVALUE_INVALIDDNSCONTENT = "InvalidParameterValue.InvalidDNSContent" +// INVALIDPARAMETERVALUE_INVALIDDNSNAME = "InvalidParameterValue.InvalidDNSName" +// INVALIDPARAMETERVALUE_RECORDALREADYEXISTS = "InvalidParameterValue.RecordAlreadyExists" +// INVALIDPARAMETERVALUE_RECORDNOTALLOWED = "InvalidParameterValue.RecordNotAllowed" +// OPERATIONDENIED = "OperationDenied" +// RESOURCEINUSE = "ResourceInUse" +// RESOURCENOTFOUND = "ResourceNotFound" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) ModifyDnsRecordWithContext(ctx context.Context, request *ModifyDnsRecordRequest) (response *ModifyDnsRecordResponse, err error) { + if request == nil { + request = NewModifyDnsRecordRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("ModifyDnsRecord require credential") + } + + request.SetContext(ctx) + + response = NewModifyDnsRecordResponse() + err = c.Send(request, response) + return +} + +func NewModifyDnssecRequest() (request *ModifyDnssecRequest) { + request = &ModifyDnssecRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "ModifyDnssec") + + + return +} + +func NewModifyDnssecResponse() (response *ModifyDnssecResponse) { + response = &ModifyDnssecResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// ModifyDnssec +// 修改 DNSSEC 状态 +// +// 可能返回的错误码: +// FAILEDOPERATION = "FailedOperation" +func (c *Client) ModifyDnssec(request *ModifyDnssecRequest) (response *ModifyDnssecResponse, err error) { + return c.ModifyDnssecWithContext(context.Background(), request) +} + +// ModifyDnssec +// 修改 DNSSEC 状态 +// +// 可能返回的错误码: +// FAILEDOPERATION = "FailedOperation" +func (c *Client) ModifyDnssecWithContext(ctx context.Context, request *ModifyDnssecRequest) (response *ModifyDnssecResponse, err error) { + if request == nil { + request = NewModifyDnssecRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("ModifyDnssec require credential") + } + + request.SetContext(ctx) + + response = NewModifyDnssecResponse() + err = c.Send(request, response) + return +} + +func NewModifyHostsCertificateRequest() (request *ModifyHostsCertificateRequest) { + request = &ModifyHostsCertificateRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "ModifyHostsCertificate") + + + return +} + +func NewModifyHostsCertificateResponse() (response *ModifyHostsCertificateResponse) { + response = &ModifyHostsCertificateResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// ModifyHostsCertificate +// 用于修改域名证书 +// +// 可能返回的错误码: +// FAILEDOPERATION_CERTIFICATENOTFOUND = "FailedOperation.CertificateNotFound" +// INTERNALERROR_GETROLEERROR = "InternalError.GetRoleError" +// INTERNALERROR_SYSTEMERROR = "InternalError.SystemError" +// INVALIDPARAMETER_INVALIDCERTINFO = "InvalidParameter.InvalidCertInfo" +// OPERATIONDENIED = "OperationDenied" +// RESOURCEUNAVAILABLE_HOSTNOTFOUND = "ResourceUnavailable.HostNotFound" +func (c *Client) ModifyHostsCertificate(request *ModifyHostsCertificateRequest) (response *ModifyHostsCertificateResponse, err error) { + return c.ModifyHostsCertificateWithContext(context.Background(), request) +} + +// ModifyHostsCertificate +// 用于修改域名证书 +// +// 可能返回的错误码: +// FAILEDOPERATION_CERTIFICATENOTFOUND = "FailedOperation.CertificateNotFound" +// INTERNALERROR_GETROLEERROR = "InternalError.GetRoleError" +// INTERNALERROR_SYSTEMERROR = "InternalError.SystemError" +// INVALIDPARAMETER_INVALIDCERTINFO = "InvalidParameter.InvalidCertInfo" +// OPERATIONDENIED = "OperationDenied" +// RESOURCEUNAVAILABLE_HOSTNOTFOUND = "ResourceUnavailable.HostNotFound" +func (c *Client) ModifyHostsCertificateWithContext(ctx context.Context, request *ModifyHostsCertificateRequest) (response *ModifyHostsCertificateResponse, err error) { + if request == nil { + request = NewModifyHostsCertificateRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("ModifyHostsCertificate require credential") + } + + request.SetContext(ctx) + + response = NewModifyHostsCertificateResponse() + err = c.Send(request, response) + return +} + +func NewModifyLoadBalancingRequest() (request *ModifyLoadBalancingRequest) { + request = &ModifyLoadBalancingRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "ModifyLoadBalancing") + + + return +} + +func NewModifyLoadBalancingResponse() (response *ModifyLoadBalancingResponse) { + response = &ModifyLoadBalancingResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// ModifyLoadBalancing +// 修改负载均衡 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +func (c *Client) ModifyLoadBalancing(request *ModifyLoadBalancingRequest) (response *ModifyLoadBalancingResponse, err error) { + return c.ModifyLoadBalancingWithContext(context.Background(), request) +} + +// ModifyLoadBalancing +// 修改负载均衡 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +func (c *Client) ModifyLoadBalancingWithContext(ctx context.Context, request *ModifyLoadBalancingRequest) (response *ModifyLoadBalancingResponse, err error) { + if request == nil { + request = NewModifyLoadBalancingRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("ModifyLoadBalancing require credential") + } + + request.SetContext(ctx) + + response = NewModifyLoadBalancingResponse() + err = c.Send(request, response) + return +} + +func NewModifyLoadBalancingStatusRequest() (request *ModifyLoadBalancingStatusRequest) { + request = &ModifyLoadBalancingStatusRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "ModifyLoadBalancingStatus") + + + return +} + +func NewModifyLoadBalancingStatusResponse() (response *ModifyLoadBalancingStatusResponse) { + response = &ModifyLoadBalancingStatusResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// ModifyLoadBalancingStatus +// 修改负载均衡状态 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +func (c *Client) ModifyLoadBalancingStatus(request *ModifyLoadBalancingStatusRequest) (response *ModifyLoadBalancingStatusResponse, err error) { + return c.ModifyLoadBalancingStatusWithContext(context.Background(), request) +} + +// ModifyLoadBalancingStatus +// 修改负载均衡状态 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +func (c *Client) ModifyLoadBalancingStatusWithContext(ctx context.Context, request *ModifyLoadBalancingStatusRequest) (response *ModifyLoadBalancingStatusResponse, err error) { + if request == nil { + request = NewModifyLoadBalancingStatusRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("ModifyLoadBalancingStatus require credential") + } + + request.SetContext(ctx) + + response = NewModifyLoadBalancingStatusResponse() + err = c.Send(request, response) + return +} + +func NewModifyOriginGroupRequest() (request *ModifyOriginGroupRequest) { + request = &ModifyOriginGroupRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "ModifyOriginGroup") + + + return +} + +func NewModifyOriginGroupResponse() (response *ModifyOriginGroupResponse) { + response = &ModifyOriginGroupResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// ModifyOriginGroup +// 源站组修改 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +func (c *Client) ModifyOriginGroup(request *ModifyOriginGroupRequest) (response *ModifyOriginGroupResponse, err error) { + return c.ModifyOriginGroupWithContext(context.Background(), request) +} + +// ModifyOriginGroup +// 源站组修改 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +func (c *Client) ModifyOriginGroupWithContext(ctx context.Context, request *ModifyOriginGroupRequest) (response *ModifyOriginGroupResponse, err error) { + if request == nil { + request = NewModifyOriginGroupRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("ModifyOriginGroup require credential") + } + + request.SetContext(ctx) + + response = NewModifyOriginGroupResponse() + err = c.Send(request, response) + return +} + +func NewModifyRuleRequest() (request *ModifyRuleRequest) { + request = &ModifyRuleRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "ModifyRule") + + + return +} + +func NewModifyRuleResponse() (response *ModifyRuleResponse) { + response = &ModifyRuleResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// ModifyRule +// 修改规则引擎规则。 +// +// 可能返回的错误码: +// INVALIDPARAMETER_INVALIDRULEENGINETARGETSEXTENSION = "InvalidParameter.InvalidRuleEngineTargetsExtension" +func (c *Client) ModifyRule(request *ModifyRuleRequest) (response *ModifyRuleResponse, err error) { + return c.ModifyRuleWithContext(context.Background(), request) +} + +// ModifyRule +// 修改规则引擎规则。 +// +// 可能返回的错误码: +// INVALIDPARAMETER_INVALIDRULEENGINETARGETSEXTENSION = "InvalidParameter.InvalidRuleEngineTargetsExtension" +func (c *Client) ModifyRuleWithContext(ctx context.Context, request *ModifyRuleRequest) (response *ModifyRuleResponse, err error) { + if request == nil { + request = NewModifyRuleRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("ModifyRule require credential") + } + + request.SetContext(ctx) + + response = NewModifyRuleResponse() + err = c.Send(request, response) + return +} + +func NewModifyRulePriorityRequest() (request *ModifyRulePriorityRequest) { + request = &ModifyRulePriorityRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "ModifyRulePriority") + + + return +} + +func NewModifyRulePriorityResponse() (response *ModifyRulePriorityResponse) { + response = &ModifyRulePriorityResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// ModifyRulePriority +// 修改规则引擎规则优先级 +// +// 可能返回的错误码: +// INVALIDPARAMETER_INVALIDRULEENGINETARGETSEXTENSION = "InvalidParameter.InvalidRuleEngineTargetsExtension" +func (c *Client) ModifyRulePriority(request *ModifyRulePriorityRequest) (response *ModifyRulePriorityResponse, err error) { + return c.ModifyRulePriorityWithContext(context.Background(), request) +} + +// ModifyRulePriority +// 修改规则引擎规则优先级 +// +// 可能返回的错误码: +// INVALIDPARAMETER_INVALIDRULEENGINETARGETSEXTENSION = "InvalidParameter.InvalidRuleEngineTargetsExtension" +func (c *Client) ModifyRulePriorityWithContext(ctx context.Context, request *ModifyRulePriorityRequest) (response *ModifyRulePriorityResponse, err error) { + if request == nil { + request = NewModifyRulePriorityRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("ModifyRulePriority require credential") + } + + request.SetContext(ctx) + + response = NewModifyRulePriorityResponse() + err = c.Send(request, response) + return +} + +func NewModifySecurityPolicyRequest() (request *ModifySecurityPolicyRequest) { + request = &ModifySecurityPolicyRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "ModifySecurityPolicy") + + + return +} + +func NewModifySecurityPolicyResponse() (response *ModifySecurityPolicyResponse) { + response = &ModifySecurityPolicyResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// ModifySecurityPolicy +// 修改Web&Bot安全配置 +// +// 可能返回的错误码: +// INTERNALERROR_ROUTEERROR = "InternalError.RouteError" +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) ModifySecurityPolicy(request *ModifySecurityPolicyRequest) (response *ModifySecurityPolicyResponse, err error) { + return c.ModifySecurityPolicyWithContext(context.Background(), request) +} + +// ModifySecurityPolicy +// 修改Web&Bot安全配置 +// +// 可能返回的错误码: +// INTERNALERROR_ROUTEERROR = "InternalError.RouteError" +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +func (c *Client) ModifySecurityPolicyWithContext(ctx context.Context, request *ModifySecurityPolicyRequest) (response *ModifySecurityPolicyResponse, err error) { + if request == nil { + request = NewModifySecurityPolicyRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("ModifySecurityPolicy require credential") + } + + request.SetContext(ctx) + + response = NewModifySecurityPolicyResponse() + err = c.Send(request, response) + return +} + +func NewModifyZoneRequest() (request *ModifyZoneRequest) { + request = &ModifyZoneRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "ModifyZone") + + + return +} + +func NewModifyZoneResponse() (response *ModifyZoneResponse) { + response = &ModifyZoneResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// ModifyZone +// 用该站点信息 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// RESOURCENOTFOUND = "ResourceNotFound" +// RESOURCEUNAVAILABLE = "ResourceUnavailable" +func (c *Client) ModifyZone(request *ModifyZoneRequest) (response *ModifyZoneResponse, err error) { + return c.ModifyZoneWithContext(context.Background(), request) +} + +// ModifyZone +// 用该站点信息 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// RESOURCENOTFOUND = "ResourceNotFound" +// RESOURCEUNAVAILABLE = "ResourceUnavailable" +func (c *Client) ModifyZoneWithContext(ctx context.Context, request *ModifyZoneRequest) (response *ModifyZoneResponse, err error) { + if request == nil { + request = NewModifyZoneRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("ModifyZone require credential") + } + + request.SetContext(ctx) + + response = NewModifyZoneResponse() + err = c.Send(request, response) + return +} + +func NewModifyZoneCnameSpeedUpRequest() (request *ModifyZoneCnameSpeedUpRequest) { + request = &ModifyZoneCnameSpeedUpRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "ModifyZoneCnameSpeedUp") + + + return +} + +func NewModifyZoneCnameSpeedUpResponse() (response *ModifyZoneCnameSpeedUpResponse) { + response = &ModifyZoneCnameSpeedUpResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// ModifyZoneCnameSpeedUp +// 开启,关闭 CNAME 加速 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) ModifyZoneCnameSpeedUp(request *ModifyZoneCnameSpeedUpRequest) (response *ModifyZoneCnameSpeedUpResponse, err error) { + return c.ModifyZoneCnameSpeedUpWithContext(context.Background(), request) +} + +// ModifyZoneCnameSpeedUp +// 开启,关闭 CNAME 加速 +// +// 可能返回的错误码: +// OPERATIONDENIED = "OperationDenied" +// RESOURCENOTFOUND = "ResourceNotFound" +func (c *Client) ModifyZoneCnameSpeedUpWithContext(ctx context.Context, request *ModifyZoneCnameSpeedUpRequest) (response *ModifyZoneCnameSpeedUpResponse, err error) { + if request == nil { + request = NewModifyZoneCnameSpeedUpRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("ModifyZoneCnameSpeedUp require credential") + } + + request.SetContext(ctx) + + response = NewModifyZoneCnameSpeedUpResponse() + err = c.Send(request, response) + return +} + +func NewModifyZoneSettingRequest() (request *ModifyZoneSettingRequest) { + request = &ModifyZoneSettingRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "ModifyZoneSetting") + + + return +} + +func NewModifyZoneSettingResponse() (response *ModifyZoneSettingResponse) { + response = &ModifyZoneSettingResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// ModifyZoneSetting +// 用于修改站点配置 +// +// 可能返回的错误码: +// INVALIDPARAMETER_INVALIDCACHEONLYONSWITCH = "InvalidParameter.InvalidCacheOnlyOnSwitch" +// INVALIDPARAMETER_INVALIDCLIENTIPHEADERNAME = "InvalidParameter.InvalidClientIpHeaderName" +// INVALIDPARAMETER_INVALIDDYNAMICROUTINEBILLING = "InvalidParameter.InvalidDynamicRoutineBilling" +// INVALIDPARAMETER_INVALIDORIGIN = "InvalidParameter.InvalidOrigin" +// INVALIDPARAMETER_INVALIDPOSTMAXSIZEBILLING = "InvalidParameter.InvalidPostMaxSizeBilling" +// INVALIDPARAMETER_INVALIDREQUESTHEADERNAME = "InvalidParameter.InvalidRequestHeaderName" +// INVALIDPARAMETER_INVALIDRESOURCEIDBILLING = "InvalidParameter.InvalidResourceIdBilling" +// INVALIDPARAMETER_INVALIDWEBSOCKETTIMEOUT = "InvalidParameter.InvalidWebSocketTimeout" +// INVALIDPARAMETER_SETTINGINVALIDPARAM = "InvalidParameter.SettingInvalidParam" +// INVALIDPARAMETER_ZONENOTFOUND = "InvalidParameter.ZoneNotFound" +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +// UNAUTHORIZEDOPERATION_NOPERMISSION = "UnauthorizedOperation.NoPermission" +func (c *Client) ModifyZoneSetting(request *ModifyZoneSettingRequest) (response *ModifyZoneSettingResponse, err error) { + return c.ModifyZoneSettingWithContext(context.Background(), request) +} + +// ModifyZoneSetting +// 用于修改站点配置 +// +// 可能返回的错误码: +// INVALIDPARAMETER_INVALIDCACHEONLYONSWITCH = "InvalidParameter.InvalidCacheOnlyOnSwitch" +// INVALIDPARAMETER_INVALIDCLIENTIPHEADERNAME = "InvalidParameter.InvalidClientIpHeaderName" +// INVALIDPARAMETER_INVALIDDYNAMICROUTINEBILLING = "InvalidParameter.InvalidDynamicRoutineBilling" +// INVALIDPARAMETER_INVALIDORIGIN = "InvalidParameter.InvalidOrigin" +// INVALIDPARAMETER_INVALIDPOSTMAXSIZEBILLING = "InvalidParameter.InvalidPostMaxSizeBilling" +// INVALIDPARAMETER_INVALIDREQUESTHEADERNAME = "InvalidParameter.InvalidRequestHeaderName" +// INVALIDPARAMETER_INVALIDRESOURCEIDBILLING = "InvalidParameter.InvalidResourceIdBilling" +// INVALIDPARAMETER_INVALIDWEBSOCKETTIMEOUT = "InvalidParameter.InvalidWebSocketTimeout" +// INVALIDPARAMETER_SETTINGINVALIDPARAM = "InvalidParameter.SettingInvalidParam" +// INVALIDPARAMETER_ZONENOTFOUND = "InvalidParameter.ZoneNotFound" +// OPERATIONDENIED = "OperationDenied" +// UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" +// UNAUTHORIZEDOPERATION_NOPERMISSION = "UnauthorizedOperation.NoPermission" +func (c *Client) ModifyZoneSettingWithContext(ctx context.Context, request *ModifyZoneSettingRequest) (response *ModifyZoneSettingResponse, err error) { + if request == nil { + request = NewModifyZoneSettingRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("ModifyZoneSetting require credential") + } + + request.SetContext(ctx) + + response = NewModifyZoneSettingResponse() + err = c.Send(request, response) + return +} + +func NewModifyZoneStatusRequest() (request *ModifyZoneStatusRequest) { + request = &ModifyZoneStatusRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "ModifyZoneStatus") + + + return +} + +func NewModifyZoneStatusResponse() (response *ModifyZoneStatusResponse) { + response = &ModifyZoneStatusResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// ModifyZoneStatus +// 用于开启,关闭站点 +// +// 可能返回的错误码: +// RESOURCENOTFOUND = "ResourceNotFound" +// RESOURCEUNAVAILABLE = "ResourceUnavailable" +func (c *Client) ModifyZoneStatus(request *ModifyZoneStatusRequest) (response *ModifyZoneStatusResponse, err error) { + return c.ModifyZoneStatusWithContext(context.Background(), request) +} + +// ModifyZoneStatus +// 用于开启,关闭站点 +// +// 可能返回的错误码: +// RESOURCENOTFOUND = "ResourceNotFound" +// RESOURCEUNAVAILABLE = "ResourceUnavailable" +func (c *Client) ModifyZoneStatusWithContext(ctx context.Context, request *ModifyZoneStatusRequest) (response *ModifyZoneStatusResponse, err error) { + if request == nil { + request = NewModifyZoneStatusRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("ModifyZoneStatus require credential") + } + + request.SetContext(ctx) + + response = NewModifyZoneStatusResponse() + err = c.Send(request, response) + return +} + +func NewReclaimZoneRequest() (request *ReclaimZoneRequest) { + request = &ReclaimZoneRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "ReclaimZone") + + + return +} + +func NewReclaimZoneResponse() (response *ReclaimZoneResponse) { + response = &ReclaimZoneResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// ReclaimZone +// 站点被其他用户接入后,验证了站点所有权之后,可以找回该站点 +// +// 可能返回的错误码: +// RESOURCENOTFOUND = "ResourceNotFound" +// RESOURCEUNAVAILABLE = "ResourceUnavailable" +func (c *Client) ReclaimZone(request *ReclaimZoneRequest) (response *ReclaimZoneResponse, err error) { + return c.ReclaimZoneWithContext(context.Background(), request) +} + +// ReclaimZone +// 站点被其他用户接入后,验证了站点所有权之后,可以找回该站点 +// +// 可能返回的错误码: +// RESOURCENOTFOUND = "ResourceNotFound" +// RESOURCEUNAVAILABLE = "ResourceUnavailable" +func (c *Client) ReclaimZoneWithContext(ctx context.Context, request *ReclaimZoneRequest) (response *ReclaimZoneResponse, err error) { + if request == nil { + request = NewReclaimZoneRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("ReclaimZone require credential") + } + + request.SetContext(ctx) + + response = NewReclaimZoneResponse() + err = c.Send(request, response) + return +} + +func NewScanDnsRecordsRequest() (request *ScanDnsRecordsRequest) { + request = &ScanDnsRecordsRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("teo", APIVersion, "ScanDnsRecords") + + + return +} + +func NewScanDnsRecordsResponse() (response *ScanDnsRecordsResponse) { + response = &ScanDnsRecordsResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// ScanDnsRecords +// 扫描站点历史解析记录 +// +// 可能返回的错误码: +// RESOURCENOTFOUND = "ResourceNotFound" +// RESOURCEUNAVAILABLE = "ResourceUnavailable" +func (c *Client) ScanDnsRecords(request *ScanDnsRecordsRequest) (response *ScanDnsRecordsResponse, err error) { + return c.ScanDnsRecordsWithContext(context.Background(), request) +} + +// ScanDnsRecords +// 扫描站点历史解析记录 +// +// 可能返回的错误码: +// RESOURCENOTFOUND = "ResourceNotFound" +// RESOURCEUNAVAILABLE = "ResourceUnavailable" +func (c *Client) ScanDnsRecordsWithContext(ctx context.Context, request *ScanDnsRecordsRequest) (response *ScanDnsRecordsResponse, err error) { + if request == nil { + request = NewScanDnsRecordsRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("ScanDnsRecords require credential") + } + + request.SetContext(ctx) + + response = NewScanDnsRecordsResponse() + err = c.Send(request, response) + return +} diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220106/errors.go b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220106/errors.go new file mode 100644 index 0000000000..ced4592f31 --- /dev/null +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220106/errors.go @@ -0,0 +1,196 @@ +// Copyright (c) 2017-2018 THL A29 Limited, a Tencent company. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package v20220106 + +const ( + // 此产品的特有错误码 + + // DryRun 操作,代表请求将会是成功的,只是多传了 DryRun 参数。 + DRYRUNOPERATION = "DryRunOperation" + + // 操作失败。 + FAILEDOPERATION = "FailedOperation" + + // 证书不存在。 + FAILEDOPERATION_CERTIFICATENOTFOUND = "FailedOperation.CertificateNotFound" + + // 内部错误。 + INTERNALERROR = "InternalError" + + // 后台处理出错。 + INTERNALERROR_BACKENDERROR = "InternalError.BackendError" + + // 数据库错误。 + INTERNALERROR_DBERROR = "InternalError.DBError" + + // 获取配置失败。 + INTERNALERROR_DOMAINCONFIG = "InternalError.DomainConfig" + + // 上传链接生成失败。 + INTERNALERROR_FAILEDTOGENERATEURL = "InternalError.FailedToGenerateUrl" + + // 获取角色失败。 + INTERNALERROR_GETROLEERROR = "InternalError.GetRoleError" + + // 后端服务器发生未知错误。 + INTERNALERROR_PROXYSERVER = "InternalError.ProxyServer" + + // 配额系统处理失败。 + INTERNALERROR_QUOTASYSTEM = "InternalError.QuotaSystem" + + // 后端服务路由地址错误。 + INTERNALERROR_ROUTEERROR = "InternalError.RouteError" + + // 内部错误。 + INTERNALERROR_SYSTEMERROR = "InternalError.SystemError" + + // 参数错误。 + INVALIDPARAMETER = "InvalidParameter" + + // 域名不存在或不属于该账号。 + INVALIDPARAMETER_DOMAINNOTFOUND = "InvalidParameter.DomainNotFound" + + // 无效的节点缓存。 + INVALIDPARAMETER_INVALIDCACHEONLYONSWITCH = "InvalidParameter.InvalidCacheOnlyOnSwitch" + + // 证书信息错误。 + INVALIDPARAMETER_INVALIDCERTINFO = "InvalidParameter.InvalidCertInfo" + + // 无效的客户端IP请求头。 + INVALIDPARAMETER_INVALIDCLIENTIPHEADERNAME = "InvalidParameter.InvalidClientIpHeaderName" + + // 套餐包不支持智能加速配置。 + INVALIDPARAMETER_INVALIDDYNAMICROUTINEBILLING = "InvalidParameter.InvalidDynamicRoutineBilling" + + // 无效的源站。 + INVALIDPARAMETER_INVALIDORIGIN = "InvalidParameter.InvalidOrigin" + + // 套餐包不支持最大上传大小。 + INVALIDPARAMETER_INVALIDPOSTMAXSIZEBILLING = "InvalidParameter.InvalidPostMaxSizeBilling" + + // 无效的请求头header。 + INVALIDPARAMETER_INVALIDREQUESTHEADERNAME = "InvalidParameter.InvalidRequestHeaderName" + + // 无套餐包。 + INVALIDPARAMETER_INVALIDRESOURCEIDBILLING = "InvalidParameter.InvalidResourceIdBilling" + + // 无效的规则引擎条件。 + INVALIDPARAMETER_INVALIDRULEENGINETARGET = "InvalidParameter.InvalidRuleEngineTarget" + + // 无效的规则引擎文件后缀条件。 + INVALIDPARAMETER_INVALIDRULEENGINETARGETSEXTENSION = "InvalidParameter.InvalidRuleEngineTargetsExtension" + + // 无效的WebSocket。 + INVALIDPARAMETER_INVALIDWEBSOCKETTIMEOUT = "InvalidParameter.InvalidWebSocketTimeout" + + // 参数错误。 + INVALIDPARAMETER_PARAMETERERROR = "InvalidParameter.ParameterError" + + // 参数错误 + INVALIDPARAMETER_SECURITY = "InvalidParameter.Security" + + // 域名配置错误。 + INVALIDPARAMETER_SETTINGINVALIDPARAM = "InvalidParameter.SettingInvalidParam" + + // 资源存在错误。 + INVALIDPARAMETER_TARGET = "InvalidParameter.Target" + + // 任务无法生成。 + INVALIDPARAMETER_TASKNOTGENERATED = "InvalidParameter.TaskNotGenerated" + + // 文件上传链接存在问题。 + INVALIDPARAMETER_UPLOADURL = "InvalidParameter.UploadUrl" + + // 站点不存在。 + INVALIDPARAMETER_ZONENOTFOUND = "InvalidParameter.ZoneNotFound" + + // 与已经添加的记录冲突。 + INVALIDPARAMETERVALUE_CONFLICTRECORD = "InvalidParameterValue.ConflictRecord" + + // DNS 记录与 DNSSEC 功能冲突。 + INVALIDPARAMETERVALUE_CONFLICTWITHDNSSEC = "InvalidParameterValue.ConflictWithDNSSEC" + + // DNS 记录与 LB 记录冲突。 + INVALIDPARAMETERVALUE_CONFLICTWITHLBRECORD = "InvalidParameterValue.ConflictWithLBRecord" + + // DNS 记录与 NS 记录冲突。 + INVALIDPARAMETERVALUE_CONFLICTWITHNSRECORD = "InvalidParameterValue.ConflictWithNSRecord" + + // DNS 记录内容错误。 + INVALIDPARAMETERVALUE_INVALIDDNSCONTENT = "InvalidParameterValue.InvalidDNSContent" + + // DNS 记录名称错误。 + INVALIDPARAMETERVALUE_INVALIDDNSNAME = "InvalidParameterValue.InvalidDNSName" + + // DNS 代理域名错误。 + INVALIDPARAMETERVALUE_INVALIDPROXYNAME = "InvalidParameterValue.InvalidProxyName" + + // DNS 代理域名源站错误。 + INVALIDPARAMETERVALUE_INVALIDPROXYORIGIN = "InvalidParameterValue.InvalidProxyOrigin" + + // 记录已存在。 + INVALIDPARAMETERVALUE_RECORDALREADYEXISTS = "InvalidParameterValue.RecordAlreadyExists" + + // 记录不允许添加。 + INVALIDPARAMETERVALUE_RECORDNOTALLOWED = "InvalidParameterValue.RecordNotAllowed" + + // 超过配额限制。 + LIMITEXCEEDED = "LimitExceeded" + + // 本次提交的资源数超过上限。 + LIMITEXCEEDED_BATCHQUOTA = "LimitExceeded.BatchQuota" + + // 当天提交的资源数超过上限。 + LIMITEXCEEDED_DAILYQUOTA = "LimitExceeded.DailyQuota" + + // 操作被拒绝。 + OPERATIONDENIED = "OperationDenied" + + // 域名尚未备案。 + OPERATIONDENIED_DOMAINNOICP = "OperationDenied.DomainNoICP" + + // 资源被占用。 + RESOURCEINUSE = "ResourceInUse" + + // 资源被其他用户接入。 + RESOURCEINUSE_OTHERS = "ResourceInUse.Others" + + // 资源不足。 + RESOURCEINSUFFICIENT = "ResourceInsufficient" + + // 资源不存在。 + RESOURCENOTFOUND = "ResourceNotFound" + + // 资源不可用。 + RESOURCEUNAVAILABLE = "ResourceUnavailable" + + // 证书不存在或未授权。 + RESOURCEUNAVAILABLE_CERTNOTFOUND = "ResourceUnavailable.CertNotFound" + + // 域名不存在或未开启代理。 + RESOURCEUNAVAILABLE_HOSTNOTFOUND = "ResourceUnavailable.HostNotFound" + + // 站点不存在或不属于该账号。 + RESOURCEUNAVAILABLE_ZONENOTFOUND = "ResourceUnavailable.ZoneNotFound" + + // Cam 未授权。 + UNAUTHORIZEDOPERATION_CAMUNAUTHORIZED = "UnauthorizedOperation.CamUnauthorized" + + // 鉴权错误。 + UNAUTHORIZEDOPERATION_DOMAINEMPTY = "UnauthorizedOperation.DomainEmpty" + + // 子账户没有操作权限,请添加权限后继续操作。 + UNAUTHORIZEDOPERATION_NOPERMISSION = "UnauthorizedOperation.NoPermission" +) diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220106/models.go b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220106/models.go new file mode 100644 index 0000000000..4dc9141090 --- /dev/null +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220106/models.go @@ -0,0 +1,12112 @@ +// Copyright (c) 2017-2018 THL A29 Limited, a Tencent company. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package v20220106 + +import ( + "encoding/json" + tcerr "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors" + tchttp "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http" +) + +type ACLCondition struct { + // 匹配字段 + MatchFrom *string `json:"MatchFrom,omitempty" name:"MatchFrom"` + + // 匹配字符串 + MatchParam *string `json:"MatchParam,omitempty" name:"MatchParam"` + + // 匹配关系 + Operator *string `json:"Operator,omitempty" name:"Operator"` + + // 匹配内容 + MatchContent *string `json:"MatchContent,omitempty" name:"MatchContent"` +} + +type ACLUserRule struct { + // 规则名 + RuleName *string `json:"RuleName,omitempty" name:"RuleName"` + + // 动作 + Action *string `json:"Action,omitempty" name:"Action"` + + // 状态 + RuleStatus *string `json:"RuleStatus,omitempty" name:"RuleStatus"` + + // ACL规则 + Conditions []*ACLCondition `json:"Conditions,omitempty" name:"Conditions"` + + // 规则优先级 + RulePriority *int64 `json:"RulePriority,omitempty" name:"RulePriority"` + + // 规则id + // 注意:此字段可能返回 null,表示取不到有效值。 + RuleID *int64 `json:"RuleID,omitempty" name:"RuleID"` + + // 更新时间 + // 注意:此字段可能返回 null,表示取不到有效值。 + UpdateTime *string `json:"UpdateTime,omitempty" name:"UpdateTime"` + + // ip封禁的惩罚时间 + // 注意:此字段可能返回 null,表示取不到有效值。 + PunishTime *int64 `json:"PunishTime,omitempty" name:"PunishTime"` + + // ip封禁的惩罚时间单位 + // 注意:此字段可能返回 null,表示取不到有效值。 + PunishTimeUnit *string `json:"PunishTimeUnit,omitempty" name:"PunishTimeUnit"` + + // 自定义返回页面的名称 + // 注意:此字段可能返回 null,表示取不到有效值。 + Name *string `json:"Name,omitempty" name:"Name"` + + // 自定义返回页面的实例id + // 注意:此字段可能返回 null,表示取不到有效值。 + PageId *int64 `json:"PageId,omitempty" name:"PageId"` + + // 重定向时候的地址,必须为本用户接入的站点子域名 + // 注意:此字段可能返回 null,表示取不到有效值。 + RedirectUrl *string `json:"RedirectUrl,omitempty" name:"RedirectUrl"` + + // 重定向时候的返回码 + // 注意:此字段可能返回 null,表示取不到有效值。 + ResponseCode *int64 `json:"ResponseCode,omitempty" name:"ResponseCode"` +} + +type AclConfig struct { + // 开关 + Switch *string `json:"Switch,omitempty" name:"Switch"` + + // ACL用户规则 + UserRules []*ACLUserRule `json:"UserRules,omitempty" name:"UserRules"` +} + +type AiRule struct { + // smart_status_close-关闭;smart_status_open-拦截处置; + // smart_status_observe-观察处置 + // 注意:此字段可能返回 null,表示取不到有效值。 + Mode *string `json:"Mode,omitempty" name:"Mode"` +} + +type ApplicationProxy struct { + // 代理ID。 + ProxyId *string `json:"ProxyId,omitempty" name:"ProxyId"` + + // 当ProxyType=hostname时,表示域名或子域名; + // 当ProxyType=instance时,表示代理名称。 + ProxyName *string `json:"ProxyName,omitempty" name:"ProxyName"` + + // 调度模式,取值有: + //