Skip to content

Commit

Permalink
Redis: Improves the invoking redis api method and supports refreshing…
Browse files Browse the repository at this point in the history
… credential automatically
  • Loading branch information
xiaozhu36 committed Dec 25, 2024
1 parent 0ed2303 commit 1516195
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 441 deletions.
5 changes: 5 additions & 0 deletions alicloud/connectivity/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2322,6 +2322,11 @@ func (client *AliyunClient) WithRKvstoreClient(do func(*r_kvstore.Client) (inter
r_kvstoreConn.AppendUserAgent(Module, client.config.ConfigurationSource)
r_kvstoreConn.AppendUserAgent(TerraformTraceId, client.config.TerraformTraceId)
client.r_kvstoreConn = r_kvstoreConn
} else {
err := client.r_kvstoreConn.InitWithOptions(client.config.RegionId, client.getSdkConfig(), client.config.getAuthCredential(true))
if err != nil {
return nil, fmt.Errorf("unable to initialize the Redis client: %#v", err)
}
}
return do(client.r_kvstoreConn)
}
Expand Down
11 changes: 2 additions & 9 deletions alicloud/data_source_alicloud_kvstore_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"time"

"github.com/PaesslerAG/jsonpath"
util "github.com/alibabacloud-go/tea-utils/service"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"

"github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity"
Expand Down Expand Up @@ -437,17 +436,11 @@ func dataSourceAlicloudKvstoreInstancesRead(d *schema.ResourceData, meta interfa
}

var response map[string]interface{}
conn, err := client.NewRedisaClient()
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("2015-01-01"), StringPointer("AK"), nil, request, &runtime)
response, err = client.RpcPost("R-kvstore", "2015-01-01", action, nil, request, true)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down
15 changes: 4 additions & 11 deletions alicloud/resource_alicloud_kvstore_audit_log_config.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 @@ -53,12 +52,9 @@ func resourceAlicloudKvstoreAuditLogConfig() *schema.Resource {
func resourceAlicloudKvstoreAuditLogConfigCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*connectivity.AliyunClient)
var response map[string]interface{}
var err error
action := "ModifyAuditLogConfig"
request := make(map[string]interface{})
conn, err := client.NewRedisaClient()
if err != nil {
return WrapError(err)
}
if v, ok := d.GetOkExists("db_audit"); ok {
request["DbAudit"] = v
}
Expand All @@ -70,7 +66,7 @@ func resourceAlicloudKvstoreAuditLogConfigCreate(d *schema.ResourceData, meta in
}
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, request, &util.RuntimeOptions{})
response, err = client.RpcPost("R-kvstore", "2015-01-01", action, nil, request, false)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down Expand Up @@ -123,11 +119,8 @@ func resourceAlicloudKvstoreAuditLogConfigRead(d *schema.ResourceData, meta inte
func resourceAlicloudKvstoreAuditLogConfigUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*connectivity.AliyunClient)
rKvstoreService := RKvstoreService{client}
conn, err := client.NewRedisaClient()
if err != nil {
return WrapError(err)
}
var response map[string]interface{}
var err error
update := false
request := map[string]interface{}{
"InstanceId": d.Id(),
Expand All @@ -150,7 +143,7 @@ func resourceAlicloudKvstoreAuditLogConfigUpdate(d *schema.ResourceData, meta in
action := "ModifyAuditLogConfig"
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2015-01-01"), StringPointer("AK"), nil, request, &util.RuntimeOptions{})
response, err = client.RpcPost("R-kvstore", "2015-01-01", action, nil, request, false)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down
Loading

0 comments on commit 1516195

Please sign in to comment.