@@ -69,8 +69,8 @@ func (t *transport) handleRPC(req *http.Request) (*http.Response, error) {
6969
7070 host := strings .ToLower (req .URL .Hostname ())
7171 action := strings .TrimSpace (req .URL .Query ().Get ("Action" ))
72- switch host {
73- case "sts.aliyuncs.com " :
72+ switch rpcProductFromHost ( host ) {
73+ case "sts" :
7474 if action == "GetCallerIdentity" {
7575 return jsonResponse (req , http .StatusOK , api.GetCallerIdentityResponse {
7676 IdentityType : "RAMUser" ,
@@ -81,7 +81,7 @@ func (t *transport) handleRPC(req *http.Request) (*http.Response, error) {
8181 Arn : demoCallerArn (),
8282 }), nil
8383 }
84- case "business.aliyuncs.com " :
84+ case "bssopenapi " :
8585 if action == "QueryAccountBalance" {
8686 return jsonResponse (req , http .StatusOK , api.QueryAccountBalanceResponse {
8787 Code : "Success" ,
@@ -93,23 +93,51 @@ func (t *transport) handleRPC(req *http.Request) (*http.Response, error) {
9393 },
9494 }), nil
9595 }
96- case "ecs.aliyuncs.com " :
96+ case "ecs" :
9797 return t .handleECS (req , action )
98- case "ram.aliyuncs.com " :
98+ case "ram" :
9999 return t .handleRAM (req , action )
100- case "rds.aliyuncs.com " :
100+ case "rds" :
101101 return t .handleRDS (req , action )
102- case "tds.aliyuncs.com " :
102+ case "sas " :
103103 return t .handleSAS (req , action )
104- case "alidns.aliyuncs.com " :
104+ case "alidns" :
105105 return t .handleDNS (req , action )
106- case "dysmsapi.aliyuncs.com " :
106+ case "dysmsapi" :
107107 return t .handleSMS (req , action )
108+ case "location" :
109+ return t .handleLocation (req , action )
108110 }
109111
110112 return rpcErrorResponse (req , http .StatusNotFound , "InvalidAction.NotFound" , fmt .Sprintf ("Unsupported replay action: %s" , action )), nil
111113}
112114
115+ func (t * transport ) handleLocation (req * http.Request , action string ) (* http.Response , error ) {
116+ if action != "DescribeEndpoints" {
117+ return rpcErrorResponse (req , http .StatusNotFound , "InvalidAction.NotFound" , fmt .Sprintf ("Unsupported Location replay action: %s" , action )), nil
118+ }
119+
120+ serviceCode := strings .TrimSpace (req .URL .Query ().Get ("ServiceCode" ))
121+ region := strings .TrimSpace (req .URL .Query ().Get ("Id" ))
122+ if region == "" {
123+ region = api .DefaultRegion
124+ }
125+ host := ""
126+ switch serviceCode {
127+ case "ecs" :
128+ host = replayECSEndpoint (region )
129+ }
130+ return jsonResponse (req , http .StatusOK , map [string ]any {
131+ "RequestId" : "req-location-endpoints" ,
132+ "Success" : true ,
133+ "Endpoints" : map [string ]any {
134+ "Endpoint" : []map [string ]string {
135+ {"Endpoint" : host },
136+ },
137+ },
138+ }), nil
139+ }
140+
113141func (t * transport ) handleECS (req * http.Request , action string ) (* http.Response , error ) {
114142 query := req .URL .Query ()
115143 switch action {
@@ -906,6 +934,68 @@ func isSLSHost(req *http.Request) bool {
906934 return strings .Contains (strings .ToLower (req .URL .Hostname ()), ".log.aliyuncs.com" )
907935}
908936
937+ func rpcProductFromHost (host string ) string {
938+ host = normalizeRPCReplayHost (host )
939+ switch {
940+ case host == "sts.aliyuncs.com" || strings .HasPrefix (host , "sts-vpc." ):
941+ return "sts"
942+ case host == "location-readonly.aliyuncs.com" :
943+ return "location"
944+ case host == "business.aliyuncs.com" || strings .HasPrefix (host , "business." ):
945+ return "bssopenapi"
946+ case host == "ram.aliyuncs.com" :
947+ return "ram"
948+ case host == "alidns.aliyuncs.com" :
949+ return "alidns"
950+ case host == "dysmsapi.aliyuncs.com" :
951+ return "dysmsapi"
952+ case host == "tds.aliyuncs.com" :
953+ return "sas"
954+ case isECSRPCHost (host ):
955+ return "ecs"
956+ case isRDSRPCHost (host ):
957+ return "rds"
958+ default :
959+ return ""
960+ }
961+ }
962+
963+ func isECSRPCHost (host string ) bool {
964+ host = normalizeRPCReplayHost (host )
965+ return host == "ecs.aliyuncs.com" ||
966+ strings .HasPrefix (host , "ecs-" ) ||
967+ strings .HasPrefix (host , "ecs." ) ||
968+ strings .HasPrefix (host , "ecs-vpc." )
969+ }
970+
971+ func isRDSRPCHost (host string ) bool {
972+ host = normalizeRPCReplayHost (host )
973+ return host == "rds.aliyuncs.com" ||
974+ strings .HasPrefix (host , "rds-" ) ||
975+ strings .HasPrefix (host , "rds." ) ||
976+ strings .HasPrefix (host , "rds-vpc." )
977+ }
978+
979+ func replayECSEndpoint (region string ) string {
980+ region = strings .TrimSpace (region )
981+ if region == "" {
982+ region = api .DefaultRegion
983+ }
984+ switch {
985+ case strings .HasPrefix (region , "cn-" ):
986+ return "ecs-" + region + ".aliyuncs.com"
987+ default :
988+ return "ecs." + region + ".aliyuncs.com"
989+ }
990+ }
991+
992+ func normalizeRPCReplayHost (host string ) string {
993+ host = strings .ToLower (strings .TrimSpace (host ))
994+ host = strings .TrimSuffix (host , ":443" )
995+ host = strings .TrimSuffix (host , ":80" )
996+ return host
997+ }
998+
909999func requestHost (req * http.Request ) string {
9101000 if req == nil {
9111001 return ""
0 commit comments