(serviceUrl)
| 164 | * ``` |
| 165 | */ |
| 166 | export 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 | } |
no test coverage detected