Skip to content

Commit

Permalink
Closes-Bug: #1491217
Browse files Browse the repository at this point in the history
If a tenant is disabled and getting tokens API to keystones throws error,
so handled the null case before accessing variable.

Conflicts:
	src/serverroot/orchestration/plugins/openstack/keystone.api.js

Change-Id: I03021444f9ed36135bd85b0129bbb3e4e0c5a86f
(cherry picked from commit db0e962)
  • Loading branch information
biswajit-mandal committed Sep 4, 2015
1 parent 56e9cc6 commit 9c9ef0b
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 7 deletions.
40 changes: 33 additions & 7 deletions src/serverroot/orchestration/plugins/openstack/keystone.api.js
Expand Up @@ -905,11 +905,14 @@ function getUserRoleByAllTenants (username, password, tenantlist, callback)
var dataLen = data.length;
var tokenObjs = {};
for (var i = 0; i < dataLen; i++) {
var project = data[i]['tokenObj']['token']['tenant']['name'];
tokenObjs[project] = data[i]['tokenObj'];
if (null == data[i]) {
var project =
commonUtils.getValueByJsonPath(data[i],
'tokenObj;token;tenant;name',
null);
if (null == project) {
continue;
}
tokenObjs[project] = data[i]['tokenObj'];
userRoles =
getUserRoleByAuthResponse(data[i]['roles']);
var userRolesCnt = userRoles.length;
Expand Down Expand Up @@ -1066,10 +1069,24 @@ function getProjectDetails (projects, userObj, callback)
var tokenObjs = {};
var tokenCnt = tokenList.length;
for (var i = 0; i < tokenCnt; i++) {
var project = tokenList[i]['tenant']['name'];
var project =
commonUtils.getValueByJsonPath(tokenList[i], 'tenant;name',
null);
if (null == project) {
continue;
}
tokenObjs[project] = {};
tokenObjs[project]['token'] = tokenList[i];
tokenObjs[project]['token']['id'] =
var tokenID =
commonUtils.getValueByJsonPath(tokenObjs[project],
'token;id', null);
if (null == tokenID) {
logutils.logger.error('We did not get valid token id for ' +
'project: ' + project);
delete tokenObjs[project];
continue;
}
tokenObjs[project]['token']['id'] = removeSpecialChars(tokenID);
removeSpecialChars(tokenObjs[project]['token']['id'] );
}
callback(err, data, tokenObjs);
Expand All @@ -1089,7 +1106,13 @@ function getUserRoleByProjectList (projects, userObj, callback)
var projCnt = projs.length;
for (var i = 0; i < projCnt; i++) {
try {
var projName = projs[i]['token']['project']['name'];
var projName =
commonUtils.getValueByJsonPath(projs[i],
'token;project;name',
null);
if (null == projName) {
continue;
}
resTokenObjs[projName] = projs[i];
if (null != tokenObjs[projName]) {
resTokenObjs[projName]['token']['id'] =
Expand All @@ -1107,7 +1130,10 @@ function getUserRoleByProjectList (projects, userObj, callback)
}
var resCnt = projs.length;
for (var i = 0; i < resCnt; i++) {
var userRole = getUserRoleByAuthResponse(projs[i]['token']['roles']);
var roles =
commonUtils.getValueByJsonPath(projs[i],
'token;roles', null);
var userRole = getUserRoleByAuthResponse(roles);
if (global.STR_ROLE_ADMIN == userRole) {
callback(userRole, resTokenObjs);
return;
Expand Down
26 changes: 26 additions & 0 deletions src/serverroot/utils/common.utils.js
Expand Up @@ -1810,6 +1810,31 @@ function prefixToNetMask(prefixLen) {
return v4.Address.fromHex(parseInt(binaryString,2).toString(16)).address;
}

/**
* Get the value of a property inside a json object with a given path
*/
function getValueByJsonPath(obj,pathStr,defValue) {
try {
var currObj = obj;
var pathArr = pathStr.split(';');
var arrLength = pathArr.length;
for(var i=0;i<arrLength;i++) {
if(currObj[pathArr[i]] != null) {
currObj = currObj[pathArr[i]];
} else
return defValue;
}
if(currObj instanceof Array)
return cloneObj(currObj);
else if(typeof(currObj) == "object")
return cloneObj(currObj);
else
return currObj;
} catch(e) {
return defValue;
}
}

exports.createJSONBySandeshResponseArr = createJSONBySandeshResponseArr;
exports.createJSONBySandeshResponse = createJSONBySandeshResponse;
exports.createJSONByUVEResponse = createJSONByUVEResponse;
Expand Down Expand Up @@ -1864,3 +1889,4 @@ exports.getWebConfigValueByName = getWebConfigValueByName;
exports.isMultiTenancyEnabled = isMultiTenancyEnabled;
exports.prefixToNetMask = prefixToNetMask;
exports.convertApiServerUUIDtoKeystoneUUID = convertApiServerUUIDtoKeystoneUUID;
exports.getValueByJsonPath = getValueByJsonPath;

0 comments on commit 9c9ef0b

Please sign in to comment.