diff --git a/constants.js b/constants.js index 73e050031a..46bda9c4de 100644 --- a/constants.js +++ b/constants.js @@ -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. diff --git a/lib/Config.js b/lib/Config.js index 38a3d9e897..cab7760b97 100644 --- a/lib/Config.js +++ b/lib/Config.js @@ -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 => { @@ -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); + } + if (process.env.CI_CEPH === 'true') { // eslint-disable-next-line no-param-reassign locationConstraints[l].details.https = false; @@ -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'); @@ -2006,6 +1915,5 @@ module.exports = { bucketNotifAssert, azureGetStorageAccountName, azureGetLocationCredentials, - azureArchiveLocationConstraintAssert, parseSupportedLifecycleRules, }; diff --git a/locationConfig.json b/locationConfig.json index 247f820f56..7b4a94046b 100644 --- a/locationConfig.json +++ b/locationConfig.json @@ -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, diff --git a/package.json b/package.json index 56635fe215..029915c6fa 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/tests/locationConfig/locationConfigCeph.json b/tests/locationConfig/locationConfigCeph.json index e4470aa963..f5746854b3 100644 --- a/tests/locationConfig/locationConfigCeph.json +++ b/tests/locationConfig/locationConfigCeph.json @@ -258,7 +258,7 @@ "isTransient": true }, "location-dmf-v1": { - "type": "dmf", + "type": "tlp", "objectId": "location-dmf-v1", "legacyAwsBehavior": false, "isCold": true, diff --git a/tests/locationConfig/locationConfigLegacy.json b/tests/locationConfig/locationConfigLegacy.json index 6d1cc88ca7..bd22731bfd 100644 --- a/tests/locationConfig/locationConfigLegacy.json +++ b/tests/locationConfig/locationConfigLegacy.json @@ -180,7 +180,7 @@ "isTransient": true }, "location-dmf-v1": { - "type": "dmf", + "type": "tlp", "objectId": "location-dmf-v1", "legacyAwsBehavior": false, "isCold": true, diff --git a/tests/locationConfig/locationConfigTests.json b/tests/locationConfig/locationConfigTests.json index 46ae4919ed..95670be99f 100644 --- a/tests/locationConfig/locationConfigTests.json +++ b/tests/locationConfig/locationConfigTests.json @@ -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": {} } } diff --git a/tests/unit/Config.js b/tests/unit/Config.js index e17d8974a5..5036dc3dfe 100644 --- a/tests/unit/Config.js +++ b/tests/unit/Config.js @@ -1,6 +1,6 @@ const assert = require('assert'); const { - azureArchiveLocationConstraintAssert, + locationConstraintAssert, parseSupportedLifecycleRules, ConfigObject: ConfigObjectForTest, } = require('../../lib/Config'); @@ -262,6 +262,72 @@ describe('Config', () => { }); }); + describe('locationConstraintAssert', () => { + const memLocation = { + 'details': {}, + 'isCold': false, + 'isTransient': false, + 'legacyAwsBehavior': false, + 'locationType': 'location-mem-v1', + 'objectId': 'a9d9b632-5fa5-11ef-8715-b21941dbc3ea', + 'type': 'mem', + }; + + it('should parse tlp location', () => { + const locationConstraints = { + 'dmf-1': { + 'details': {}, + 'isCold': true, + 'legacyAwsBehavior': false, + 'locationType': 'location-dmf-v1', + 'objectId': 'b9d9b632-5fa5-11ef-8715-b21941dbc3ea', + 'type': 'tlp' + }, + 'us-east-1': memLocation, + }; + locationConstraintAssert(locationConstraints); + }); + + it('should fail tlp location is not cold', () => { + const locationConstraints = { + 'dmf-1': { + 'details': {}, + 'isCold': false, + 'legacyAwsBehavior': false, + 'locationType': 'location-dmf-v1', + 'objectId': 'b9d9b632-5fa5-11ef-8715-b21941dbc3ea', + 'type': 'tlp' + }, + 'us-east-1': memLocation, + }; + assert.throws(() => locationConstraintAssert(locationConstraints)); + }); + + it('should fail if tlp location has details', () => { + const locationConstraints = { + 'dmf-1': { + 'details': { + 'endpoint': 'http://localhost:8000', + }, + 'isCold': true, + 'legacyAwsBehavior': false, + 'locationType': 'location-dmf-v1', + 'objectId': 'b9d9b632-5fa5-11ef-8715-b21941dbc3ea', + 'type': 'tlp' + }, + 'us-east-1': memLocation, + }; + assert.throws(() => locationConstraintAssert(locationConstraints)); + }); + + it('should fail if there is no us-east-1 location', () => { + const locationConstraints = { + 'us-west-1': memLocation, + }; + assert.throws(() => locationConstraintAssert(locationConstraints)); + }); + }); + describe('time options', () => { it('should getTimeOptions', () => { const config = new ConfigObjectForTest(); @@ -518,164 +584,6 @@ describe('Config', () => { assert.strictEqual(config.overlayVersion, 0); }); - describe('azureArchiveLocationConstraintAssert', () => { - it('should succeed azureStorageEndpoint is missing', () => { - const locationObj = { - details: { - azureContainerName: 'mycontainer', - } - }; - assert.strictEqual(azureArchiveLocationConstraintAssert(locationObj), undefined); - }); - - it('should succeed if azureContainerName is missing', () => { - const locationObj = { - details: { - azureStorageEndpoint: 'http://test.com/', - } - }; - assert.strictEqual(azureArchiveLocationConstraintAssert(locationObj), undefined); - }); - - it('should succeed if both azureStorageEndpoint and azureContainerName are missing', () => { - const locationObj = { - details: { - } - }; - assert.strictEqual(azureArchiveLocationConstraintAssert(locationObj), undefined); - }); - - it('should fail assert if azureStorageEndpoint is not a string', () => { - const locationObj = { - details: { - azureContainerName: 'mycontainer', - azureStorageEndpoint: true, - } - }; - assert.throws(() => azureArchiveLocationConstraintAssert(locationObj)); - }); - - it('should assert if azureContainerName is not a string', () => { - const locationObj = { - details: { - azureContainerName: 42, - azureStorageEndpoint: 'endpoint', - } - }; - assert.throws(() => azureArchiveLocationConstraintAssert(locationObj)); - }); - - it('should assert if missing an authentication method', () => { - const locationObj = { - details: { - azureContainerName: 'mycontainer', - azureStorageEndpoint: 'endpoint', - } - }; - assert.throws(() => azureArchiveLocationConstraintAssert(locationObj)); - }); - - it('should assert if sasToken is not a string', () => { - const locationObj = { - details: { - azureContainerName: 'mycontainer', - azureStorageEndpoint: 'endpoint', - sasToken: 42, - } - }; - assert.throws(() => azureArchiveLocationConstraintAssert(locationObj)); - }); - - it('should assert if missing azureStorageAccountName but azureStorageAccessKey defined', () => { - const locationObj = { - details: { - azureContainerName: 'mycontainer', - azureStorageEndpoint: 'endpoint', - azureStorageAccessKey: 'key', - } - }; - assert.throws(() => azureArchiveLocationConstraintAssert(locationObj)); - }); - - it('should assert if azureStorageAccountName is not a string', () => { - const locationObj = { - details: { - azureContainerName: 'mycontainer', - azureStorageEndpoint: 'endpoint', - azureStorageAccountName: 42, - azureStorageAccessKey: 'key', - } - }; - assert.throws(() => azureArchiveLocationConstraintAssert(locationObj)); - }); - - it('should assert if azureStorageAccessKey is not a string', () => { - const locationObj = { - details: { - azureContainerName: 'mycontainer', - azureStorageEndpoint: 'endpoint', - azureStorageAccountName: 'account', - azureStorageAccessKey: false, - } - }; - assert.throws(() => azureArchiveLocationConstraintAssert(locationObj)); - }); - - it('should assert if tenantId is not a string', () => { - const locationObj = { - details: { - azureContainerName: 'mycontainer', - azureStorageEndpoint: 'endpoint', - tenantId: 42, - clientId: 'client', - clientKey: 'key', - } - }; - assert.throws(() => azureArchiveLocationConstraintAssert(locationObj)); - }); - - it('should assert if tenantId is not a string', () => { - const locationObj = { - details: { - azureContainerName: 'mycontainer', - azureStorageEndpoint: 'endpoint', - tenantId: 'tenant', - clientId: 42, - clientKey: 'key', - } - }; - assert.throws(() => azureArchiveLocationConstraintAssert(locationObj)); - }); - - it('should assert if tenantId is not a string', () => { - const locationObj = { - details: { - azureContainerName: 'mycontainer', - azureStorageEndpoint: 'endpoint', - tenantId: 'tenant', - clientId: 'client', - clientKey: 42, - } - }; - assert.throws(() => azureArchiveLocationConstraintAssert(locationObj)); - }); - - it('should assert if multiple auth method are provided', () => { - const locationObj = { - details: { - azureContainerName: 'mycontainer', - azureStorageEndpoint: 'endpoint', - tenantId: 'tenant', - clientId: 'client', - clientKey: 'key', - azureStorageAccountName: 'account', - azureStorageAccessKey: 'key', - } - }; - assert.throws(() => azureArchiveLocationConstraintAssert(locationObj)); - }); - }); - describe('parseSupportedLifecycleRules', () => { it('should throw when an empty array is provided', () => { assert.throws(() => parseSupportedLifecycleRules([])); diff --git a/tests/unit/testConfigs/locConstraintAssert.js b/tests/unit/testConfigs/locConstraintAssert.js index 0cf384a4a8..a82dc0ca15 100644 --- a/tests/unit/testConfigs/locConstraintAssert.js +++ b/tests/unit/testConfigs/locConstraintAssert.js @@ -63,7 +63,7 @@ describe('locationConstraintAssert', () => { locationConstraintAssert({ 'scality-east': locationConstraint }); }, /bad config: locationConstraints[region].type must be/ + - /one of mem,file,scality,dmf/); + /one of mem,file,scality,tlp/); }); it('should throw error if legacyAwsBehavior is not a boolean', () => { const locationConstraint = new LocationConstraint(