Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

loopback-bluemix

Package Overview
Dependencies
Maintainers
19
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

loopback-bluemix - npm Package Compare versions

Comparing version 1.1.1 to 2.0.0

.vscode/apiconnect.json

16

CHANGES.md

@@ -0,1 +1,17 @@

2017-05-03, Version 2.0.0
=========================
* Make login tests conditional (Raymond Feng)
* add tests (Hage Yaapa)
* Simplify bluemix code generation (Raymond Feng)
* Improve login/accessToken passing (Raymond Feng)
* Add scripts for adding and deleting Bluemix fixtures (Hage Yaapa)
* scripts for adding and deleting Bluemix fixtures (Hage Yaapa)
2017-04-20, Version 1.1.1

@@ -2,0 +18,0 @@ =========================

111

lib/cf.js

@@ -40,2 +40,28 @@ // Copyright IBM Corp. 2017. All Rights Reserved.

/**
* Invoke an HTTP call
* @param {object} httpReq HTTP request object
* @param {function} cb Callback function
*/
function invokeHttp(httpReq, cb) {
request(httpReq, function(err, res) {
if (err) return cb(err);
if (res.statusCode >= 300) {
var errObj = {};
if (res.body && typeof res.body === 'object') {
errObj = res.body;
}
var msg = errObj.description || errObj.error_description ||
('Bluemix api error: ' + res.statusCode);
err = new Error(msg);
for (var i in errObj) {
err[i] = res.body[i];
}
cb(err);
} else {
cb(err, res);
}
});
}
/**
* Get a cloud foundry resource

@@ -97,19 +123,3 @@ * @param path {string} The resource url

}
request(httpReq, function(err, res) {
if (err) return cb(err);
if (res.statusCode >= 300) {
var errObj = {};
if (res.body && typeof res.body === 'object') {
errObj = res.body;
}
var msg = errObj.description || ('Bluemix api error: ' + res.statusCode);
err = new Error(msg);
for (var i in errObj) {
err[i] = res.body[i];
}
cb(err);
} else {
cb(err, res);
}
});
invokeHttp(httpReq, cb);
}

@@ -145,5 +155,15 @@

var tokenURL = authURL + '/oauth/token';
var body = 'grant_type=password&username=' + userId +
'&password=' + password;
request.post({
var form = {
'grant_type': 'password',
'client_id': 'cf',
};
if (options.sso) {
// Get one time passcode from https://iam.ng.bluemix.net/oidc/passcode
form.passcode = password;
} else {
form.username = userId;
form.password = password;
}
var httpReq = {
method: 'post',
uri: tokenURL,

@@ -155,7 +175,7 @@ headers: {

},
body: body,
form: form,
json: true,
}, function(err, res) {
if (err) return cb(err);
cb(null, res.body);
};
invokeHttp(httpReq, function(err, res) {
cb(err, res && res.body);
});

@@ -168,16 +188,43 @@ });

* @param configFilePath {string} Path to CF config file
* @param log {function} Log function
* @returns {object}
*/
function getCfConfig(configFilePath) {
if (!configFilePath) {
var home = os.homedir();
configFilePath = path.join(home, '.cf', 'config.json');
function getCfConfig(configFilePath, log) {
if (typeof configFilePath === 'function' && log === undefined) {
log = configFilePath;
configFilePath = undefined;
}
var cfConfig = {};
var home = os.homedir();
if (typeof configFilePath !== 'string') {
configFilePath = path.join(home, '.bluemix/.loopback/config.json');
try {
cfConfig = require(configFilePath);
return cfConfig;
} catch (e) {
// Ignore the error
configFilePath = path.join(home, '.cf', 'config.json');
}
}
var accessToken;
try {
var cfConfig = require(configFilePath);
cfConfig = require(configFilePath);
accessToken = cfConfig.AccessToken.substring('bearer '.length);
} catch (e) {
console.error('Please use `cf login` to log into Bluemix first.');
return {};
// Fall back to ~/.bluemix/config.json & ~/.bluemix/.cf/config.json
configFilePath = path.join(home, '.bluemix/.cf', 'config.json');
var bxConfigFilePath = path.join(home, '.bluemix', 'config.json');
try {
cfConfig = require(configFilePath);
var bxConfig = require(bxConfigFilePath);
accessToken = cfConfig.AccessToken.substring('bearer '.length) ||
bxConfig.IAMToken.substring('Bearer '.length);
} catch (e) {
if (log) {
log('Please use `cf login` or `bx login` to log into Bluemix first.');
}
return {};
}
}
var accessToken = cfConfig.AccessToken.substring('bearer '.length);
var organizationGuid = cfConfig.OrganizationFields.GUID;

@@ -184,0 +231,0 @@ var spaceGuid = cfConfig.SpaceFields.GUID;

@@ -20,11 +20,2 @@ // Copyright IBM Corp. 2017. All Rights Reserved.

var cfConfig;
function getCfConfig() {
if (cfConfig) return cfConfig;
else {
cfConfig = cf.getCfConfig();
return cfConfig;
}
}
/**

@@ -38,3 +29,3 @@ * Present Bluemix datasource selection options

datasource.log('Finding Bluemix data service instances...');
cf.getDataServiceInstances(null, getCfConfig().accessToken,
cf.getDataServiceInstances(null, datasource.accessToken,
function(err, resources) {

@@ -157,3 +148,3 @@ if (err) return done(err);

var done = datasource.async();
cf.getSupportedServices(null, getCfConfig().accessToken, function(err, serviceDetails) {
cf.getSupportedServices(null, datasource.accessToken, function(err, serviceDetails) {
if (err) return done(err);

@@ -174,3 +165,3 @@ datasource.dataServices = serviceDetails;

datasource.servicePlans = {};
cf.getServicePlans(null, getCfConfig().accessToken, service.plansUrl,
cf.getServicePlans(null, datasource.accessToken, service.plansUrl,
function(err, servicePlans) {

@@ -205,4 +196,4 @@ if (err) return done(err);

details['service_plan_guid'] = datasource.servicePlans[answers.servicePlan];
details['space_guid'] = getCfConfig().space.guid;
cf.provisionService(getCfConfig().accessToken, details, function(err, res, service) {
details['space_guid'] = datasource.space.guid;
cf.provisionService(datasource.accessToken, details, function(err, res, service) {
if (err) return done(err);

@@ -221,3 +212,3 @@ datasource.serviceGUID = service.metadata.guid;

var done = datasource.async();
cf.getApps(null, getCfConfig().accessToken, function(err, resources) {
cf.getApps(null, datasource.accessToken, function(err, resources) {
if (err) return done(err);

@@ -233,3 +224,3 @@ var matchedApp = false;

};
cf.bindService(getCfConfig().accessToken, details, function(err) {
cf.bindService(datasource.accessToken, details, function(err) {
return done(err);

@@ -236,0 +227,0 @@ });

@@ -19,4 +19,2 @@ // Copyright IBM Corp. 2017. All Rights Reserved.

module.exports = function(bluemixOptions, copyFile, copyDir) {
var bluemixCommand = bluemixOptions.bluemixCommand;
var cmdOptions = bluemixOptions.cmdOptions;
var destDir = bluemixOptions.destDir;

@@ -29,3 +27,3 @@

if (bluemixCommand === 'bluemix') {
if (bluemixOptions.enableBluemix) {
// Create .cfignore

@@ -60,4 +58,3 @@ var cfignoreSrc = path.resolve(bluemixTemplatesDir, 'cfignore');

if (cmdOptions.toolchain || (bluemixOptions.enableToolchain &&
bluemixCommand === 'bluemix')) {
if (bluemixOptions.enableToolchain) {
// Copy toolchain files

@@ -74,4 +71,3 @@ var toolChainFiles = fs.readdirSync(bluemixDirSrc);

if (cmdOptions.docker || (bluemixOptions.enableDocker &&
bluemixCommand === 'bluemix')) {
if (bluemixOptions.enableDocker) {
// Create .dockerignore

@@ -87,3 +83,3 @@ var dockerignoreSrc = path.resolve(bluemixTemplatesDir, 'dockerignore');

if (cmdOptions.manifest || bluemixCommand === 'bluemix') {
if (bluemixOptions.enableManifest) {
// Create manifest.yml

@@ -90,0 +86,0 @@ var manifestSrc = path.resolve(bluemixTemplatesDir, 'manifest.yml');

{
"name": "loopback-bluemix",
"version": "1.1.1",
"version": "2.0.0",
"description": "Utilities for generating generate Bluemix artefacts",

@@ -10,2 +10,4 @@ "main": "index.js",

"scripts": {
"create-bm-fixtures": "node ./test/fixtures/bluemix/create-bm-fixtures",
"delete-bm-fixtures": "node ./test/fixtures/bluemix/delete-bm-fixtures",
"posttest": "npm run lint",

@@ -34,8 +36,10 @@ "lint": "eslint .",

"devDependencies": {
"cloudfoundry-cli": "^0.8.0",
"eslint": "^3.18.0",
"eslint-config-loopback": "^8.0.0",
"fs-extra": "^2.1.2",
"fs-extra": "^3.0.0",
"loopback-workspace": "^3.40.1",
"mocha": "^3.2.0"
"mocha": "^3.2.0",
"uuid": "^3.0.1"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc