MCPcopy Index your code
hub / github.com/SuperMap/iClient-JavaScript / getServiceKey

Function getServiceKey

src/common/util/EncryptRequest.js:166–201  ·  view source on GitHub ↗
(serviceUrl)

Source from the content-addressed store, hash-verified

164 * ```
165 */
166export async function getServiceKey(serviceUrl) {
167 try {
168 const workspaceServerUrl = ((serviceUrl &&
169 serviceUrl.match(/.+(?=(\/restjsr\/v1\/vectortile\/|\/rest\/maps\/|\/rest\/data\/))/)) ||
170 [])[0];
171 if (!workspaceServerUrl) {
172 return;
173 }
174 const servicesResponse = await FetchRequest.get(workspaceServerUrl);
175 const servicesResult = await servicesResponse.json();
176 const matchRestData = (servicesResult || []).find(
177 (item) => serviceUrl.includes(item.name) && item.serviceEncryptInfo
178 );
179 if (!matchRestData) {
180 return;
181 }
182 const iserverHost = workspaceServerUrl.split('/services/')[0];
183 const encryptRequest = new EncryptRequest(iserverHost);
184 const svckeyUrl =
185 matchRestData && `${iserverHost}/services/security/svckeys/${matchRestData.serviceEncryptInfo.encrptKeyID}.json`;
186 const svcReponse = await encryptRequest.request({
187 method: 'get',
188 url: svckeyUrl
189 });
190 const serviceKey = await svcReponse.json();
191 if (!serviceKey) {
192 return;
193 }
194 return {
195 serviceKey,
196 algorithm: matchRestData.serviceEncryptInfo.encrptSpec.algorithm
197 };
198 } catch (error) {
199 console.error(error);
200 }
201}

Callers 3

MapExtend.jsFile · 0.90

Calls 4

requestMethod · 0.95
matchMethod · 0.80
getMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected