Skip to content

Commit

Permalink
Merge pull request #287 from tobiaslohr/org-support-more-properties
Browse files Browse the repository at this point in the history
Org support more properties
  • Loading branch information
tobiaslohr authored Feb 15, 2022
2 parents c538155 + 1902a35 commit 3d9f1a4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
29 changes: 14 additions & 15 deletions lib/org.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ var auth = require('./auth');
var console = require('./log');

const API_BASE = '/dw/rest/v1';
const ORG_ALLOWED_READ_PROPERTIES = [ 'id', 'name', 'realms', 'twoFARoles' ];

/**
* Helper to capture most-common responses due to errors which occur across resources. In case a well-known issue
Expand Down Expand Up @@ -93,32 +92,29 @@ function getOrg(org, token, callback) {
return ( cand.name === org );
});
if ( filtered.length === 1 ) {
callback(undefined, filterOrg(filtered[0]));
callback(undefined, toExternalOrg(filtered[0]));
return;
}
// report ambiguousness
callback(new Error(util.format('Org %s is ambiguous', org)));
return;
}
// do the callback with the body
callback(undefined, filterOrg(body.content[0]));
callback(undefined, toExternalOrg(body.content[0]));
});
}

/**
* Filters properties of the passed org and returns a reduced object containing only
* an allowed list of properties.
* Transforms the API org representation to an external format. Certain properties are
* transformed into an object representation.
*
* @param {Object} org the original org object
* @return {Object} the filtered org
* @return {Object} the transformed org object
*/
function filterOrg(org) {
for (var prop in org) {
if (org.hasOwnProperty(prop) && ORG_ALLOWED_READ_PROPERTIES.indexOf(prop) === -1) {
// delete the property if not allowed to read
delete org[prop];
}
}
function toExternalOrg(org) {
// always delete some properties
delete org['links'];

return org;
}

Expand Down Expand Up @@ -197,9 +193,12 @@ module.exports.cli = {
}

// table fields
var data = [['id', 'name','realms','twoFARoles']];
var data = [['id', 'name','realms','twoFARoles','twoFAEnabled','allowedVerifierTypes','vaasEnabled',
'sfIdentityFederation']];
for (var i of list) {
data.push([i.id, i.name, i.realms.length, ( i.twoFARoles.length > 0 )]);
var org = toExternalOrg(i);
data.push([org.id, org.name, org.realms.length, org.twoFARoles.length, org.twoFAEnabled,
org.allowedVerifierTypes.length, org.vaasEnabled, org.sfIdentityFederation]);
}

console.table(data);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/org.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ describe('Tests for lib/org.js', function() {
it('properly filters internal properties', function(done) {
var org = proxyquire('../../lib/org', {
'request': function (opts, callback) {
callback(undefined, {statusCode: 200}, {content:[{id:1,name:"myorg",internal:'yes'}]});
callback(undefined, {statusCode: 200}, {content:[{id:1,name:"myorg",links:'yes'}]});
},
'./auth': {
'getToken' : () => 'mytoken',
Expand Down

0 comments on commit 3d9f1a4

Please sign in to comment.