MCPcopy Create free account
hub / github.com/aliyun/openapi-core-nodejs-sdk / request

Method request

lib/rpc.js:164–260  ·  view source on GitHub ↗
(action, params = {}, opts = {})

Source from the content-addressed store, hash-verified

162 }
163
164 async request(action, params = {}, opts = {}) {
165 const credentials = await this.credentialsProvider.getCredentials();
166 // 1. compose params and opts
167 opts = Object.assign({
168 headers: {
169 'x-sdk-client': helper.DEFAULT_CLIENT,
170 'user-agent': helper.DEFAULT_UA,
171 'x-acs-action': action,
172 'x-acs-version': this.apiVersion
173 }
174 }, this.opts, opts);
175
176 // format action until formatAction is false
177 if (opts.formatAction !== false) {
178 action = firstLetterUpper(action);
179 }
180
181 // format params until formatParams is false
182 if (opts.formatParams !== false) {
183 params = formatParams(params);
184 }
185 const defaultParams = {
186 Format: 'JSON',
187 Timestamp: timestamp(),
188 Version: this.apiVersion,
189 };
190 if (credentials && credentials.accessKeyId && credentials.accessKeySecret) {
191 defaultParams.SignatureMethod = 'HMAC-SHA1';
192 defaultParams.SignatureVersion = '1.0';
193 defaultParams.SignatureNonce = kitx.makeNonce();
194 defaultParams.AccessKeyId = credentials.accessKeyId;
195 if (credentials.securityToken) {
196 defaultParams.SecurityToken = credentials.securityToken;
197 }
198 }
199 params = Object.assign({ Action: action }, defaultParams, params);
200
201 const method = (opts.method || 'GET').toUpperCase();
202 const normalized = normalize(params);
203 // 2. caculate signature
204 if (credentials && credentials.accessKeyId && credentials.accessKeySecret) {
205 const canonicalized = canonicalize(normalized);
206 // 2.1 get string to sign
207 const stringToSign = `${method}&${encode('/')}&${encode(canonicalized)}`;
208 // 2.2 get signature
209 const key = credentials.accessKeySecret + '&';
210 const signature = kitx.sha1(stringToSign, key, 'base64');
211 // add signature
212 normalized.push(['Signature', encode(signature)]);
213 }
214
215 // 3. generate final url
216 const url = opts.method === 'POST' ? `${this.endpoint}/` : `${this.endpoint}/?${canonicalize(normalized)}`;
217 // 4. send request
218 const entry = {
219 url: url,
220 request: null,
221 response: null

Callers 4

rpc.integration.jsFile · 0.45
rpc.test.jsFile · 0.45
roa.integration.jsFile · 0.45
roa.test.jsFile · 0.45

Calls 6

firstLetterUpperFunction · 0.85
formatParamsFunction · 0.85
timestampFunction · 0.85
normalizeFunction · 0.85
canonicalizeFunction · 0.85
encodeFunction · 0.85

Tested by

no test coverage detected