Skip to content

Commit 380f257

Browse files
committed
remove redundancy code and add field
1 parent 5ad5c7c commit 380f257

File tree

4 files changed

+42
-36
lines changed

4 files changed

+42
-36
lines changed

tencentcloud/data_source_tc_cdn_domains.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ func dataSourceTencentCloudCdnDomains() *schema.Resource {
5757
ValidateFunc: validateAllowedStringValue(CDN_HTTPS_SWITCH),
5858
Description: "HTTPS configuration. The available value include `on`, `off` and `processing`.",
5959
},
60+
"offset": {
61+
Type: schema.TypeInt,
62+
Optional: true,
63+
Default: 10,
64+
ValidateFunc: validateIntegerInRange(1, 10000),
65+
Description: "Record offset. Default is 10.",
66+
},
6067
"result_output_file": {
6168
Type: schema.TypeString,
6269
Optional: true,
@@ -68,7 +75,7 @@ func dataSourceTencentCloudCdnDomains() *schema.Resource {
6875
Description: "An information list of cdn domain. Each element contains the following attributes:",
6976
Elem: &schema.Resource{
7077
Schema: map[string]*schema.Schema{
71-
"resource_id": {
78+
"id": {
7279
Type: schema.TypeString,
7380
Computed: true,
7481
Description: "Domain name ID.",
@@ -226,35 +233,35 @@ func dataSourceTencentCloudCdnDomainsRead(d *schema.ResourceData, meta interface
226233
cdnService := CdnService{client: client}
227234
tagService := TagService{client: client}
228235

236+
offset, _ := d.Get("offset").(int)
229237
var domainFilterMap = make(map[string]interface{}, 5)
230-
231238
if v, ok := d.GetOk("domain"); ok {
232239
domainFilterMap["domain"] = v.(string)
233240
}
234241
if v, ok := d.GetOk("service_type"); ok {
235-
domainFilterMap["service_type"] = v.(string)
242+
domainFilterMap["serviceType"] = v.(string)
236243
}
237244
if v, ok := d.GetOk("https_switch"); ok {
238-
domainFilterMap["https_switch"] = v.(string)
245+
domainFilterMap["httpsSwitch"] = v.(string)
239246
}
240247
if v, ok := d.GetOk("origin_pull_protocol"); ok {
241-
domainFilterMap["origin_pull_protocol"] = v.(string)
248+
domainFilterMap["originPullProtocol"] = v.(string)
242249
}
243-
if v, ok := d.GetOk("full_url_cache"); ok {
250+
if v, ok := d.GetOkExists("full_url_cache"); ok {
244251
var value string
245252
if v.(bool) {
246253
value = "on"
247254
} else {
248255
value = "off"
249256
}
250257

251-
domainFilterMap["full_url_cache"] = value
258+
domainFilterMap["fullUrlCache"] = value
252259
}
253260

254261
var domainConfigs []*cdn.DetailDomain
255262
var errRet error
256263
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
257-
domainConfigs, errRet = cdnService.DescribeDomainsConfigByFilters(ctx, domainFilterMap)
264+
domainConfigs, errRet = cdnService.DescribeDomainsConfigByFilters(ctx, domainFilterMap, int64(offset))
258265
if errRet != nil {
259266
return retryError(errRet, InternalError)
260267
}
@@ -303,7 +310,7 @@ func dataSourceTencentCloudCdnDomainsRead(d *schema.ResourceData, meta interface
303310
}
304311

305312
mapping := map[string]interface{}{
306-
"resource_id": detailDomain.ResourceId,
313+
"id": detailDomain.ResourceId,
307314
"domain": detailDomain.Domain,
308315
"cname": detailDomain.Cname,
309316
"status": detailDomain.Status,

tencentcloud/data_source_tc_cdn_domains_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ func TestAccTencentCloudCdnDomains(t *testing.T) {
3434
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "tags.test", "world"),
3535
),
3636
},
37-
{
38-
ResourceName: "tencentcloud_cdn_domain.foo",
39-
ImportState: true,
40-
ImportStateVerify: true,
41-
ImportStateVerifyIgnore: []string{"https_config"},
42-
},
4337
},
4438
})
4539
}

tencentcloud/service_tencentcloud_cdn.go

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package tencentcloud
33
import (
44
"context"
55
"log"
6-
"strings"
76

87
cdn "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn/v20180606"
98
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
@@ -90,21 +89,35 @@ func (me *CdnService) StartDomain(ctx context.Context, domain string) error {
9089
return nil
9190
}
9291

93-
func (me *CdnService) DescribeDomainsConfigByFilters(ctx context.Context, filterMap map[string]interface{}) (domainConfig []*cdn.DetailDomain, errRet error) {
92+
func (me *CdnService) DescribeDomainsConfigByFilters(ctx context.Context,
93+
filterMap map[string]interface{},
94+
leftNumber int64) (domainConfig []*cdn.DetailDomain, errRet error) {
95+
9496
logId := getLogId(ctx)
9597
request := cdn.NewDescribeDomainsConfigRequest()
9698
request.Filters = make([]*cdn.DomainFilter, 0, len(filterMap))
9799

98100
for k, v := range filterMap {
99101
value := v.(string)
100-
101102
filter := &cdn.DomainFilter{
102-
Name: helper.String(underlineToHump([]byte(k))),
103+
Name: helper.String(k),
103104
Value: []*string{&value},
104105
}
105106
request.Filters = append(request.Filters, filter)
106107
}
107108

109+
var offset, limit int64 = 0, 100
110+
needMoreDomains:
111+
if leftNumber <= 0 {
112+
return
113+
}
114+
if leftNumber < limit {
115+
limit = leftNumber
116+
}
117+
118+
request.Limit = &limit
119+
request.Offset = &offset
120+
108121
ratelimit.Check(request.GetAction())
109122
response, err := me.client.UseCdnClient().DescribeDomainsConfig(request)
110123
if err != nil {
@@ -119,25 +132,16 @@ func (me *CdnService) DescribeDomainsConfigByFilters(ctx context.Context, filter
119132
return
120133
}
121134

135+
totalCount := *response.Response.TotalNumber
136+
leftNumber = leftNumber - limit
137+
offset += limit
138+
122139
if len(response.Response.Domains) > 0 {
123-
domainConfig = response.Response.Domains
140+
domainConfig = append(domainConfig, response.Response.Domains...)
124141
}
125-
return
126-
}
127142

128-
func underlineToHump(underline []byte) (humpValue string) {
129-
lenUnderLine := len(underline)
130-
for i := 0; i < lenUnderLine; i++ {
131-
if string(underline[i]) == "_" {
132-
if i+1 < lenUnderLine {
133-
humpValue += strings.ToUpper(string(underline[i+1]))
134-
i++
135-
}
136-
continue
137-
}
138-
139-
humpValue += string(underline[i])
143+
if leftNumber > 0 && totalCount-offset > 0 {
144+
goto needMoreDomains
140145
}
141-
142146
return
143147
}

website/docs/d/cdn_domains.html.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ The following arguments are supported:
2929
* `domain` - (Optional) Acceleration domain name.
3030
* `full_url_cache` - (Optional) Whether to enable full-path cache.
3131
* `https_switch` - (Optional) HTTPS configuration. The available value include `on`, `off` and `processing`.
32+
* `offset` - (Optional) Record offset. Default is 10.
3233
* `origin_pull_protocol` - (Optional) Origin-pull protocol configuration. The available value include `http`, `https` and `follow`.
3334
* `result_output_file` - (Optional) Used to save results.
3435
* `service_type` - (Optional) Service type of acceleration domain name. The available value include `web`, `download` and `media`.
@@ -49,6 +50,7 @@ In addition to all arguments above, the following attributes are exported:
4950
* `ocsp_stapling_switch` - OCSP configuration switch.
5051
* `spdy_switch` - Spdy configuration switch.
5152
* `verify_client` - Client certificate authentication feature.
53+
* `id` - Domain name ID.
5254
* `origin` - Origin server configuration.
5355
* `backup_origin_list` - Backup origin server list.
5456
* `backup_origin_type` - Backup origin server type.
@@ -59,7 +61,6 @@ In addition to all arguments above, the following attributes are exported:
5961
* `origin_type` - Master origin server type.
6062
* `server_name` - Host header used when accessing the master origin server. If left empty, the acceleration domain name will be used by default.
6163
* `project_id` - The project CDN belongs to.
62-
* `resource_id` - Domain name ID.
6364
* `service_type` - Service type of acceleration domain name.
6465
* `status` - Acceleration service status.
6566
* `tags` - Tags of cdn domain.

0 commit comments

Comments
 (0)