Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const constants = {
},
},
/* eslint-disable camelcase */
externalBackends: { aws_s3: true, azure: true, gcp: true, pfs: true, dmf: true, azure_archive: true },
externalBackends: { aws_s3: true, azure: true, gcp: true, pfs: true, tlp: true },
// some of the available data backends (if called directly rather
// than through the multiple backend gateway) need a key provided
// as a string as first parameter of the get/delete methods.
Expand Down
116 changes: 12 additions & 104 deletions lib/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,104 +300,10 @@ function hdClientLocationConstraintAssert(configHd) {
return hdclientFields;
}

function azureArchiveLocationConstraintAssert(locationObj) {
const checkedFields = [
'azureContainerName',
'azureStorageEndpoint',
];
if (Object.keys(locationObj.details).length === 0 ||
!checkedFields.every(field => field in locationObj.details)) {
return;
}
const {
azureContainerName,
azureStorageEndpoint,
} = locationObj.details;
const stringFields = [
azureContainerName,
azureStorageEndpoint,
];
stringFields.forEach(field => {
assert(typeof field === 'string',
`bad config: ${field} must be a string`);
});

let hasAuthMethod = false;
if (locationObj.details.sasToken !== undefined) {
assert(typeof locationObj.details.sasToken === 'string',
`bad config: ${locationObj.details.sasToken} must be a string`);
hasAuthMethod = true;
}

if (locationObj.details.azureStorageAccountName !== undefined &&
locationObj.details.azureStorageAccessKey !== undefined) {
assert(typeof locationObj.details.azureStorageAccountName === 'string',
`bad config: ${locationObj.details.azureStorageAccountName} must be a string`);
assert(typeof locationObj.details.azureStorageAccessKey === 'string',
`bad config: ${locationObj.details.azureStorageAccessKey} must be a string`);
assert(!hasAuthMethod, 'Multiple authentication methods are not allowed');
hasAuthMethod = true;
}

if (locationObj.details.tenantId !== undefined &&
locationObj.details.clientId !== undefined &&
locationObj.details.clientKey !== undefined) {
assert(typeof locationObj.details.tenantId === 'string',
`bad config: ${locationObj.details.tenantId} must be a string`);
assert(typeof locationObj.details.clientId === 'string',
`bad config: ${locationObj.details.clientId} must be a string`);
assert(typeof locationObj.details.clientKey === 'string',
`bad config: ${locationObj.details.clientKey} must be a string`);
assert(!hasAuthMethod, 'Multiple authentication methods are not allowed');
hasAuthMethod = true;
}
assert(hasAuthMethod, 'Missing authentication method');
}

function dmfLocationConstraintAssert(locationObj) {
const checkedFields = [
'endpoint',
'username',
'password',
'repoId',
'nsId',
];
if (Object.keys(locationObj.details).length === 0 ||
!checkedFields.every(field => field in locationObj.details)) {
return;
}
const {
endpoint,
username,
password,
repoId,
nsId,
} = locationObj.details;
const stringFields = [
endpoint,
username,
password,
nsId,
];
stringFields.forEach(field => {
assert(typeof field === 'string',
`bad config: ${field} must be a string`);
});
assert.strictEqual(Array.isArray(repoId), true);
repoId.forEach(rId => {
assert(typeof rId === 'string',
`bad config: ${rId} must be a string`);
});
assert(repoId.every(
r => typeof r === 'string'),
'bad config: each repoId must be a string',
);
}

function locationConstraintAssert(locationConstraints) {
const supportedBackends =
['mem', 'file', 'scality',
'mongodb', 'dmf', 'azure_archive'].concat(Object.keys(validExternalBackends));
const supportedBackends = [
'mem', 'file', 'scality', 'mongodb', 'tlp',
].concat(Object.keys(validExternalBackends));
assert(typeof locationConstraints === 'object',
'bad config: locationConstraints must be an object');
Object.keys(locationConstraints).forEach(l => {
Expand Down Expand Up @@ -467,6 +373,15 @@ function locationConstraintAssert(locationConstraints) {
assert(typeof details.credentials.secretKey === 'string',
'bad config: credentials must include secretKey as string');
}

if (locationConstraints[l].type === 'tlp') {
// should have no detail
assert(Object.keys(locationConstraints[l].details).length === 0);

// should be a cold location
assert(locationConstraints[l].isCold === true);
}
Comment on lines +377 to +383
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we stop validating the locations here? is it because we rely on the validation at the location creation time? If yes, can we put a comment?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean "stop" validating locations?

  • we keep the whole validation, there is no early exit
  • we do not store any details anymore (as they are useless for cloudserver, and contain secrets), so the validation of these details is now removed, and we now check that details is indeed empty
  • the block was just moved early to simplify testing no details are provided (since default fields are added later in the process)


if (process.env.CI_CEPH === 'true') {
// eslint-disable-next-line no-param-reassign
locationConstraints[l].details.https = false;
Expand Down Expand Up @@ -505,12 +420,6 @@ function locationConstraintAssert(locationConstraints) {
if (locationConstraints[l].type === 'gcp') {
gcpLocationConstraintAssert(l, locationConstraints[l]);
}
if (locationConstraints[l].type === 'dmf') {
dmfLocationConstraintAssert(locationConstraints[l]);
}
if (locationConstraints[l].type === 'azure_archive') {
azureArchiveLocationConstraintAssert(locationConstraints[l]);
}
if (locationConstraints[l].type === 'pfs') {
assert(typeof details.pfsDaemonEndpoint === 'object',
'bad config: pfsDaemonEndpoint is mandatory and must be an object');
Expand Down Expand Up @@ -2006,6 +1915,5 @@ module.exports = {
bucketNotifAssert,
azureGetStorageAccountName,
azureGetLocationCredentials,
azureArchiveLocationConstraintAssert,
parseSupportedLifecycleRules,
};
4 changes: 2 additions & 2 deletions locationConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@
"details": {}
},
"location-dmf-v1": {
"type": "dmf",
"type": "tlp",
"objectId": "location-dmf-v1",
"legacyAwsBehavior": false,
"isCold": true,
"details": {}
},
"location-azure-archive-v1": {
"type": "azure_archive",
"type": "tlp",
"objectId": "location-azure-archive-v1",
"legacyAwsBehavior": false,
"isCold": true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenko/cloudserver",
"version": "9.0.4",
"version": "9.0.5",
"description": "Zenko CloudServer, an open-source Node.js implementation of a server handling the Amazon S3 protocol",
"main": "index.js",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion tests/locationConfig/locationConfigCeph.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@
"isTransient": true
},
"location-dmf-v1": {
"type": "dmf",
"type": "tlp",
"objectId": "location-dmf-v1",
"legacyAwsBehavior": false,
"isCold": true,
Expand Down
2 changes: 1 addition & 1 deletion tests/locationConfig/locationConfigLegacy.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
"isTransient": true
},
"location-dmf-v1": {
"type": "dmf",
"type": "tlp",
"objectId": "location-dmf-v1",
"legacyAwsBehavior": false,
"isCold": true,
Expand Down
10 changes: 2 additions & 8 deletions tests/locationConfig/locationConfigTests.json
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,10 @@
"isTransient": true
},
"location-dmf-v1": {
"type": "dmf",
"type": "tlp",
"objectId": "location-dmf-v1",
"legacyAwsBehavior": false,
"isCold": true,
"details": {
"endpoint": "10.0.0.200:24000",
"repoId": ["repo1"],
"username": "username",
"password": "password",
"nsId": "nsId"
}
"details": {}
}
}
Loading
Loading