mirror of
https://github.com/bitwarden/directory-connector
synced 2025-12-14 23:33:19 +00:00
Improve okta group performance (#132)
* Avoid unnecessary API calls to Okta Filter excluded/included groups as early as possible to avoid using up API calls and long waits * Remove console timing calls
This commit is contained in:
@@ -14,9 +14,12 @@ import { LogService } from 'jslib-common/abstractions/log.service';
|
|||||||
|
|
||||||
import * as https from 'https';
|
import * as https from 'https';
|
||||||
|
|
||||||
|
const DelayBetweenBuildGroupCallsInMilliseconds = 500;
|
||||||
|
|
||||||
export class OktaDirectoryService extends BaseDirectoryService implements IDirectoryService {
|
export class OktaDirectoryService extends BaseDirectoryService implements IDirectoryService {
|
||||||
private dirConfig: OktaConfiguration;
|
private dirConfig: OktaConfiguration;
|
||||||
private syncConfig: SyncConfiguration;
|
private syncConfig: SyncConfiguration;
|
||||||
|
private lastBuildGroupCall: number;
|
||||||
|
|
||||||
constructor(private configurationService: ConfigurationService, private logService: LogService,
|
constructor(private configurationService: ConfigurationService, private logService: LogService,
|
||||||
private i18nService: I18nService) {
|
private i18nService: I18nService) {
|
||||||
@@ -116,13 +119,11 @@ export class OktaDirectoryService extends BaseDirectoryService implements IDirec
|
|||||||
|
|
||||||
this.logService.info('Querying groups.');
|
this.logService.info('Querying groups.');
|
||||||
await this.apiGetMany('groups?filter=' + this.encodeUrlParameter(oktaFilter)).then(async (groups: any[]) => {
|
await this.apiGetMany('groups?filter=' + this.encodeUrlParameter(oktaFilter)).then(async (groups: any[]) => {
|
||||||
for (const group of groups) {
|
for (const group of groups.filter(g => !this.filterOutResult(setFilter, g.profile.name))) {
|
||||||
const entry = await this.buildGroup(group);
|
const entry = await this.buildGroup(group);
|
||||||
if (entry != null && !this.filterOutResult(setFilter, entry.name)) {
|
if (entry != null) {
|
||||||
entries.push(entry);
|
entries.push(entry);
|
||||||
}
|
}
|
||||||
// throttle some to avoid rate limiting
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 500));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return entries;
|
return entries;
|
||||||
@@ -134,6 +135,14 @@ export class OktaDirectoryService extends BaseDirectoryService implements IDirec
|
|||||||
entry.referenceId = group.id;
|
entry.referenceId = group.id;
|
||||||
entry.name = group.profile.name;
|
entry.name = group.profile.name;
|
||||||
|
|
||||||
|
// throttle some to avoid rate limiting
|
||||||
|
const neededDelay = DelayBetweenBuildGroupCallsInMilliseconds - (Date.now() - this.lastBuildGroupCall);
|
||||||
|
if (neededDelay > 0) {
|
||||||
|
await new Promise(resolve =>
|
||||||
|
setTimeout(resolve, neededDelay));
|
||||||
|
}
|
||||||
|
this.lastBuildGroupCall = Date.now();
|
||||||
|
|
||||||
await this.apiGetMany('groups/' + group.id + '/users').then((users: any[]) => {
|
await this.apiGetMany('groups/' + group.id + '/users').then((users: any[]) => {
|
||||||
for (const user of users) {
|
for (const user of users) {
|
||||||
entry.userMemberExternalIds.add(user.id);
|
entry.userMemberExternalIds.add(user.id);
|
||||||
|
|||||||
Reference in New Issue
Block a user