1 |
|
2 |
|
3 |
|
4 |
|
5 | import Util, * as $Util from '@alicloud/tea-util';
|
6 | import Credential, * as $Credential from '@alicloud/credentials';
|
7 | import OpenApiUtil from '@alicloud/openapi-util';
|
8 | import SPI, * as $SPI from '@alicloud/gateway-spi';
|
9 | import XML from '@alicloud/tea-xml';
|
10 | import { Readable } from 'stream';
|
11 | import * as $tea from '@alicloud/tea-typescript';
|
12 |
|
13 | export class GlobalParameters extends $tea.Model {
|
14 | headers?: { [key: string]: string };
|
15 | queries?: { [key: string]: string };
|
16 | static names(): { [key: string]: string } {
|
17 | return {
|
18 | headers: 'headers',
|
19 | queries: 'queries',
|
20 | };
|
21 | }
|
22 |
|
23 | static types(): { [key: string]: any } {
|
24 | return {
|
25 | headers: { 'type': 'map', 'keyType': 'string', 'valueType': 'string' },
|
26 | queries: { 'type': 'map', 'keyType': 'string', 'valueType': 'string' },
|
27 | };
|
28 | }
|
29 |
|
30 | constructor(map?: { [key: string]: any }) {
|
31 | super(map);
|
32 | }
|
33 | }
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | export class Config extends $tea.Model {
|
39 | accessKeyId?: string;
|
40 | accessKeySecret?: string;
|
41 | securityToken?: string;
|
42 | protocol?: string;
|
43 | method?: string;
|
44 | regionId?: string;
|
45 | readTimeout?: number;
|
46 | connectTimeout?: number;
|
47 | httpProxy?: string;
|
48 | httpsProxy?: string;
|
49 | credential?: Credential;
|
50 | endpoint?: string;
|
51 | noProxy?: string;
|
52 | maxIdleConns?: number;
|
53 | network?: string;
|
54 | userAgent?: string;
|
55 | suffix?: string;
|
56 | socks5Proxy?: string;
|
57 | socks5NetWork?: string;
|
58 | endpointType?: string;
|
59 | openPlatformEndpoint?: string;
|
60 | type?: string;
|
61 | signatureVersion?: string;
|
62 | signatureAlgorithm?: string;
|
63 | globalParameters?: GlobalParameters;
|
64 | key?: string;
|
65 | cert?: string;
|
66 | ca?: string;
|
67 | static names(): { [key: string]: string } {
|
68 | return {
|
69 | accessKeyId: 'accessKeyId',
|
70 | accessKeySecret: 'accessKeySecret',
|
71 | securityToken: 'securityToken',
|
72 | protocol: 'protocol',
|
73 | method: 'method',
|
74 | regionId: 'regionId',
|
75 | readTimeout: 'readTimeout',
|
76 | connectTimeout: 'connectTimeout',
|
77 | httpProxy: 'httpProxy',
|
78 | httpsProxy: 'httpsProxy',
|
79 | credential: 'credential',
|
80 | endpoint: 'endpoint',
|
81 | noProxy: 'noProxy',
|
82 | maxIdleConns: 'maxIdleConns',
|
83 | network: 'network',
|
84 | userAgent: 'userAgent',
|
85 | suffix: 'suffix',
|
86 | socks5Proxy: 'socks5Proxy',
|
87 | socks5NetWork: 'socks5NetWork',
|
88 | endpointType: 'endpointType',
|
89 | openPlatformEndpoint: 'openPlatformEndpoint',
|
90 | type: 'type',
|
91 | signatureVersion: 'signatureVersion',
|
92 | signatureAlgorithm: 'signatureAlgorithm',
|
93 | globalParameters: 'globalParameters',
|
94 | key: 'key',
|
95 | cert: 'cert',
|
96 | ca: 'ca',
|
97 | };
|
98 | }
|
99 |
|
100 | static types(): { [key: string]: any } {
|
101 | return {
|
102 | accessKeyId: 'string',
|
103 | accessKeySecret: 'string',
|
104 | securityToken: 'string',
|
105 | protocol: 'string',
|
106 | method: 'string',
|
107 | regionId: 'string',
|
108 | readTimeout: 'number',
|
109 | connectTimeout: 'number',
|
110 | httpProxy: 'string',
|
111 | httpsProxy: 'string',
|
112 | credential: Credential,
|
113 | endpoint: 'string',
|
114 | noProxy: 'string',
|
115 | maxIdleConns: 'number',
|
116 | network: 'string',
|
117 | userAgent: 'string',
|
118 | suffix: 'string',
|
119 | socks5Proxy: 'string',
|
120 | socks5NetWork: 'string',
|
121 | endpointType: 'string',
|
122 | openPlatformEndpoint: 'string',
|
123 | type: 'string',
|
124 | signatureVersion: 'string',
|
125 | signatureAlgorithm: 'string',
|
126 | globalParameters: GlobalParameters,
|
127 | key: 'string',
|
128 | cert: 'string',
|
129 | ca: 'string',
|
130 | };
|
131 | }
|
132 |
|
133 | constructor(map?: { [key: string]: any }) {
|
134 | super(map);
|
135 | }
|
136 | }
|
137 |
|
138 | export class OpenApiRequest extends $tea.Model {
|
139 | headers?: { [key: string]: string };
|
140 | query?: { [key: string]: string };
|
141 | body?: any;
|
142 | stream?: Readable;
|
143 | hostMap?: { [key: string]: string };
|
144 | endpointOverride?: string;
|
145 | static names(): { [key: string]: string } {
|
146 | return {
|
147 | headers: 'headers',
|
148 | query: 'query',
|
149 | body: 'body',
|
150 | stream: 'stream',
|
151 | hostMap: 'hostMap',
|
152 | endpointOverride: 'endpointOverride',
|
153 | };
|
154 | }
|
155 |
|
156 | static types(): { [key: string]: any } {
|
157 | return {
|
158 | headers: { 'type': 'map', 'keyType': 'string', 'valueType': 'string' },
|
159 | query: { 'type': 'map', 'keyType': 'string', 'valueType': 'string' },
|
160 | body: 'any',
|
161 | stream: 'Readable',
|
162 | hostMap: { 'type': 'map', 'keyType': 'string', 'valueType': 'string' },
|
163 | endpointOverride: 'string',
|
164 | };
|
165 | }
|
166 |
|
167 | constructor(map?: { [key: string]: any }) {
|
168 | super(map);
|
169 | }
|
170 | }
|
171 |
|
172 | export class Params extends $tea.Model {
|
173 | action: string;
|
174 | version: string;
|
175 | protocol: string;
|
176 | pathname: string;
|
177 | method: string;
|
178 | authType: string;
|
179 | bodyType: string;
|
180 | reqBodyType: string;
|
181 | style?: string;
|
182 | static names(): { [key: string]: string } {
|
183 | return {
|
184 | action: 'action',
|
185 | version: 'version',
|
186 | protocol: 'protocol',
|
187 | pathname: 'pathname',
|
188 | method: 'method',
|
189 | authType: 'authType',
|
190 | bodyType: 'bodyType',
|
191 | reqBodyType: 'reqBodyType',
|
192 | style: 'style',
|
193 | };
|
194 | }
|
195 |
|
196 | static types(): { [key: string]: any } {
|
197 | return {
|
198 | action: 'string',
|
199 | version: 'string',
|
200 | protocol: 'string',
|
201 | pathname: 'string',
|
202 | method: 'string',
|
203 | authType: 'string',
|
204 | bodyType: 'string',
|
205 | reqBodyType: 'string',
|
206 | style: 'string',
|
207 | };
|
208 | }
|
209 |
|
210 | constructor(map?: { [key: string]: any }) {
|
211 | super(map);
|
212 | }
|
213 | }
|
214 |
|
215 |
|
216 | export default class Client {
|
217 | _endpoint: string;
|
218 | _regionId: string;
|
219 | _protocol: string;
|
220 | _method: string;
|
221 | _userAgent: string;
|
222 | _endpointRule: string;
|
223 | _endpointMap: {[key: string ]: string};
|
224 | _suffix: string;
|
225 | _readTimeout: number;
|
226 | _connectTimeout: number;
|
227 | _httpProxy: string;
|
228 | _httpsProxy: string;
|
229 | _socks5Proxy: string;
|
230 | _socks5NetWork: string;
|
231 | _noProxy: string;
|
232 | _network: string;
|
233 | _productId: string;
|
234 | _maxIdleConns: number;
|
235 | _endpointType: string;
|
236 | _openPlatformEndpoint: string;
|
237 | _credential: Credential;
|
238 | _signatureVersion: string;
|
239 | _signatureAlgorithm: string;
|
240 | _headers: {[key: string ]: string};
|
241 | _spi: SPI;
|
242 | _globalParameters: GlobalParameters;
|
243 | _key: string;
|
244 | _cert: string;
|
245 | _ca: string;
|
246 |
|
247 | |
248 |
|
249 |
|
250 |
|
251 | constructor(config: Config) {
|
252 | if (Util.isUnset(config)) {
|
253 | throw $tea.newError({
|
254 | code: "ParameterMissing",
|
255 | message: "'config' can not be unset",
|
256 | });
|
257 | }
|
258 |
|
259 | if (!Util.empty(config.accessKeyId) && !Util.empty(config.accessKeySecret)) {
|
260 | if (!Util.empty(config.securityToken)) {
|
261 | config.type = "sts";
|
262 | } else {
|
263 | config.type = "access_key";
|
264 | }
|
265 |
|
266 | let credentialConfig = new $Credential.Config({
|
267 | accessKeyId: config.accessKeyId,
|
268 | type: config.type,
|
269 | accessKeySecret: config.accessKeySecret,
|
270 | });
|
271 | credentialConfig.securityToken = config.securityToken;
|
272 | this._credential = new Credential(credentialConfig);
|
273 | } else if (!Util.isUnset(config.credential)) {
|
274 | this._credential = config.credential;
|
275 | }
|
276 |
|
277 | this._endpoint = config.endpoint;
|
278 | this._endpointType = config.endpointType;
|
279 | this._network = config.network;
|
280 | this._suffix = config.suffix;
|
281 | this._protocol = config.protocol;
|
282 | this._method = config.method;
|
283 | this._regionId = config.regionId;
|
284 | this._userAgent = config.userAgent;
|
285 | this._readTimeout = config.readTimeout;
|
286 | this._connectTimeout = config.connectTimeout;
|
287 | this._httpProxy = config.httpProxy;
|
288 | this._httpsProxy = config.httpsProxy;
|
289 | this._noProxy = config.noProxy;
|
290 | this._socks5Proxy = config.socks5Proxy;
|
291 | this._socks5NetWork = config.socks5NetWork;
|
292 | this._maxIdleConns = config.maxIdleConns;
|
293 | this._signatureVersion = config.signatureVersion;
|
294 | this._signatureAlgorithm = config.signatureAlgorithm;
|
295 | this._globalParameters = config.globalParameters;
|
296 | this._key = config.key;
|
297 | this._cert = config.cert;
|
298 | this._ca = config.ca;
|
299 | }
|
300 |
|
301 | |
302 |
|
303 |
|
304 |
|
305 |
|
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 | async doRPCRequest(action: string, version: string, protocol: string, method: string, authType: string, bodyType: string, request: OpenApiRequest, runtime: $Util.RuntimeOptions): Promise<{[key: string]: any}> {
|
314 | let _runtime: { [key: string]: any } = {
|
315 | timeouted: "retry",
|
316 | key: Util.defaultString(runtime.key, this._key),
|
317 | cert: Util.defaultString(runtime.cert, this._cert),
|
318 | ca: Util.defaultString(runtime.ca, this._ca),
|
319 | readTimeout: Util.defaultNumber(runtime.readTimeout, this._readTimeout),
|
320 | connectTimeout: Util.defaultNumber(runtime.connectTimeout, this._connectTimeout),
|
321 | httpProxy: Util.defaultString(runtime.httpProxy, this._httpProxy),
|
322 | httpsProxy: Util.defaultString(runtime.httpsProxy, this._httpsProxy),
|
323 | noProxy: Util.defaultString(runtime.noProxy, this._noProxy),
|
324 | socks5Proxy: Util.defaultString(runtime.socks5Proxy, this._socks5Proxy),
|
325 | socks5NetWork: Util.defaultString(runtime.socks5NetWork, this._socks5NetWork),
|
326 | maxIdleConns: Util.defaultNumber(runtime.maxIdleConns, this._maxIdleConns),
|
327 | retry: {
|
328 | retryable: runtime.autoretry,
|
329 | maxAttempts: Util.defaultNumber(runtime.maxAttempts, 3),
|
330 | },
|
331 | backoff: {
|
332 | policy: Util.defaultString(runtime.backoffPolicy, "no"),
|
333 | period: Util.defaultNumber(runtime.backoffPeriod, 1),
|
334 | },
|
335 | ignoreSSL: runtime.ignoreSSL,
|
336 | }
|
337 |
|
338 | let _lastRequest = null;
|
339 | let _now = Date.now();
|
340 | let _retryTimes = 0;
|
341 | while ($tea.allowRetry(_runtime['retry'], _retryTimes, _now)) {
|
342 | if (_retryTimes > 0) {
|
343 | let _backoffTime = $tea.getBackoffTime(_runtime['backoff'], _retryTimes);
|
344 | if (_backoffTime > 0) {
|
345 | await $tea.sleep(_backoffTime);
|
346 | }
|
347 | }
|
348 |
|
349 | _retryTimes = _retryTimes + 1;
|
350 | try {
|
351 | let request_ = new $tea.Request();
|
352 | request_.protocol = Util.defaultString(this._protocol, protocol);
|
353 | request_.method = method;
|
354 | request_.pathname = "/";
|
355 | let globalQueries : {[key: string ]: string} = { };
|
356 | let globalHeaders : {[key: string ]: string} = { };
|
357 | if (!Util.isUnset(this._globalParameters)) {
|
358 | let globalParams = this._globalParameters;
|
359 | if (!Util.isUnset(globalParams.queries)) {
|
360 | globalQueries = globalParams.queries;
|
361 | }
|
362 |
|
363 | if (!Util.isUnset(globalParams.headers)) {
|
364 | globalHeaders = globalParams.headers;
|
365 | }
|
366 |
|
367 | }
|
368 |
|
369 | request_.query = {
|
370 | Action: action,
|
371 | Format: "json",
|
372 | Version: version,
|
373 | Timestamp: OpenApiUtil.getTimestamp(),
|
374 | SignatureNonce: Util.getNonce(),
|
375 | ...globalQueries,
|
376 | ...request.query,
|
377 | };
|
378 | let headers = this.getRpcHeaders();
|
379 | if (Util.isUnset(headers)) {
|
380 |
|
381 | request_.headers = {
|
382 | host: this._endpoint,
|
383 | 'x-acs-version': version,
|
384 | 'x-acs-action': action,
|
385 | 'user-agent': this.getUserAgent(),
|
386 | ...globalHeaders,
|
387 | };
|
388 | } else {
|
389 | request_.headers = {
|
390 | host: this._endpoint,
|
391 | 'x-acs-version': version,
|
392 | 'x-acs-action': action,
|
393 | 'user-agent': this.getUserAgent(),
|
394 | ...globalHeaders,
|
395 | ...headers,
|
396 | };
|
397 | }
|
398 |
|
399 | if (!Util.isUnset(request.body)) {
|
400 | let m = Util.assertAsMap(request.body);
|
401 | let tmp = Util.anyifyMapValue(OpenApiUtil.query(m));
|
402 | request_.body = new $tea.BytesReadable(Util.toFormString(tmp));
|
403 | request_.headers["content-type"] = "application/x-www-form-urlencoded";
|
404 | }
|
405 |
|
406 | if (!Util.equalString(authType, "Anonymous")) {
|
407 | let accessKeyId = await this.getAccessKeyId();
|
408 | let accessKeySecret = await this.getAccessKeySecret();
|
409 | let securityToken = await this.getSecurityToken();
|
410 | if (!Util.empty(securityToken)) {
|
411 | request_.query["SecurityToken"] = securityToken;
|
412 | }
|
413 |
|
414 | request_.query["SignatureMethod"] = "HMAC-SHA1";
|
415 | request_.query["SignatureVersion"] = "1.0";
|
416 | request_.query["AccessKeyId"] = accessKeyId;
|
417 | let t : {[key: string ]: any} = null;
|
418 | if (!Util.isUnset(request.body)) {
|
419 | t = Util.assertAsMap(request.body);
|
420 | }
|
421 |
|
422 | let signedParam = {
|
423 | ...request_.query,
|
424 | ...OpenApiUtil.query(t),
|
425 | };
|
426 | request_.query["Signature"] = OpenApiUtil.getRPCSignature(signedParam, request_.method, accessKeySecret);
|
427 | }
|
428 |
|
429 | _lastRequest = request_;
|
430 | let response_ = await $tea.doAction(request_, _runtime);
|
431 |
|
432 | if (Util.is4xx(response_.statusCode) || Util.is5xx(response_.statusCode)) {
|
433 | let _res = await Util.readAsJSON(response_.body);
|
434 | let err = Util.assertAsMap(_res);
|
435 | let requestId = Client.defaultAny(err["RequestId"], err["requestId"]);
|
436 | err["statusCode"] = response_.statusCode;
|
437 | throw $tea.newError({
|
438 | code: `${Client.defaultAny(err["Code"], err["code"])}`,
|
439 | message: `code: ${response_.statusCode}, ${Client.defaultAny(err["Message"], err["message"])} request id: ${requestId}`,
|
440 | data: err,
|
441 | description: `${Client.defaultAny(err["Description"], err["description"])}`,
|
442 | accessDeniedDetail: Client.defaultAny(err["AccessDeniedDetail"], err["accessDeniedDetail"]),
|
443 | });
|
444 | }
|
445 |
|
446 | if (Util.equalString(bodyType, "binary")) {
|
447 | let resp = {
|
448 | body: response_.body,
|
449 | headers: response_.headers,
|
450 | statusCode: response_.statusCode,
|
451 | };
|
452 | return resp;
|
453 | } else if (Util.equalString(bodyType, "byte")) {
|
454 | let byt = await Util.readAsBytes(response_.body);
|
455 | return {
|
456 | body: byt,
|
457 | headers: response_.headers,
|
458 | statusCode: response_.statusCode,
|
459 | };
|
460 | } else if (Util.equalString(bodyType, "string")) {
|
461 | let str = await Util.readAsString(response_.body);
|
462 | return {
|
463 | body: str,
|
464 | headers: response_.headers,
|
465 | statusCode: response_.statusCode,
|
466 | };
|
467 | } else if (Util.equalString(bodyType, "json")) {
|
468 | let obj = await Util.readAsJSON(response_.body);
|
469 | let res = Util.assertAsMap(obj);
|
470 | return {
|
471 | body: res,
|
472 | headers: response_.headers,
|
473 | statusCode: response_.statusCode,
|
474 | };
|
475 | } else if (Util.equalString(bodyType, "array")) {
|
476 | let arr = await Util.readAsJSON(response_.body);
|
477 | return {
|
478 | body: arr,
|
479 | headers: response_.headers,
|
480 | statusCode: response_.statusCode,
|
481 | };
|
482 | } else {
|
483 | return {
|
484 | headers: response_.headers,
|
485 | statusCode: response_.statusCode,
|
486 | };
|
487 | }
|
488 |
|
489 | } catch (ex) {
|
490 | if ($tea.isRetryable(ex)) {
|
491 | continue;
|
492 | }
|
493 | throw ex;
|
494 | }
|
495 | }
|
496 |
|
497 | throw $tea.newUnretryableError(_lastRequest);
|
498 | }
|
499 |
|
500 | |
501 |
|
502 |
|
503 |
|
504 |
|
505 |
|
506 |
|
507 |
|
508 |
|
509 |
|
510 |
|
511 |
|
512 |
|
513 | async doROARequest(action: string, version: string, protocol: string, method: string, authType: string, pathname: string, bodyType: string, request: OpenApiRequest, runtime: $Util.RuntimeOptions): Promise<{[key: string]: any}> {
|
514 | let _runtime: { [key: string]: any } = {
|
515 | timeouted: "retry",
|
516 | key: Util.defaultString(runtime.key, this._key),
|
517 | cert: Util.defaultString(runtime.cert, this._cert),
|
518 | ca: Util.defaultString(runtime.ca, this._ca),
|
519 | readTimeout: Util.defaultNumber(runtime.readTimeout, this._readTimeout),
|
520 | connectTimeout: Util.defaultNumber(runtime.connectTimeout, this._connectTimeout),
|
521 | httpProxy: Util.defaultString(runtime.httpProxy, this._httpProxy),
|
522 | httpsProxy: Util.defaultString(runtime.httpsProxy, this._httpsProxy),
|
523 | noProxy: Util.defaultString(runtime.noProxy, this._noProxy),
|
524 | socks5Proxy: Util.defaultString(runtime.socks5Proxy, this._socks5Proxy),
|
525 | socks5NetWork: Util.defaultString(runtime.socks5NetWork, this._socks5NetWork),
|
526 | maxIdleConns: Util.defaultNumber(runtime.maxIdleConns, this._maxIdleConns),
|
527 | retry: {
|
528 | retryable: runtime.autoretry,
|
529 | maxAttempts: Util.defaultNumber(runtime.maxAttempts, 3),
|
530 | },
|
531 | backoff: {
|
532 | policy: Util.defaultString(runtime.backoffPolicy, "no"),
|
533 | period: Util.defaultNumber(runtime.backoffPeriod, 1),
|
534 | },
|
535 | ignoreSSL: runtime.ignoreSSL,
|
536 | }
|
537 |
|
538 | let _lastRequest = null;
|
539 | let _now = Date.now();
|
540 | let _retryTimes = 0;
|
541 | while ($tea.allowRetry(_runtime['retry'], _retryTimes, _now)) {
|
542 | if (_retryTimes > 0) {
|
543 | let _backoffTime = $tea.getBackoffTime(_runtime['backoff'], _retryTimes);
|
544 | if (_backoffTime > 0) {
|
545 | await $tea.sleep(_backoffTime);
|
546 | }
|
547 | }
|
548 |
|
549 | _retryTimes = _retryTimes + 1;
|
550 | try {
|
551 | let request_ = new $tea.Request();
|
552 | request_.protocol = Util.defaultString(this._protocol, protocol);
|
553 | request_.method = method;
|
554 | request_.pathname = pathname;
|
555 | let globalQueries : {[key: string ]: string} = { };
|
556 | let globalHeaders : {[key: string ]: string} = { };
|
557 | if (!Util.isUnset(this._globalParameters)) {
|
558 | let globalParams = this._globalParameters;
|
559 | if (!Util.isUnset(globalParams.queries)) {
|
560 | globalQueries = globalParams.queries;
|
561 | }
|
562 |
|
563 | if (!Util.isUnset(globalParams.headers)) {
|
564 | globalHeaders = globalParams.headers;
|
565 | }
|
566 |
|
567 | }
|
568 |
|
569 | request_.headers = {
|
570 | date: Util.getDateUTCString(),
|
571 | host: this._endpoint,
|
572 | accept: "application/json",
|
573 | 'x-acs-signature-nonce': Util.getNonce(),
|
574 | 'x-acs-signature-method': "HMAC-SHA1",
|
575 | 'x-acs-signature-version': "1.0",
|
576 | 'x-acs-version': version,
|
577 | 'x-acs-action': action,
|
578 | 'user-agent': Util.getUserAgent(this._userAgent),
|
579 | ...globalHeaders,
|
580 | ...request.headers,
|
581 | };
|
582 | if (!Util.isUnset(request.body)) {
|
583 | request_.body = new $tea.BytesReadable(Util.toJSONString(request.body));
|
584 | request_.headers["content-type"] = "application/json; charset=utf-8";
|
585 | }
|
586 |
|
587 | request_.query = globalQueries;
|
588 | if (!Util.isUnset(request.query)) {
|
589 | request_.query = {
|
590 | ...request_.query,
|
591 | ...request.query,
|
592 | };
|
593 | }
|
594 |
|
595 | if (!Util.equalString(authType, "Anonymous")) {
|
596 | let accessKeyId = await this.getAccessKeyId();
|
597 | let accessKeySecret = await this.getAccessKeySecret();
|
598 | let securityToken = await this.getSecurityToken();
|
599 | if (!Util.empty(securityToken)) {
|
600 | request_.headers["x-acs-accesskey-id"] = accessKeyId;
|
601 | request_.headers["x-acs-security-token"] = securityToken;
|
602 | }
|
603 |
|
604 | let stringToSign = OpenApiUtil.getStringToSign(request_);
|
605 | request_.headers["authorization"] = `acs ${accessKeyId}:${OpenApiUtil.getROASignature(stringToSign, accessKeySecret)}`;
|
606 | }
|
607 |
|
608 | _lastRequest = request_;
|
609 | let response_ = await $tea.doAction(request_, _runtime);
|
610 |
|
611 | if (Util.equalNumber(response_.statusCode, 204)) {
|
612 | return {
|
613 | headers: response_.headers,
|
614 | };
|
615 | }
|
616 |
|
617 | if (Util.is4xx(response_.statusCode) || Util.is5xx(response_.statusCode)) {
|
618 | let _res = await Util.readAsJSON(response_.body);
|
619 | let err = Util.assertAsMap(_res);
|
620 | let requestId = Client.defaultAny(err["RequestId"], err["requestId"]);
|
621 | requestId = Client.defaultAny(requestId, err["requestid"]);
|
622 | err["statusCode"] = response_.statusCode;
|
623 | throw $tea.newError({
|
624 | code: `${Client.defaultAny(err["Code"], err["code"])}`,
|
625 | message: `code: ${response_.statusCode}, ${Client.defaultAny(err["Message"], err["message"])} request id: ${requestId}`,
|
626 | data: err,
|
627 | description: `${Client.defaultAny(err["Description"], err["description"])}`,
|
628 | accessDeniedDetail: Client.defaultAny(err["AccessDeniedDetail"], err["accessDeniedDetail"]),
|
629 | });
|
630 | }
|
631 |
|
632 | if (Util.equalString(bodyType, "binary")) {
|
633 | let resp = {
|
634 | body: response_.body,
|
635 | headers: response_.headers,
|
636 | statusCode: response_.statusCode,
|
637 | };
|
638 | return resp;
|
639 | } else if (Util.equalString(bodyType, "byte")) {
|
640 | let byt = await Util.readAsBytes(response_.body);
|
641 | return {
|
642 | body: byt,
|
643 | headers: response_.headers,
|
644 | statusCode: response_.statusCode,
|
645 | };
|
646 | } else if (Util.equalString(bodyType, "string")) {
|
647 | let str = await Util.readAsString(response_.body);
|
648 | return {
|
649 | body: str,
|
650 | headers: response_.headers,
|
651 | statusCode: response_.statusCode,
|
652 | };
|
653 | } else if (Util.equalString(bodyType, "json")) {
|
654 | let obj = await Util.readAsJSON(response_.body);
|
655 | let res = Util.assertAsMap(obj);
|
656 | return {
|
657 | body: res,
|
658 | headers: response_.headers,
|
659 | statusCode: response_.statusCode,
|
660 | };
|
661 | } else if (Util.equalString(bodyType, "array")) {
|
662 | let arr = await Util.readAsJSON(response_.body);
|
663 | return {
|
664 | body: arr,
|
665 | headers: response_.headers,
|
666 | statusCode: response_.statusCode,
|
667 | };
|
668 | } else {
|
669 | return {
|
670 | headers: response_.headers,
|
671 | statusCode: response_.statusCode,
|
672 | };
|
673 | }
|
674 |
|
675 | } catch (ex) {
|
676 | if ($tea.isRetryable(ex)) {
|
677 | continue;
|
678 | }
|
679 | throw ex;
|
680 | }
|
681 | }
|
682 |
|
683 | throw $tea.newUnretryableError(_lastRequest);
|
684 | }
|
685 |
|
686 | |
687 |
|
688 |
|
689 |
|
690 |
|
691 |
|
692 |
|
693 |
|
694 |
|
695 |
|
696 |
|
697 |
|
698 |
|
699 | async doROARequestWithForm(action: string, version: string, protocol: string, method: string, authType: string, pathname: string, bodyType: string, request: OpenApiRequest, runtime: $Util.RuntimeOptions): Promise<{[key: string]: any}> {
|
700 | let _runtime: { [key: string]: any } = {
|
701 | timeouted: "retry",
|
702 | key: Util.defaultString(runtime.key, this._key),
|
703 | cert: Util.defaultString(runtime.cert, this._cert),
|
704 | ca: Util.defaultString(runtime.ca, this._ca),
|
705 | readTimeout: Util.defaultNumber(runtime.readTimeout, this._readTimeout),
|
706 | connectTimeout: Util.defaultNumber(runtime.connectTimeout, this._connectTimeout),
|
707 | httpProxy: Util.defaultString(runtime.httpProxy, this._httpProxy),
|
708 | httpsProxy: Util.defaultString(runtime.httpsProxy, this._httpsProxy),
|
709 | noProxy: Util.defaultString(runtime.noProxy, this._noProxy),
|
710 | socks5Proxy: Util.defaultString(runtime.socks5Proxy, this._socks5Proxy),
|
711 | socks5NetWork: Util.defaultString(runtime.socks5NetWork, this._socks5NetWork),
|
712 | maxIdleConns: Util.defaultNumber(runtime.maxIdleConns, this._maxIdleConns),
|
713 | retry: {
|
714 | retryable: runtime.autoretry,
|
715 | maxAttempts: Util.defaultNumber(runtime.maxAttempts, 3),
|
716 | },
|
717 | backoff: {
|
718 | policy: Util.defaultString(runtime.backoffPolicy, "no"),
|
719 | period: Util.defaultNumber(runtime.backoffPeriod, 1),
|
720 | },
|
721 | ignoreSSL: runtime.ignoreSSL,
|
722 | }
|
723 |
|
724 | let _lastRequest = null;
|
725 | let _now = Date.now();
|
726 | let _retryTimes = 0;
|
727 | while ($tea.allowRetry(_runtime['retry'], _retryTimes, _now)) {
|
728 | if (_retryTimes > 0) {
|
729 | let _backoffTime = $tea.getBackoffTime(_runtime['backoff'], _retryTimes);
|
730 | if (_backoffTime > 0) {
|
731 | await $tea.sleep(_backoffTime);
|
732 | }
|
733 | }
|
734 |
|
735 | _retryTimes = _retryTimes + 1;
|
736 | try {
|
737 | let request_ = new $tea.Request();
|
738 | request_.protocol = Util.defaultString(this._protocol, protocol);
|
739 | request_.method = method;
|
740 | request_.pathname = pathname;
|
741 | let globalQueries : {[key: string ]: string} = { };
|
742 | let globalHeaders : {[key: string ]: string} = { };
|
743 | if (!Util.isUnset(this._globalParameters)) {
|
744 | let globalParams = this._globalParameters;
|
745 | if (!Util.isUnset(globalParams.queries)) {
|
746 | globalQueries = globalParams.queries;
|
747 | }
|
748 |
|
749 | if (!Util.isUnset(globalParams.headers)) {
|
750 | globalHeaders = globalParams.headers;
|
751 | }
|
752 |
|
753 | }
|
754 |
|
755 | request_.headers = {
|
756 | date: Util.getDateUTCString(),
|
757 | host: this._endpoint,
|
758 | accept: "application/json",
|
759 | 'x-acs-signature-nonce': Util.getNonce(),
|
760 | 'x-acs-signature-method': "HMAC-SHA1",
|
761 | 'x-acs-signature-version': "1.0",
|
762 | 'x-acs-version': version,
|
763 | 'x-acs-action': action,
|
764 | 'user-agent': Util.getUserAgent(this._userAgent),
|
765 | ...globalHeaders,
|
766 | ...request.headers,
|
767 | };
|
768 | if (!Util.isUnset(request.body)) {
|
769 | let m = Util.assertAsMap(request.body);
|
770 | request_.body = new $tea.BytesReadable(OpenApiUtil.toForm(m));
|
771 | request_.headers["content-type"] = "application/x-www-form-urlencoded";
|
772 | }
|
773 |
|
774 | request_.query = globalQueries;
|
775 | if (!Util.isUnset(request.query)) {
|
776 | request_.query = {
|
777 | ...request_.query,
|
778 | ...request.query,
|
779 | };
|
780 | }
|
781 |
|
782 | if (!Util.equalString(authType, "Anonymous")) {
|
783 | let accessKeyId = await this.getAccessKeyId();
|
784 | let accessKeySecret = await this.getAccessKeySecret();
|
785 | let securityToken = await this.getSecurityToken();
|
786 | if (!Util.empty(securityToken)) {
|
787 | request_.headers["x-acs-accesskey-id"] = accessKeyId;
|
788 | request_.headers["x-acs-security-token"] = securityToken;
|
789 | }
|
790 |
|
791 | let stringToSign = OpenApiUtil.getStringToSign(request_);
|
792 | request_.headers["authorization"] = `acs ${accessKeyId}:${OpenApiUtil.getROASignature(stringToSign, accessKeySecret)}`;
|
793 | }
|
794 |
|
795 | _lastRequest = request_;
|
796 | let response_ = await $tea.doAction(request_, _runtime);
|
797 |
|
798 | if (Util.equalNumber(response_.statusCode, 204)) {
|
799 | return {
|
800 | headers: response_.headers,
|
801 | };
|
802 | }
|
803 |
|
804 | if (Util.is4xx(response_.statusCode) || Util.is5xx(response_.statusCode)) {
|
805 | let _res = await Util.readAsJSON(response_.body);
|
806 | let err = Util.assertAsMap(_res);
|
807 | err["statusCode"] = response_.statusCode;
|
808 | throw $tea.newError({
|
809 | code: `${Client.defaultAny(err["Code"], err["code"])}`,
|
810 | message: `code: ${response_.statusCode}, ${Client.defaultAny(err["Message"], err["message"])} request id: ${Client.defaultAny(err["RequestId"], err["requestId"])}`,
|
811 | data: err,
|
812 | description: `${Client.defaultAny(err["Description"], err["description"])}`,
|
813 | accessDeniedDetail: Client.defaultAny(err["AccessDeniedDetail"], err["accessDeniedDetail"]),
|
814 | });
|
815 | }
|
816 |
|
817 | if (Util.equalString(bodyType, "binary")) {
|
818 | let resp = {
|
819 | body: response_.body,
|
820 | headers: response_.headers,
|
821 | statusCode: response_.statusCode,
|
822 | };
|
823 | return resp;
|
824 | } else if (Util.equalString(bodyType, "byte")) {
|
825 | let byt = await Util.readAsBytes(response_.body);
|
826 | return {
|
827 | body: byt,
|
828 | headers: response_.headers,
|
829 | statusCode: response_.statusCode,
|
830 | };
|
831 | } else if (Util.equalString(bodyType, "string")) {
|
832 | let str = await Util.readAsString(response_.body);
|
833 | return {
|
834 | body: str,
|
835 | headers: response_.headers,
|
836 | statusCode: response_.statusCode,
|
837 | };
|
838 | } else if (Util.equalString(bodyType, "json")) {
|
839 | let obj = await Util.readAsJSON(response_.body);
|
840 | let res = Util.assertAsMap(obj);
|
841 | return {
|
842 | body: res,
|
843 | headers: response_.headers,
|
844 | statusCode: response_.statusCode,
|
845 | };
|
846 | } else if (Util.equalString(bodyType, "array")) {
|
847 | let arr = await Util.readAsJSON(response_.body);
|
848 | return {
|
849 | body: arr,
|
850 | headers: response_.headers,
|
851 | statusCode: response_.statusCode,
|
852 | };
|
853 | } else {
|
854 | return {
|
855 | headers: response_.headers,
|
856 | statusCode: response_.statusCode,
|
857 | };
|
858 | }
|
859 |
|
860 | } catch (ex) {
|
861 | if ($tea.isRetryable(ex)) {
|
862 | continue;
|
863 | }
|
864 | throw ex;
|
865 | }
|
866 | }
|
867 |
|
868 | throw $tea.newUnretryableError(_lastRequest);
|
869 | }
|
870 |
|
871 | |
872 |
|
873 |
|
874 |
|
875 |
|
876 |
|
877 |
|
878 |
|
879 |
|
880 |
|
881 |
|
882 |
|
883 | async doRequest(params: Params, request: OpenApiRequest, runtime: $Util.RuntimeOptions): Promise<{[key: string]: any}> {
|
884 | let _runtime: { [key: string]: any } = {
|
885 | timeouted: "retry",
|
886 | key: Util.defaultString(runtime.key, this._key),
|
887 | cert: Util.defaultString(runtime.cert, this._cert),
|
888 | ca: Util.defaultString(runtime.ca, this._ca),
|
889 | readTimeout: Util.defaultNumber(runtime.readTimeout, this._readTimeout),
|
890 | connectTimeout: Util.defaultNumber(runtime.connectTimeout, this._connectTimeout),
|
891 | httpProxy: Util.defaultString(runtime.httpProxy, this._httpProxy),
|
892 | httpsProxy: Util.defaultString(runtime.httpsProxy, this._httpsProxy),
|
893 | noProxy: Util.defaultString(runtime.noProxy, this._noProxy),
|
894 | socks5Proxy: Util.defaultString(runtime.socks5Proxy, this._socks5Proxy),
|
895 | socks5NetWork: Util.defaultString(runtime.socks5NetWork, this._socks5NetWork),
|
896 | maxIdleConns: Util.defaultNumber(runtime.maxIdleConns, this._maxIdleConns),
|
897 | retry: {
|
898 | retryable: runtime.autoretry,
|
899 | maxAttempts: Util.defaultNumber(runtime.maxAttempts, 3),
|
900 | },
|
901 | backoff: {
|
902 | policy: Util.defaultString(runtime.backoffPolicy, "no"),
|
903 | period: Util.defaultNumber(runtime.backoffPeriod, 1),
|
904 | },
|
905 | ignoreSSL: runtime.ignoreSSL,
|
906 | }
|
907 |
|
908 | let _lastRequest = null;
|
909 | let _now = Date.now();
|
910 | let _retryTimes = 0;
|
911 | while ($tea.allowRetry(_runtime['retry'], _retryTimes, _now)) {
|
912 | if (_retryTimes > 0) {
|
913 | let _backoffTime = $tea.getBackoffTime(_runtime['backoff'], _retryTimes);
|
914 | if (_backoffTime > 0) {
|
915 | await $tea.sleep(_backoffTime);
|
916 | }
|
917 | }
|
918 |
|
919 | _retryTimes = _retryTimes + 1;
|
920 | try {
|
921 | let request_ = new $tea.Request();
|
922 | request_.protocol = Util.defaultString(this._protocol, params.protocol);
|
923 | request_.method = params.method;
|
924 | request_.pathname = params.pathname;
|
925 | let globalQueries : {[key: string ]: string} = { };
|
926 | let globalHeaders : {[key: string ]: string} = { };
|
927 | if (!Util.isUnset(this._globalParameters)) {
|
928 | let globalParams = this._globalParameters;
|
929 | if (!Util.isUnset(globalParams.queries)) {
|
930 | globalQueries = globalParams.queries;
|
931 | }
|
932 |
|
933 | if (!Util.isUnset(globalParams.headers)) {
|
934 | globalHeaders = globalParams.headers;
|
935 | }
|
936 |
|
937 | }
|
938 |
|
939 | request_.query = {
|
940 | ...globalQueries,
|
941 | ...request.query,
|
942 | };
|
943 |
|
944 | request_.headers = {
|
945 | host: this._endpoint,
|
946 | 'x-acs-version': params.version,
|
947 | 'x-acs-action': params.action,
|
948 | 'user-agent': this.getUserAgent(),
|
949 | 'x-acs-date': OpenApiUtil.getTimestamp(),
|
950 | 'x-acs-signature-nonce': Util.getNonce(),
|
951 | accept: "application/json",
|
952 | ...globalHeaders,
|
953 | ...request.headers,
|
954 | };
|
955 | if (Util.equalString(params.style, "RPC")) {
|
956 | let headers = this.getRpcHeaders();
|
957 | if (!Util.isUnset(headers)) {
|
958 | request_.headers = {
|
959 | ...request_.headers,
|
960 | ...headers,
|
961 | };
|
962 | }
|
963 |
|
964 | }
|
965 |
|
966 | let signatureAlgorithm = Util.defaultString(this._signatureAlgorithm, "ACS3-HMAC-SHA256");
|
967 | let hashedRequestPayload = OpenApiUtil.hexEncode(OpenApiUtil.hash(Util.toBytes(""), signatureAlgorithm));
|
968 | if (!Util.isUnset(request.stream)) {
|
969 | let tmp = await Util.readAsBytes(request.stream);
|
970 | hashedRequestPayload = OpenApiUtil.hexEncode(OpenApiUtil.hash(tmp, signatureAlgorithm));
|
971 | request_.body = new $tea.BytesReadable(tmp);
|
972 | request_.headers["content-type"] = "application/octet-stream";
|
973 | } else {
|
974 | if (!Util.isUnset(request.body)) {
|
975 | if (Util.equalString(params.reqBodyType, "json")) {
|
976 | let jsonObj = Util.toJSONString(request.body);
|
977 | hashedRequestPayload = OpenApiUtil.hexEncode(OpenApiUtil.hash(Util.toBytes(jsonObj), signatureAlgorithm));
|
978 | request_.body = new $tea.BytesReadable(jsonObj);
|
979 | request_.headers["content-type"] = "application/json; charset=utf-8";
|
980 | } else {
|
981 | let m = Util.assertAsMap(request.body);
|
982 | let formObj = OpenApiUtil.toForm(m);
|
983 | hashedRequestPayload = OpenApiUtil.hexEncode(OpenApiUtil.hash(Util.toBytes(formObj), signatureAlgorithm));
|
984 | request_.body = new $tea.BytesReadable(formObj);
|
985 | request_.headers["content-type"] = "application/x-www-form-urlencoded";
|
986 | }
|
987 |
|
988 | }
|
989 |
|
990 | }
|
991 |
|
992 | request_.headers["x-acs-content-sha256"] = hashedRequestPayload;
|
993 | if (!Util.equalString(params.authType, "Anonymous")) {
|
994 | let authType = await this.getType();
|
995 | if (Util.equalString(authType, "bearer")) {
|
996 | let bearerToken = await this.getBearerToken();
|
997 | request_.headers["x-acs-bearer-token"] = bearerToken;
|
998 | } else {
|
999 | let accessKeyId = await this.getAccessKeyId();
|
1000 | let accessKeySecret = await this.getAccessKeySecret();
|
1001 | let securityToken = await this.getSecurityToken();
|
1002 | if (!Util.empty(securityToken)) {
|
1003 | request_.headers["x-acs-accesskey-id"] = accessKeyId;
|
1004 | request_.headers["x-acs-security-token"] = securityToken;
|
1005 | }
|
1006 |
|
1007 | request_.headers["Authorization"] = OpenApiUtil.getAuthorization(request_, signatureAlgorithm, hashedRequestPayload, accessKeyId, accessKeySecret);
|
1008 | }
|
1009 |
|
1010 | }
|
1011 |
|
1012 | _lastRequest = request_;
|
1013 | let response_ = await $tea.doAction(request_, _runtime);
|
1014 |
|
1015 | if (Util.is4xx(response_.statusCode) || Util.is5xx(response_.statusCode)) {
|
1016 | let err : {[key: string ]: any} = { };
|
1017 | if (!Util.isUnset(response_.headers["content-type"]) && Util.equalString(response_.headers["content-type"], "text/xml;charset=utf-8")) {
|
1018 | let _str = await Util.readAsString(response_.body);
|
1019 | let respMap = XML.parseXml(_str, null);
|
1020 | err = Util.assertAsMap(respMap["Error"]);
|
1021 | } else {
|
1022 | let _res = await Util.readAsJSON(response_.body);
|
1023 | err = Util.assertAsMap(_res);
|
1024 | }
|
1025 |
|
1026 | err["statusCode"] = response_.statusCode;
|
1027 | throw $tea.newError({
|
1028 | code: `${Client.defaultAny(err["Code"], err["code"])}`,
|
1029 | message: `code: ${response_.statusCode}, ${Client.defaultAny(err["Message"], err["message"])} request id: ${Client.defaultAny(err["RequestId"], err["requestId"])}`,
|
1030 | data: err,
|
1031 | description: `${Client.defaultAny(err["Description"], err["description"])}`,
|
1032 | accessDeniedDetail: Client.defaultAny(err["AccessDeniedDetail"], err["accessDeniedDetail"]),
|
1033 | });
|
1034 | }
|
1035 |
|
1036 | if (Util.equalString(params.bodyType, "binary")) {
|
1037 | let resp = {
|
1038 | body: response_.body,
|
1039 | headers: response_.headers,
|
1040 | statusCode: response_.statusCode,
|
1041 | };
|
1042 | return resp;
|
1043 | } else if (Util.equalString(params.bodyType, "byte")) {
|
1044 | let byt = await Util.readAsBytes(response_.body);
|
1045 | return {
|
1046 | body: byt,
|
1047 | headers: response_.headers,
|
1048 | statusCode: response_.statusCode,
|
1049 | };
|
1050 | } else if (Util.equalString(params.bodyType, "string")) {
|
1051 | let str = await Util.readAsString(response_.body);
|
1052 | return {
|
1053 | body: str,
|
1054 | headers: response_.headers,
|
1055 | statusCode: response_.statusCode,
|
1056 | };
|
1057 | } else if (Util.equalString(params.bodyType, "json")) {
|
1058 | let obj = await Util.readAsJSON(response_.body);
|
1059 | let res = Util.assertAsMap(obj);
|
1060 | return {
|
1061 | body: res,
|
1062 | headers: response_.headers,
|
1063 | statusCode: response_.statusCode,
|
1064 | };
|
1065 | } else if (Util.equalString(params.bodyType, "array")) {
|
1066 | let arr = await Util.readAsJSON(response_.body);
|
1067 | return {
|
1068 | body: arr,
|
1069 | headers: response_.headers,
|
1070 | statusCode: response_.statusCode,
|
1071 | };
|
1072 | } else {
|
1073 | return {
|
1074 | headers: response_.headers,
|
1075 | statusCode: response_.statusCode,
|
1076 | };
|
1077 | }
|
1078 |
|
1079 | } catch (ex) {
|
1080 | if ($tea.isRetryable(ex)) {
|
1081 | continue;
|
1082 | }
|
1083 | throw ex;
|
1084 | }
|
1085 | }
|
1086 |
|
1087 | throw $tea.newUnretryableError(_lastRequest);
|
1088 | }
|
1089 |
|
1090 | |
1091 |
|
1092 |
|
1093 |
|
1094 |
|
1095 |
|
1096 |
|
1097 |
|
1098 |
|
1099 |
|
1100 |
|
1101 |
|
1102 | async execute(params: Params, request: OpenApiRequest, runtime: $Util.RuntimeOptions): Promise<{[key: string]: any}> {
|
1103 | let _runtime: { [key: string]: any } = {
|
1104 | timeouted: "retry",
|
1105 | key: Util.defaultString(runtime.key, this._key),
|
1106 | cert: Util.defaultString(runtime.cert, this._cert),
|
1107 | ca: Util.defaultString(runtime.ca, this._ca),
|
1108 | readTimeout: Util.defaultNumber(runtime.readTimeout, this._readTimeout),
|
1109 | connectTimeout: Util.defaultNumber(runtime.connectTimeout, this._connectTimeout),
|
1110 | httpProxy: Util.defaultString(runtime.httpProxy, this._httpProxy),
|
1111 | httpsProxy: Util.defaultString(runtime.httpsProxy, this._httpsProxy),
|
1112 | noProxy: Util.defaultString(runtime.noProxy, this._noProxy),
|
1113 | socks5Proxy: Util.defaultString(runtime.socks5Proxy, this._socks5Proxy),
|
1114 | socks5NetWork: Util.defaultString(runtime.socks5NetWork, this._socks5NetWork),
|
1115 | maxIdleConns: Util.defaultNumber(runtime.maxIdleConns, this._maxIdleConns),
|
1116 | retry: {
|
1117 | retryable: runtime.autoretry,
|
1118 | maxAttempts: Util.defaultNumber(runtime.maxAttempts, 3),
|
1119 | },
|
1120 | backoff: {
|
1121 | policy: Util.defaultString(runtime.backoffPolicy, "no"),
|
1122 | period: Util.defaultNumber(runtime.backoffPeriod, 1),
|
1123 | },
|
1124 | ignoreSSL: runtime.ignoreSSL,
|
1125 | }
|
1126 |
|
1127 | let _lastRequest = null;
|
1128 | let _now = Date.now();
|
1129 | let _retryTimes = 0;
|
1130 | while ($tea.allowRetry(_runtime['retry'], _retryTimes, _now)) {
|
1131 | if (_retryTimes > 0) {
|
1132 | let _backoffTime = $tea.getBackoffTime(_runtime['backoff'], _retryTimes);
|
1133 | if (_backoffTime > 0) {
|
1134 | await $tea.sleep(_backoffTime);
|
1135 | }
|
1136 | }
|
1137 |
|
1138 | _retryTimes = _retryTimes + 1;
|
1139 | try {
|
1140 | let request_ = new $tea.Request();
|
1141 |
|
1142 | let headers = this.getRpcHeaders();
|
1143 | let globalQueries : {[key: string ]: string} = { };
|
1144 | let globalHeaders : {[key: string ]: string} = { };
|
1145 | if (!Util.isUnset(this._globalParameters)) {
|
1146 | let globalParams = this._globalParameters;
|
1147 | if (!Util.isUnset(globalParams.queries)) {
|
1148 | globalQueries = globalParams.queries;
|
1149 | }
|
1150 |
|
1151 | if (!Util.isUnset(globalParams.headers)) {
|
1152 | globalHeaders = globalParams.headers;
|
1153 | }
|
1154 |
|
1155 | }
|
1156 |
|
1157 | let requestContext = new $SPI.InterceptorContextRequest({
|
1158 | headers: {
|
1159 | ...globalHeaders,
|
1160 | ...request.headers,
|
1161 | ...headers,
|
1162 | },
|
1163 | query: {
|
1164 | ...globalQueries,
|
1165 | ...request.query,
|
1166 | },
|
1167 | body: request.body,
|
1168 | stream: request.stream,
|
1169 | hostMap: request.hostMap,
|
1170 | pathname: params.pathname,
|
1171 | productId: this._productId,
|
1172 | action: params.action,
|
1173 | version: params.version,
|
1174 | protocol: Util.defaultString(this._protocol, params.protocol),
|
1175 | method: Util.defaultString(this._method, params.method),
|
1176 | authType: params.authType,
|
1177 | bodyType: params.bodyType,
|
1178 | reqBodyType: params.reqBodyType,
|
1179 | style: params.style,
|
1180 | credential: this._credential,
|
1181 | signatureVersion: this._signatureVersion,
|
1182 | signatureAlgorithm: this._signatureAlgorithm,
|
1183 | userAgent: this.getUserAgent(),
|
1184 | });
|
1185 | let configurationContext = new $SPI.InterceptorContextConfiguration({
|
1186 | regionId: this._regionId,
|
1187 | endpoint: Util.defaultString(request.endpointOverride, this._endpoint),
|
1188 | endpointRule: this._endpointRule,
|
1189 | endpointMap: this._endpointMap,
|
1190 | endpointType: this._endpointType,
|
1191 | network: this._network,
|
1192 | suffix: this._suffix,
|
1193 | });
|
1194 | let interceptorContext = new $SPI.InterceptorContext({
|
1195 | request: requestContext,
|
1196 | configuration: configurationContext,
|
1197 | });
|
1198 | let attributeMap = new $SPI.AttributeMap({ });
|
1199 |
|
1200 | await this._spi.modifyConfiguration(interceptorContext, attributeMap);
|
1201 |
|
1202 | await this._spi.modifyRequest(interceptorContext, attributeMap);
|
1203 | request_.protocol = interceptorContext.request.protocol;
|
1204 | request_.method = interceptorContext.request.method;
|
1205 | request_.pathname = interceptorContext.request.pathname;
|
1206 | request_.query = interceptorContext.request.query;
|
1207 | request_.body = interceptorContext.request.stream;
|
1208 | request_.headers = interceptorContext.request.headers;
|
1209 | _lastRequest = request_;
|
1210 | let response_ = await $tea.doAction(request_, _runtime);
|
1211 |
|
1212 | let responseContext = new $SPI.InterceptorContextResponse({
|
1213 | statusCode: response_.statusCode,
|
1214 | headers: response_.headers,
|
1215 | body: response_.body,
|
1216 | });
|
1217 | interceptorContext.response = responseContext;
|
1218 |
|
1219 | await this._spi.modifyResponse(interceptorContext, attributeMap);
|
1220 | return {
|
1221 | headers: interceptorContext.response.headers,
|
1222 | statusCode: interceptorContext.response.statusCode,
|
1223 | body: interceptorContext.response.deserializedBody,
|
1224 | };
|
1225 | } catch (ex) {
|
1226 | if ($tea.isRetryable(ex)) {
|
1227 | continue;
|
1228 | }
|
1229 | throw ex;
|
1230 | }
|
1231 | }
|
1232 |
|
1233 | throw $tea.newUnretryableError(_lastRequest);
|
1234 | }
|
1235 |
|
1236 | async callApi(params: Params, request: OpenApiRequest, runtime: $Util.RuntimeOptions): Promise<{[key: string]: any}> {
|
1237 | if (Util.isUnset(params)) {
|
1238 | throw $tea.newError({
|
1239 | code: "ParameterMissing",
|
1240 | message: "'params' can not be unset",
|
1241 | });
|
1242 | }
|
1243 |
|
1244 | if (Util.isUnset(this._signatureAlgorithm) || !Util.equalString(this._signatureAlgorithm, "v2")) {
|
1245 | return await this.doRequest(params, request, runtime);
|
1246 | } else if (Util.equalString(params.style, "ROA") && Util.equalString(params.reqBodyType, "json")) {
|
1247 | return await this.doROARequest(params.action, params.version, params.protocol, params.method, params.authType, params.pathname, params.bodyType, request, runtime);
|
1248 | } else if (Util.equalString(params.style, "ROA")) {
|
1249 | return await this.doROARequestWithForm(params.action, params.version, params.protocol, params.method, params.authType, params.pathname, params.bodyType, request, runtime);
|
1250 | } else {
|
1251 | return await this.doRPCRequest(params.action, params.version, params.protocol, params.method, params.authType, params.bodyType, request, runtime);
|
1252 | }
|
1253 |
|
1254 | }
|
1255 |
|
1256 | |
1257 |
|
1258 |
|
1259 |
|
1260 | getUserAgent(): string {
|
1261 | let userAgent = Util.getUserAgent(this._userAgent);
|
1262 | return userAgent;
|
1263 | }
|
1264 |
|
1265 | |
1266 |
|
1267 |
|
1268 |
|
1269 | async getAccessKeyId(): Promise<string> {
|
1270 | if (Util.isUnset(this._credential)) {
|
1271 | return "";
|
1272 | }
|
1273 |
|
1274 | let accessKeyId = await this._credential.getAccessKeyId();
|
1275 | return accessKeyId;
|
1276 | }
|
1277 |
|
1278 | |
1279 |
|
1280 |
|
1281 |
|
1282 | async getAccessKeySecret(): Promise<string> {
|
1283 | if (Util.isUnset(this._credential)) {
|
1284 | return "";
|
1285 | }
|
1286 |
|
1287 | let secret = await this._credential.getAccessKeySecret();
|
1288 | return secret;
|
1289 | }
|
1290 |
|
1291 | |
1292 |
|
1293 |
|
1294 |
|
1295 | async getSecurityToken(): Promise<string> {
|
1296 | if (Util.isUnset(this._credential)) {
|
1297 | return "";
|
1298 | }
|
1299 |
|
1300 | let token = await this._credential.getSecurityToken();
|
1301 | return token;
|
1302 | }
|
1303 |
|
1304 | |
1305 |
|
1306 |
|
1307 |
|
1308 | async getBearerToken(): Promise<string> {
|
1309 | if (Util.isUnset(this._credential)) {
|
1310 | return "";
|
1311 | }
|
1312 |
|
1313 | let token = this._credential.getBearerToken();
|
1314 | return token;
|
1315 | }
|
1316 |
|
1317 | |
1318 |
|
1319 |
|
1320 |
|
1321 | async getType(): Promise<string> {
|
1322 | if (Util.isUnset(this._credential)) {
|
1323 | return "";
|
1324 | }
|
1325 |
|
1326 | let authType = this._credential.getType();
|
1327 | return authType;
|
1328 | }
|
1329 |
|
1330 | |
1331 |
|
1332 |
|
1333 |
|
1334 |
|
1335 |
|
1336 | static defaultAny(inputValue: any, defaultValue: any): any {
|
1337 | if (Util.isUnset(inputValue)) {
|
1338 | return defaultValue;
|
1339 | }
|
1340 |
|
1341 | return inputValue;
|
1342 | }
|
1343 |
|
1344 | |
1345 |
|
1346 |
|
1347 |
|
1348 | checkConfig(config: Config): void {
|
1349 | if (Util.empty(this._endpointRule) && Util.empty(config.endpoint)) {
|
1350 | throw $tea.newError({
|
1351 | code: "ParameterMissing",
|
1352 | message: "'config.endpoint' can not be empty",
|
1353 | });
|
1354 | }
|
1355 |
|
1356 | }
|
1357 |
|
1358 | |
1359 |
|
1360 |
|
1361 |
|
1362 | setGatewayClient(spi: SPI): void {
|
1363 | this._spi = spi;
|
1364 | }
|
1365 |
|
1366 | |
1367 |
|
1368 |
|
1369 |
|
1370 | setRpcHeaders(headers: {[key: string ]: string}): void {
|
1371 | this._headers = headers;
|
1372 | }
|
1373 |
|
1374 | |
1375 |
|
1376 |
|
1377 | getRpcHeaders(): {[key: string ]: string} {
|
1378 | let headers : {[key: string ]: string} = this._headers;
|
1379 | this._headers = null;
|
1380 | return headers;
|
1381 | }
|
1382 |
|
1383 | }
|