Merge pull request #122 from vergara/fix-user

Added support for external providers as npm modules.
This commit is contained in:
Raymond Feng 2017-03-01 15:07:28 -08:00 committed by GitHub
commit b6e06dbceb
1 changed files with 18 additions and 4 deletions

View File

@ -84,8 +84,17 @@ function createClient(options) {
// Try to load the provider from providers folder
handler = require('./providers/' + provider);
} catch (err) {
// Fall back to pkgcloud
handler = require('pkgcloud').storage;
try {
// Fall back to using an external provider
handler = require(provider);
if (!handler || !handler.createClient) {
// Fall back to pkgcloud
handler = require('pkgcloud').storage;
}
} catch(err) {
// Fall back to pkgcloud
handler = require('pkgcloud').storage;
}
}
patchContainerAndFileClass(provider);
return handler.createClient(options);
@ -101,8 +110,13 @@ function getProvider(provider) {
// Try to load the provider from providers folder
return require('./providers/' + provider);
} catch (err) {
// Fall back to pkgcloud
return require('pkgcloud').providers[provider];
try {
// Fall back to using an external provider
return require(provider);
} catch(err) {
// Fall back to pkgcloud
return require('pkgcloud').providers[provider];
}
}
}