sit #11
@@ -107,10 +107,22 @@ async function verify(baseUrls, token, namespace, configGroup, dataId, expectedC
|
||||
const expectedHash = sha256(expectedContent);
|
||||
for (const baseUrl of baseUrls) {
|
||||
const query = new URLSearchParams({ dataId, group: configGroup, tenant: namespace });
|
||||
const response = await fetch(`${baseUrl}/nacos/v1/cs/configs?${query}&accessToken=${encodeURIComponent(token)}`);
|
||||
const content = await response.text();
|
||||
if (!response.ok || sha256(content) !== expectedHash) {
|
||||
throw new Error(`Nacos 配置校验失败:${baseUrl}/${namespace}/${dataId} HTTP ${response.status}`);
|
||||
let lastStatus = 0;
|
||||
let lastContent = '';
|
||||
for (let attempt = 1; attempt <= 3; attempt += 1) {
|
||||
const response = await fetch(`${baseUrl}/nacos/v1/cs/configs?${query}&accessToken=${encodeURIComponent(token)}`);
|
||||
const content = await response.text();
|
||||
lastStatus = response.status;
|
||||
lastContent = content;
|
||||
if (response.ok && sha256(content) === expectedHash) {
|
||||
break;
|
||||
}
|
||||
if (attempt < 3) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
}
|
||||
}
|
||||
if (lastStatus !== 200 || sha256(lastContent) !== expectedHash) {
|
||||
throw new Error(`Nacos 配置校验失败:${baseUrl}/${namespace}/${dataId} HTTP ${lastStatus} ${lastContent.slice(0, 200)}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user