Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redis: Improves the invoking redis api method and supports refreshing credential automatically #8020

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions alicloud/connectivity/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2285,27 +2285,14 @@ func (client *AliyunClient) WithDcdnClient(do func(*dcdn.Client) (interface{}, e
}

func (client *AliyunClient) WithRKvstoreClient(do func(*r_kvstore.Client) (interface{}, error)) (interface{}, error) {
productCode := "r_kvstore"
endpoint := ""
if client.r_kvstoreConn == nil {
if endpoint == "" {
endpoint = loadEndpoint(client.config.RegionId, RKvstoreCode)
}
if endpoint == "" {
if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" {
if err := client.loadEndpoint(productCode); err != nil {
endpoint = "r-kvstore.aliyuncs.com"
client.config.Endpoints.Store(productCode, endpoint)
log.Printf("[ERROR] loading %s endpoint got an error: %#v. Using the endpoint %s instead.", productCode, err, endpoint)
}
}
if v, ok := client.config.Endpoints.Load(productCode); ok && v.(string) != "" {
endpoint = v.(string)
productCode := "r_kvstore"
endpoint := ""
if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" {
if err := client.loadEndpoint(productCode); err != nil {
return nil, err
}
}
if strings.HasPrefix(endpoint, "http") {
endpoint = fmt.Sprintf("https://%s", strings.TrimPrefix(endpoint, "http://"))
}
if endpoint != "" {
endpoints.AddEndpointMapping(client.config.RegionId, "r-kvstore", endpoint)
}
Expand All @@ -2323,6 +2310,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
Loading