From efb72a430c070e2308aa19704d872620003f76a4 Mon Sep 17 00:00:00 2001 From: "guimin.hgm" Date: Thu, 14 Nov 2024 16:29:03 +0800 Subject: [PATCH] debug --- alicloud/connectivity/client.go | 100 ++++++++---------- ...data_source_alicloud_wafv3_domains_test.go | 3 +- alicloud/resource_alicloud_waf_domain_test.go | 5 +- website/docs/d/waf_domains.html.markdown | 7 +- 4 files changed, 49 insertions(+), 66 deletions(-) diff --git a/alicloud/connectivity/client.go b/alicloud/connectivity/client.go index 08d69163733..dbbb1052086 100644 --- a/alicloud/connectivity/client.go +++ b/alicloud/connectivity/client.go @@ -182,7 +182,7 @@ var loadSdkfromRemoteMutex = sync.Mutex{} var loadSdkEndpointMutex = sync.Mutex{} // The main version number that is being run at the moment. -var providerVersion = "1.233.1" +var providerVersion = "1.234.0" // Temporarily maintain map for old ecs client methods and store special endpoint information var EndpointMap = map[string]string{ @@ -5669,65 +5669,29 @@ func (client *AliyunClient) NewPaiworkspaceClient() (*roa.Client, error) { } return conn, nil } - -type ossCredentials struct { - client *AliyunClient -} - -func (defCre *ossCredentials) GetAccessKeyID() string { - value, err := defCre.client.teaSdkConfig.Credential.GetAccessKeyId() - if err == nil && value != nil { - return *value - } - return defCre.client.config.AccessKey -} - -func (defCre *ossCredentials) GetAccessKeySecret() string { - value, err := defCre.client.teaSdkConfig.Credential.GetAccessKeySecret() - if err == nil && value != nil { - return *value +func (client *AliyunClient) NewVpcipamClient() (*rpc.Client, error) { + productCode := "vpcipam" + endpoint := "" + if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { + if err := client.loadEndpoint(productCode); err != nil { + endpoint = fmt.Sprintf("vpcipam.%s.aliyuncs.com", client.config.RegionId) + client.config.Endpoints.Store(productCode, endpoint) + log.Printf("[ERROR] loading %s endpoint got an error: %#v. Using the endpoint %s instead.", productCode, err, endpoint) + } } - return defCre.client.config.SecretKey -} - -func (defCre *ossCredentials) GetSecurityToken() string { - value, err := defCre.client.teaSdkConfig.Credential.GetSecurityToken() - if err == nil && value != nil { - return *value + if v, ok := client.config.Endpoints.Load(productCode); ok && v.(string) != "" { + endpoint = v.(string) } - return defCre.client.config.SecurityToken -} - -type ossCredentialsProvider struct { - client *AliyunClient -} - -func (defBuild *ossCredentialsProvider) GetCredentials() oss.Credentials { - return &ossCredentials{client: defBuild.client} -} - -func (client *AliyunClient) GetRetryTimeout(defaultTimeout time.Duration) time.Duration { - - maxRetryTimeout := client.config.MaxRetryTimeout - if maxRetryTimeout != 0 { - return time.Duration(maxRetryTimeout) * time.Second + if endpoint == "" { + return nil, fmt.Errorf("[ERROR] missing the product %s endpoint.", productCode) } - - return defaultTimeout -} - -func (client *AliyunClient) GenRoaParam(action, method, version, path string) *openapi.Params { - return &openapi.Params{ - Action: tea.String(action), - Version: tea.String(version), - Protocol: tea.String(client.config.Protocol), - Pathname: tea.String(path), - Method: tea.String(method), - AuthType: tea.String("AK"), - Style: tea.String("ROA"), - ReqBodyType: tea.String("formData"), - BodyType: tea.String("json"), + sdkConfig := client.teaSdkConfig + sdkConfig.SetEndpoint(endpoint) + conn, err := rpc.NewClient(&sdkConfig) + if err != nil { + return nil, fmt.Errorf("unable to initialize the %s client: %#v", productCode, err) } + return conn, nil } func (client *AliyunClient) NewGwlbClient() (*rpc.Client, error) { productCode := "gwlb" @@ -5753,6 +5717,30 @@ func (client *AliyunClient) NewGwlbClient() (*rpc.Client, error) { } return conn, nil } +func (client *AliyunClient) NewEsaClient() (*rpc.Client, error) { + productCode := "dcdnservices" + endpoint := "" + if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { + if err := client.loadEndpoint(productCode); err != nil { + endpoint = fmt.Sprintf("%s", client.config.RegionId) + 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) + } + if endpoint == "" { + return nil, fmt.Errorf("[ERROR] missing the product %s endpoint.", productCode) + } + sdkConfig := client.teaSdkConfig + sdkConfig.SetEndpoint(endpoint) + conn, err := rpc.NewClient(&sdkConfig) + if err != nil { + return nil, fmt.Errorf("unable to initialize the %s client: %#v", productCode, err) + } + return conn, nil +} type ossCredentials struct { client *AliyunClient diff --git a/alicloud/data_source_alicloud_wafv3_domains_test.go b/alicloud/data_source_alicloud_wafv3_domains_test.go index 0ae00563c3d..ba92e5ab486 100644 --- a/alicloud/data_source_alicloud_wafv3_domains_test.go +++ b/alicloud/data_source_alicloud_wafv3_domains_test.go @@ -2,7 +2,6 @@ package alicloud import ( "fmt" - "os" "strings" "testing" @@ -229,6 +228,6 @@ EOF enable_details = true %s } -`, rand, os.Getenv("ALICLOUD_REGION"), strings.Join(pairs, "\n ")) +`, rand, "cn-hangzhou", strings.Join(pairs, "\n ")) return config } diff --git a/alicloud/resource_alicloud_waf_domain_test.go b/alicloud/resource_alicloud_waf_domain_test.go index 59d5103334c..b7ffcb9feae 100644 --- a/alicloud/resource_alicloud_waf_domain_test.go +++ b/alicloud/resource_alicloud_waf_domain_test.go @@ -7,8 +7,6 @@ import ( "testing" "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" @@ -37,10 +35,9 @@ func testSweepWafDomains(region string) error { wafInstanceIds := make([]string, 0) domainIds := make([]string, 0) request := make(map[string]interface{}) - var err error action := "DescribeInstanceInfos" - response, err := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2019-09-10"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err := client.RpcPost("waf-openapi", "2019-09-10", action, nil, request, false) if err != nil { log.Printf("[ERROR] Failed to retrieve waf instance in service list: %s", err) } diff --git a/website/docs/d/waf_domains.html.markdown b/website/docs/d/waf_domains.html.markdown index ccb4050d605..b79412f038b 100644 --- a/website/docs/d/waf_domains.html.markdown +++ b/website/docs/d/waf_domains.html.markdown @@ -7,17 +7,17 @@ description: |- Provides a datasource to retrieve domain names. --- -# alicloud\_waf\_domains +# alicloud_waf_domains Provides a WAF datasource to retrieve domains. For information about WAF and how to use it, see [What is Alibaba Cloud WAF](https://www.alibabacloud.com/help/doc-detail/28517.htm). --> **NOTE:** Available in 1.86.0+ . +-> **NOTE:** Available since v1.86.0. ## Example Usage -``` +```terraform data "alicloud_waf_domains" "default" { instance_id = "waf-cf-xxxxx" } @@ -61,4 +61,3 @@ The following attributes are exported in addition to the arguments listed above: * `source_ips` - List of the IP address or domain of the origin server to which the specified domain points. * `version` - The system data identifier that is used to control optimistic locking. * `write_time` - The timeout period for a WAF exclusive cluster write connection. Unit: seconds. -```