From d3bca819e218b20d6d4d035b107f34235d4c0ef8 Mon Sep 17 00:00:00 2001 From: "guimin.hgm" Date: Sat, 21 Dec 2024 00:18:21 +0800 Subject: [PATCH] SMS: Improves the invoking sms api method and supports refreshing credential automatically --- alicloud/resource_alicloud_sms_short_url.go | 15 ++++----------- alicloud/service_alicloud_dysmsapi.go | 10 ++-------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/alicloud/resource_alicloud_sms_short_url.go b/alicloud/resource_alicloud_sms_short_url.go index 1d2ac706e7af..748c0e7ecbc3 100644 --- a/alicloud/resource_alicloud_sms_short_url.go +++ b/alicloud/resource_alicloud_sms_short_url.go @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/validation" - 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" @@ -53,18 +52,15 @@ func resourceAlicloudSmsShortUrl() *schema.Resource { func resourceAlicloudSmsShortUrlCreate(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) var response map[string]interface{} + var err error action := "AddShortUrl" request := make(map[string]interface{}) - conn, err := client.NewDysmsClient() - if err != nil { - return WrapError(err) - } request["EffectiveDays"] = d.Get("effective_days") request["ShortUrlName"] = d.Get("short_url_name") request["SourceUrl"] = d.Get("source_url") wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2017-05-25"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("Dysmsapi", "2017-05-25", action, nil, request, false) if err != nil { if IsExpectedErrors(err, []string{"undefined"}) || NeedRetry(err) { wait() @@ -109,16 +105,13 @@ func resourceAlicloudSmsShortUrlRead(d *schema.ResourceData, meta interface{}) e func resourceAlicloudSmsShortUrlDelete(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) var response map[string]interface{} + var err error action := "DeleteShortUrl" request := make(map[string]interface{}) - conn, err := client.NewDysmsClient() - if err != nil { - return WrapError(err) - } request["SourceUrl"] = d.Id() wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2017-05-25"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("Dysmsapi", "2017-05-25", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() diff --git a/alicloud/service_alicloud_dysmsapi.go b/alicloud/service_alicloud_dysmsapi.go index 1562de6020e5..1772530b2e77 100644 --- a/alicloud/service_alicloud_dysmsapi.go +++ b/alicloud/service_alicloud_dysmsapi.go @@ -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" ) @@ -15,20 +14,15 @@ type DysmsapiService struct { } func (s *DysmsapiService) DescribeSmsShortUrl(id string) (object map[string]interface{}, err error) { + client := s.client var response map[string]interface{} - conn, err := s.client.NewDysmsClient() - if err != nil { - return nil, WrapError(err) - } action := "QueryShortUrl" request := map[string]interface{}{ "ShortUrl": 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("2017-05-25"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("Dysmsapi", "2017-05-25", action, nil, request, true) if err != nil { if NeedRetry(err) { wait()