Say I am writing an SDK (just suppose…)
Is the following reasonable, and if so, should it be documented as a best practice?
OLD:
var appEnv = require('cfenv').getAppEnv();
var someClient = require('Some Random Thing').setup({ credentials: appEnv.getServiceCreds(/Something.*/) });
IMPROVED?
var appEnv = require('cfenv').getAppEnv();
var someClient = require('Some Random Thing').setup({ appEnv: appEnv });
implemented within the SDK by:
… function setup(opts) {
if(opts.appEnv && !opts.credentials) { // if appEnv is available, use it
opts.credentials = opts.appEnv.getServiceCreds( someRegex );
}
Any pitfalls? My idea is to reduce the amount of copy and paste user code. User can just pass in appEnv if they have one, otherwise credentials can be supplied.
Say I am writing an SDK (just suppose…)
Is the following reasonable, and if so, should it be documented as a best practice?
OLD:
IMPROVED?
implemented within the SDK by:
Any pitfalls? My idea is to reduce the amount of copy and paste user code. User can just pass in
appEnvif they have one, otherwise credentials can be supplied.