Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaozhu36 committed Jan 24, 2025
1 parent ffbb41f commit edf6395
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 84 deletions.
20 changes: 9 additions & 11 deletions alicloud/data_source_alicloud_threat_detection_instances.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"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -89,6 +88,9 @@ func dataSourceAlicloudThreatDetectionInstancesRead(d *schema.ResourceData, meta
}
request["ProductCode"] = "sas"
request["ProductType"] = "sas"
if client.IsInternationalAccount() {
request["ProductType"] = ""
}
if v, ok := d.GetOk("renew_status"); ok {
request["RenewStatus"] = v
}
Expand All @@ -113,32 +115,28 @@ func dataSourceAlicloudThreatDetectionInstancesRead(d *schema.ResourceData, meta
}
}

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 := "QueryAvailableInstances"
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)
if !client.IsInternationalAccount() && IsExpectedErrors(err, []string{"NotApplicable"}) {
request["ProductType"] = ""
endpoint = connectivity.BssOpenAPIEndpointInternational
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
response = resp
addDebug(action, response, request)
return nil
})
Expand Down
4 changes: 2 additions & 2 deletions alicloud/resource_alicloud_threat_detection_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ func resourceAliCloudThreatDetectionInstanceUpdate(d *schema.ResourceData, meta
request["ProductType"] = ""
}
wait := incrementalWait(3*time.Second, 5*time.Second)
err := resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
err := resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
response, err := client.RpcPostWithEndpoint("BssOpenApi", "2017-12-14", action, query, request, true, endpoint)
if err != nil {
if NeedRetry(err) {
Expand Down Expand Up @@ -758,7 +758,7 @@ func resourceAliCloudThreatDetectionInstanceUpdate(d *schema.ResourceData, meta
request["ProductType"] = ""
}
wait := incrementalWait(3*time.Second, 5*time.Second)
err := resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
err := resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
response, err := client.RpcPostWithEndpoint("BssOpenApi", "2017-12-14", action, query, request, true, endpoint)
if err != nil {
if NeedRetry(err) {
Expand Down
4 changes: 4 additions & 0 deletions alicloud/resource_alicloud_threat_detection_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestAccAliCloudThreatDetectionInstance_basic1826(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccPreCheckWithAccountSiteType(t, IntlSite)
testAccPreCheckForCleanUpInstances(t, "", "sas", "sas", "sas", "")
},
IDRefreshName: resourceId,
Expand Down Expand Up @@ -161,6 +162,7 @@ func TestAccAliCloudThreatDetectionInstance_basic4253(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccPreCheckWithAccountSiteType(t, IntlSite)
testAccPreCheckForCleanUpInstances(t, "", "sas", "sas", "sas", "")
},
IDRefreshName: resourceId,
Expand Down Expand Up @@ -632,6 +634,7 @@ func TestAccAliCloudThreatDetectionInstance_basic4253_twin(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccPreCheckWithAccountSiteType(t, IntlSite)
testAccPreCheckForCleanUpInstances(t, "", "sas", "sas", "sas", "")
},
IDRefreshName: resourceId,
Expand Down Expand Up @@ -821,6 +824,7 @@ func TestAccAliCloudThreatDetectionInstance_basic4253_twin_fix(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccPreCheckWithAccountSiteType(t, IntlSite)
testAccPreCheckForCleanUpInstances(t, "", "sas", "sas", "sas", "")
},
IDRefreshName: resourceId,
Expand Down
38 changes: 15 additions & 23 deletions alicloud/service_alicloud_bss_open_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,28 +209,24 @@ func (s *BssOpenApiService) QueryAvailableInstance(id string) (object map[string
}

func (s *BssOpenApiService) DescribeCloudFirewallInstanceOrderDetail(orderId string) (object map[string]interface{}, err error) {
client := s.client
var response map[string]interface{}
conn, err := s.client.NewBssopenapiClient()
if err != nil {
return nil, WrapError(err)
}
var endpoint string
action := "GetOrderDetail"
request := map[string]interface{}{
"OrderId": orderId,
}

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-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)
if !client.IsInternationalAccount() && IsExpectedErrors(err, []string{"NotApplicable"}) {
endpoint = connectivity.BssOpenAPIEndpointInternational
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
Expand All @@ -243,10 +239,6 @@ func (s *BssOpenApiService) DescribeCloudFirewallInstanceOrderDetail(orderId str
return object, WrapErrorf(err, DefaultErrorMsg, orderId, action, AlibabaCloudSdkGoERROR)
}

if fmt.Sprint(response["Code"]) != "Success" {
return object, WrapError(fmt.Errorf("%s failed, response: %v", action, response))
}

v, err := jsonpath.Get("$.Data.OrderList.Order", response)
if err != nil {
return object, WrapErrorf(err, FailedGetAttributeMsg, orderId, "$.Data.OrderList.Order", response)
Expand Down Expand Up @@ -287,11 +279,9 @@ func (s *BssOpenApiService) CloudFirewallInstanceOrderDetailStateRefreshFunc(ord
}

func (s *BssOpenApiService) QueryAvailableInstanceList(instanceRegion, productCode, productType, productCodeIntl, productTypeIntl string) (object []interface{}, err error) {
client := s.client
var response map[string]interface{}
conn, err := s.client.NewBssopenapiClient()
if err != nil {
return nil, WrapError(err)
}
var endpoint string
action := "QueryAvailableInstances"
request := map[string]interface{}{
"ProductCode": productCode,
Expand All @@ -307,16 +297,21 @@ func (s *BssOpenApiService) QueryAvailableInstanceList(instanceRegion, productCo
if instanceRegion != "" {
request["Region"] = instanceRegion
}
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-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"}) {
request["ProductType"] = productTypeIntl
request["ProductCode"] = productCodeIntl
endpoint = connectivity.BssOpenAPIEndpointInternational
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
Expand All @@ -325,9 +320,6 @@ func (s *BssOpenApiService) QueryAvailableInstanceList(instanceRegion, productCo
if err != nil {
return object, WrapError(err)
}
if fmt.Sprint(response["Code"]) != "Success" {
return object, WrapError(fmt.Errorf("%s failed, response: %v", action, response))
}
v, err := jsonpath.Get("$.Data.InstanceList", response)
if err != nil {
return object, WrapError(err)
Expand Down
48 changes: 0 additions & 48 deletions alicloud/service_alicloud_threat_detection.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,51 +278,3 @@ func (s *ThreatDetectionService) DescribeThreatDetectionHoneypotPreset(id string
}
return v.(map[string]interface{}), nil
}

func (s *ThreatDetectionService) DescribeThreatDetectionInstance(id string) (object map[string]interface{}, err error) {
conn, err := s.client.NewBssopenapiClient()
if err != nil {
return object, WrapError(err)
}

request := map[string]interface{}{
"InstanceIDs": id,
"ProductCode": "sas",
"ProductType": "sas",
}

var response map[string]interface{}
action := "QueryAvailableInstances"
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)
if err != nil {
if NeedRetry(err) {
wait()
return resource.RetryableError(err)
}
if IsExpectedErrors(err, []string{"NotApplicable"}) {
conn.Endpoint = String(connectivity.BssOpenAPIEndpointInternational)
request["ProductType"] = ""
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
response = resp
addDebug(action, response, request)
return nil
})
if err != nil {
return object, WrapErrorf(err, DefaultErrorMsg, id, action, AlibabaCloudSdkGoERROR)
}
v, err := jsonpath.Get("$.Data.InstanceList", response)
if err != nil {
return object, WrapErrorf(err, FailedGetAttributeMsg, id, "$.Data.InstanceList", response)
}
if len(v.([]interface{})) < 1 {
return object, WrapErrorf(Error(GetNotFoundMessage("Instance", id)), NotFoundWithResponse, response)
}
return v.([]interface{})[0].(map[string]interface{}), nil
}

0 comments on commit edf6395

Please sign in to comment.