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

Function locationConstraintAssert

lib/Config.js:308–436  ·  view source on GitHub ↗
(locationConstraints)

Source from the content-addressed store, hash-verified

306}
307
308function locationConstraintAssert(locationConstraints) {
309 const supportedBackends = [
310 'mem', 'file', 'scality', 'mongodb', 'tlp', 'crr'
311 ].concat(Object.keys(validExternalBackends));
312 assert(typeof locationConstraints === 'object',
313 'bad config: locationConstraints must be an object');
314 Object.keys(locationConstraints).forEach(l => {
315 assert(typeof locationConstraints[l] === 'object',
316 'bad config: locationConstraints[region] must be an object');
317 assert(typeof locationConstraints[l].type === 'string',
318 'bad config: locationConstraints[region].type is ' +
319 'mandatory and must be a string');
320 assert(supportedBackends.indexOf(locationConstraints[l].type) > -1,
321 'bad config: locationConstraints[region].type must ' +
322 `be one of ${supportedBackends}`);
323 assert(typeof locationConstraints[l].objectId === 'string',
324 'bad config: locationConstraints[region].objectId is ' +
325 'mandatory and must be a unique string across locations');
326 assert(Object.keys(locationConstraints)
327 .filter(loc => (locationConstraints[loc].objectId ===
328 locationConstraints[l].objectId))
329 .length === 1,
330 'bad config: location constraint objectId ' +
331 `"${locationConstraints[l].objectId}" is not unique across ` +
332 'configured locations');
333 assert(typeof locationConstraints[l].legacyAwsBehavior
334 === 'boolean',
335 'bad config: locationConstraints[region]' +
336 '.legacyAwsBehavior is mandatory and must be a boolean');
337 assert(['undefined', 'boolean'].includes(
338 typeof locationConstraints[l].isTransient),
339 'bad config: locationConstraints[region]' +
340 '.isTransient must be a boolean');
341 if (locationConstraints[l].sizeLimitGB !== undefined) {
342 assert(typeof locationConstraints[l].sizeLimitGB === 'number' ||
343 locationConstraints[l].sizeLimitGB === null,
344 'bad config: locationConstraints[region].sizeLimitGB ' +
345 'must be a number (in gigabytes)');
346 }
347
348 const details = locationConstraints[l].details;
349 assert(typeof details === 'object',
350 'bad config: locationConstraints[region].details is ' +
351 'mandatory and must be an object');
352 if (details.serverSideEncryption !== undefined) {
353 assert(typeof details.serverSideEncryption === 'boolean',
354 'bad config: locationConstraints[region]' +
355 '.details.serverSideEncryption must be a boolean');
356 }
357 const stringFields = [
358 'awsEndpoint',
359 'bucketName',
360 'credentialsProfile',
361 'region',
362 ];
363 stringFields.forEach(field => {
364 if (details[field] !== undefined) {
365 assert(typeof details[field] === 'string',

Callers 3

_getLocationConfigMethod · 0.85
Config.jsFile · 0.85

Tested by

no test coverage detected