From 506b912519a64722518e2b2c631a53b8bdda9379 Mon Sep 17 00:00:00 2001 From: Kevin Nielsen Date: Mon, 16 Mar 2020 19:43:08 -0700 Subject: [PATCH] v1.2.0 Added a placeholder method to retrieve consolidated user records from a relationship tree. Bumped to 1.2 range just for the sake of version pariety with @al/common and @al/session. --- package.json | 2 +- src/aims-client.ts | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index d00a9b9..ae65ddd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@al/aims", - "version": "1.1.6", + "version": "1.2.0", "license": "MIT", "description": "A client for interacting with the Alert Logic AIMS Public API", "author": { diff --git a/src/aims-client.ts b/src/aims-client.ts index 868ff41..8ad32da 100644 --- a/src/aims-client.ts +++ b/src/aims-client.ts @@ -158,6 +158,29 @@ export class AIMSClientInstance { return managedAccounts.accounts as AIMSAccount[]; } + /** + * Retrieve a union of user records corresponding to a managed relationship hierarchy between two accounts. + * This is a placeholder for a better implementation based on a relationship topology endpoint from AIMS.0 + */ + async getUsersFromManagedRelationship( leafAccountId:string, terminalAccountId?:string, failOnError:boolean = true ):Promise { + let users = await this.getUsers( leafAccountId, { include_role_ids: false, include_user_credential: false } ); + try { + let managing = await this.getAccountsByRelationship( leafAccountId, "managing" ); + if ( managing.length > 0 ) { + managing.sort( ( a, b ) => parseInt( b.id, 10 ) - parseInt( a.id, 10 ) ); // this is gross hackery. Kevin did not implement this. Tell no-one of what you've seen! + let parentUsers = await this.getUsersFromManagedRelationship( managing[0].id, terminalAccountId ); + if ( Array.isArray( parentUsers ) ) { + users = users.concat( parentUsers ); + } + } + } catch( e ) { + if ( failOnError ) { + throw e; + } + } + return users; + } + /** * Update account MFA requirements * POST