Skip to content

Commit 7258a79

Browse files
committed
♻️ remove useless argument to follow caller
Issue: CLDSRV-878
1 parent 6f9012b commit 7258a79

File tree

5 files changed

+24
-31
lines changed

5 files changed

+24
-31
lines changed

lib/routes/veeam/get.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ async function getVeeamFile(request, response, bucketMd, log) {
2222
}
2323

2424
try {
25-
const result = await buildVeeamFileData(request, bucketMd, log, 'getVeeamFile');
25+
const result = await buildVeeamFileData(request, bucketMd, log);
2626
return await respondWithData(request, response, log, result.bucketData, result.xmlContent, result.modified);
2727
} catch (err) {
2828
return responseXMLBody(err, null, response, log);

lib/routes/veeam/head.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async function headVeeamFile(request, response, bucketMd, log) {
1717
}
1818

1919
try {
20-
const result = await buildVeeamFileData(request, bucketMd, log, 'headVeeamFile');
20+
const result = await buildVeeamFileData(request, bucketMd, log);
2121
return responseContentHeaders(
2222
null,
2323
{},

lib/routes/veeam/list.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ async function listVeeamFiles(request, response, bucketMd, log) {
106106
let bucketMetrics;
107107
if (data._capabilities?.VeeamSOSApi?.CapacityInfo) {
108108
try {
109-
bucketMetrics = await fetchCapacityMetrics(bucketMd, request, log, 'listVeeamFiles');
109+
bucketMetrics = await fetchCapacityMetrics(bucketMd, request, log);
110110
} catch {
111111
return responseXMLBody(errors.InternalError, null, response, log);
112112
}

lib/routes/veeam/utils.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ const UtilizationService = require('../../utilization/instance');
1010
const metadata = require('../../metadata/wrapper');
1111

1212
const pipeline = promisify(streamPipeline);
13-
const getUtilizationMetrics = promisify(UtilizationService.getUtilizationMetrics.bind(UtilizationService));
14-
metadata.getBucketPromised = promisify(metadata.getBucket);
13+
const getUtilizationMetrics = promisify((...args) => UtilizationService.getUtilizationMetrics(...args));
14+
const getBucket = promisify((...args) => metadata.getBucket(...args));
1515

1616
/**
1717
* Decodes an URI and return the result.
@@ -216,22 +216,20 @@ function getFileToBuild(request, data, inlineLastModified = false) {
216216
* @returns {Promise<object>} bucketMetrics always has at least a `date` field;
217217
* on a real 404 the date defaults to new Date()
218218
*/
219-
async function fetchCapacityMetrics(bucketMd, request, log, method) {
219+
async function fetchCapacityMetrics(bucketMd, request, log) {
220220
const bucketKey = `${bucketMd._name}_${new Date(bucketMd._creationDate).getTime()}`;
221221
try {
222222
return await getUtilizationMetrics('bucket', bucketKey, null, {});
223223
} catch (err) {
224224
const statusCode = err.response?.status || err.statusCode || err.code;
225225
if (statusCode === 404) {
226226
log.warn('UtilizationService returned 404 when fetching capacity metrics', {
227-
method,
228227
bucket: request.bucketName,
229228
error: err.message || err.code,
230229
});
231230
return { date: new Date() };
232231
}
233232
log.error('error fetching capacity metrics from UtilizationService', {
234-
method,
235233
bucket: request.bucketName,
236234
error: err.message || err.code,
237235
statusCode,
@@ -246,13 +244,12 @@ async function fetchCapacityMetrics(bucketMd, request, log, method) {
246244
* @param {object} request - incoming request
247245
* @param {object} bucketMd - bucket metadata from the router
248246
* @param {object} log - logger object
249-
* @param {string} name - calling method name (for log context)
250247
* @returns {Promise<object>} result with { xmlContent, dataBuffer, modified, bucketData }
251248
*/
252-
async function buildVeeamFileData(request, bucketMd, log, name) {
249+
async function buildVeeamFileData(request, bucketMd, log) {
253250
let data;
254251
try {
255-
data = await metadata.getBucketPromised(request.bucketName, log);
252+
data = await getBucket(request.bucketName, log);
256253
} catch {
257254
throw errors.InternalError;
258255
}
@@ -266,7 +263,7 @@ async function buildVeeamFileData(request, bucketMd, log, name) {
266263
let bucketMetrics;
267264
if (!isSystemXML(request.objectKey)) {
268265
try {
269-
bucketMetrics = await fetchCapacityMetrics(bucketMd, request, log, name);
266+
bucketMetrics = await fetchCapacityMetrics(bucketMd, request, log);
270267
} catch {
271268
throw errors.InternalError;
272269
}
@@ -275,11 +272,9 @@ async function buildVeeamFileData(request, bucketMd, log, name) {
275272
}
276273

277274
const modified = bucketMetrics.date;
278-
if (
279-
bucketMetrics.bytesTotal !== undefined
275+
if (bucketMetrics.bytesTotal !== undefined
280276
&& fileToBuild.value.CapacityInfo
281-
&& !fileToBuild.value.CapacityInfo.Used
282-
) {
277+
&& !fileToBuild.value.CapacityInfo.Used) {
283278
fileToBuild.value.CapacityInfo.Used = Number(bucketMetrics.bytesTotal);
284279
fileToBuild.value.CapacityInfo.Available =
285280
Number(fileToBuild.value.CapacityInfo.Capacity) - Number(bucketMetrics.bytesTotal);

tests/unit/routes/veeam-utils.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('fetchCapacityMetrics', () => {
3737
it('should call UtilizationService with the correct bucket key', async () => {
3838
utilizationStub.callsArgWith(4, null, {});
3939

40-
await fetchCapacityMetrics(bucketMd, request, log, 'testMethod');
40+
await fetchCapacityMetrics(bucketMd, request, log);
4141

4242
const expectedKey = `test-bucket_${new Date('2024-01-01T00:00:00.000Z').getTime()}`;
4343
assert.strictEqual(utilizationStub.getCall(0).args[0], 'bucket');
@@ -48,7 +48,7 @@ describe('fetchCapacityMetrics', () => {
4848
const bucketMetrics = { bytesTotal: 42, date: '2026-03-26T19:00:08.996Z' };
4949
utilizationStub.callsArgWith(4, null, bucketMetrics);
5050

51-
const metrics = await fetchCapacityMetrics(bucketMd, request, log, 'testMethod');
51+
const metrics = await fetchCapacityMetrics(bucketMd, request, log);
5252

5353
assert.strictEqual(metrics, bucketMetrics);
5454
assert(!logWarnSpy.called);
@@ -60,12 +60,11 @@ describe('fetchCapacityMetrics', () => {
6060
error404.response = { status: 404 };
6161
utilizationStub.callsArgWith(4, error404);
6262

63-
const metrics = await fetchCapacityMetrics(bucketMd, request, log, 'testMethod');
63+
const metrics = await fetchCapacityMetrics(bucketMd, request, log);
6464

6565
assert(metrics && metrics.date instanceof Date, 'metrics should have a Date for date');
6666
assert(logWarnSpy.calledOnce);
6767
assert(logWarnSpy.getCall(0).args[0].includes('404'));
68-
assert.strictEqual(logWarnSpy.getCall(0).args[1].method, 'testMethod');
6968
assert.strictEqual(logWarnSpy.getCall(0).args[1].bucket, 'test-bucket');
7069
assert(!logErrorSpy.called);
7170
});
@@ -75,7 +74,7 @@ describe('fetchCapacityMetrics', () => {
7574
error404.statusCode = 404;
7675
utilizationStub.callsArgWith(4, error404);
7776

78-
const metrics = await fetchCapacityMetrics(bucketMd, request, log, 'testMethod');
77+
const metrics = await fetchCapacityMetrics(bucketMd, request, log);
7978

8079
assert(metrics && metrics.date instanceof Date, 'metrics should have a Date for date');
8180
assert(logWarnSpy.calledOnce);
@@ -87,12 +86,11 @@ describe('fetchCapacityMetrics', () => {
8786
utilizationStub.callsArgWith(4, error500);
8887

8988
await assert.rejects(
90-
fetchCapacityMetrics(bucketMd, request, log, 'testMethod'),
89+
fetchCapacityMetrics(bucketMd, request, log),
9190
err => err === error500,
9291
);
9392

9493
assert(logErrorSpy.calledOnce);
95-
assert.strictEqual(logErrorSpy.getCall(0).args[1].method, 'testMethod');
9694
assert.strictEqual(logErrorSpy.getCall(0).args[1].bucket, 'test-bucket');
9795
assert.strictEqual(logErrorSpy.getCall(0).args[1].statusCode, 500);
9896
assert(!logWarnSpy.called);
@@ -104,7 +102,7 @@ describe('fetchCapacityMetrics', () => {
104102
utilizationStub.callsArgWith(4, connError);
105103

106104
await assert.rejects(
107-
fetchCapacityMetrics(bucketMd, request, log, 'testMethod'),
105+
fetchCapacityMetrics(bucketMd, request, log),
108106
err => err === connError,
109107
);
110108

@@ -174,7 +172,7 @@ describe('buildVeeamFileData', () => {
174172
metadataStub.callsArgWith(2, new Error('DB error'));
175173

176174
await assert.rejects(
177-
buildVeeamFileData(createRequest(capacityObjectKey), bucketMd, log, 'test'),
175+
buildVeeamFileData(createRequest(capacityObjectKey), bucketMd, log),
178176
err => err.code === 500,
179177
);
180178
});
@@ -183,7 +181,7 @@ describe('buildVeeamFileData', () => {
183181
metadataStub.callsArgWith(2, null, { _capabilities: {} });
184182

185183
await assert.rejects(
186-
buildVeeamFileData(createRequest(capacityObjectKey), bucketMd, log, 'test'),
184+
buildVeeamFileData(createRequest(capacityObjectKey), bucketMd, log),
187185
err => err.code === 404,
188186
);
189187
});
@@ -195,7 +193,7 @@ describe('buildVeeamFileData', () => {
195193
utilizationStub.callsArgWith(4, error500);
196194

197195
await assert.rejects(
198-
buildVeeamFileData(createRequest(capacityObjectKey), bucketMd, log, 'test'),
196+
buildVeeamFileData(createRequest(capacityObjectKey), bucketMd, log),
199197
err => err.code === 500,
200198
);
201199
});
@@ -205,7 +203,7 @@ describe('buildVeeamFileData', () => {
205203
metadataStub.callsArgWith(2, null, bucketMd);
206204
utilizationStub.callsArgWith(4, null, { date: metricsDate, bytesTotal: 100 });
207205

208-
const result = await buildVeeamFileData(createRequest(capacityObjectKey), bucketMd, log, 'test');
206+
const result = await buildVeeamFileData(createRequest(capacityObjectKey), bucketMd, log);
209207

210208
assert.strictEqual(result.modified, metricsDate);
211209
assert(result.xmlContent.includes('CapacityInfo'));
@@ -223,7 +221,7 @@ describe('buildVeeamFileData', () => {
223221
error404.response = { status: 404 };
224222
utilizationStub.callsArgWith(4, error404);
225223

226-
const result = await buildVeeamFileData(createRequest(capacityObjectKey), bucketMd, log, 'test');
224+
const result = await buildVeeamFileData(createRequest(capacityObjectKey), bucketMd, log);
227225

228226
assert(result.modified instanceof Date);
229227
assert(result.modified.getTime() >= before);
@@ -234,7 +232,7 @@ describe('buildVeeamFileData', () => {
234232
metadataStub.callsArgWith(2, null, bucketMdWithSystem);
235233
const before = Date.now();
236234

237-
const result = await buildVeeamFileData(createRequest(systemObjectKey), bucketMdWithSystem, log, 'test');
235+
const result = await buildVeeamFileData(createRequest(systemObjectKey), bucketMdWithSystem, log);
238236

239237
assert(!utilizationStub.called, 'should not call UtilizationService for system.xml');
240238
assert(result.modified instanceof Date);
@@ -261,7 +259,7 @@ describe('buildVeeamFileData', () => {
261259
metadataStub.callsArgWith(2, null, bucketMdWithUsed);
262260
utilizationStub.callsArgWith(4, null, { date: new Date(), bytesTotal: 999 });
263261

264-
const result = await buildVeeamFileData(createRequest(capacityObjectKey), bucketMdWithUsed, log, 'test');
262+
const result = await buildVeeamFileData(createRequest(capacityObjectKey), bucketMdWithUsed, log);
265263

266264
assert(result.xmlContent.includes('<Used>400</Used>'), 'should keep existing Used value');
267265
});

0 commit comments

Comments
 (0)