Skip to content

Best practice for leveraging cfEnv? #12

@srl295

Description

@srl295

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions