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

Function checkLocationConstraint

lib/api/bucketPut.js:36–73  ·  view source on GitHub ↗

* checkLocationConstraint - check that a location constraint is explicitly * set on the bucket and the value of the location is listed in the * locationConstraint config. * Note: if data backend equals "multiple", you must set a location constraint * @param {object} request - http request object

(request, locationConstraint, log)

Source from the content-addressed store, hash-verified

34 * @return {undefined}
35 */
36function checkLocationConstraint(request, locationConstraint, log) {
37 // AWS JS SDK sends a request with locationConstraint us-east-1 if
38 // no locationConstraint provided.
39 const { parsedHost } = request;
40 let locationConstraintChecked;
41 let locationConstraintAddon;
42 if (locationConstraint) {
43 locationConstraintAddon = locationConstraint.split(zenkoSeparator)[1];
44 locationConstraintChecked = locationConstraint.split(zenkoSeparator)[0];
45 } else if (parsedHost && restEndpoints[parsedHost]) {
46 locationConstraintChecked = restEndpoints[parsedHost];
47 } else {
48 log.trace('no location constraint provided on bucket put;' +
49 'setting us-east-1');
50 locationConstraintChecked = 'us-east-1';
51 }
52
53 if (!locationConstraints[locationConstraintChecked]) {
54 const errMsg = 'value of the location you are attempting to set - ' +
55 `${locationConstraintChecked} - is not listed in the ` +
56 'locationConstraint config';
57 log.trace(`locationConstraint is invalid - ${errMsg}`,
58 { locationConstraint: locationConstraintChecked });
59 return { error: errorInstances.InvalidLocationConstraint.
60 customizeDescription(errMsg) };
61 }
62 if (locationConstraints[locationConstraintChecked].isCold ||
63 locationConstraints[locationConstraintChecked].isCRR) {
64 return { error: errors.InvalidLocationConstraint };
65 }
66 if (locationConstraintAddon) {
67 // We are introducing a new format for location constraints.
68 // with `zenkoSeparator`, we are currently including the ingestion
69 // flag in the location constraint.
70 locationConstraintChecked = locationConstraint;
71 }
72 return { error: null, locationConstraint: locationConstraintChecked };
73}
74
75/*
76 Format of xml request:

Callers 2

_parseXMLFunction · 0.85
bucketPut.jsFile · 0.85

Calls 1

traceMethod · 0.80

Tested by

no test coverage detected