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