Skip to content

Commit

Permalink
SSLCertificatesService: Improves the invoking cas api method and supp…
Browse files Browse the repository at this point in the history
…orts refreshing credential automatically
  • Loading branch information
xiaozhu36 committed Oct 21, 2024
1 parent 3f51e60 commit fd73611
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 47 deletions.
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 @@ -173,17 +172,11 @@ func dataSourceAliCloudSslCertificatesServiceCertificatesRead(d *schema.Resource
}

var response map[string]interface{}
conn, err := client.NewCasClient()
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("2020-04-07"), StringPointer("AK"), nil, request, &runtime)
response, err = client.RpcPost("cas", "2020-04-07", action, nil, request, true)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down
22 changes: 4 additions & 18 deletions alicloud/resource_alicloud_ssl_certificates_service_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"log"
"time"

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 @@ -56,13 +55,9 @@ func resourceAliCloudSslCertificatesServiceCertificate() *schema.Resource {
func resourceAliCloudSslCertificatesServiceCertificateCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*connectivity.AliyunClient)
var response map[string]interface{}
var err error
action := "CreateUserCertificate"
request := make(map[string]interface{})
conn, err := client.NewCasClient()
if err != nil {
return WrapError(err)
}

request["Cert"] = d.Get("cert")
request["Key"] = d.Get("key")

Expand All @@ -78,11 +73,9 @@ func resourceAliCloudSslCertificatesServiceCertificateCreate(d *schema.ResourceD
request["Lang"] = v
}

runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutCreate)), func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-07-13"), StringPointer("AK"), nil, request, &runtime)
response, err = client.RpcPost("cas", "2018-07-13", action, nil, request, false)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down Expand Up @@ -135,12 +128,7 @@ func resourceAliCloudSslCertificatesServiceCertificateDelete(d *schema.ResourceD
casService := CasService{client}
action := "DeleteUserCertificate"
var response map[string]interface{}

conn, err := client.NewCasClient()
if err != nil {
return WrapError(err)
}

var err error
request := map[string]interface{}{
"CertId": d.Id(),
}
Expand All @@ -149,11 +137,9 @@ func resourceAliCloudSslCertificatesServiceCertificateDelete(d *schema.ResourceD
request["Lang"] = v
}

runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutDelete)), func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-07-13"), StringPointer("AK"), nil, request, &runtime)
response, err = client.RpcPost("cas", "2018-07-13", 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 @@ -8,8 +8,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/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
Expand Down Expand Up @@ -39,16 +37,10 @@ func testSweepSslCertificatesServiceCertificate(region string) error {
request["CurrentPage"] = 1
ids := make([]string, 0)
var response map[string]interface{}
conn, err := client.NewCasClient()
if err != nil {
return WrapError(err)
}
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("2018-07-13"), StringPointer("AK"), nil, request, &runtime)
response, err = client.RpcPost("cas", "2018-07-13", action, nil, request, true)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down Expand Up @@ -97,7 +89,7 @@ func testSweepSslCertificatesServiceCertificate(region string) error {
}
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(1*time.Minute, func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-07-13"), StringPointer("AK"), nil, request, &util.RuntimeOptions{})
response, err = client.RpcPost("cas", "2018-07-13", action, nil, request, false)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down
12 changes: 2 additions & 10 deletions alicloud/service_alicloud_cas.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"

"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"
)
Expand All @@ -17,24 +16,17 @@ type CasService struct {
}

func (s *CasService) DescribeSslCertificatesServiceCertificate(id string) (object map[string]interface{}, err error) {
client := s.client
var response map[string]interface{}
action := "DescribeUserCertificateDetail"

conn, err := s.client.NewCasClient()
if err != nil {
return nil, WrapError(err)
}

request := map[string]interface{}{
"RegionId": s.client.RegionId,
"CertId": id,
}

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("2018-07-13"), StringPointer("AK"), nil, request, &runtime)
response, err = client.RpcPost("cas", "2018-07-13", action, nil, request, true)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down

0 comments on commit fd73611

Please sign in to comment.