diff --git a/alicloud/connectivity/client.go b/alicloud/connectivity/client.go index 4e027e09340e..a1d664e2f9a3 100644 --- a/alicloud/connectivity/client.go +++ b/alicloud/connectivity/client.go @@ -604,66 +604,6 @@ func (client *AliyunClient) WithEssClient(do func(*ess.Client) (interface{}, err return do(client.essconn) } -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 - } - return defCre.client.config.SecretKey -} - -func (defCre *ossCredentials) GetSecurityToken() string { - value, err := defCre.client.teaSdkConfig.Credential.GetSecurityToken() - if err == nil && value != nil { - return *value - } - 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 - } - - 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"), - } -} - func (client *AliyunClient) WithOssClient(do func(*oss.Client) (interface{}, error)) (interface{}, error) { goSdkMutex.Lock() defer goSdkMutex.Unlock() @@ -2258,7 +2198,7 @@ func (client *AliyunClient) WithDcdnClient(do func(*dcdn.Client) (interface{}, e } func (client *AliyunClient) WithRKvstoreClient(do func(*r_kvstore.Client) (interface{}, error)) (interface{}, error) { - productCode := "redisa" + productCode := "r_kvstore" endpoint := "" if client.r_kvstoreConn == nil { if endpoint == "" { @@ -2372,7 +2312,7 @@ func (client *AliyunClient) NewConfigClient() (*rpc.Client, error) { } func (client *AliyunClient) NewWafClient() (*rpc.Client, error) { - productCode := "waf" + productCode := "waf_openapi" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -2541,7 +2481,7 @@ func (client *AliyunClient) NewDcdnClient() (*rpc.Client, error) { } func (client *AliyunClient) NewOdpsClient() (*roa.Client, error) { - productCode := "odps" + productCode := "maxcompute" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -2564,7 +2504,7 @@ func (client *AliyunClient) NewOdpsClient() (*roa.Client, error) { } func (client *AliyunClient) NewRessharingClient() (*rpc.Client, error) { - productCode := "ressharing" + productCode := "resourcesharing" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -2587,7 +2527,7 @@ func (client *AliyunClient) NewRessharingClient() (*rpc.Client, error) { } func (client *AliyunClient) NewGaplusClient() (*rpc.Client, error) { - productCode := "gaplus" + productCode := "ga" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -2704,7 +2644,7 @@ func (client *AliyunClient) NewHitsdbClient() (*rpc.Client, error) { } func (client *AliyunClient) NewAistudioClient() (*rpc.Client, error) { - productCode := "aistudio" + productCode := "brain_industrial" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -2928,7 +2868,7 @@ func (client *AliyunClient) NewNasClient() (*rpc.Client, error) { } func (client *AliyunClient) NewDmsenterpriseClient() (*rpc.Client, error) { - productCode := "dmsenterprise" + productCode := "dms_enterprise" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -2953,7 +2893,7 @@ func (client *AliyunClient) NewDmsenterpriseClient() (*rpc.Client, error) { } func (client *AliyunClient) NewHcsSgwClient() (*rpc.Client, error) { - productCode := "hcs_sgw" + productCode := "sgw" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -3164,7 +3104,7 @@ func (client *AliyunClient) NewEventbridgeClient() (*rpc.Client, error) { } func (client *AliyunClient) NewOnsproxyClient() (*rpc.Client, error) { - productCode := "onsproxy" + productCode := "amqp" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -3187,7 +3127,7 @@ func (client *AliyunClient) NewOnsproxyClient() (*rpc.Client, error) { } func (client *AliyunClient) NewCdsClient() (*rpc.Client, error) { - productCode := "cds" + productCode := "cassandra" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -3315,7 +3255,7 @@ func (client *AliyunClient) NewCloudfwClient() (*rpc.Client, error) { } func (client *AliyunClient) NewServerlessClient() (*roa.Client, error) { - productCode := "serverless" + productCode := "sae" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -3363,7 +3303,7 @@ func (client *AliyunClient) NewAlbClient() (*rpc.Client, error) { } func (client *AliyunClient) NewRedisaClient() (*rpc.Client, error) { - productCode := "redisa" + productCode := "r_kvstore" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -3388,7 +3328,7 @@ func (client *AliyunClient) NewRedisaClient() (*rpc.Client, error) { } func (client *AliyunClient) NewGwsecdClient() (*rpc.Client, error) { - productCode := "gwsecd" + productCode := "ecd" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -3463,7 +3403,7 @@ func (client *AliyunClient) NewScdnClient() (*rpc.Client, error) { } func (client *AliyunClient) NewDataworkspublicClient() (*rpc.Client, error) { - productCode := "dataworkspublic" + productCode := "dataworks_public" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -3539,7 +3479,7 @@ func (client *AliyunClient) NewCddcClient() (*rpc.Client, error) { } func (client *AliyunClient) NewMscopensubscriptionClient() (*rpc.Client, error) { - productCode := "mscsub" + productCode := "mscopensubscription" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -3638,7 +3578,7 @@ func (client *AliyunClient) NewSasClient() (*rpc.Client, error) { } func (client *AliyunClient) NewAlidfsClient() (*rpc.Client, error) { - productCode := "alidfs" + productCode := "dfs" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -3888,7 +3828,7 @@ func (client *AliyunClient) NewCloudssoClient() (*rpc.Client, error) { } func (client *AliyunClient) NewSwasClient() (*rpc.Client, error) { - productCode := "swas" + productCode := "swas_open" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -3938,7 +3878,7 @@ func (client *AliyunClient) NewVsClient() (*rpc.Client, error) { } func (client *AliyunClient) NewQuickbiClient() (*rpc.Client, error) { - productCode := "quickbi" + productCode := "quickbi_public" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -3963,7 +3903,7 @@ func (client *AliyunClient) NewQuickbiClient() (*rpc.Client, error) { } func (client *AliyunClient) NewDevopsrdcClient() (*rpc.Client, error) { - productCode := "rdcdevops" + productCode := "devops_rdc" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -4038,7 +3978,7 @@ func (client *AliyunClient) NewOpensearchClient() (*roa.Client, error) { } func (client *AliyunClient) NewGdsClient() (*rpc.Client, error) { - productCode := "gds" + productCode := "gdb" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -4163,7 +4103,7 @@ func (client *AliyunClient) NewImpClient() (*rpc.Client, error) { } func (client *AliyunClient) NewMhubClient() (*rpc.Client, error) { - productCode := "emas" + productCode := "mhub" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -4210,7 +4150,7 @@ func (client *AliyunClient) NewServicemeshClient() (*rpc.Client, error) { } func (client *AliyunClient) NewAcrClient() (*rpc.Client, error) { - productCode := "acr" + productCode := "cr" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -4235,7 +4175,7 @@ func (client *AliyunClient) NewAcrClient() (*rpc.Client, error) { } func (client *AliyunClient) NewEdsuserClient() (*rpc.Client, error) { - productCode := "eds-user" + productCode := "eds_user" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -4367,7 +4307,7 @@ func (client *AliyunClient) NewEssClient() (*rpc.Client, error) { } func (client *AliyunClient) NewDdosbasicClient() (*rpc.Client, error) { - productCode := "ddosbasic" + productCode := "antiddos_public" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -4468,7 +4408,7 @@ func (client *AliyunClient) NewEdasClient() (*roa.Client, error) { } func (client *AliyunClient) NewEdasschedulerxClient() (*rpc.Client, error) { - productCode := "edasschedulerx" + productCode := "schedulerx2" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -4494,7 +4434,7 @@ func (client *AliyunClient) NewEdasschedulerxClient() (*rpc.Client, error) { } func (client *AliyunClient) NewEhsClient() (*rpc.Client, error) { - productCode := "ehs" + productCode := "ehpc" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -4519,7 +4459,7 @@ func (client *AliyunClient) NewEhsClient() (*rpc.Client, error) { } func (client *AliyunClient) NewDysmsClient() (*rpc.Client, error) { - productCode := "dysms" + productCode := "sms" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -4544,7 +4484,7 @@ func (client *AliyunClient) NewDysmsClient() (*rpc.Client, error) { } func (client *AliyunClient) NewFcClient() (*roa.Client, error) { - productCode := "fc" + productCode := "fc_open" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -4651,7 +4591,7 @@ func (client *AliyunClient) NewVpcpeerClient() (*rpc.Client, error) { } func (client *AliyunClient) NewCbsClient() (*rpc.Client, error) { - productCode := "cbs" + productCode := "dbs" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -4726,7 +4666,7 @@ func (client *AliyunClient) NewEbsClient() (*rpc.Client, error) { } func (client *AliyunClient) NewMnsClient() (*rpc.Client, error) { - productCode := "mns" + productCode := "mns_open" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -4803,7 +4743,7 @@ func (client *AliyunClient) NewDasClient() (*rpc.Client, error) { } func (client *AliyunClient) NewCloudfirewallClient() (*rpc.Client, error) { - productCode := "cloudfirewall" + productCode := "cloudfw" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -4855,7 +4795,7 @@ func (client *AliyunClient) NewThreatdetectionClient() (*rpc.Client, error) { } func (client *AliyunClient) NewSrvcatalogClient() (*rpc.Client, error) { - productCode := "srvcatalog" + productCode := "servicecatalog" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -4881,7 +4821,7 @@ func (client *AliyunClient) NewSrvcatalogClient() (*rpc.Client, error) { } func (client *AliyunClient) NewVpcPeerClient() (*rpc.Client, error) { - productCode := "VpcPeer" + productCode := "vpcpeer" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -4933,7 +4873,7 @@ func (client *AliyunClient) NewEfloClient() (*rpc.Client, error) { } func (client *AliyunClient) NewOceanbaseClient() (*rpc.Client, error) { - productCode := "oceanbase" + productCode := "oceanbasepro" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -4958,7 +4898,7 @@ func (client *AliyunClient) NewOceanbaseClient() (*rpc.Client, error) { } func (client *AliyunClient) NewBeebotClient() (*rpc.Client, error) { - productCode := "beebot" + productCode := "chatbot" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -5012,7 +4952,7 @@ func (client *AliyunClient) NewComputenestClient() (*rpc.Client, error) { return conn, nil } func (client *AliyunClient) NewRedisClient() (*rpc.Client, error) { - productCode := "redisa" + productCode := "r_kvstore" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -5193,7 +5133,7 @@ func (client *AliyunClient) NewSlsClient() (*openapi.Client, error) { return openapiClient, nil } func (client *AliyunClient) NewRocketmqClient() (*roa.Client, error) { - productCode := "rmq" + productCode := "rocketmq" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -5433,7 +5373,7 @@ func (client *AliyunClient) NewCloudmonitorserviceClient() (*rpc.Client, error) return conn, nil } func (client *AliyunClient) NewWafv3Client() (*rpc.Client, error) { - productCode := "waf" + productCode := "waf_openapi" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -5457,7 +5397,7 @@ func (client *AliyunClient) NewWafv3Client() (*rpc.Client, error) { return conn, nil } func (client *AliyunClient) NewDfsClient() (*rpc.Client, error) { - productCode := "alidfs" + productCode := "dfs" endpoint := "" if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { if err := client.loadEndpoint(productCode); err != nil { @@ -5480,30 +5420,7 @@ func (client *AliyunClient) NewDfsClient() (*rpc.Client, error) { } return conn, nil } -func (client *AliyunClient) NewAmqpClient() (*rpc.Client, error) { - productCode := "onsproxy" - endpoint := "" - if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { - if err := client.loadEndpoint(productCode); err != nil { - endpoint = fmt.Sprintf("amqp-open.%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) - } - } - 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) NewCenClient() (*rpc.Client, error) { productCode := "cbn" endpoint := "" @@ -5601,21 +5518,32 @@ func (client *AliyunClient) NewGovernanceClient() (*rpc.Client, error) { return conn, nil } -func (client *AliyunClient) loadApiEndpoint(locationCode string) (string, error) { - if v, ok := client.config.Endpoints.Load(locationCode); !ok || v.(string) == "" { - if err := client.loadEndpoint(locationCode); err != nil { - return "", fmt.Errorf("[ERROR] loading %s endpoint got an error: %#v.", locationCode, err) +func (client *AliyunClient) loadApiEndpoint(productCode string) (string, error) { + if v, ok := client.config.Endpoints.Load(productCode); !ok || v.(string) == "" { + if err := client.loadEndpoint(productCode); err != nil { + return "", fmt.Errorf("[ERROR] loading %s endpoint got an error: %#v.", productCode, err) } } else { return v.(string), nil } - if v, ok := client.config.Endpoints.Load(locationCode); ok && v.(string) != "" { + if v, ok := client.config.Endpoints.Load(productCode); ok && v.(string) != "" { return v.(string), nil } - return "", fmt.Errorf("[ERROR] missing the product %s endpoint.", locationCode) + return "", fmt.Errorf("[ERROR] missing the product %s endpoint.", productCode) } -func (client *AliyunClient) RpcPost(locationCode string, apiVersion string, apiName string, query map[string]interface{}, body map[string]interface{}, autoRetry bool) (map[string]interface{}, error) { - endpoint, err := client.loadApiEndpoint(locationCode) + +// RpcPost invoking RPC API request with POST method +// parameters: +// +// apiProductCode: API Product code, its value equals to the gateway code of the API +// apiVersion - API version +// apiName - API Name +// query - API parameters in query +// body - API parameters in body +// autoRetry - whether to auto retry while the runtime has a 5xx error +func (client *AliyunClient) RpcPost(apiProductCode string, apiVersion string, apiName string, query map[string]interface{}, body map[string]interface{}, autoRetry bool) (map[string]interface{}, error) { + apiProductCode = strings.ToLower(ConvertKebabToSnake(apiProductCode)) + endpoint, err := client.loadApiEndpoint(apiProductCode) if err != nil { return nil, err } @@ -5630,9 +5558,69 @@ func (client *AliyunClient) RpcPost(locationCode string, apiVersion string, apiN sdkConfig.SetSecurityToken(*credential.SecurityToken) conn, err := rpc.NewClient(&sdkConfig) if err != nil { - return nil, fmt.Errorf("unable to initialize the %s client: %#v", locationCode, err) + return nil, fmt.Errorf("unable to initialize the %s api client: %#v", apiProductCode, err) } runtime := &util.RuntimeOptions{} runtime.SetAutoretry(autoRetry) return conn.DoRequest(tea.String(apiName), nil, tea.String("POST"), tea.String(apiVersion), tea.String("AK"), query, body, runtime) } + +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 + } + return defCre.client.config.SecretKey +} + +func (defCre *ossCredentials) GetSecurityToken() string { + value, err := defCre.client.teaSdkConfig.Credential.GetSecurityToken() + if err == nil && value != nil { + return *value + } + 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 + } + + 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"), + } +} diff --git a/alicloud/connectivity/endpoint.go b/alicloud/connectivity/endpoint.go index cf815a3866f4..5d8f2c34dcca 100644 --- a/alicloud/connectivity/endpoint.go +++ b/alicloud/connectivity/endpoint.go @@ -4,6 +4,7 @@ import ( "encoding/xml" "fmt" "io/ioutil" + "log" "os" "regexp" "strings" @@ -165,26 +166,290 @@ func loadEndpoint(region string, serviceCode ServiceCode) string { return "" } -// regularProductCode specially records those product codes that -// cannot be parsed out by the location service or have been confirmed to be regional endpoints. +// productCodeToLocationCode records all products' code mapping to location +// Key: product code, its value equals to the gateway code of the API after converting it to lowercase and using underscores +// Value: location code +var productCodeToLocationCode = map[string]string{ + "ecs": "ecs", // ECS + "adb": "ads", //ADB + "ess": "ess", //AutoScaling + "cs": "cs", // ACK + "polardb": "polardb", // PolarDB + "cr": "acr", // CR + "dds": "dds", //MongoDB + "gpdb": "gpdb", //GPDB + "fc_open": "fc", // FC, FCV2 + "fc": "fc", // FCV3 + "apigateway": "apigateway", + "datahub": "datahub", // DataHub + "mns_open": "mns", // MessageService + "elasticsearch": "elasticsearch", // Elasticsearch + "ddoscoo": "ddoscoo", // DdosCoo + "ddosbgp": "ddosbgp", // DdosBgp + "antiddos_public": "ddosbasic", // DdosBasic + "bssopenapi": "bssopenapi", //BssOpenApi + "alikafka": "alikafka", //AliKafka + "emr": "emr", //EMR + "smartag": "smartag", // Smartag + "yundun_dbaudit": "dbaudit", //DBAudit + "yundun_bastionhost": "bastionhost", //Bastionhost + "hbase": "hbase", //HBase + "edas": "edas", // EDAS + "alidns": "alidns", //Alidns + "cassandra": "cds", //Cassandra + "eci": "eci", // ECI + "dcdn": "dcdn", // DCDN + "r_kvstore": "redisa", // Redis + "ons": "ons", //Ons + "config": "config", //Config + "fnf": "fnf", // FnF + "ros": "ros", // ROS + "mse": "mse", // MSE + "pvtz": "pvtz", //PrivateZone + "privatelink": "privatelink", // PrivateLink + "maxcompute": "odps", //MaxCompute + "resourcesharing": "ressharing", // ResourceManager + "ga": "gaplus", // Ga + "actiontrail": "actiontrail", //ActionTrail + "hitsdb": "hitsdb", //Lindorm + "brain_industrial": "aistudio", //BrainIndustrial + "eipanycast": "eipanycast", // Eipanycast + "oos": "oos", // OOS + "ims": "ims", //IMS + "resourcemanager": "resourcemanager", // ResourceManager + "nas": "nas", //NAS + "dms_enterprise": "dmsenterprise", //DMSEnterprise + "sgw": "hcs_sgw", // CloudStorageGateway + "slb": "slb", // SLB + "kms": "kms", //KMS + "dm": "dm", //DirectMail + "eventbridge": "eventbridge", // EventBridge + "hbr": "hbr", //HBR + "cas": "cas", //SSLCertificatesService + "arms": "arms", // ARMS + "cloudfw": "cloudfirewall", //CloudFirewall + "sae": "serverless", //SAE + "alb": "alb", // ALB + "ecd": "gwsecd", // ECD + "cloudphone": "cloudphone", // ECP + "scdn": "scdn", //SCDN + "dataworks_public": "dide", //DataWorks + "cdn": "cdn", // CDN + "cddc": "cddc", // CDDC + "mscopensubscription": "mscsub", //MscSub + "sddp": "sddp", // SDDP + "sas": "sas", // ThreatDetection + "ehpc": "ehs", // Ehpc + "ens": "ens", // ENS + "iot": "iot", // Iot + "imm": "imm", // IMM + "clickhouse": "clickhouse", // ClickHouse + "selectdb": "selectdb", //SelectDB + "dts": "dts", // DTS + "dg": "dg", // DatabaseGateway + "cloudsso": "cloudsso", // CloudSSO + "swas_open": "swas", // SimpleApplicationServer + "vs": "vs", // VideoSurveillanceSystem + "quickbi_public": "quickbi", // QuickBI + "devops_rdc": "rdcdevops", // RDC + "vod": "vod", // VOD + "opensearch": "opensearch", // OpenSearch + "gdb": "gds", // GraphDatabase + "dbfs": "dbfs", // DBFS + "eais": "eais", // EAIS + "cloudauth": "cloudauth", // Cloudauth + "imp": "imp", // IMP + "mhub": "emas", // MHUB + "servicemesh": "servicemesh", // ServiceMesh + "eds_user": "edsuser", // ECD + "tag": "tag", // Tag + "schedulerx2": "edasschedulerx", // Schedulerx + "sms": "dysms", // SMS + "vpcpeer": "vpcpeer", // VpcPeer + "dbs": "cbs", // DBS + "nlb": "nlb", // NLB + "ebs": "ebs", // EBS + "bpstudio": "bpstudio", // BPStudio + "das": "hdm", // DAS + "servicecatalog": "srvcatalog", // ServiceCatalog + "eflo": "eflo", //Eflo + "oceanbasepro": "oceanbase", // OceanBase + "chatbot": "beebot", // Chatbot + "computenest": "computenest", // ComputeNest + "drds": "drds", // DRDS + "polardbx": "polardbx", // DRDS + "adcp": "adcp", // AckOne + "sls": "sls", // SLS + "rocketmq": "rmq", // RocketMQ + "resourcecenter": "", // ResourceManager + "hologram": "hologram", // Hologram + "foasconsole": "foasconsole", // RealtimeCompute + "vpc": "vpc", // VPC, VPNGateway,ExpressConnect, CBWP, EIP + "sss": "oss", // OSS + "cms": "cms", // CloudMonitorService + "waf_openapi": "waf", //WAFV3,WAF + "dfs": "alidfs", //DFS + "amqp": "onsproxy", // Amqp + "cbn": "cbn", // CEN + "expressconnectrouter": "ecr", // ExpressConnectRouter + "green": "green", // Aligreen + "governance": "governance", // Governance + "ots": "ots", // OTS + "tablestore": "ots", // OTS + "ram": "ram", //RAM + "market": "market", //Market +} + +// irregularProductEndpoint specially records those product codes that +// cannot be parsed out by the location service. +// Key: product code, its value equals to the gateway code of the API after converting it to lowercase and using underscores +// Value: product endpoint +// The priority of this configuration is higher than location service, lower than user environment variable configuration +var irregularProductEndpoint = map[string]string{ + "tablestore": "tablestore.%s.aliyuncs.com", + "bssopenapi": BssOpenAPIEndpointDomestic, + "ram": "ram.aliyuncs.com", + "ddoscoo": "ddoscoo.cn-hangzhou.aliyuncs.com", + "dcdn": "dcdn.aliyuncs.com", + "config": "config.cn-shanghai.aliyuncs.com", + "ga": "ga.cn-hangzhou.aliyuncs.com", + "brain_industrial": "brain-industrial.cn-hangzhou.aliyuncs.com", + "eipanycast": "eipanycast.cn-hangzhou.aliyuncs.com", + "ims": "ims.aliyuncs.com", + "resourcemanager": "resourcemanager.aliyuncs.com", + "quotas": "quotas.aliyuncs.com", + "cassandra": "cassandra.aliyuncs.com", + "cas": "cas.aliyuncs.com", + "cloudfw": "cloudfw.aliyuncs.com", + "scdn": "scdn.aliyuncs.com", + "cdn": "cdn.aliyuncs.com", + "mscopensubscription": "mscopensubscription.aliyuncs.com", + "cloudauth": "cloudauth.aliyuncs.com", + "imp": "imp.aliyuncs.com", + "mhub": "mhub.cn-shanghai.aliyuncs.com", + "eds_user": "eds-user.cn-shanghai.aliyuncs.com", //eds-user.ap-southeast-1.aliyuncs.com + "vpcpeer": "vpcpeer.aliyuncs.com", + "das": "das.cn-shanghai.aliyuncs.com", + "servicecatalog": "servicecatalog.cn-hangzhou.aliyuncs.com", + "chatbot": "chatbot.cn-shanghai.aliyuncs.com", + "computenest": "computenest.cn-hangzhou.aliyuncs.com", + "resourcecenter": "resourcecenter.aliyuncs.com", //resourcecenter-intl.aliyuncs.com + "market": "market.aliyuncs.com", +} + +// irregularProductEndpointForIntl specially records those product codes that +// cannot be parsed out by the location service and for international region or account. +// Key: product code, its value equals to the gateway code of the API after converting it to lowercase and using underscores +// Value: product endpoint // The priority of this configuration is higher than location service, lower than user environment variable configuration -var regularProductCode = map[string]string{ - "mse": "mse.%s.aliyuncs.com", - "tablestore": "tablestore.%s.aliyuncs.com", - "bssopenapi": BssOpenAPIEndpointDomestic, +var irregularProductEndpointForIntl = map[string]string{ + "ddoscoo": "ddoscoo.ap-southeast-1.aliyuncs.com", + "dcdn": "dcdn.aliyuncs.com", + "config": "config.ap-southeast-1.aliyuncs.com", + "cas": "cas.ap-southeast-1.aliyuncs.com", + "cdn": "cdn.ap-southeast-1.aliyuncs.com", + "eds_user": "eds-user.ap-southeast-1.aliyuncs.com", + "computenest": "computenest.ap-southeast-1.aliyuncs.com", + "resourcecenter": "resourcecenter-intl.aliyuncs.com", +} + +// regularProductEndpoint specially records those product codes that have been confirmed to be +// regional or central endpoints. +// Key: product code, its value equals to the gateway code of the API after converting it to lowercase and using underscores +// Value: product endpoint +// The priority of this configuration is lower than location service, and as a backup endpoint +var regularProductEndpoint = map[string]string{ + "mse": "mse.%s.aliyuncs.com", + "vpc": "vpc.%s.aliyuncs.com", + "oss": "oss-%s.aliyuncs.com", + "cr": "cr.%s.aliyuncs.com", + "cms": "metrics.%s.aliyuncs.com", + "sls": "%s.log.aliyuncs.com", + "drds": "drds.%s.aliyuncs.com", + "polardbx": "polardbx.%s.aliyuncs.com", + "fc_open": "%s.fc.aliyuncs.com", + "fc": "%s.fc.aliyuncs.com", + "apigateway": "apigateway.%s.aliyuncs.com", + "mns_open": "mns-open.%s.aliyuncs.com", + "elasticsearch": "elasticsearch.%s.aliyuncs.com", + "alikafka": "alikafka.%s.aliyuncs.com", + "emr": "emr.%s.aliyuncs.com", + "smartag": "smartag.%s.aliyuncs.com", + "alidns": "alidns.%s.aliyuncs.com", + "eci": "eci.%s.aliyuncs.com", + "ons": "ons.%s.aliyuncs.com", + "ros": "ros.aliyuncs.com", + "pvtz": "pvtz.aliyuncs.com", + "privatelink": "privatelink.%s.aliyuncs.com", + "maxcompute": "maxcompute.%s.aliyuncs.com", + "resourcesharing": "resourcesharing.%s.aliyuncs.com", + "actiontrail": "actiontrail.%s.aliyuncs.com", + "hitsdb": "hitsdb.%s.aliyuncs.com", + "oos": "oos.%s.aliyuncs.com", + "nas": "nas.%s.aliyuncs.com", + "dms_enterprise": "dms-enterprise.%s.aliyuncs.com", + "kms": "kms.%s.aliyuncs.com", + "eventbridge": "eventbridge-console.%s.aliyuncs.com", + "hbr": "hbr.%s.aliyuncs.com", + "arms": "arms.%s.aliyuncs.com", + "sae": "sae.%s.aliyuncs.com", + "alb": "alb.%s.aliyuncs.com", + "ecd": "ecd.%s.aliyuncs.com", + "cloudphone": "cloudphone.%s.aliyuncs.com", + "dataworks_public": "dataworks.%s.aliyuncs.com", + "sas": "tds.aliyuncs.com", + "ehpc": "ehpc.%s.aliyuncs.com", + "ens": "ens.aliyuncs.com", + "iot": "iot.%s.aliyuncs.com", + "imm": "imm.%s.aliyuncs.com", + "swas_open": "swas.%s.aliyuncs.com", + "vs": "vs.%s.aliyuncs.com", + "vod": "vod.%s.aliyuncs.com", + "opensearch": "opensearch.%s.aliyuncs.com", + "dbfs": "dbfs.%s.aliyuncs.com", + "eais": "eais.%s.aliyuncs.com", + "servicemesh": "servicemesh.aliyuncs.com", + "tag": "tag.%s.aliyuncs.com", + "schedulerx2": "schedulerx.%s.aliyuncs.com", + "dbs": "dbs-api.%s.aliyuncs.com", + "nlb": "nlb.%s.aliyuncs.com", + "ebs": "ebs.%s.aliyuncs.com", + "eflo": "eflo.%s.aliyuncs.com", + "oceanbasepro": "oceanbasepro.%s.aliyuncs.com", + "adcp": "adcp.%s.aliyuncs.com", + "rocketmq": "rocketmq.%s.aliyuncs.com", + "hologram": "hologram.%s.aliyuncs.com", + "foasconsole": "foasconsole.aliyuncs.com", + "cs": "cs.%s.aliyuncs.com", + "waf_openapi": "wafopenapi.cn-hangzhou.aliyuncs.com", // wafopenapi.ap-southeast-1.aliyuncs.com + "dfs": "dfs.%s.aliyuncs.com", + "amqp": "amqp-open.%s.aliyuncs.com", + "cbn": "cbn.aliyuncs.com", + "expressconnectrouter": "expressconnectrouter.cn-shanghai.aliyuncs.com", + "green": "green.%s.aliyuncs.com", + "governance": "governance.cn-hangzhou.aliyuncs.com", // governance.ap-southeast-1.aliyuncs.com + "sms": "dysmsapi.aliyuncs.com", // dysmsapi.ap-southeast-1.aliyuncs.com + "sddp": "sddp.cn-zhangjiakou.aliyuncs.com", // sddp.ap-southeast-1.aliyuncs.com } // NOTE: The productCode must be lower. func (client *AliyunClient) loadEndpoint(productCode string) error { // Firstly, load endpoint from environment variables - endpoint := strings.TrimSpace(os.Getenv(fmt.Sprintf("%s_ENDPOINT", strings.ToUpper(productCode)))) + endpoint := strings.TrimSpace(os.Getenv(fmt.Sprintf("ALIBABA_CLOUD_ENDPOINT_%s", strings.ToUpper(productCode)))) + if endpoint == "" { + // Compatible with the previous implementation method + endpoint = strings.TrimSpace(os.Getenv(fmt.Sprintf("%s_ENDPOINT", strings.ToUpper(productCode)))) + } if endpoint != "" { client.config.Endpoints.Store(productCode, endpoint) return nil } // Secondly, load endpoint from known rules - if endpointFmt, ok := regularProductCode[productCode]; ok { + if endpointFmt, ok := irregularProductEndpoint[productCode]; ok { + if v, ok := irregularProductEndpointForIntl[productCode]; ok && !strings.HasPrefix(client.RegionId, "cn-") { + endpointFmt = v + } if strings.Contains(endpointFmt, "%s") { endpointFmt = fmt.Sprintf(endpointFmt, client.RegionId) } @@ -193,13 +458,16 @@ func (client *AliyunClient) loadEndpoint(productCode string) error { } // Thirdly, load endpoint from location - serviceCode := serviceCodeMapping[productCode] - if serviceCode == "" { - serviceCode = productCode - } - endpoint, err := client.describeEndpointForService(serviceCode) + endpoint, err := client.describeEndpointForService(productCode) if err == nil { - client.config.Endpoints.Store(strings.ToLower(serviceCode), endpoint) + client.config.Endpoints.Store(strings.ToLower(productCode), endpoint) + } else if v, ok := regularProductEndpoint[productCode]; ok { + if strings.Contains(v, "%s") { + v = fmt.Sprintf(v, client.RegionId) + } + client.config.Endpoints.Store(productCode, v) + log.Printf("[WARN] loading %s endpoint got an error: %#v. Using the endpoint %s instead.", productCode, err, v) + return nil } return err } @@ -242,9 +510,13 @@ func incrementalWait(firstDuration time.Duration, increaseDuration time.Duration retryCount++ } } -func (client *AliyunClient) describeEndpointForService(serviceCode string) (string, error) { +func (client *AliyunClient) describeEndpointForService(productCode string) (string, error) { + locationCode := productCodeToLocationCode[productCode] + if locationCode == "" { + locationCode = productCode + } args := location.CreateDescribeEndpointsRequest() - args.ServiceCode = serviceCode + args.ServiceCode = locationCode args.Id = client.config.RegionId args.Domain = client.config.LocationEndpoint if args.Domain == "" { @@ -288,18 +560,14 @@ func (client *AliyunClient) describeEndpointForService(serviceCode string) (stri return nil }) if err != nil { - return "", fmt.Errorf("Describe %s endpoint using region: %#v got an error: %#v.", serviceCode, client.RegionId, err) + return "", fmt.Errorf("Describe %s endpoint using region: %#v got an error: %#v.", productCode, client.RegionId, err) } if endpointResult == "" { - return "", fmt.Errorf("There is no any available endpoint for %s in region %s.", serviceCode, client.RegionId) + return "", fmt.Errorf("There is no any available endpoint for %s in region %s.", productCode, client.RegionId) } return endpointResult, nil } -var serviceCodeMapping = map[string]string{ - "cloudapi": "apigateway", -} - const ( OpenApiGatewayService = "apigateway.cn-hangzhou.aliyuncs.com" OpenOtsService = "ots.cn-hangzhou.aliyuncs.com" diff --git a/alicloud/connectivity/helper.go b/alicloud/connectivity/helper.go new file mode 100644 index 000000000000..ae627d33cb78 --- /dev/null +++ b/alicloud/connectivity/helper.go @@ -0,0 +1,7 @@ +package connectivity + +import "strings" + +func ConvertKebabToSnake(s string) string { + return strings.ReplaceAll(s, "-", "_") +} diff --git a/alicloud/data_source_alicloud_dcdn_domains.go b/alicloud/data_source_alicloud_dcdn_domains.go index 0dcc9753455b..9a17f7c5a2ef 100644 --- a/alicloud/data_source_alicloud_dcdn_domains.go +++ b/alicloud/data_source_alicloud_dcdn_domains.go @@ -5,7 +5,6 @@ import ( "regexp" "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/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" @@ -214,14 +213,9 @@ func dataSourceAlicloudDcdnDomainsRead(d *schema.ResourceData, meta interface{}) } } var response map[string]interface{} - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error for { - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { return WrapErrorf(err, DataDefaultErrorMsg, "alicloud_dcdn_domains", action, AlibabaCloudSdkGoERROR) } diff --git a/alicloud/data_source_alicloud_dcdn_domains_test.go b/alicloud/data_source_alicloud_dcdn_domains_test.go index be66a81f5c76..0746c721cfe0 100644 --- a/alicloud/data_source_alicloud_dcdn_domains_test.go +++ b/alicloud/data_source_alicloud_dcdn_domains_test.go @@ -110,6 +110,7 @@ resource "alicloud_dcdn_domain" "default" { port = "80" priority = "20" type = "ipaddr" + weight = 10 } resource_group_id = data.alicloud_resource_manager_resource_groups.default.ids.0 scope = "overseas" diff --git a/alicloud/data_source_alicloud_dcdn_ipa_domains.go b/alicloud/data_source_alicloud_dcdn_ipa_domains.go index 6e7af1e62e24..6a6fa7a7b87c 100644 --- a/alicloud/data_source_alicloud_dcdn_ipa_domains.go +++ b/alicloud/data_source_alicloud_dcdn_ipa_domains.go @@ -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" @@ -157,16 +156,11 @@ func dataSourceAlicloudDcdnIpaDomainsRead(d *schema.ResourceData, meta interface } } var response map[string]interface{} - conn, err := client.NewDcdnClient() - 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("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() diff --git a/alicloud/data_source_alicloud_dcdn_ipa_domains_test.go b/alicloud/data_source_alicloud_dcdn_ipa_domains_test.go index a48edea3accf..f3876d0713ba 100644 --- a/alicloud/data_source_alicloud_dcdn_ipa_domains_test.go +++ b/alicloud/data_source_alicloud_dcdn_ipa_domains_test.go @@ -64,7 +64,7 @@ func TestAccAlicloudDCDNIpaDomainsDataSource(t *testing.T) { "domains.0.description": "", "domains.0.id": CHECKSET, "domains.0.resource_group_id": CHECKSET, - "domains.0.scope": "domestic", + "domains.0.scope": "overseas", "domains.0.sources.#": "1", "domains.0.sources.0.content": "www.alicloud-provider.cn", "domains.0.sources.0.port": "8898", @@ -108,7 +108,7 @@ variable "domain_name" { resource "alicloud_dcdn_ipa_domain" "default" { domain_name = "${var.domain_name}" - scope = "domestic" + scope = "overseas" sources { content = "www.alicloud-provider.cn" port = 8898 diff --git a/alicloud/data_source_alicloud_dcdn_waf_domains.go b/alicloud/data_source_alicloud_dcdn_waf_domains.go index b4fcd2c251a7..c44450d7f98e 100644 --- a/alicloud/data_source_alicloud_dcdn_waf_domains.go +++ b/alicloud/data_source_alicloud_dcdn_waf_domains.go @@ -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" @@ -97,16 +96,11 @@ func dataSourceAlicloudDcdnWafDomainsRead(d *schema.ResourceData, meta interface } } var response map[string]interface{} - conn, err := client.NewDcdnClient() - 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("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() diff --git a/alicloud/data_source_alicloud_dcdn_waf_policies.go b/alicloud/data_source_alicloud_dcdn_waf_policies.go index 98cbd0e7bac2..574deb1970af 100644 --- a/alicloud/data_source_alicloud_dcdn_waf_policies.go +++ b/alicloud/data_source_alicloud_dcdn_waf_policies.go @@ -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" @@ -125,16 +124,11 @@ func dataSourceAlicloudDcdnWafPoliciesRead(d *schema.ResourceData, meta interfac } status, statusOk := d.GetOk("status") var response map[string]interface{} - conn, err := client.NewDcdnClient() - 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("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() diff --git a/alicloud/data_source_alicloud_dcdn_waf_rules.go b/alicloud/data_source_alicloud_dcdn_waf_rules.go index 56eb3798c289..c3ecde89ad1c 100644 --- a/alicloud/data_source_alicloud_dcdn_waf_rules.go +++ b/alicloud/data_source_alicloud_dcdn_waf_rules.go @@ -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" @@ -225,20 +224,15 @@ func dataSourceAlicloudDcdnWafRulesRead(d *schema.ResourceData, meta interface{} } } - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error var objects []interface{} var response map[string]interface{} for { action := "DescribeDcdnWafRules" - 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("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -246,7 +240,6 @@ func dataSourceAlicloudDcdnWafRulesRead(d *schema.ResourceData, meta interface{} } return resource.NonRetryableError(err) } - response = resp addDebug(action, response, request) return nil }) diff --git a/alicloud/provider.go b/alicloud/provider.go index 5911df07460a..eb75dbe63940 100644 --- a/alicloud/provider.go +++ b/alicloud/provider.go @@ -1908,6 +1908,12 @@ func providerConfigure(d *schema.ResourceData, p *schema.Provider) (interface{}, for _, endpointsSetI := range endpointsSet.List() { endpoints := endpointsSetI.(map[string]interface{}) for key, val := range endpoints { + // Compatible with the deprecated endpoint setting + if val == nil || val.(string) == "" { + if v, ok := deprecatedEndpointMap[key]; ok { + val = endpoints[v] + } + } endpointInit.Store(key, val) } config.EcsEndpoint = strings.TrimSpace(endpoints["ecs"].(string)) @@ -2559,6 +2565,12 @@ func endpointsSchema() *schema.Schema { Default: "", Description: descriptions["beebot_endpoint"], }, + "chatbot": { + Type: schema.TypeString, + Optional: true, + Default: "", + Description: descriptions["beebot_endpoint"], + }, "eflo": { Type: schema.TypeString, @@ -2573,7 +2585,12 @@ func endpointsSchema() *schema.Schema { Default: "", Description: descriptions["srvcatalog_endpoint"], }, - + "servicecatalog": { + Type: schema.TypeString, + Optional: true, + Default: "", + Description: descriptions["srvcatalog_endpoint"], + }, "cloudfirewall": { Type: schema.TypeString, Optional: true, @@ -2622,6 +2639,12 @@ func endpointsSchema() *schema.Schema { Default: "", Description: descriptions["cbs_endpoint"], }, + "dbs": { + Type: schema.TypeString, + Optional: true, + Default: "", + Description: descriptions["cbs_endpoint"], + }, "vpcpeer": { Type: schema.TypeString, @@ -2636,6 +2659,12 @@ func endpointsSchema() *schema.Schema { Default: "", Description: descriptions["dysms_endpoint"], }, + "sms": { + Type: schema.TypeString, + Optional: true, + Default: "", + Description: descriptions["dysms_endpoint"], + }, "edas": { Type: schema.TypeString, @@ -2650,7 +2679,12 @@ func endpointsSchema() *schema.Schema { Default: "", Description: descriptions["edasschedulerx_endpoint"], }, - + "schedulerx2": { + Type: schema.TypeString, + Optional: true, + Default: "", + Description: descriptions["edasschedulerx_endpoint"], + }, "ehs": { Type: schema.TypeString, Optional: true, @@ -2672,6 +2706,12 @@ func endpointsSchema() *schema.Schema { Description: descriptions["ddosbasic_endpoint"], }, + "antiddos_public": { + Type: schema.TypeString, + Optional: true, + Default: "", + Description: descriptions["ddosbasic_endpoint"], + }, "smartag": { Type: schema.TypeString, Optional: true, @@ -2685,6 +2725,12 @@ func endpointsSchema() *schema.Schema { Default: "", Description: descriptions["oceanbase_endpoint"], }, + "oceanbasepro": { + Type: schema.TypeString, + Optional: true, + Default: "", + Description: descriptions["oceanbase_endpoint"], + }, "gaplus": { Type: schema.TypeString, @@ -2706,6 +2752,12 @@ func endpointsSchema() *schema.Schema { Default: "", Description: descriptions["edsuser_endpoint"], }, + "eds_user": { + Type: schema.TypeString, + Optional: true, + Default: "", + Description: descriptions["edsuser_endpoint"], + }, "acr": { Type: schema.TypeString, @@ -2751,6 +2803,12 @@ func endpointsSchema() *schema.Schema { Default: "", Description: descriptions["quickbi_endpoint"], }, + "quickbi_public": { + Type: schema.TypeString, + Optional: true, + Default: "", + Description: descriptions["quickbi_endpoint"], + }, "vod": { Type: schema.TypeString, Optional: true, @@ -2769,6 +2827,12 @@ func endpointsSchema() *schema.Schema { Default: "", Description: descriptions["gds_endpoint"], }, + "gdb": { + Type: schema.TypeString, + Optional: true, + Default: "", + Description: descriptions["gds_endpoint"], + }, "dbfs": { Type: schema.TypeString, Optional: true, @@ -2824,6 +2888,12 @@ func endpointsSchema() *schema.Schema { Default: "", Description: descriptions["swas_endpoint"], }, + "swas_open": { + Type: schema.TypeString, + Optional: true, + Default: "", + Description: descriptions["swas_endpoint"], + }, "imm": { Type: schema.TypeString, @@ -2850,6 +2920,12 @@ func endpointsSchema() *schema.Schema { Default: "", Description: descriptions["alidfs_endpoint"], }, + "dfs": { + Type: schema.TypeString, + Optional: true, + Default: "", + Description: descriptions["alidfs_endpoint"], + }, "ens": { Type: schema.TypeString, @@ -2904,7 +2980,12 @@ func endpointsSchema() *schema.Schema { Default: "", Description: descriptions["dataworkspublic_endpoint"], }, - + "dataworks_public": { + Type: schema.TypeString, + Optional: true, + Default: "", + Description: descriptions["dataworkspublic_endpoint"], + }, "hcs_sgw": { Type: schema.TypeString, Optional: true, @@ -2937,6 +3018,12 @@ func endpointsSchema() *schema.Schema { Default: "", Description: descriptions["gwsecd_endpoint"], }, + "ecd": { + Type: schema.TypeString, + Optional: true, + Default: "", + Description: descriptions["gwsecd_endpoint"], + }, "scdn": { Type: schema.TypeString, Optional: true, @@ -2956,7 +3043,12 @@ func endpointsSchema() *schema.Schema { Default: "", Description: descriptions["serverless_endpoint"], }, - + "sae": { + Type: schema.TypeString, + Optional: true, + Default: "", + Description: descriptions["serverless_endpoint"], + }, "hbr": { Type: schema.TypeString, Optional: true, @@ -2964,6 +3056,13 @@ func endpointsSchema() *schema.Schema { Description: descriptions["hbr_endpoint"], }, + "amqp": { + Type: schema.TypeString, + Optional: true, + Default: "", + Description: descriptions["onsproxy_endpoint"], + }, + "onsproxy": { Type: schema.TypeString, Optional: true, @@ -3025,6 +3124,11 @@ func endpointsSchema() *schema.Schema { Default: "", Description: descriptions["resourcesharing_endpoint"], }, + "resourcesharing": { + Type: schema.TypeString, + Optional: true, + Default: "", + }, "ga": { Type: schema.TypeString, Optional: true, @@ -3277,6 +3381,12 @@ func endpointsSchema() *schema.Schema { Default: "", Description: descriptions["drds_endpoint"], }, + "polardbx": { + Type: schema.TypeString, + Optional: true, + Default: "", + Description: descriptions["drds_endpoint"], + }, "dds": { Type: schema.TypeString, Optional: true, @@ -3307,6 +3417,12 @@ func endpointsSchema() *schema.Schema { Default: "", Description: descriptions["fc_endpoint"], }, + "fc_open": { + Type: schema.TypeString, + Optional: true, + Default: "", + Description: descriptions["fc_endpoint"], + }, "apigateway": { Type: schema.TypeString, Optional: true, @@ -3319,12 +3435,28 @@ func endpointsSchema() *schema.Schema { Default: "", Description: descriptions["datahub_endpoint"], }, + "devops_rdc": { + Type: schema.TypeString, + Optional: true, + Default: "", + }, "mns": { Type: schema.TypeString, Optional: true, Default: "", Description: descriptions["mns_endpoint"], }, + "mns_open": { + Type: schema.TypeString, + Optional: true, + Default: "", + Description: descriptions["mns_endpoint"], + }, + "rocketmq": { + Type: schema.TypeString, + Optional: true, + Default: "", + }, "location": { Type: schema.TypeString, Optional: true, @@ -3539,6 +3671,38 @@ func endpointsToHash(v interface{}) int { return hashcode.String(buf.String()) } +// deprecatedEndpointMap is used to map old service name to new service name +// key: new endpoint key +// value: deprecated endpoint key +var deprecatedEndpointMap = map[string]string{ + "resourcesharing": "ressharing", + "ga": "gaplus", + "dms_enterprise": "dmsenterprise", + "sgw": "hcs_sgw", + "amqp": "onsproxy", + "cassandra": "cds", + "cloudfw": "cloudfirewall", + "sae": "serverless", + "r_kvstore": "redisa", + "ecd": "gwsecd", + "dataworks_public": "dataworkspublic", + "dfs": "alidfs", + "swas_open": "swas", + "quickbi_public": "quickbi", + "gdb": "gds", + "cr": "acr", + "eds_user": "edsuser", + "antiddos_public": "ddosbasic", + "schedulerx2": "edasschedulerx", + "ehpc": "ehs", + "sms": "dysms", + "dbs": "cbs", + "mns_open": "mns", + "servicecatalog": "srvcatalog", + "oceanbasepro": "oceanbase", + "chatbot": "beebot", +} + func getConfigFromProfile(d *schema.ResourceData, ProfileKey string) (interface{}, error) { if providerConfig == nil { diff --git a/alicloud/resource_alicloud_dcdn_domain.go b/alicloud/resource_alicloud_dcdn_domain.go index 4cfee2956f1a..f8c04d1e507f 100644 --- a/alicloud/resource_alicloud_dcdn_domain.go +++ b/alicloud/resource_alicloud_dcdn_domain.go @@ -9,7 +9,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" @@ -168,10 +167,7 @@ func resourceAliCloudDcdnDomainCreate(d *schema.ResourceData, meta interface{}) var request map[string]interface{} var response map[string]interface{} query := make(map[string]interface{}) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error request = make(map[string]interface{}) query["DomainName"] = d.Get("domain_name") @@ -219,11 +215,9 @@ func resourceAliCloudDcdnDomainCreate(d *schema.ResourceData, meta interface{}) request["Sources"] = string(sourcesMapsJson) } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, query, request, false) if err != nil { if IsExpectedErrors(err, []string{"ServiceBusy"}) || NeedRetry(err) { wait() @@ -360,10 +354,7 @@ func resourceAliCloudDcdnDomainUpdate(d *schema.ResourceData, meta interface{}) update := false d.Partial(true) action := "ModifyDCdnDomainSchdmByProperty" - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error request = make(map[string]interface{}) query = make(map[string]interface{}) query["DomainName"] = d.Id() @@ -374,11 +365,9 @@ func resourceAliCloudDcdnDomainUpdate(d *schema.ResourceData, meta interface{}) } if update { - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, query, request, false) if err != nil { if NeedRetry(err) { wait() @@ -400,10 +389,6 @@ func resourceAliCloudDcdnDomainUpdate(d *schema.ResourceData, meta interface{}) } update = false action = "UpdateDcdnDomain" - conn, err = client.NewDcdnClient() - if err != nil { - return WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) query["DomainName"] = d.Id() @@ -441,11 +426,9 @@ func resourceAliCloudDcdnDomainUpdate(d *schema.ResourceData, meta interface{}) request["TopLevelDomain"] = v } if update { - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, query, request, false) if err != nil { if NeedRetry(err) { wait() @@ -475,10 +458,6 @@ func resourceAliCloudDcdnDomainUpdate(d *schema.ResourceData, meta interface{}) update = false action = "SetDcdnDomainSSLCertificate" - conn, err = client.NewDcdnClient() - if err != nil { - return WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) query["DomainName"] = d.Id() @@ -522,11 +501,9 @@ func resourceAliCloudDcdnDomainUpdate(d *schema.ResourceData, meta interface{}) request["Env"] = v } if update { - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, query, request, false) if err != nil { if NeedRetry(err) { wait() @@ -559,19 +536,13 @@ func resourceAliCloudDcdnDomainUpdate(d *schema.ResourceData, meta interface{}) if object["DomainStatus"].(string) != target { if target == "online" { action = "StartDcdnDomain" - conn, err = client.NewDcdnClient() - if err != nil { - return WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) query["DomainName"] = d.Id() - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, query, request, false) if err != nil { if NeedRetry(err) { wait() @@ -594,19 +565,13 @@ func resourceAliCloudDcdnDomainUpdate(d *schema.ResourceData, meta interface{}) } if target == "offline" { action = "StopDcdnDomain" - conn, err = client.NewDcdnClient() - if err != nil { - return WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) query["DomainName"] = d.Id() - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, query, request, false) if err != nil { if NeedRetry(err) { wait() @@ -641,18 +606,13 @@ func resourceAliCloudDcdnDomainDelete(d *schema.ResourceData, meta interface{}) var request map[string]interface{} var response map[string]interface{} query := make(map[string]interface{}) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error request = make(map[string]interface{}) query["DomainName"] = d.Id() - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, query, request, false) if err != nil { if NeedRetry(err) { diff --git a/alicloud/resource_alicloud_dcdn_domain_config.go b/alicloud/resource_alicloud_dcdn_domain_config.go index 4bab62d6eb86..44923d45f1d0 100644 --- a/alicloud/resource_alicloud_dcdn_domain_config.go +++ b/alicloud/resource_alicloud_dcdn_domain_config.go @@ -7,7 +7,6 @@ import ( "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" @@ -73,10 +72,7 @@ func resourceAliCloudDcdnDomainConfigCreate(d *schema.ResourceData, meta interfa var response map[string]interface{} action := "BatchSetDcdnDomainConfigs" request := make(map[string]interface{}) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error request["DomainNames"] = d.Get("domain_name").(string) @@ -107,11 +103,9 @@ func resourceAliCloudDcdnDomainConfigCreate(d *schema.ResourceData, meta interfa request["Functions"] = string(bytConfig) - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) 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("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if IsExpectedErrors(err, []string{"FlowControlError"}) || NeedRetry(err) { wait() @@ -215,10 +209,6 @@ func resourceAliCloudDcdnDomainConfigUpdate(d *schema.ResourceData, meta interfa if d.HasChange("function_args") || d.HasChange("parent_id") { action := "BatchSetDcdnDomainConfigs" request := make(map[string]interface{}) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } parts, err := ParseResourceId(d.Id(), 3) if err != nil { @@ -252,12 +242,9 @@ func resourceAliCloudDcdnDomainConfigUpdate(d *schema.ResourceData, meta interfa bytconfig, _ := json.Marshal(config) request["Functions"] = string(bytconfig) - - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) 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("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if IsExpectedErrors(err, []string{"FlowControlError"}) || NeedRetry(err) { wait() @@ -288,10 +275,7 @@ func resourceAliCloudDcdnDomainConfigDelete(d *schema.ResourceData, meta interfa action := "DeleteDcdnSpecificConfig" var response map[string]interface{} - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error parts, err := ParseResourceId(d.Id(), 3) if err != nil { @@ -303,11 +287,9 @@ func resourceAliCloudDcdnDomainConfigDelete(d *schema.ResourceData, meta interfa "ConfigId": parts[2], } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() diff --git a/alicloud/resource_alicloud_dcdn_domain_test.go b/alicloud/resource_alicloud_dcdn_domain_test.go index e7601fb78666..3ade1637ad6e 100644 --- a/alicloud/resource_alicloud_dcdn_domain_test.go +++ b/alicloud/resource_alicloud_dcdn_domain_test.go @@ -2,11 +2,11 @@ package alicloud import ( "fmt" + "github.com/PaesslerAG/jsonpath" "log" "strings" "testing" - - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" + "time" "github.com/aliyun/alibaba-cloud-sdk-go/services/dcdn" "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" @@ -29,50 +29,63 @@ func testSweepDcdnDomain(region string) error { return WrapError(err) } client := rawClient.(*connectivity.AliyunClient) - queryRequest := dcdn.CreateDescribeDcdnUserDomainsRequest() - var allDomains []dcdn.PageData - queryRequest.PageSize = requests.NewInteger(PageSizeLarge) - queryRequest.PageNumber = requests.NewInteger(1) + + action := "DescribeDcdnUserDomains" + request := make(map[string]interface{}) + request["PageSize"] = PageSizeLarge + request["PageNumber"] = 1 + + var allDomains []string + var response map[string]interface{} for { - raw, err := client.WithDcdnClient(func(dcdnClient *dcdn.Client) (interface{}, error) { - return dcdnClient.DescribeDcdnUserDomains(queryRequest) - }) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { - log.Printf("[ERROR] %s get an error %#v", queryRequest.GetActionName(), err) + return WrapErrorf(err, DataDefaultErrorMsg, "alicloud_dcdn_domains", action, AlibabaCloudSdkGoERROR) } - addDebug(queryRequest.GetActionName(), raw) - response, _ := raw.(*dcdn.DescribeDcdnUserDomainsResponse) - domains := response.Domains.PageData + addDebug(action, response, request) - for _, domain := range domains { - if strings.HasPrefix(domain.DomainName, "tf-testacc") { - allDomains = append(allDomains, domain) + resp, err := jsonpath.Get("$.Domains.PageData", response) + if err != nil { + return WrapErrorf(err, FailedGetAttributeMsg, action, "$.Domains.PageData", response) + } + result, _ := resp.([]interface{}) + for _, v := range result { + item := v.(map[string]interface{}) + if strings.HasPrefix(item["DomainName"].(string), "tf-testacc") { + allDomains = append(allDomains, item["DomainName"].(string)) } else { - log.Printf("Skip %#v", domain) + log.Printf("Skip %#v", item["DomainName"].(string)) } } - - if len(domains) < PageSizeLarge { + if len(result) < PageSizeLarge { break } - if page, err := getNextpageNumber(queryRequest.PageNumber); err != nil { - return WrapError(err) - } else { - queryRequest.PageNumber = page - } + request["PageNumber"] = request["PageNumber"].(int) + 1 } - removeRequest := dcdn.CreateDeleteDcdnDomainRequest() - removeRequest.DomainName = "" + + action = "DeleteDcdnDomain" for _, domain := range allDomains { - removeRequest.DomainName = domain.DomainName - raw, err := client.WithDcdnClient(func(dcdnClient *dcdn.Client) (interface{}, error) { - return dcdnClient.DeleteDcdnDomain(removeRequest) + query := make(map[string]interface{}) + request = make(map[string]interface{}) + query["DomainName"] = domain + + wait := incrementalWait(3*time.Second, 5*time.Second) + err = resource.Retry(1*time.Minute, func() *resource.RetryError { + response, err = client.RpcPost("dcdn", "2018-01-15", action, query, request, false) + if err != nil { + if NeedRetry(err) { + wait() + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) + } + addDebug(action, response, request) + return nil }) if err != nil { - log.Printf("[ERROR] %s get an error %s", removeRequest.GetActionName(), err) + return WrapErrorf(err, DefaultErrorMsg, domain, action, AlibabaCloudSdkGoERROR) } - addDebug(removeRequest.GetActionName(), raw) } return nil diff --git a/alicloud/resource_alicloud_dcdn_er.go b/alicloud/resource_alicloud_dcdn_er.go index 9f6b56ff034c..e88139fe365a 100644 --- a/alicloud/resource_alicloud_dcdn_er.go +++ b/alicloud/resource_alicloud_dcdn_er.go @@ -5,7 +5,6 @@ import ( "fmt" "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" @@ -1017,10 +1016,7 @@ func resourceAliCloudDcdnErCreate(d *schema.ResourceData, meta interface{}) erro var response map[string]interface{} action := "CreateRoutine" request := make(map[string]interface{}) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error request["Name"] = d.Get("er_name") @@ -1893,11 +1889,9 @@ func resourceAliCloudDcdnErCreate(d *schema.ResourceData, meta interface{}) erro request["EnvConf"] = envConfJson } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutCreate)), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -2844,6 +2838,7 @@ func resourceAliCloudDcdnErRead(d *schema.ResourceData, meta interface{}) error func resourceAliCloudDcdnErUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) var response map[string]interface{} + var err error update := false request := map[string]interface{}{ @@ -3727,16 +3722,9 @@ func resourceAliCloudDcdnErUpdate(d *schema.ResourceData, meta interface{}) erro if update { action := "EditRoutineConf" - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } - - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutUpdate)), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -3761,20 +3749,15 @@ func resourceAliCloudDcdnErDelete(d *schema.ResourceData, meta interface{}) erro action := "DeleteRoutine" var response map[string]interface{} - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error request := map[string]interface{}{ "Name": d.Id(), } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutDelete)), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() diff --git a/alicloud/resource_alicloud_dcdn_ipa_domain.go b/alicloud/resource_alicloud_dcdn_ipa_domain.go index 03b6a432d6d8..b81505be0b10 100644 --- a/alicloud/resource_alicloud_dcdn_ipa_domain.go +++ b/alicloud/resource_alicloud_dcdn_ipa_domain.go @@ -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" @@ -92,10 +91,7 @@ func resourceAlicloudDcdnIpaDomainCreate(d *schema.ResourceData, meta interface{ var response map[string]interface{} action := "AddDcdnIpaDomain" request := make(map[string]interface{}) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error request["DomainName"] = d.Get("domain_name") if v, ok := d.GetOk("resource_group_id"); ok { request["ResourceGroupId"] = v @@ -110,7 +106,7 @@ func resourceAlicloudDcdnIpaDomainCreate(d *schema.ResourceData, meta interface{ request["Sources"] = sources 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("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -174,10 +170,7 @@ func resourceAlicloudDcdnIpaDomainRead(d *schema.ResourceData, meta interface{}) func resourceAlicloudDcdnIpaDomainUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) dcdnService := DcdnService{client} - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error var response map[string]interface{} update := false request := map[string]interface{}{ @@ -202,7 +195,7 @@ func resourceAlicloudDcdnIpaDomainUpdate(d *schema.ResourceData, meta interface{ action := "UpdateDcdnIpaDomain" 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("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -238,7 +231,7 @@ func resourceAlicloudDcdnIpaDomainUpdate(d *schema.ResourceData, meta interface{ action := "StopDcdnIpaDomain" 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("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -264,7 +257,7 @@ func resourceAlicloudDcdnIpaDomainUpdate(d *schema.ResourceData, meta interface{ action := "StartDcdnIpaDomain" 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("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -294,17 +287,14 @@ func resourceAlicloudDcdnIpaDomainDelete(d *schema.ResourceData, meta interface{ dcdnService := DcdnService{client} action := "DeleteDcdnIpaDomain" var response map[string]interface{} - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error request := map[string]interface{}{ "DomainName": d.Id(), } wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) || IsExpectedErrors(err, []string{"ServiceBusy"}) { wait() diff --git a/alicloud/resource_alicloud_dcdn_ipa_domain_test.go b/alicloud/resource_alicloud_dcdn_ipa_domain_test.go index 2374b5d32cff..119bc9c98efa 100644 --- a/alicloud/resource_alicloud_dcdn_ipa_domain_test.go +++ b/alicloud/resource_alicloud_dcdn_ipa_domain_test.go @@ -42,7 +42,7 @@ func testSweepDcdnIpaDomain(region string) error { if err != nil { return fmt.Errorf("error getting Alicloud client: %s", err) } - aliyunClient := rawClient.(*connectivity.AliyunClient) + client := rawClient.(*connectivity.AliyunClient) prefixes := []string{ "tf-testAcc", "tf_testAcc", @@ -54,17 +54,10 @@ func testSweepDcdnIpaDomain(region string) error { request["PageNumber"] = 1 var response map[string]interface{} - conn, err := aliyunClient.NewDcdnClient() - if err != nil { - log.Printf("[ERROR] %s get an error: %#v", action, err) - return nil - } for { - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(1*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -103,7 +96,7 @@ func testSweepDcdnIpaDomain(region string) error { request := map[string]interface{}{ "DomainName": item["DomainName"], } - _, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + _, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { log.Printf("[ERROR] Failed to delete Dcdn Ipa Domain (%s): %s", item["DomainName"].(string), err) } diff --git a/alicloud/resource_alicloud_dcdn_kv.go b/alicloud/resource_alicloud_dcdn_kv.go index b941cbd56824..efb8168869ef 100644 --- a/alicloud/resource_alicloud_dcdn_kv.go +++ b/alicloud/resource_alicloud_dcdn_kv.go @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/validation" - 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" @@ -50,10 +49,7 @@ func resourceAlicloudDcdnKv() *schema.Resource { func resourceAlicloudDcdnKvCreate(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) request := make(map[string]interface{}) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error if v, ok := d.GetOk("key"); ok { request["Key"] = v @@ -69,7 +65,7 @@ func resourceAlicloudDcdnKvCreate(d *schema.ResourceData, meta interface{}) erro action := "PutDcdnKv" wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutCreate)), func() *resource.RetryError { - resp, err := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -77,7 +73,6 @@ func resourceAlicloudDcdnKvCreate(d *schema.ResourceData, meta interface{}) erro } return resource.NonRetryableError(err) } - response = resp addDebug(action, response, request) return nil }) @@ -118,10 +113,7 @@ func resourceAlicloudDcdnKvRead(d *schema.ResourceData, meta interface{}) error func resourceAlicloudDcdnKvUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error parts, err := ParseResourceId(d.Id(), 2) if err != nil { return WrapError(err) @@ -141,7 +133,7 @@ func resourceAlicloudDcdnKvUpdate(d *schema.ResourceData, meta interface{}) erro action := "PutDcdnKv" wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutUpdate)), func() *resource.RetryError { - resp, err := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err := client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -149,7 +141,7 @@ func resourceAlicloudDcdnKvUpdate(d *schema.ResourceData, meta interface{}) erro } return resource.NonRetryableError(err) } - addDebug(action, resp, request) + addDebug(action, response, request) return nil }) if err != nil { @@ -162,10 +154,7 @@ func resourceAlicloudDcdnKvUpdate(d *schema.ResourceData, meta interface{}) erro func resourceAlicloudDcdnKvDelete(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error parts, err := ParseResourceId(d.Id(), 2) if err != nil { return WrapError(err) @@ -179,7 +168,7 @@ func resourceAlicloudDcdnKvDelete(d *schema.ResourceData, meta interface{}) erro action := "DeleteDcdnKv" wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutDelete)), func() *resource.RetryError { - resp, err := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err := client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -187,7 +176,7 @@ func resourceAlicloudDcdnKvDelete(d *schema.ResourceData, meta interface{}) erro } return resource.NonRetryableError(err) } - addDebug(action, resp, request) + addDebug(action, response, request) return nil }) if err != nil { diff --git a/alicloud/resource_alicloud_dcdn_kv_namespace.go b/alicloud/resource_alicloud_dcdn_kv_namespace.go index 755268c5d3d3..3389681538a9 100644 --- a/alicloud/resource_alicloud_dcdn_kv_namespace.go +++ b/alicloud/resource_alicloud_dcdn_kv_namespace.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "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" @@ -50,10 +49,7 @@ func resourceAlicloudDcdnKvNamespace() *schema.Resource { func resourceAlicloudDcdnKvNamespaceCreate(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) request := make(map[string]interface{}) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error if v, ok := d.GetOk("description"); ok { request["Description"] = v @@ -66,7 +62,7 @@ func resourceAlicloudDcdnKvNamespaceCreate(d *schema.ResourceData, meta interfac action := "PutDcdnKvNamespace" wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutCreate)), func() *resource.RetryError { - resp, err := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -74,7 +70,6 @@ func resourceAlicloudDcdnKvNamespaceCreate(d *schema.ResourceData, meta interfac } return resource.NonRetryableError(err) } - response = resp addDebug(action, response, request) return nil }) @@ -113,10 +108,7 @@ func resourceAlicloudDcdnKvNamespaceRead(d *schema.ResourceData, meta interface{ func resourceAlicloudDcdnKvNamespaceDelete(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error dcdnService := DcdnService{client} request := map[string]interface{}{ @@ -126,7 +118,7 @@ func resourceAlicloudDcdnKvNamespaceDelete(d *schema.ResourceData, meta interfac action := "DeleteDcdnKvNamespace" wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutDelete)), func() *resource.RetryError { - resp, err := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err := client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -134,7 +126,7 @@ func resourceAlicloudDcdnKvNamespaceDelete(d *schema.ResourceData, meta interfac } return resource.NonRetryableError(err) } - addDebug(action, resp, request) + addDebug(action, response, request) return nil }) if err != nil { diff --git a/alicloud/resource_alicloud_dcdn_waf_domain.go b/alicloud/resource_alicloud_dcdn_waf_domain.go index 1441021178e3..c012e28ceec5 100644 --- a/alicloud/resource_alicloud_dcdn_waf_domain.go +++ b/alicloud/resource_alicloud_dcdn_waf_domain.go @@ -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" @@ -44,10 +43,7 @@ func resourceAlicloudDcdnWafDomainCreate(d *schema.ResourceData, meta interface{ var response map[string]interface{} action := "BatchSetDcdnWafDomainConfigs" request := make(map[string]interface{}) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error if v, ok := d.GetOk("client_ip_tag"); ok { request["ClientIpTag"] = v } @@ -55,7 +51,7 @@ func resourceAlicloudDcdnWafDomainCreate(d *schema.ResourceData, meta interface{ request["DomainNames"] = d.Get("domain_name") wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutCreate)), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -94,10 +90,7 @@ func resourceAlicloudDcdnWafDomainRead(d *schema.ResourceData, meta interface{}) func resourceAlicloudDcdnWafDomainUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) var response map[string]interface{} - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error if d.HasChange("client_ip_tag") { action := "BatchSetDcdnWafDomainConfigs" @@ -110,7 +103,7 @@ func resourceAlicloudDcdnWafDomainUpdate(d *schema.ResourceData, meta interface{ } wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutUpdate)), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -132,17 +125,14 @@ func resourceAlicloudDcdnWafDomainDelete(d *schema.ResourceData, meta interface{ client := meta.(*connectivity.AliyunClient) action := "BatchSetDcdnWafDomainConfigs" var response map[string]interface{} - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error request := map[string]interface{}{ "DomainNames": d.Id(), } request["DefenseStatus"] = "off" wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutDelete)), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() diff --git a/alicloud/resource_alicloud_dcdn_waf_policy.go b/alicloud/resource_alicloud_dcdn_waf_policy.go index 867bd348819f..a8bba2a3aa08 100644 --- a/alicloud/resource_alicloud_dcdn_waf_policy.go +++ b/alicloud/resource_alicloud_dcdn_waf_policy.go @@ -8,7 +8,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/validation" - 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" @@ -60,17 +59,14 @@ func resourceAlicloudDcdnWafPolicyCreate(d *schema.ResourceData, meta interface{ var response map[string]interface{} action := "CreateDcdnWafPolicy" request := make(map[string]interface{}) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error request["DefenseScene"] = d.Get("defense_scene") request["PolicyName"] = d.Get("policy_name") request["PolicyType"] = d.Get("policy_type") request["PolicyStatus"] = d.Get("status") wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutCreate)), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -109,10 +105,7 @@ func resourceAlicloudDcdnWafPolicyRead(d *schema.ResourceData, meta interface{}) } func resourceAlicloudDcdnWafPolicyUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error var response map[string]interface{} update := false request := map[string]interface{}{ @@ -130,7 +123,7 @@ func resourceAlicloudDcdnWafPolicyUpdate(d *schema.ResourceData, meta interface{ action := "ModifyDcdnWafPolicy" wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutUpdate)), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -151,17 +144,14 @@ func resourceAlicloudDcdnWafPolicyDelete(d *schema.ResourceData, meta interface{ client := meta.(*connectivity.AliyunClient) action := "DeleteDcdnWafPolicy" var response map[string]interface{} - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error request := map[string]interface{}{ "PolicyId": d.Id(), } wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutDelete)), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() diff --git a/alicloud/resource_alicloud_dcdn_waf_policy_domain_attachment.go b/alicloud/resource_alicloud_dcdn_waf_policy_domain_attachment.go index e7479d234900..744811afd5a9 100644 --- a/alicloud/resource_alicloud_dcdn_waf_policy_domain_attachment.go +++ b/alicloud/resource_alicloud_dcdn_waf_policy_domain_attachment.go @@ -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" @@ -43,15 +42,12 @@ func resourceAlicloudDcdnWafPolicyDomainAttachmentCreate(d *schema.ResourceData, var response map[string]interface{} action := "ModifyDcdnWafPolicyDomains" request := make(map[string]interface{}) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error request["BindDomains"] = d.Get("domain_name") request["PolicyId"] = d.Get("policy_id") 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("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -99,17 +95,13 @@ func resourceAlicloudDcdnWafPolicyDomainAttachmentDelete(d *schema.ResourceData, return WrapError(err) } var response map[string]interface{} - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } request := map[string]interface{}{ "PolicyId": parts[0], "UnbindDomains": parts[1], } wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() diff --git a/alicloud/resource_alicloud_dcdn_waf_policy_test.go b/alicloud/resource_alicloud_dcdn_waf_policy_test.go index 9bc85ffe939e..99601df5845b 100644 --- a/alicloud/resource_alicloud_dcdn_waf_policy_test.go +++ b/alicloud/resource_alicloud_dcdn_waf_policy_test.go @@ -41,30 +41,25 @@ func testSweepDcdnWafPolicy(region string) error { if err != nil { return fmt.Errorf("error getting Alicloud client: %s", err) } - aliyunClient := rawClient.(*connectivity.AliyunClient) + client := rawClient.(*connectivity.AliyunClient) prefixes := []string{ "tf-testAcc", "tf_testAcc", } action := "DescribeDcdnWafPolicies" request := map[string]interface{}{} - request["RegionId"] = aliyunClient.RegionId + request["RegionId"] = client.RegionId request["PageSize"] = PageSizeLarge request["PageNumber"] = 1 var response map[string]interface{} - conn, err := aliyunClient.NewDcdnClient() - if err != nil { - log.Printf("[ERROR] %s get an error: %#v", action, err) - return nil - } for { runtime := util.RuntimeOptions{} runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(1*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -103,7 +98,7 @@ func testSweepDcdnWafPolicy(region string) error { request := map[string]interface{}{ "PolicyId": item["PolicyId"], } - _, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + _, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { log.Printf("[ERROR] Failed to delete Dcdn Waf Policy (%s): %s", item["PolicyName"].(string), err) } diff --git a/alicloud/resource_alicloud_dcdn_waf_rule.go b/alicloud/resource_alicloud_dcdn_waf_rule.go index 5bb274aa311d..e0aa5861db8e 100644 --- a/alicloud/resource_alicloud_dcdn_waf_rule.go +++ b/alicloud/resource_alicloud_dcdn_waf_rule.go @@ -8,7 +8,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "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" @@ -195,10 +194,7 @@ func resourceAlicloudDcdnWafRule() *schema.Resource { func resourceAlicloudDcdnWafRuleCreate(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) request := make(map[string]interface{}) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error ruleConfigMap := make(map[string]interface{}, 0) if v, ok := d.GetOk("cc_status"); ok { ruleConfigMap["ccStatus"] = v @@ -285,7 +281,7 @@ func resourceAlicloudDcdnWafRuleCreate(d *schema.ResourceData, meta interface{}) action := "BatchCreateDcdnWafRules" wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutCreate)), func() *resource.RetryError { - resp, err := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("dcdn", "2018-01-15", action, request, nil, false) if err != nil { if NeedRetry(err) || IsExpectedErrors(err, []string{"InternalError"}) { wait() @@ -293,7 +289,6 @@ func resourceAlicloudDcdnWafRuleCreate(d *schema.ResourceData, meta interface{}) } return resource.NonRetryableError(err) } - response = resp addDebug(action, response, request) return nil }) @@ -389,10 +384,7 @@ func resourceAlicloudDcdnWafRuleRead(d *schema.ResourceData, meta interface{}) e func resourceAlicloudDcdnWafRuleUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error update := false request := map[string]interface{}{ "RuleId": d.Id(), @@ -524,7 +516,7 @@ func resourceAlicloudDcdnWafRuleUpdate(d *schema.ResourceData, meta interface{}) action := "ModifyDcdnWafRule" wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutUpdate)), func() *resource.RetryError { - resp, err := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err := client.RpcPost("dcdn", "2018-01-15", action, request, nil, false) if err != nil { if NeedRetry(err) || IsExpectedErrors(err, []string{"InternalError"}) { wait() @@ -532,7 +524,7 @@ func resourceAlicloudDcdnWafRuleUpdate(d *schema.ResourceData, meta interface{}) } return resource.NonRetryableError(err) } - addDebug(action, resp, request) + addDebug(action, response, request) return nil }) if err != nil { @@ -545,10 +537,7 @@ func resourceAlicloudDcdnWafRuleUpdate(d *schema.ResourceData, meta interface{}) func resourceAlicloudDcdnWafRuleDelete(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) - conn, err := client.NewDcdnClient() - if err != nil { - return WrapError(err) - } + var err error request := map[string]interface{}{ "RuleIds": d.Id(), @@ -557,7 +546,7 @@ func resourceAlicloudDcdnWafRuleDelete(d *schema.ResourceData, meta interface{}) action := "BatchDeleteDcdnWafRules" wait := incrementalWait(3*time.Second, 3*time.Second) err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutDelete)), func() *resource.RetryError { - resp, err := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err := client.RpcPost("dcdn", "2018-01-15", action, request, nil, false) if err != nil { if NeedRetry(err) { wait() @@ -565,7 +554,7 @@ func resourceAlicloudDcdnWafRuleDelete(d *schema.ResourceData, meta interface{}) } return resource.NonRetryableError(err) } - addDebug(action, resp, request) + addDebug(action, response, request) return nil }) if err != nil { diff --git a/alicloud/service_alicloud_dcdn.go b/alicloud/service_alicloud_dcdn.go index 5facd84b5546..6d55217f1c02 100644 --- a/alicloud/service_alicloud_dcdn.go +++ b/alicloud/service_alicloud_dcdn.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "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" ) @@ -39,18 +38,13 @@ func (s *DcdnService) convertSourcesToString(v []interface{}) (string, error) { func (s *DcdnService) DescribeDcdnDomainCertificateInfo(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewDcdnClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "DescribeDcdnDomainCertificateInfo" request := map[string]interface{}{ "RegionId": s.client.RegionId, "DomainName": id, } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { err = WrapErrorf(err, DefaultErrorMsg, id, action, AlibabaCloudSdkGoERROR) return @@ -73,18 +67,13 @@ func (s *DcdnService) DescribeDcdnDomainCertificateInfo(id string) (object map[s func (s *DcdnService) DescribeDcdnDomain(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewDcdnClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "DescribeDcdnDomainDetail" request := map[string]interface{}{ "RegionId": s.client.RegionId, "DomainName": id, } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { if IsExpectedErrors(err, []string{"InvalidDomain.NotFound"}) { err = WrapErrorf(Error(GetNotFoundMessage("DcdnDomain", id)), NotFoundMsg, ProviderERROR) @@ -125,12 +114,7 @@ func (s *DcdnService) DcdnDomainStateRefreshFunc(id string, failStates []string) func (s *DcdnService) DescribeDcdnDomainConfig(id string) (object map[string]interface{}, err error) { var response map[string]interface{} action := "DescribeDcdnDomainConfigs" - - conn, err := s.client.NewDcdnClient() - if err != nil { - return nil, WrapError(err) - } - + client := s.client parts, err := ParseResourceId(id, 3) if err != nil { return nil, WrapError(err) @@ -143,11 +127,9 @@ func (s *DcdnService) DescribeDcdnDomainConfig(id string) (object map[string]int } idExist := false - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(5*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -158,7 +140,6 @@ func (s *DcdnService) DescribeDcdnDomainConfig(id string) (object map[string]int return nil }) addDebug(action, response, request) - if err != nil { if IsExpectedErrors(err, []string{"InvalidDomain.NotFound"}) { return object, WrapErrorf(Error(GetNotFoundMessage("Dcdn:DomainConfig", id)), NotFoundMsg, ProviderERROR, fmt.Sprint(response["RequestId"])) @@ -211,19 +192,14 @@ func (s *DcdnService) DcdnDomainConfigStateRefreshFunc(id string, failStates []s func (s *DcdnService) DescribeDcdnIpaDomain(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewDcdnClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "DescribeDcdnIpaDomainDetail" request := map[string]interface{}{ "DomainName": id, } - 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("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -271,21 +247,16 @@ func (s *DcdnService) DcdnIpaDomainStateRefreshFunc(id string, failStates []stri func (s *DcdnService) DescribeDcdnWafPolicy(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewDcdnClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "DescribeDcdnWafPolicies" request := map[string]interface{}{ "QueryArgs": fmt.Sprintf("{\"PolicyIds\":\"%s\"}", id), "PageNumber": 1, "PageSize": PageSizeLarge, } - 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("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -313,10 +284,7 @@ func (s *DcdnService) DescribeDcdnWafPolicy(id string) (object map[string]interf func (s *DcdnService) DescribeDcdnWafDomain(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewDcdnClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "DescribeDcdnWafDomains" request := map[string]interface{}{ "PageNumber": 1, @@ -324,11 +292,9 @@ func (s *DcdnService) DescribeDcdnWafDomain(id string) (object map[string]interf } 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("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -364,19 +330,14 @@ func (s *DcdnService) DescribeDcdnWafDomain(id string) (object map[string]interf func (s *DcdnService) DescribeDcdnWafDomainDefenseScenes(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewDcdnClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "DescribeDcdnWafDomainDetail" request := map[string]interface{}{ "DomainName": id, } - 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("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -400,10 +361,7 @@ func (s *DcdnService) DescribeDcdnWafDomainDefenseScenes(id string) (object map[ func (s *DcdnService) DescribeDcdnWafPolicyDomainAttachment(id string) (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewDcdnClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client parts, err := ParseResourceId(id, 2) if err != nil { return object, WrapError(err) @@ -413,11 +371,9 @@ func (s *DcdnService) DescribeDcdnWafPolicyDomainAttachment(id string) (object m "PolicyId": parts[0], } 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("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -452,10 +408,7 @@ func (s *DcdnService) DescribeDcdnWafPolicyDomainAttachment(id string) (object m } func (s *DcdnService) DescribeDcdnKv(id string) (object map[string]interface{}, err error) { - conn, err := s.client.NewDcdnClient() - if err != nil { - return object, WrapError(err) - } + client := s.client parts, err := ParseResourceId(id, 2) if err != nil { return object, WrapError(err) @@ -468,11 +421,9 @@ func (s *DcdnService) DescribeDcdnKv(id string) (object map[string]interface{}, var response map[string]interface{} action := "GetDcdnKv" - 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("GET"), StringPointer("2018-01-15"), StringPointer("AK"), request, nil, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, request, nil, true) if err != nil { if NeedRetry(err) { wait() @@ -480,7 +431,6 @@ func (s *DcdnService) DescribeDcdnKv(id string) (object map[string]interface{}, } return resource.NonRetryableError(err) } - response = resp addDebug(action, response, request) return nil }) @@ -498,10 +448,7 @@ func (s *DcdnService) DescribeDcdnKv(id string) (object map[string]interface{}, } func (s *DcdnService) DescribeDcdnKvNamespace(id string) (object map[string]interface{}, err error) { - conn, err := s.client.NewDcdnClient() - if err != nil { - return object, WrapError(err) - } + client := s.client request := map[string]interface{}{ "Namespace": id, @@ -509,11 +456,9 @@ func (s *DcdnService) DescribeDcdnKvNamespace(id string) (object map[string]inte var response map[string]interface{} action := "DescribeDcdnKvNamespace" - 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("GET"), StringPointer("2018-01-15"), StringPointer("AK"), request, nil, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, request, nil, true) if err != nil { if NeedRetry(err) { wait() @@ -521,7 +466,6 @@ func (s *DcdnService) DescribeDcdnKvNamespace(id string) (object map[string]inte } return resource.NonRetryableError(err) } - response = resp addDebug(action, response, request) return nil }) @@ -558,18 +502,13 @@ func (s *DcdnService) DcdnKvNamespaceStateRefreshFunc(id string, failStates []st func (s *DcdnService) DescribeDcdnKvAccountStatus() (object map[string]interface{}, err error) { var response map[string]interface{} - conn, err := s.client.NewDcdnClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "DescribeDcdnKvAccountStatus" request := map[string]interface{}{} - 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("GET"), StringPointer("2018-01-15"), StringPointer("AK"), request, nil, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, request, nil, true) if err != nil { if NeedRetry(err) { wait() @@ -593,22 +532,16 @@ func (s *DcdnService) DescribeDcdnKvAccountStatus() (object map[string]interface } func (s *DcdnService) DescribeDcdnWafRule(id string) (object map[string]interface{}, err error) { - conn, err := s.client.NewDcdnClient() - if err != nil { - return object, WrapError(err) - } - + client := s.client request := map[string]interface{}{ "RuleId": id, } var response map[string]interface{} action := "DescribeDcdnWafRule" - 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("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { if NeedRetry(err) || IsExpectedErrors(err, []string{"InternalError"}) { wait() @@ -616,7 +549,6 @@ func (s *DcdnService) DescribeDcdnWafRule(id string) (object map[string]interfac } return resource.NonRetryableError(err) } - response = resp addDebug(action, response, request) return nil }) @@ -639,20 +571,15 @@ func (s *DcdnService) DescribeDcdnEr(id string) (object map[string]interface{}, var response map[string]interface{} action := "DescribeRoutine" - conn, err := s.client.NewDcdnClient() - if err != nil { - return object, WrapError(err) - } + client := s.client request := map[string]interface{}{ "Name": id, } - 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("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -682,12 +609,8 @@ func (s *DcdnService) DescribeDcdnEr(id string) (object map[string]interface{}, } func (s *DcdnService) ListTagResources(id string, resourceType string) (object interface{}, err error) { - conn, err := s.client.NewDcdnClient() - if err != nil { - return nil, WrapError(err) - } + client := s.client action := "DescribeDcdnTagResources" - request := map[string]interface{}{ "ResourceType": resourceType, } @@ -707,12 +630,9 @@ func (s *DcdnService) ListTagResources(id string, resourceType string) (object i tags := make([]interface{}, 0) var response map[string]interface{} - - 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("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -721,7 +641,6 @@ func (s *DcdnService) ListTagResources(id string, resourceType string) (object i return resource.NonRetryableError(err) } addDebug(action, response, request) - resp, err := jsonpath.Get("$.TagResources", response) if err != nil { return resource.NonRetryableError(WrapErrorf(err, FailedGetAttributeMsg, id, "$.TagResources", response)) @@ -743,16 +662,12 @@ func (s *DcdnService) ListTagResources(id string, resourceType string) (object i } func (s *DcdnService) SetResourceTags(d *schema.ResourceData, resourceType string) error { - + client := s.client resourceIdNum := strings.Count(d.Id(), ":") - + var response map[string]interface{} + var err error if d.HasChange("tags") { added, removed := parsingTags(d) - conn, err := s.client.NewDcdnClient() - if err != nil { - return WrapError(err) - } - removedTagKeys := make([]string, 0) for _, v := range removed { if !ignoredTags(v, "") { @@ -781,11 +696,9 @@ func (s *DcdnService) SetResourceTags(d *schema.ResourceData, resourceType strin request[fmt.Sprintf("TagKey.%d", i+1)] = key } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(2*time.Second, 1*time.Second) err := resource.Retry(10*time.Minute, func() *resource.RetryError { - response, err := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -825,11 +738,9 @@ func (s *DcdnService) SetResourceTags(d *schema.ResourceData, resourceType strin count++ } - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(2*time.Second, 1*time.Second) err := resource.Retry(10*time.Minute, func() *resource.RetryError { - response, err := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() diff --git a/alicloud/service_alicloud_dcdn_v2.go b/alicloud/service_alicloud_dcdn_v2.go index 9abeb6c01ead..526795032568 100644 --- a/alicloud/service_alicloud_dcdn_v2.go +++ b/alicloud/service_alicloud_dcdn_v2.go @@ -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" ) @@ -22,19 +21,13 @@ func (s *DcdnServiceV2) DescribeDcdnDomain(id string) (object map[string]interfa var response map[string]interface{} var query map[string]interface{} action := "DescribeDcdnDomainDetail" - conn, err := client.NewDcdnClient() - if err != nil { - return object, WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) query["DomainName"] = id - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(1*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, query, request, true) if err != nil { if NeedRetry(err) { @@ -67,19 +60,13 @@ func (s *DcdnServiceV2) DescribeDescribeDcdnDomainCertificateInfo(id string) (ob var response map[string]interface{} var query map[string]interface{} action := "DescribeDcdnDomainCertificateInfo" - conn, err := client.NewDcdnClient() - if err != nil { - return object, WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) query["DomainName"] = id - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(1*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, query, request, true) if err != nil { if NeedRetry(err) { @@ -116,20 +103,14 @@ func (s *DcdnServiceV2) DescribeDescribeDcdnTagResources(id string) (object map[ var response map[string]interface{} var query map[string]interface{} action := "DescribeDcdnTagResources" - conn, err := client.NewDcdnClient() - if err != nil { - return object, WrapError(err) - } request = make(map[string]interface{}) query = make(map[string]interface{}) request["ResourceId.1"] = id request["ResourceType"] = "DOMAIN" - runtime := util.RuntimeOptions{} - runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(1*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2018-01-15"), StringPointer("AK"), query, request, &runtime) + response, err = client.RpcPost("dcdn", "2018-01-15", action, query, request, true) if err != nil { if NeedRetry(err) { diff --git a/website/docs/d/dcdn_domains.html.markdown b/website/docs/d/dcdn_domains.html.markdown index 4559f591b527..a55bd4f46d31 100644 --- a/website/docs/d/dcdn_domains.html.markdown +++ b/website/docs/d/dcdn_domains.html.markdown @@ -11,11 +11,11 @@ description: |- Provides a collection of DCDN Domains to the specified filters. -~> **NOTE:** Available in 1.94.0+. +-> **NOTE:** Available since 1.94.0. ## Example Usage - ``` +```terraform data "alicloud_dcdn_domains" "example" { ids = ["example.com"] } @@ -44,24 +44,24 @@ The following arguments are supported: The following attributes are exported in addition to the arguments listed above: - * `ids` - A list ids of DCDN Domain. - * `names` - A list of DCDN Domain names. - * `domains` - A list of domains. Each element contains the following attributes: - * `id` - The ID of the DCDN Domain. - * `cert_name` - Indicates the name of the certificate. - * `resource_group_id` - The ID of the resource group. - * `domain_name` - The name of the DCDN Domain. - * `ssl_protocol` - Indicates whether the SSL certificate is enabled. - * `ssl_pub` - Indicates the public key of the certificate. - * `scope` - The acceleration region. - * `status` - The status of DCDN Domain. Valid values: `online`, `offline`, `check_failed`, `checking`, `configure_failed`, `configuring`. - * `cname` - The canonical name (CNAME) of the accelerated domain. - * `description` - The reason that causes the review failure. - * `gmt_modified` - The time when the accelerated domain was last modified. - * `sources` - The origin information. - * `content` - The origin address. - * `type` - The type of the origin. Valid values: - * `port` - The port number. - * `priority` - The priority of the origin if multiple origins are specified. - * `weight` - The weight of the origin if multiple origins are specified. - * `enabled` - The status of the origin. +* `ids` - A list ids of DCDN Domain. +* `names` - A list of DCDN Domain names. +* `domains` - A list of domains. Each element contains the following attributes: + * `id` - The ID of the DCDN Domain. + * `cert_name` - Indicates the name of the certificate. + * `resource_group_id` - The ID of the resource group. + * `domain_name` - The name of the DCDN Domain. + * `ssl_protocol` - Indicates whether the SSL certificate is enabled. + * `ssl_pub` - Indicates the public key of the certificate. + * `scope` - The acceleration region. + * `status` - The status of DCDN Domain. Valid values: `online`, `offline`, `check_failed`, `checking`, `configure_failed`, `configuring`. + * `cname` - The canonical name (CNAME) of the accelerated domain. + * `description` - The reason that causes the review failure. + * `gmt_modified` - The time when the accelerated domain was last modified. + * `sources` - The origin information. + * `content` - The origin address. + * `type` - The type of the origin. Valid values: + * `port` - The port number. + * `priority` - The priority of the origin if multiple origins are specified. + * `weight` - The weight of the origin if multiple origins are specified. + * `enabled` - The status of the origin. diff --git a/website/docs/d/dcdn_ipa_domains.html.markdown b/website/docs/d/dcdn_ipa_domains.html.markdown index 02d54fa89598..6c3a9a31667e 100644 --- a/website/docs/d/dcdn_ipa_domains.html.markdown +++ b/website/docs/d/dcdn_ipa_domains.html.markdown @@ -7,11 +7,11 @@ description: |- Provides a list of Dcdn Ipa Domains to the user. --- -# alicloud\_dcdn\_ipa\_domains +# alicloud_dcdn_ipa_domains This data source provides the Dcdn Ipa Domains of the current Alibaba Cloud user. --> **NOTE:** Available in v1.158.0+. +-> **NOTE:** Available since v1.158.0. ## Example Usage @@ -44,26 +44,26 @@ The following arguments are supported: * `output_file` - (Optional) File name where to save data source results (after running `terraform plan`). * `status` - (Optional, ForceNew) The status of the accelerated domain name. Valid values: `check_failed`, `checking`, `configure_failed`, `configuring`, `offline`, `online`. -## Argument Reference +## Attributes Reference The following attributes are exported in addition to the arguments listed above: * `names` - A list of Dcdn Ipa Domain names. * `domains` - A list of Dcdn Ipa Domains. Each element contains the following attributes: - * `cert_name` - CertName. - * `cname` - The CNAME assigned to the domain name. - * `create_time` - The time when the accelerated domain name was created. - * `description` - The description. - * `domain_name` - The accelerated domain names. - * `id` - The ID of the Ipa Domain. - * `resource_group_id` - The ID of the resource group. - * `scope` - The accelerated region. - * `sources` - The information about the origin server. - * `priority` - The priority of the origin server if multiple origin servers are specified. - * `type` - The type of the origin server. - * `weight` - The weight of the origin server if multiple origin servers are specified. - * `content` - The address of the origin server. - * `port` - The custom port. - * `ssl_protocol` - Indicates whether the Security Socket Layer (SSL) certificate is enabled. - * `ssl_pub` - Indicates the public key of the certificate if the HTTPS protocol is enabled. - * `status` - The status of the accelerated domain name. \ No newline at end of file + * `cert_name` - CertName. + * `cname` - The CNAME assigned to the domain name. + * `create_time` - The time when the accelerated domain name was created. + * `description` - The description. + * `domain_name` - The accelerated domain names. + * `id` - The ID of the Ipa Domain. + * `resource_group_id` - The ID of the resource group. + * `scope` - The accelerated region. + * `sources` - The information about the origin server. + * `priority` - The priority of the origin server if multiple origin servers are specified. + * `type` - The type of the origin server. + * `weight` - The weight of the origin server if multiple origin servers are specified. + * `content` - The address of the origin server. + * `port` - The custom port. + * `ssl_protocol` - Indicates whether the Security Socket Layer (SSL) certificate is enabled. + * `ssl_pub` - Indicates the public key of the certificate if the HTTPS protocol is enabled. + * `status` - The status of the accelerated domain name. \ No newline at end of file diff --git a/website/docs/d/dcdn_kv_account.html.markdown b/website/docs/d/dcdn_kv_account.html.markdown index d604762d120b..fda67027a9a1 100644 --- a/website/docs/d/dcdn_kv_account.html.markdown +++ b/website/docs/d/dcdn_kv_account.html.markdown @@ -4,7 +4,7 @@ layout: "alicloud" page_title: "Alicloud: alicloud_dcdn_kv_account" sidebar_current: "docs-alicloud-datasource-dcdn-kv-account" description: |- - Provides a datasource to open the DCDN kv account automatically. + Provides a datasource to open the DCDN kv account automatically. --- # alicloud_dcdn_kv_account diff --git a/website/docs/d/dcdn_waf_domains.html.markdown b/website/docs/d/dcdn_waf_domains.html.markdown index bd6a7a80b8e6..4fd36695e534 100644 --- a/website/docs/d/dcdn_waf_domains.html.markdown +++ b/website/docs/d/dcdn_waf_domains.html.markdown @@ -7,11 +7,11 @@ description: |- Provides a list of Dcdn Waf Domains to the user. --- -# alicloud\_dcdn\_waf\_domains +# alicloud_dcdn_waf_domains This data source provides the Dcdn Waf Domains of the current Alibaba Cloud user. --> **NOTE:** Available in v1.185.0+. +-> **NOTE:** Available since v1.185.0. ## Example Usage @@ -33,7 +33,7 @@ The following arguments are supported: * `output_file` - (Optional) File name where to save data source results (after running `terraform plan`). * `query_args` - (Optional, ForceNew) The query conditions. You can filter domain names by name. Fuzzy match is supported `QueryArgs={"DomainName":"Accelerated domain name"}`. -## Argument Reference +## Attributes Reference The following attributes are exported in addition to the arguments listed above: diff --git a/website/docs/d/dcdn_waf_policies.html.markdown b/website/docs/d/dcdn_waf_policies.html.markdown index 2589b258239b..4110c3f44b48 100644 --- a/website/docs/d/dcdn_waf_policies.html.markdown +++ b/website/docs/d/dcdn_waf_policies.html.markdown @@ -7,11 +7,11 @@ description: |- Provides a list of Dcdn Waf Policies to the user. --- -# alicloud\_dcdn\_waf\_policies +# alicloud_dcdn_waf_policies This data source provides the Dcdn Waf Policies of the current Alibaba Cloud user. --> **NOTE:** Available in v1.184.0+. +-> **NOTE:** Available since v1.184.0. ## Example Usage @@ -33,7 +33,7 @@ The following arguments are supported: * `query_args` - (Optional, ForceNew) The query conditions. The value is a string in the JSON format. Format: `{"PolicyIds":"The ID of the proteuleIds":"Thection policy","R range of protection rule IDs","PolicyNameLike":"The name of the protection policy","DomainNames":"The protected domain names","PolicyType":"default","DefenseScenes":"waf_group","PolicyStatus":"on","OrderBy":"GmtModified","Desc":"false"}`. * `status` - (Optional, ForceNew) The status of the resource. Valid values: `on`, `off`. -## Argument Reference +## Attributes Reference The following attributes are exported in addition to the arguments listed above: