fix(preferred provider): Throwing error if provider set in env var and clinet tries to change it

This commit is contained in:
Chris Troutner
2022-10-25 15:38:07 -07:00
parent 433931111c
commit 1a32b941df
2 changed files with 10 additions and 4 deletions
@@ -30,4 +30,7 @@ export DBURL=mongodb://localhost:27017/ipfs-service-dev
export CONSUMER_ENV=production
# Lock the consumer into a preferred service provider.
#export PREFERRED_PROVIDER=12D3KooWEzE3HNH86WCb2Xocu6PgBCnSGUD7myJmuTHvoedMwp7K
npm start
+7 -4
View File
@@ -3,6 +3,7 @@
*/
const { wlogger } = require('../../../adapters/wlogger')
const config = require('../../../../config')
// let _this
@@ -23,10 +24,7 @@ class BchRESTControllerLib {
}
// Encapsulate dependencies
// this.UserModel = this.adapters.localdb.Users
// this.userUseCases = this.useCases.user
// _this = this
this.config = config
}
/**
@@ -66,6 +64,11 @@ class BchRESTControllerLib {
try {
const providerId = ctx.request.body.provider
// Throw an error, if the provider has been set by an environment variable.
if(this.config.preferredProvider) {
throw new Error(`Consumer has preferredProvider set in environment variable. Refusing to switch providers.`)
}
await this.adapters.bch.selectProvider(providerId)
const body = {