Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ga: Improves the invoking ga api method and supports refreshing credential automatically #7757

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
252 changes: 120 additions & 132 deletions alicloud/connectivity/client.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions alicloud/connectivity/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Config struct {
SecurityToken string
OtsInstanceName string
AccountId string
AccountType string
Protocol string
ClientReadTimeout int
ClientConnectTimeout int
Expand Down
340 changes: 318 additions & 22 deletions alicloud/connectivity/endpoint.go

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions alicloud/connectivity/helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package connectivity

import "strings"

func ConvertKebabToSnake(s string) string {
return strings.ReplaceAll(s, "-", "_")
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"time"

"github.com/PaesslerAG/jsonpath"
util "github.com/alibabacloud-go/tea-utils/service"
"github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -86,15 +85,10 @@ func dataSourceAlicloudGaAcceleratorSpareIpAttachmentsRead(d *schema.ResourceDat
}
status, statusOk := d.GetOk("status")
var response map[string]interface{}
conn, err := client.NewGaplusClient()
if err != nil {
return WrapError(err)
}
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
var err error
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2019-11-20"), StringPointer("AK"), nil, request, &runtime)
response, err = client.RpcPost("Ga", "2019-11-20", action, nil, request, true)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down
10 changes: 2 additions & 8 deletions alicloud/data_source_alicloud_ga_accelerators.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"regexp"

"github.com/PaesslerAG/jsonpath"
util "github.com/alibabacloud-go/tea-utils/service"
"github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
Expand Down Expand Up @@ -175,14 +174,9 @@ func dataSourceAlicloudGaAcceleratorsRead(d *schema.ResourceData, meta interface
status, statusOk := d.GetOk("status")
bandwidthBillingType, BandwidthBillingTypeOk := d.GetOk("bandwidth_billing_type")
var response map[string]interface{}
conn, err := client.NewGaplusClient()
if err != nil {
return WrapError(err)
}
var err error
for {
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2019-11-20"), StringPointer("AK"), nil, request, &runtime)
response, err = client.RpcPost("Ga", "2019-11-20", action, nil, request, true)
if err != nil {
return WrapErrorf(err, DataDefaultErrorMsg, "alicloud_ga_accelerators", action, AlibabaCloudSdkGoERROR)
}
Expand Down
10 changes: 2 additions & 8 deletions alicloud/data_source_alicloud_ga_acls.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

"github.com/PaesslerAG/jsonpath"
util "github.com/alibabacloud-go/tea-utils/service"
"github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -134,16 +133,11 @@ func dataSourceAlicloudGaAclsRead(d *schema.ResourceData, meta interface{}) erro
}
status, statusOk := d.GetOk("status")
var response map[string]interface{}
conn, err := client.NewGaplusClient()
if err != nil {
return WrapError(err)
}
var err error
for {
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2019-11-20"), StringPointer("AK"), nil, request, &runtime)
response, err = client.RpcPost("Ga", "2019-11-20", action, nil, request, true)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down
10 changes: 2 additions & 8 deletions alicloud/data_source_alicloud_ga_additional_certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"time"

"github.com/PaesslerAG/jsonpath"
util "github.com/alibabacloud-go/tea-utils/service"
"github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -90,16 +89,11 @@ func dataSourceAlicloudGaAdditionalCertificatesRead(d *schema.ResourceData, meta
}
}
var response map[string]interface{}
conn, err := client.NewGaplusClient()
if err != nil {
return WrapError(err)
}
var err error
for {
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2019-11-20"), StringPointer("AK"), nil, request, &runtime)
response, err = client.RpcPost("Ga", "2019-11-20", action, nil, request, true)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down
10 changes: 2 additions & 8 deletions alicloud/data_source_alicloud_ga_bandwidth_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"regexp"

"github.com/PaesslerAG/jsonpath"
util "github.com/alibabacloud-go/tea-utils/service"
"github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
Expand Down Expand Up @@ -149,14 +148,9 @@ func dataSourceAlicloudGaBandwidthPackagesRead(d *schema.ResourceData, meta inte
}
status, statusOk := d.GetOk("status")
var response map[string]interface{}
conn, err := client.NewGaplusClient()
if err != nil {
return WrapError(err)
}
var err error
for {
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2019-11-20"), StringPointer("AK"), nil, request, &runtime)
response, err = client.RpcPost("Ga", "2019-11-20", action, nil, request, true)
if err != nil {
return WrapErrorf(err, DataDefaultErrorMsg, "alicloud_ga_bandwidth_packages", action, AlibabaCloudSdkGoERROR)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"time"

"github.com/PaesslerAG/jsonpath"
util "github.com/alibabacloud-go/tea-utils/service"
"github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -139,17 +138,12 @@ func dataSourceAlicloudGaBasicAccelerateIpEndpointRelationsRead(d *schema.Resour
}

var response map[string]interface{}
conn, err := client.NewGaplusClient()
if err != nil {
return WrapError(err)
}
var err error

for {
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2019-11-20"), StringPointer("AK"), nil, request, &runtime)
response, err = client.RpcPost("Ga", "2019-11-20", action, nil, request, true)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down
10 changes: 2 additions & 8 deletions alicloud/data_source_alicloud_ga_basic_accelerate_ips.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"time"

"github.com/PaesslerAG/jsonpath"
util "github.com/alibabacloud-go/tea-utils/service"
"github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -115,17 +114,12 @@ func dataSourceAlicloudGaBasicAccelerateIpsRead(d *schema.ResourceData, meta int
}

var response map[string]interface{}
conn, err := client.NewGaplusClient()
if err != nil {
return WrapError(err)
}
var err error

for {
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2019-11-20"), StringPointer("AK"), nil, request, &runtime)
response, err = client.RpcPost("Ga", "2019-11-20", action, nil, request, true)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down
10 changes: 2 additions & 8 deletions alicloud/data_source_alicloud_ga_basic_accelerators.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

"github.com/PaesslerAG/jsonpath"
util "github.com/alibabacloud-go/tea-utils/service"
"github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -192,16 +191,11 @@ func dataSourceAlicloudGaBasicAcceleratorsRead(d *schema.ResourceData, meta inte
}

var response map[string]interface{}
conn, err := client.NewGaplusClient()
if err != nil {
return WrapError(err)
}
var err error
for {
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2019-11-20"), StringPointer("AK"), nil, request, &runtime)
response, err = client.RpcPost("Ga", "2019-11-20", action, nil, request, true)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down
10 changes: 2 additions & 8 deletions alicloud/data_source_alicloud_ga_basic_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

"github.com/PaesslerAG/jsonpath"
util "github.com/alibabacloud-go/tea-utils/service"
"github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -166,17 +165,12 @@ func dataSourceAlicloudGaBasicEndpointsRead(d *schema.ResourceData, meta interfa
}

var response map[string]interface{}
conn, err := client.NewGaplusClient()
if err != nil {
return WrapError(err)
}
var err error

for {
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2019-11-20"), StringPointer("AK"), nil, request, &runtime)
response, err = client.RpcPost("Ga", "2019-11-20", action, nil, request, true)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"

"github.com/PaesslerAG/jsonpath"
util "github.com/alibabacloud-go/tea-utils/service"
"github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -157,17 +156,12 @@ func dataSourceAlicloudGaCustomRoutingEndpointGroupDestinationsRead(d *schema.Re
}

var response map[string]interface{}
conn, err := client.NewGaplusClient()
if err != nil {
return WrapError(err)
}
var err error

for {
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2019-11-20"), StringPointer("AK"), nil, request, &runtime)
response, err = client.RpcPost("Ga", "2019-11-20", action, nil, request, true)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

"github.com/PaesslerAG/jsonpath"
util "github.com/alibabacloud-go/tea-utils/service"
"github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -163,17 +162,12 @@ func dataSourceAlicloudGaCustomRoutingEndpointGroupsRead(d *schema.ResourceData,
}

var response map[string]interface{}
conn, err := client.NewGaplusClient()
if err != nil {
return WrapError(err)
}
var err error

for {
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2019-11-20"), StringPointer("AK"), nil, request, &runtime)
response, err = client.RpcPost("Ga", "2019-11-20", action, nil, request, true)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"time"

"github.com/PaesslerAG/jsonpath"
util "github.com/alibabacloud-go/tea-utils/service"
"github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -153,17 +152,12 @@ func dataSourceAliCloudGaCustomRoutingEndpointTrafficPoliciesRead(d *schema.Reso
}

var response map[string]interface{}
conn, err := client.NewGaplusClient()
if err != nil {
return WrapError(err)
}
var err error

for {
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2019-11-20"), StringPointer("AK"), nil, request, &runtime)
response, err = client.RpcPost("Ga", "2019-11-20", action, nil, request, true)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down
10 changes: 2 additions & 8 deletions alicloud/data_source_alicloud_ga_custom_routing_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"time"

"github.com/PaesslerAG/jsonpath"
util "github.com/alibabacloud-go/tea-utils/service"
"github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -123,17 +122,12 @@ func dataSourceAlicloudGaCustomRoutingEndpointsRead(d *schema.ResourceData, meta
}

var response map[string]interface{}
conn, err := client.NewGaplusClient()
if err != nil {
return WrapError(err)
}
var err error

for {
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2019-11-20"), StringPointer("AK"), nil, request, &runtime)
response, err = client.RpcPost("Ga", "2019-11-20", action, nil, request, true)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down
10 changes: 2 additions & 8 deletions alicloud/data_source_alicloud_ga_custom_routing_port_mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"time"

"github.com/PaesslerAG/jsonpath"
util "github.com/alibabacloud-go/tea-utils/service"
"github.com/alibabacloud-go/tea/tea"
"github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity"
"github.com/hashicorp/terraform-plugin-sdk/helper/hashcode"
Expand Down Expand Up @@ -138,17 +137,12 @@ func dataSourceAlicloudGaCustomRoutingPortMappingsRead(d *schema.ResourceData, m
var objects []map[string]interface{}

var response map[string]interface{}
conn, err := client.NewGaplusClient()
if err != nil {
return WrapError(err)
}
var err error

for {
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2019-11-20"), StringPointer("AK"), nil, request, &runtime)
response, err = client.RpcPost("Ga", "2019-11-20", action, nil, request, true)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down
Loading
Loading