Skip to content

Commit

Permalink
data-source/alicloud_bss_open_api_products: Improves the invkoing api…
Browse files Browse the repository at this point in the history
… method; data-source/alicloud_bss_open_api_pricing_modules: Improves the invkoing api method
  • Loading branch information
xiaozhu36 committed Jan 25, 2025
1 parent fd037b5 commit 246c4b5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 45 deletions.
27 changes: 0 additions & 27 deletions alicloud/connectivity/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2393,33 +2393,6 @@ func (client *AliyunClient) NewWafClient() (*rpc.Client, error) {
return conn, nil
}

func (client *AliyunClient) NewBssopenapiClient() (*rpc.Client, error) {
productCode := "bssopenapi"
endpoint := ""
// bss endpoint depends on the account type.
// Domestic account is business.aliyuncs.com and International account is business.ap-southeast-1.aliyuncs.com
if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" {
if err := client.loadEndpoint(productCode); err != nil {
endpoint = BssOpenAPIEndpointDomestic
client.config.Endpoints.Store(productCode, endpoint)
log.Printf("[ERROR] loading %s endpoint got an error: %#v. Using the central 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
}

func (client *AliyunClient) NewFnfClient() (*rpc.Client, error) {
productCode := "fnf"
endpoint := ""
Expand Down
17 changes: 5 additions & 12 deletions alicloud/data_source_alicloud_bss_open_api_pricing_modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,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"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -155,31 +154,25 @@ func dataSourceAlicloudBssOpenApiPricingModulesRead(d *schema.ResourceData, meta
pricingModuleNameRegex = r
}

conn, err := client.NewBssopenapiClient()
if err != nil {
return WrapError(err)
}
var objects []interface{}
var response map[string]interface{}
var endpoint string
var err error
action := "DescribePricingModule"
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
resp, err := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2017-12-14"), StringPointer("AK"), nil, request, &runtime)
response, err = client.RpcPostWithEndpoint("BssOpenApi", "2017-12-14", action, nil, request, true, endpoint)
if err != nil {
if NeedRetry(err) {
wait()
return resource.RetryableError(err)
}
if IsExpectedErrors(err, []string{"NotApplicable"}) {
conn.Endpoint = String(connectivity.BssOpenAPIEndpointInternational)
request["ProductType"] = ""
if !client.IsInternationalAccount() && IsExpectedErrors(err, []string{"NotApplicable"}) {
endpoint = connectivity.BssOpenAPIEndpointInternational
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
response = resp
addDebug(action, response, request)
return nil
})
Expand Down
13 changes: 7 additions & 6 deletions alicloud/data_source_alicloud_bss_open_api_products.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,28 +100,29 @@ func dataSourceAlicloudBssOpenApiProductsRead(d *schema.ResourceData, meta inter
productNameRegex = r
}

conn, err := client.NewBssopenapiClient()
if err != nil {
return WrapError(err)
}
var objects []interface{}
var response map[string]interface{}
var endpoint string
var err error

for {
action := "QueryProductList"
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
resp, err := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2017-12-14"), StringPointer("AK"), nil, request, &runtime)
response, err = client.RpcPostWithEndpoint("BssOpenApi", "2017-12-14", action, nil, request, true, endpoint)
if err != nil {
if NeedRetry(err) {
wait()
return resource.RetryableError(err)
}
if !client.IsInternationalAccount() && IsExpectedErrors(err, []string{"NotApplicable"}) {
endpoint = connectivity.BssOpenAPIEndpointInternational
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
response = resp
addDebug(action, response, request)
return nil
})
Expand Down

0 comments on commit 246c4b5

Please sign in to comment.