Added adapter-manager service

no-issue

This services handles the registration and retrieval of adapters,
it normalises the config to look like:

{
    [adapterType]: {
        active: adapterName,
        [adapterName]: adapterConfig
    }
}
This commit is contained in:
Fabien O'Carroll 2020-04-05 18:52:46 +02:00
parent 2d42af8d72
commit fb942af1db
6 changed files with 66 additions and 0 deletions

View File

@ -8,6 +8,7 @@
"defaultViews": "core/server/views/",
"defaultSettings": "core/frontend/services/settings/",
"internalAppPath": "core/frontend/apps/",
"internalAdaptersPath": "core/server/adapters/",
"internalStoragePath": "core/server/adapters/storage/",
"internalSchedulingPath": "core/server/adapters/scheduling/",
"migrationPath": "core/server/data/migrations",

View File

@ -53,6 +53,8 @@ exports.getContentPath = function getContentPath(type) {
return path.join(this.get('paths:contentPath'), 'images/');
case 'themes':
return path.join(this.get('paths:contentPath'), 'themes/');
case 'adapters':
return path.join(this.get('paths:contentPath'), 'adapters/');
case 'storage':
return path.join(this.get('paths:contentPath'), 'adapters', 'storage/');
case 'scheduling':

View File

@ -0,0 +1,28 @@
/**
* {
* [adapterType]: {
* active: [adapterName],
* [adapterName]: {}
* }
* }
*/
module.exports = function getAdapterServiceConfig(config) {
const adapterServiceConfig = config.get('adapters');
if (!adapterServiceConfig.storage) {
adapterServiceConfig.storage = config.get('storage');
}
if (!adapterServiceConfig.scheduling) {
const schedulingConfig = config.get('scheduling');
const activeSchedulingAdapter = schedulingConfig.active;
adapterServiceConfig.scheduling = {
active: activeSchedulingAdapter,
[activeSchedulingAdapter]: {
schedulerUrl: schedulingConfig.schedulerUrl
}
};
}
return adapterServiceConfig;
};

View File

@ -0,0 +1,27 @@
const AdapterManager = require('@tryghost/adapter-manager');
const getAdapterServiceConfig = require('./config');
const config = require('../../config');
const adapterManager = new AdapterManager({
loadAdapterFromPath: require,
pathsToAdapters: [
'', // A blank path will cause us to check node_modules for the adapter
config.getContentPath('adapters'),
config.get('paths').internalAdaptersPath
]
});
adapterManager.registerAdapter('storage', require('ghost-storage-base'));
adapterManager.registerAdapter('scheduling', require('../../adapters/scheduling/SchedulingBase'));
module.exports = {
getAdapter(adapterType) {
const adapterServiceConfig = getAdapterServiceConfig(config);
const adapterSettings = adapterServiceConfig[adapterType];
const activeAdapter = adapterSettings.active;
const activeAdapterConfig = adapterSettings[activeAdapter];
return adapterManager.getAdapter(adapterType, activeAdapter, activeAdapterConfig);
}
};

View File

@ -41,6 +41,7 @@
"dependencies": {
"@nexes/nql": "0.3.0",
"@sentry/node": "5.15.4",
"@tryghost/adapter-manager": "^0.1.0",
"@tryghost/errors": "0.1.1",
"@tryghost/helpers": "1.1.25",
"@tryghost/image-transform": "0.2.0",

View File

@ -301,6 +301,13 @@
dependencies:
defer-to-connect "^2.0.0"
"@tryghost/adapter-manager@^0.1.0":
version "0.1.0"
resolved "https://registry.yarnpkg.com/@tryghost/adapter-manager/-/adapter-manager-0.1.0.tgz#b95178b1d2f89de8b6a243ee312de61237c6a973"
integrity sha512-Z5Pnhd/b/EBsl6mCJdwmdVEESWnurgD/GAVma0g8GMuUECg0NCynyVJtvszKFny9484OagWzrpTUi7F5l4jp3Q==
dependencies:
"@tryghost/errors" "^0.1.1"
"@tryghost/errors@0.1.1", "@tryghost/errors@^0.1.1":
version "0.1.1"
resolved "https://registry.yarnpkg.com/@tryghost/errors/-/errors-0.1.1.tgz#c140f8558fc54cf69ac7e7ea719a189c763fea04"