Skip to content

Instantly share code, notes, and snippets.

@jeffwilcox
Created June 4, 2021 14:30
Show Gist options
  • Save jeffwilcox/3eb652cb088ceaebb6a62fe8ebcb5f7e to your computer and use it in GitHub Desktop.
Save jeffwilcox/3eb652cb088ceaebb6a62fe8ebcb5f7e to your computer and use it in GitHub Desktop.
Quick script to identify users that no longer resolved in the directory
//
// Copyright (c) Microsoft.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
import throat from 'throat';
import app from '../../../app';
import { IProviders } from '../../../interfaces';
import { ErrorHelper } from '../../../transitional';
app.runJob(async function ({ providers }) {
await go(providers);
return {};
}, {
enableAllGitHubApps: true,
});
async function go(providers: IProviders): Promise<void> {
// ---------------------------------------------------------------------------
const { linkProvider, graphProvider } = providers;
const all = await linkProvider.getAll();
// concerning links
let concerns = 0, ok = 0;
let i = 0;
const count = all.length;
const throttle = throat(10);
await Promise.all(all.map(link => throttle(async () => {
try {
if (link.isServiceAccount) {
// We validate service accounts a slightly different way
return;
}
const user = await graphProvider.getUserById(link.corporateId);
if (user && user.userPrincipalName) {
++ok;
} else {
console.log(`ok=${ok}, concerns=${++concerns}, i=${++i} of ${count}; [CONCERN] no graph result for name=${link.corporateDisplayName}, upn= ${link.corporateUsername}, login= ${link.thirdPartyUsername}`);
const halt = false;
}
} catch (error) {
console.log(`ok=${ok}, concerns=${++concerns}, i=${++i} of ${count}`);
if (ErrorHelper.IsNotFound(error)) {
console.log(`404: ${error}`);
} else {
console.log(error);
}
}
})));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment