From 9aba5658a2b96ab9d10c703cf47d401313d2c9ff Mon Sep 17 00:00:00 2001 From: Cristobal Vergara Date: Thu, 28 Jan 2016 11:18:37 -0800 Subject: [PATCH] Added support for external providers as npm modules. --- lib/factory.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index e03bc71..eafc86b 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -79,8 +79,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); @@ -96,8 +105,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]; + } } }