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/config.go b/alicloud/connectivity/config.go index 1370377fe937..5da7d81fbddb 100644 --- a/alicloud/connectivity/config.go +++ b/alicloud/connectivity/config.go @@ -31,6 +31,7 @@ type Config struct { SecurityToken string OtsInstanceName string AccountId string + AccountType string Protocol string ClientReadTimeout int ClientConnectTimeout int diff --git a/alicloud/connectivity/endpoint.go b/alicloud/connectivity/endpoint.go index cf815a3866f4..3e9ee927ca74 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,312 @@ 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 + "quotas": "quotas", //Quotas + "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", + "ram": "ram.aliyuncs.com", + "brain_industrial": "brain-industrial.cn-hangzhou.aliyuncs.com", + "cassandra": "cassandra.aliyuncs.com", + "cas": "cas.aliyuncs.com", + "cloudfw": "cloudfw.aliyuncs.com", + "scdn": "scdn.aliyuncs.com", + "vpcpeer": "vpcpeer.aliyuncs.com", + "resourcecenter": "resourcecenter.aliyuncs.com", //resourcecenter-intl.aliyuncs.com + "market": "market.aliyuncs.com", +} + +// irregularProductEndpointForIntlAccount specially records those product codes that +// cannot be parsed out by the location service and sensitive to account type. +// These products adapt to international 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 irregularProductEndpointForIntlAccount = map[string]string{ + "cas": "cas.ap-southeast-1.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", + "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", + "sms": "dysmsapi.aliyuncs.com", + "sddp": "sddp.cn-zhangjiakou.aliyuncs.com", + "ddoscoo": "ddoscoo.cn-hangzhou.aliyuncs.com", + "config": "config.cn-shanghai.aliyuncs.com", + "ga": "ga.cn-hangzhou.aliyuncs.com", + "dcdn": "dcdn.aliyuncs.com", + "cdn": "cdn.aliyuncs.com", + "cloudauth": "cloudauth.aliyuncs.com", + "ims": "ims.aliyuncs.com", + "mhub": "mhub.cn-shanghai.aliyuncs.com", + "eds_user": "eds-user.cn-shanghai.aliyuncs.com", + "eipanycast": "eipanycast.cn-hangzhou.aliyuncs.com", + "mscopensubscription": "mscopensubscription.aliyuncs.com", + "resourcemanager": "resourcemanager.aliyuncs.com", + "quotas": "quotas.aliyuncs.com", + "imp": "imp.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", + "bssopenapi": BssOpenAPIEndpointDomestic, +} + +// regularProductEndpointForIntlAccount specially records those product codes that have been confirmed to be +// regional or central endpoints. But the endpoints are sensitive to account type. +// These products adapt to international 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 lower than location service, and as a backup endpoint +var regularProductEndpointForIntlAccount = map[string]string{ + "config": "config.ap-southeast-1.aliyuncs.com", +} + +// regularProductEndpointForIntlRegion specially records those product codes that have been confirmed to be +// regional or central endpoints. But the endpoints are sensitive to region. +// These products adapt to international region, and conflict with regularProductEndpointForIntlAccount +// 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 regularProductEndpointForIntlRegion = map[string]string{ + "ddoscoo": "ddoscoo.ap-southeast-1.aliyuncs.com", + "mscopensubscription": "mscopensubscription.aliyuncs.com", + "eds_user": "eds-user.ap-southeast-1.aliyuncs.com", + "bssopenapi": BssOpenAPIEndpointInternational, + "sms": "dysmsapi.ap-southeast-1.aliyuncs.com", + "sddp": "sddp.ap-southeast-1.aliyuncs.com", + "governance": "governance.ap-southeast-1.aliyuncs.com", + "waf_openapi": "wafopenapi.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 := irregularProductEndpointForIntlAccount[productCode]; ok && strings.ToLower(client.config.AccountType) == "international" { + endpointFmt = v + } if strings.Contains(endpointFmt, "%s") { endpointFmt = fmt.Sprintf(endpointFmt, client.RegionId) } @@ -193,13 +480,22 @@ 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 endpointFmt, ok := regularProductEndpoint[productCode]; ok { + if v, ok := regularProductEndpointForIntlAccount[productCode]; ok && strings.ToLower(client.config.AccountType) == "international" { + endpointFmt = v + } + if v, ok := regularProductEndpointForIntlRegion[productCode]; ok && !strings.HasPrefix(client.RegionId, "cn-") { + endpointFmt = v + } + if strings.Contains(endpointFmt, "%s") { + endpointFmt = fmt.Sprintf(endpointFmt, client.RegionId) + } + client.config.Endpoints.Store(productCode, endpointFmt) + log.Printf("[WARN] loading %s endpoint got an error: %#v. Using the endpoint %s instead.", productCode, err, endpointFmt) + return nil } return err } @@ -242,9 +538,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 +588,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_ssl_certificates_service_certificates.go b/alicloud/data_source_alicloud_ssl_certificates_service_certificates.go index 23a23a3f3d0d..e11e5d3cb716 100644 --- a/alicloud/data_source_alicloud_ssl_certificates_service_certificates.go +++ b/alicloud/data_source_alicloud_ssl_certificates_service_certificates.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" @@ -173,17 +172,11 @@ func dataSourceAliCloudSslCertificatesServiceCertificatesRead(d *schema.Resource } var response map[string]interface{} - conn, err := client.NewCasClient() - 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("2020-04-07"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("cas", "2020-04-07", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() diff --git a/alicloud/provider.go b/alicloud/provider.go index aebd81d0c9a6..b4b5c31faa34 100644 --- a/alicloud/provider.go +++ b/alicloud/provider.go @@ -81,6 +81,12 @@ func Provider() terraform.ResourceProvider { DefaultFunc: schema.MultiEnvDefaultFunc([]string{"ALICLOUD_ACCOUNT_ID", "ALIBABA_CLOUD_ACCOUNT_ID"}, nil), Description: descriptions["account_id"], }, + "account_type": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: StringInSlice([]string{"Domestic", "International"}, true), + DefaultFunc: schema.MultiEnvDefaultFunc([]string{"ALICLOUD_ACCOUNT_TYPE", "ALIBABA_CLOUD_ACCOUNT_TYPE"}, nil), + }, "assume_role": assumeRoleSchema(), "sign_version": signVersionSchema(), "assume_role_with_oidc": assumeRoleWithOidcSchema(), @@ -1848,6 +1854,12 @@ func providerConfigure(d *schema.ResourceData, p *schema.Provider) (interface{}, } config.Credential = credential } + if account, ok := d.GetOk("account_id"); ok && account.(string) != "" { + config.AccountId = strings.TrimSpace(account.(string)) + } + if v, ok := d.GetOk("account_type"); ok && v.(string) != "" { + config.AccountType = v.(string) + } if v, ok := d.GetOk("security_transport"); config.SecureTransport == "" && ok && v.(string) != "" { config.SecureTransport = v.(string) } @@ -1909,6 +1921,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)) @@ -2059,10 +2077,6 @@ func providerConfigure(d *schema.ResourceData, p *schema.Provider) (interface{}, config.MnsEndpoint = strings.TrimSpace(mnsEndpoint.(string)) } - if account, ok := d.GetOk("account_id"); ok && account.(string) != "" { - config.AccountId = strings.TrimSpace(account.(string)) - } - if fcEndpoint, ok := d.GetOk("fc"); ok && fcEndpoint.(string) != "" { config.FcEndpoint = strings.TrimSpace(fcEndpoint.(string)) } @@ -2560,6 +2574,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, @@ -2574,7 +2594,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, @@ -2623,6 +2648,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, @@ -2637,6 +2668,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, @@ -2651,7 +2688,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, @@ -2673,6 +2715,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, @@ -2686,6 +2734,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, @@ -2707,6 +2761,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, @@ -2752,6 +2812,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, @@ -2770,6 +2836,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, @@ -2825,6 +2897,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, @@ -2851,6 +2929,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, @@ -2905,7 +2989,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, @@ -2938,6 +3027,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, @@ -2957,7 +3052,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, @@ -2965,6 +3065,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, @@ -3026,6 +3133,11 @@ func endpointsSchema() *schema.Schema { Default: "", Description: descriptions["resourcesharing_endpoint"], }, + "resourcesharing": { + Type: schema.TypeString, + Optional: true, + Default: "", + }, "ga": { Type: schema.TypeString, Optional: true, @@ -3278,6 +3390,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, @@ -3308,6 +3426,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, @@ -3320,12 +3444,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, @@ -3540,6 +3680,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_ssl_certificates_service_certificate.go b/alicloud/resource_alicloud_ssl_certificates_service_certificate.go index d436630ea523..d4a233857841 100644 --- a/alicloud/resource_alicloud_ssl_certificates_service_certificate.go +++ b/alicloud/resource_alicloud_ssl_certificates_service_certificate.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" @@ -56,13 +55,9 @@ func resourceAliCloudSslCertificatesServiceCertificate() *schema.Resource { func resourceAliCloudSslCertificatesServiceCertificateCreate(d *schema.ResourceData, meta interface{}) error { client := meta.(*connectivity.AliyunClient) var response map[string]interface{} + var err error action := "CreateUserCertificate" request := make(map[string]interface{}) - conn, err := client.NewCasClient() - if err != nil { - return WrapError(err) - } - request["Cert"] = d.Get("cert") request["Key"] = d.Get("key") @@ -78,11 +73,9 @@ func resourceAliCloudSslCertificatesServiceCertificateCreate(d *schema.ResourceD request["Lang"] = v } - 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-07-13"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("cas", "2018-07-13", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() @@ -135,12 +128,7 @@ func resourceAliCloudSslCertificatesServiceCertificateDelete(d *schema.ResourceD casService := CasService{client} action := "DeleteUserCertificate" var response map[string]interface{} - - conn, err := client.NewCasClient() - if err != nil { - return WrapError(err) - } - + var err error request := map[string]interface{}{ "CertId": d.Id(), } @@ -149,11 +137,9 @@ func resourceAliCloudSslCertificatesServiceCertificateDelete(d *schema.ResourceD request["Lang"] = v } - 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-07-13"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("cas", "2018-07-13", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() diff --git a/alicloud/resource_alicloud_ssl_certificates_service_certificate_test.go b/alicloud/resource_alicloud_ssl_certificates_service_certificate_test.go index 68034f9c2ed6..a4a55a2cb918 100644 --- a/alicloud/resource_alicloud_ssl_certificates_service_certificate_test.go +++ b/alicloud/resource_alicloud_ssl_certificates_service_certificate_test.go @@ -8,8 +8,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/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" @@ -39,16 +37,10 @@ func testSweepSslCertificatesServiceCertificate(region string) error { request["CurrentPage"] = 1 ids := make([]string, 0) var response map[string]interface{} - conn, err := client.NewCasClient() - if err != nil { - return WrapError(err) - } 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-07-13"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("cas", "2018-07-13", action, nil, request, true) if err != nil { if NeedRetry(err) { wait() @@ -97,7 +89,7 @@ func testSweepSslCertificatesServiceCertificate(region string) error { } 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-07-13"), StringPointer("AK"), nil, request, &util.RuntimeOptions{}) + response, err = client.RpcPost("cas", "2018-07-13", action, nil, request, false) if err != nil { if NeedRetry(err) { wait() diff --git a/alicloud/service_alicloud_cas.go b/alicloud/service_alicloud_cas.go index c0ead32472c8..aadfcc9a52df 100644 --- a/alicloud/service_alicloud_cas.go +++ b/alicloud/service_alicloud_cas.go @@ -7,7 +7,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" ) @@ -17,24 +16,17 @@ type CasService struct { } func (s *CasService) DescribeSslCertificatesServiceCertificate(id string) (object map[string]interface{}, err error) { + client := s.client var response map[string]interface{} action := "DescribeUserCertificateDetail" - - conn, err := s.client.NewCasClient() - if err != nil { - return nil, WrapError(err) - } - request := map[string]interface{}{ "RegionId": s.client.RegionId, "CertId": 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-07-13"), StringPointer("AK"), nil, request, &runtime) + response, err = client.RpcPost("cas", "2018-07-13", action, nil, request, true) if err != nil { if NeedRetry(err) { wait()