MCPcopy
hub / github.com/scality/cloudserver / buildVeeamFileData

Function buildVeeamFileData

lib/routes/veeam/utils.js:261–303  ·  view source on GitHub ↗

* Builds Veeam file data (XML content + response metadata) for a given request. * * @param {object} request - incoming request * @param {object} bucketMd - bucket metadata from the router * @param {object} log - logger object * @returns {Promise } result with { xmlContent, dataBuffer, mo

(request, bucketMd, log)

Source from the content-addressed store, hash-verified

259 * @returns {Promise<object>} result with { xmlContent, dataBuffer, modified, bucketData }
260 */
261async function buildVeeamFileData(request, bucketMd, log) {
262 let data;
263 try {
264 data = await getBucket(request.bucketName, log);
265 } catch {
266 log.error('error fetching bucket metadata', { bucket: request.bucketName });
267 throw errors.InternalError;
268 }
269
270 const fileToBuild = getFileToBuild(request, data._capabilities?.VeeamSOSApi);
271
272 if (fileToBuild.error) {
273 throw fileToBuild.error;
274 }
275
276 let bucketMetrics;
277 if (!isSystemXML(request.objectKey)) {
278 try {
279 bucketMetrics = await fetchCapacityMetrics(bucketMd, request, log);
280 } catch {
281 log.error('error fetching capacity metrics for bucket', { bucket: request.bucketName });
282 throw errors.InternalError;
283 }
284 } else {
285 bucketMetrics = { date: new Date() };
286 }
287
288 const modified = bucketMetrics.date;
289 if (bucketMetrics.bytesTotal !== undefined
290 && fileToBuild.value.CapacityInfo
291 && !fileToBuild.value.CapacityInfo.Used) {
292 fileToBuild.value.CapacityInfo.Used = Number(bucketMetrics.bytesTotal);
293 fileToBuild.value.CapacityInfo.Available =
294 Number(fileToBuild.value.CapacityInfo.Capacity) - Number(bucketMetrics.bytesTotal);
295 // TODO CLDSRV-633 when SUR backend supports realtime metrics: it will
296 // report the real last cseq/date processed by SUR, instead of the current date,
297 // ensuring no issue in a SOSAPI context. We should use this information.
298 }
299
300 const xmlContent = buildXML(fileToBuild.value);
301 const dataBuffer = Buffer.from(xmlContent);
302 return { xmlContent, dataBuffer, modified, bucketData: data };
303}
304
305module.exports = {
306 _decodeURI,

Callers 3

headVeeamFileFunction · 0.85
getVeeamFileFunction · 0.85
veeam-utils.jsFile · 0.85

Calls 5

getFileToBuildFunction · 0.85
isSystemXMLFunction · 0.85
fetchCapacityMetricsFunction · 0.85
errorMethod · 0.80
buildXMLFunction · 0.70

Tested by

no test coverage detected