Skip to content

Commit

Permalink
Merge branch '1.5.0' into 'release'
Browse files Browse the repository at this point in the history
1.5.0

See merge request !315
  • Loading branch information
vamsee committed Jul 20, 2018
2 parents 97b3ae5 + 92b6b58 commit fe3289a
Show file tree
Hide file tree
Showing 26 changed files with 636 additions and 335 deletions.
6 changes: 3 additions & 3 deletions client/explorer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<title>oeCloud.io API Explorer</title>
<!-- <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700" rel="stylesheet"> -->
<!-- <link rel="stylesheet" type="text/css" href="./swagger-ui.css" > -->
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
<link rel="icon" type="image/png" href="favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="favicon-16x16.png" sizes="16x16" />
<style>
html
{
Expand Down Expand Up @@ -78,7 +78,7 @@
// window["SwaggerUIOeCloudPreset"] = window["swagger-ui-oecloud-preset"]
// Build a system
const ui = SwaggerUIBundle({
url: "/explorer/swagger.json",
url: "swagger.json",
dom_id: '#swagger-ui',
presets: [
SwaggerUIBundle.presets.apis,
Expand Down
2 changes: 1 addition & 1 deletion common/mixins/business-rule-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @author Sambit Kumar Patra
* @mixin Business Rule Mixin
*/
var q = require('q');
var q = require('oe-promise');
var exprLang = require('../../lib/expression-language/expression-language.js');
var loopback = require('loopback');
var logger = require('oe-logger');
Expand Down
13 changes: 7 additions & 6 deletions common/mixins/model-validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Any unauthorized reproduction, storage, transmission in any form or by any means
var logger = require('oe-logger');
var log = logger('model-validations');
var async = require('async');
var q = require('q');
var q = require('oe-promise');
var validationBuilder = require('../../lib/common/validation-builder.js');
var exprLang = require('../../lib/expression-language/expression-language.js');
var getError = require('../../lib/common/error-utils').attachValidationError;
Expand Down Expand Up @@ -86,6 +86,11 @@ module.exports = function ModelValidations(Model) {
log.debug(options, 'isValid called for : ', path);
var self = inst;
var ast = self.constructor._ast;
var args = {};
args.inst = inst;
args.data = data;
args.path = path;
args.options = options;
// construct an array of promises for validateWhen and wait for expression language to resolve all the promises
inst.constructor.validationRules.forEach(function modelValidationsRulesForEachFn(obj) {
if (obj.args.validateWhen) {
Expand All @@ -109,11 +114,7 @@ module.exports = function ModelValidations(Model) {
if (d) {
// this wrapper prepares an array of functions containg all the validations attached to the model
var obj = inst.constructor.validationRules[i];
obj.args.inst = inst;
obj.args.data = data;
obj.args.path = path;
obj.args.options = options;
fnArr.push(async.apply(obj.expression, obj.args));
fnArr.push(async.apply(obj.expression, obj.args, args));
}
});
/* prepare an array of functions which are nothing but the isValid method of the
Expand Down
4 changes: 3 additions & 1 deletion common/models/framework/app-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"description": "This model is used to store application configuration",
"options": {
"validateUpsert": true,
"isFrameworkModel": true
"isFrameworkModel": true,
"queryCacheSize": 20000,
"queryCacheExpiration": 86400000
},
"properties": {
"server": {
Expand Down
2 changes: 1 addition & 1 deletion common/models/framework/auth-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,6 @@ function getFromCookie(r, p) {
return;
}
});
return result.substring(4, 68);
return result ? result.substring(4, 68) : null;
}
}
4 changes: 4 additions & 0 deletions common/models/framework/base-ACL.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
"validations": [],
"relations": {
},
"options": {
"queryCacheSize": 20000,
"queryCacheExpiration": 86400000
},
"acls": [],
"cacheable": true,
"methods": {}
Expand Down
13 changes: 13 additions & 0 deletions common/models/framework/batch-run.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "BatchRun",
"plural": "BatchRuns",
"base": "BaseEntity",
"strict": false,
"idInjection": true,
"properties": {},
"validations": [],
"relations": {
},
"acls": [],
"methods": {}
}
13 changes: 13 additions & 0 deletions common/models/framework/batch-status.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "BatchStatus",
"plural": "BatchStatus",
"base": "BaseEntity",
"strict": false,
"idInjection": true,
"properties": {},
"validations": [],
"relations": {
},
"acls": [],
"methods": {}
}
56 changes: 30 additions & 26 deletions common/models/framework/error.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
{
"name": "Error",
"base": "BaseEntity",
"plural": "errors",
"idInjection": false,
"description": "This Model stores all the Customized error details",
"options": {
"validateUpsert": true,
"isFrameworkModel": true,
"disableManualPersonalization":false
},
"properties": {
"errCode": {
"type": "string",
"max": 100
"name": "Error",
"base": "BaseEntity",
"plural": "errors",
"idInjection": false,
"description": "This Model stores all the Customized error details",
"options": {
"validateUpsert": true,
"isFrameworkModel": true,
"disableManualPersonalization": false
},
"errMessage": {
"type": "string",
"max": 250
"properties": {
"errCode": {
"type": "string",
"max": 100
},
"errMessage": {
"type": "string",
"max": 250
},
"errCategory": {
"type": "string",
"max": 100
},
"moreInformation": {
"type": "string",
"max": 500
}
},
"moreInformation": {
"type": "string",
"max": 500
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
4 changes: 3 additions & 1 deletion common/models/framework/model-definition.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"options": {
"validateUpsert": true,
"isFrameworkModel": true,
"disableManualPersonalization":false
"disableManualPersonalization":false,
"queryCacheSize": 20000,
"queryCacheExpiration": 86400000
},
"properties": {
"properties": {
Expand Down
127 changes: 127 additions & 0 deletions common/models/framework/trusted-app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/**
*
* ©2016-2017 EdgeVerve Systems Limited (a fully owned Infosys subsidiary),
* Bangalore, India. All Rights Reserved.
*
*/
var jwt = require('jsonwebtoken');
const loopback = require('loopback');
const log = require('oe-logger')('trusted-app');
var jwtUtil = require('../../../lib/jwt-token-util');


module.exports = function TrustedApp(trustedApp) {
/**
* This function accepts username and password,
* and authenticates the user with service account set with trusted app
*
*
* @param {object} data - {"username":"", "password":"", "appId":""}
* @param {object} options - callcontext options
* @param {function} cb - callback/next function
* @returns {string} token - jwt token to use to use
*/
trustedApp.authenticate = function authenticateTrustedApp(data, options, cb) {
var self = this;
var error;
// cb = cb || utils.createPromiseCallback();
// verify the trusted app is assigned with this username
if (!data.username || !data.password || !data.appId) {
error = new Error();
error.message = 'username, password and appId; all three values are mandatory';
error.statusCode = 400;
error.code = 'USERNAME_PASSWORD_REQUIRED';
error.retriable = false;
return cb(error);
}
var where = {
'where': {
'and': [{
'username': data.username
},
{
'appId': data.appId
}
]
}
};
self.findOne(where, options, function fnFetchTrustedApp(err, app) {
if (err) {
log.info(options, err);
return cb(err);
}

if (app && app.appId) {
log.debug(options, 'trusted app configured properly for ', data.appId, ' and username ', data.username);
// make login call
if (app) {
var baseUser = loopback.getModelByType('BaseUser');
baseUser.login({ 'username': data.username, 'password': data.password }, options, function fnTrustedAppLoggedIn(err, user) {
if (err) {
log.error(options, err);
return cb(err);
}

if (!user) {
log.debug(options, 'Associated service user not found for ', data.appId, ' and username ', data.username);
error = new Error();
error.message = 'Trusted app not configured properly.';
error.statusCode = 400;
error.code = 'TRUSTED_APP_AUTH_FAILED';
error.retriable = false;
return cb(error);
}
// generate a jwt for trusted app
if (user && user.id) {
var jwtConfig = jwtUtil.getJWTConfig();
var jwtOpts = {};
var jwtData = {};
jwtOpts.issuer = jwtConfig.issuer;
jwtOpts.audience = jwtConfig.audience;
// access token ttl set to jwt's expiry in seconds
jwtOpts.expiresIn = user.ttl;
jwtData.username = user.username;
jwtData.userId = user.userId;
jwtData.roles = user.roles;
jwtData.tenantId = user.tenantId;
jwtData.expiresIn = jwtOpts.expiresIn;
jwtData[jwtConfig.keyToVerify] = app.appId;

jwt.sign(jwtData, jwtConfig.secretOrKey, jwtOpts, function jwtSignCb(err, token) {
if (err) {
log.error(options, 'Trusred app JWT signing error ', err);
log.debug(options, err);
return cb(err);
}

cb(null, token);
});
}
});
}
} else {
log.debug(options, 'trusted app not configured properly for ', data.appId, ' and username ', data.username);
error = new Error();
error.message = 'Trusted app not configured properly.';
error.statusCode = 400;
error.code = 'TRUSTED_APP_ERROR';
error.retriable = false;
return cb(error);
}
});
};
// accepts object with username,
trustedApp.remoteMethod('authenticate', {
description: 'authenticate a trusted app service account',
accepts: [{ arg: 'data', type: 'object', required: true, http: { source: 'body' } }],
http: {
verb: 'POST',
path: '/authenticate'
},
returns: {
arg: 'token',
type: 'string',
root: true
}
});
};
17 changes: 16 additions & 1 deletion common/models/framework/trusted-app.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"description": "holds trusted application details",
"options": {
"validateUpsert": true,
"isFrameworkModel": true
"isFrameworkModel": true,
"queryCacheSize": 20000,
"queryCacheExpiration": 86400000
},
"properties": {
"appId": {
Expand All @@ -16,6 +18,12 @@
"appName": {
"type": "string"
},
"username": {
"type": "string"
},
"publicKey": {
"type": "string"
},
"expiry": {
"type": "number"
},
Expand All @@ -32,6 +40,12 @@
"property": "*",
"accessType": "*"
},
{
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "authenticate"
},
{
"principalType": "ROLE",
"principalId": "$authenticated",
Expand All @@ -40,5 +54,6 @@
"accessType": "*"
}
],
"cacheable": true,
"methods": {}
}
20 changes: 12 additions & 8 deletions common/models/ui/ui-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,18 @@ module.exports = function uiComponent(UIComponent) {
var refCodeType = field.refcodetype;
subtasks.push(function subTaskPushCb(fetched) {
var refCodeModel = loopback.findModel(refCodeType, options);
refCodeModel.find({}, options, function findCb(err, resp) {
if (!err) {
field.listdata = resp;
field.displayproperty = 'description';
field.valueproperty = 'code';
}
fetched(err);
});
if (refCodeModel) {
refCodeModel.find({}, options, function findCb(err, resp) {
if (!err) {
field.listdata = resp;
field.displayproperty = 'description';
field.valueproperty = 'code';
}
fetched(err);
});
} else {
log.error('Invalid refCode model ', refCodeType);
}
});
}
if (field.validateWhen) {
Expand Down
Loading

0 comments on commit fe3289a

Please sign in to comment.