Skip to content

Commit

Permalink
SMS: Improves the invoking sms api method and supports refreshing cre…
Browse files Browse the repository at this point in the history
…dential automatically
  • Loading branch information
xiaozhu36 committed Dec 20, 2024
1 parent 45ed17d commit d3bca81
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
15 changes: 4 additions & 11 deletions alicloud/resource_alicloud_sms_short_url.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/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"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 2 additions & 8 deletions alicloud/service_alicloud_dysmsapi.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"
)
Expand All @@ -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()
Expand Down

0 comments on commit d3bca81

Please sign in to comment.