diff --git a/ghost/core/core/server/services/adapter-manager/index.js b/ghost/core/core/server/services/adapter-manager/index.js index 291f763172..7215f4a4a8 100644 --- a/ghost/core/core/server/services/adapter-manager/index.js +++ b/ghost/core/core/server/services/adapter-manager/index.js @@ -26,8 +26,8 @@ module.exports = { getAdapter(name) { const adapterServiceConfig = getAdapterServiceConfig(config); - const {adapterName, adapterConfig} = resolveAdapterOptions(name, adapterServiceConfig); + const {adapterClassName, adapterConfig} = resolveAdapterOptions(name, adapterServiceConfig); - return adapterManager.getAdapter(name, adapterName, adapterConfig); + return adapterManager.getAdapter(name, adapterClassName, adapterConfig); } }; diff --git a/ghost/core/core/server/services/adapter-manager/options-resolver.js b/ghost/core/core/server/services/adapter-manager/options-resolver.js index 7ca05622b1..1866a14eea 100644 --- a/ghost/core/core/server/services/adapter-manager/options-resolver.js +++ b/ghost/core/core/server/services/adapter-manager/options-resolver.js @@ -1,28 +1,39 @@ -module.exports = function resolveAdapterOptions(name, adapterServiceConfig) { +/** + * Resolves full configuration for an adapter. Combining base class configurations + * along with feature-specific ones + * + * @param {String} name + * @param {Object} adapterServiceConfig + * + * @returns {{adapterClassName: String, adapterConfig: Object}} + */ +const resolveAdapterOptions = (name, adapterServiceConfig) => { const [adapterType, feature] = name.split(':'); const adapterSettings = adapterServiceConfig[adapterType]; - let adapterName; + let adapterClassName; let adapterConfig; const hasFeatureConfig = feature && adapterSettings[feature]; if (hasFeatureConfig && adapterSettings[adapterSettings[feature]]) { // CASE: load resource-specific adapter when there is an adapter feature // name (String) specified as well as custom feature config - adapterName = adapterSettings[feature]; - adapterConfig = adapterSettings[adapterName]; + adapterClassName = adapterSettings[feature]; + adapterConfig = adapterSettings[adapterClassName]; } else if (hasFeatureConfig && adapterSettings[feature].adapter) { // CASE: load resource-specific adapter when there is an adapter feature // name (Object) specified as well as custom feature config - adapterName = adapterSettings[feature].adapter; - const commonAdapterConfig = {...adapterSettings[adapterName]}; + adapterClassName = adapterSettings[feature].adapter; + const commonAdapterConfig = {...adapterSettings[adapterClassName]}; const featureAdapterConfig = {...adapterSettings[feature]}; delete featureAdapterConfig.adapter; adapterConfig = {...commonAdapterConfig, ...featureAdapterConfig}; } else { - adapterName = adapterSettings.active; - adapterConfig = adapterSettings[adapterName]; + adapterClassName = adapterSettings.active; + adapterConfig = adapterSettings[adapterClassName]; } - return {adapterName, adapterConfig}; + return {adapterClassName, adapterConfig}; }; + +module.exports = resolveAdapterOptions; diff --git a/ghost/core/test/unit/server/services/adapter-manager/options-resolver.test.js b/ghost/core/test/unit/server/services/adapter-manager/options-resolver.test.js index 9a8ada0bee..b46ef30696 100644 --- a/ghost/core/test/unit/server/services/adapter-manager/options-resolver.test.js +++ b/ghost/core/test/unit/server/services/adapter-manager/options-resolver.test.js @@ -12,9 +12,9 @@ describe('Adapter Manager: options resolver', function () { } }; - const {adapterName, adapterConfig} = resolveAdapterOptions(name, adapterServiceConfig); + const {adapterClassName, adapterConfig} = resolveAdapterOptions(name, adapterServiceConfig); - adapterName.should.equal('Memory'); + adapterClassName.should.equal('Memory'); should.equal(adapterConfig, undefined); }); @@ -29,9 +29,9 @@ describe('Adapter Manager: options resolver', function () { } }; - const {adapterName, adapterConfig} = resolveAdapterOptions(name, adapterServiceConfig); + const {adapterClassName, adapterConfig} = resolveAdapterOptions(name, adapterServiceConfig); - adapterName.should.equal('cloud-storage'); + adapterClassName.should.equal('cloud-storage'); adapterConfig.should.deepEqual({ custom: 'configValue' }); @@ -52,9 +52,9 @@ describe('Adapter Manager: options resolver', function () { } }; - const {adapterName, adapterConfig} = resolveAdapterOptions(name, adapterServiceConfig); + const {adapterClassName, adapterConfig} = resolveAdapterOptions(name, adapterServiceConfig); - adapterName.should.equal('local-storage'); + adapterClassName.should.equal('local-storage'); adapterConfig.should.deepEqual({ custom: 'localStorageConfig' }); @@ -76,17 +76,17 @@ describe('Adapter Manager: options resolver', function () { } }; - const {adapterName, adapterConfig} = resolveAdapterOptions(name, adapterServiceConfig); + const {adapterClassName, adapterConfig} = resolveAdapterOptions(name, adapterServiceConfig); - adapterName.should.equal('cloud-storage'); + adapterClassName.should.equal('cloud-storage'); adapterConfig.should.deepEqual({ custom: 'configValue' }); }); it('combines configurations from shared adapter and feature adapter instances', function () { - const primaryAdapterName = 'cache:images'; - const secondaryAdapterName = 'cache:settings'; + const primaryadapterClassName = 'cache:images'; + const secondaryadapterClassName = 'cache:settings'; const adapterServiceConfig = { cache: { Redis: { @@ -103,17 +103,17 @@ describe('Adapter Manager: options resolver', function () { } }; - const {adapterName, adapterConfig} = resolveAdapterOptions(primaryAdapterName, adapterServiceConfig); + const {adapterClassName, adapterConfig} = resolveAdapterOptions(primaryadapterClassName, adapterServiceConfig); - adapterName.should.equal('Redis'); + adapterClassName.should.equal('Redis'); adapterConfig.should.deepEqual({ commonConfigValue: 'common_config_value', adapterConfigValue: 'images_redis_value' }); - const {adapterName: secondAdapterName, adapterConfig: secondAdapterConfig} = resolveAdapterOptions(secondaryAdapterName, adapterServiceConfig); + const {adapterClassName: secondadapterClassName, adapterConfig: secondAdapterConfig} = resolveAdapterOptions(secondaryadapterClassName, adapterServiceConfig); - secondAdapterName.should.equal('Redis'); + secondadapterClassName.should.equal('Redis'); secondAdapterConfig.should.deepEqual({ commonConfigValue: 'common_config_value', adapterConfigValue: 'settings_redis_value' @@ -121,8 +121,8 @@ describe('Adapter Manager: options resolver', function () { }); it('combines empty configuration from shared adapter and feature adapter instances', function () { - const primaryAdapterName = 'cache:images'; - const secondaryAdapterName = 'cache:settings'; + const primaryadapterClassName = 'cache:images'; + const secondaryadapterClassName = 'cache:settings'; const adapterServiceConfig = { cache: { images: { @@ -136,23 +136,23 @@ describe('Adapter Manager: options resolver', function () { } }; - const {adapterName, adapterConfig} = resolveAdapterOptions(primaryAdapterName, adapterServiceConfig); + const {adapterClassName, adapterConfig} = resolveAdapterOptions(primaryadapterClassName, adapterServiceConfig); - adapterName.should.equal('Redis'); + adapterClassName.should.equal('Redis'); adapterConfig.should.deepEqual({ adapterConfigValue: 'images_redis_value' }); - const {adapterName: secondAdapterName, adapterConfig: secondAdapterConfig} = resolveAdapterOptions(secondaryAdapterName, adapterServiceConfig); + const {adapterClassName: secondadapterClassName, adapterConfig: secondAdapterConfig} = resolveAdapterOptions(secondaryadapterClassName, adapterServiceConfig); - secondAdapterName.should.equal('Redis'); + secondadapterClassName.should.equal('Redis'); secondAdapterConfig.should.deepEqual({ adapterConfigValue: 'settings_redis_value' }); }); it('gives priority to a feature config over a common adapter config', function () { - const primaryAdapterName = 'cache:images'; + const primaryadapterClassName = 'cache:images'; const adapterServiceConfig = { cache: { Redis: { @@ -167,9 +167,9 @@ describe('Adapter Manager: options resolver', function () { } }; - const {adapterName, adapterConfig} = resolveAdapterOptions(primaryAdapterName, adapterServiceConfig); + const {adapterClassName, adapterConfig} = resolveAdapterOptions(primaryadapterClassName, adapterServiceConfig); - adapterName.should.equal('Redis'); + adapterClassName.should.equal('Redis'); adapterConfig.should.deepEqual({ commonConfigValue: 'common_config_value', adapterConfigValue: 'images_redis_value',