From fd73611c184c512dab04a03024ee20146b40d1e0 Mon Sep 17 00:00:00 2001 From: "guimin.hgm" Date: Sun, 20 Oct 2024 16:08:58 +0800 Subject: [PATCH] SSLCertificatesService: Improves the invoking cas api method and supports refreshing credential automatically --- ...d_ssl_certificates_service_certificates.go | 11 ++-------- ...ud_ssl_certificates_service_certificate.go | 22 ++++--------------- ...l_certificates_service_certificate_test.go | 12 ++-------- alicloud/service_alicloud_cas.go | 12 ++-------- 4 files changed, 10 insertions(+), 47 deletions(-) diff --git a/alicloud/data_source_alicloud_ssl_certificates_service_certificates.go b/alicloud/data_source_alicloud_ssl_certificates_service_certificates.go index 23a23a3f3d0d..e11e5d3cb716 100644 --- a/alicloud/data_source_alicloud_ssl_certificates_service_certificates.go +++ b/alicloud/data_source_alicloud_ssl_certificates_service_certificates.go @@ -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" @@ -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() diff --git a/alicloud/resource_alicloud_ssl_certificates_service_certificate.go b/alicloud/resource_alicloud_ssl_certificates_service_certificate.go index d436630ea523..d4a233857841 100644 --- a/alicloud/resource_alicloud_ssl_certificates_service_certificate.go +++ b/alicloud/resource_alicloud_ssl_certificates_service_certificate.go @@ -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" @@ -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") @@ -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() @@ -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(), } @@ -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() diff --git a/alicloud/resource_alicloud_ssl_certificates_service_certificate_test.go b/alicloud/resource_alicloud_ssl_certificates_service_certificate_test.go index 68034f9c2ed6..a4a55a2cb918 100644 --- a/alicloud/resource_alicloud_ssl_certificates_service_certificate_test.go +++ b/alicloud/resource_alicloud_ssl_certificates_service_certificate_test.go @@ -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" @@ -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() @@ -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() diff --git a/alicloud/service_alicloud_cas.go b/alicloud/service_alicloud_cas.go index c0ead32472c8..aadfcc9a52df 100644 --- a/alicloud/service_alicloud_cas.go +++ b/alicloud/service_alicloud_cas.go @@ -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" ) @@ -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()