Handle error gracefully on msgraph api photo load
Signed-off-by: Mustansar Anwar ul Samad <mustansar.samad@gmail.com>
This commit is contained in:
committed by
Fredrik Adelöw
parent
bccb680a59
commit
115473c085
@@ -29,6 +29,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@azure/msal-node": "^1.1.0",
|
||||
"@backstage/backend-common": "^0.8.3",
|
||||
"@backstage/catalog-model": "^0.8.4",
|
||||
"@backstage/config": "^0.1.5",
|
||||
"@backstage/plugin-catalog-backend": "^0.10.4",
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
readMicrosoftGraphUsers,
|
||||
resolveRelations,
|
||||
} from './read';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
|
||||
function user(data: Partial<UserEntity>): UserEntity {
|
||||
return merge(
|
||||
@@ -82,7 +83,7 @@ describe('read microsoft graph', () => {
|
||||
'data:image/jpeg;base64,...',
|
||||
);
|
||||
|
||||
const { users } = await readMicrosoftGraphUsers(client, {
|
||||
const { users } = await readMicrosoftGraphUsers(getVoidLogger(), client, {
|
||||
userFilter: 'accountEnabled eq true',
|
||||
});
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ import {
|
||||
OrganizationTransformer,
|
||||
UserTransformer,
|
||||
} from './types';
|
||||
import { Logger } from 'winston';
|
||||
|
||||
export async function defaultUserTransformer(
|
||||
user: MicrosoftGraph.User,
|
||||
@@ -74,6 +75,7 @@ export async function defaultUserTransformer(
|
||||
}
|
||||
|
||||
export async function readMicrosoftGraphUsers(
|
||||
logger: Logger,
|
||||
client: MicrosoftGraphClient,
|
||||
options?: { userFilter?: string; transformer?: UserTransformer },
|
||||
): Promise<{
|
||||
@@ -91,12 +93,17 @@ export async function readMicrosoftGraphUsers(
|
||||
// Process all users in parallel, otherwise it can take quite some time
|
||||
promises.push(
|
||||
limiter(async () => {
|
||||
const userPhoto = await client.getUserPhotoWithSizeLimit(
|
||||
user.id!,
|
||||
// We are limiting the photo size, as users with full resolution photos
|
||||
// can make the Backstage API slow
|
||||
120,
|
||||
);
|
||||
let userPhoto;
|
||||
try {
|
||||
userPhoto = await client.getUserPhotoWithSizeLimit(
|
||||
user.id!,
|
||||
// We are limiting the photo size, as users with full resolution photos
|
||||
// can make the Backstage API slow
|
||||
120,
|
||||
);
|
||||
} catch (e) {
|
||||
logger.warn(`Unable to load photo for ${user.id}`);
|
||||
}
|
||||
|
||||
const entity = await transformer(user, userPhoto);
|
||||
|
||||
@@ -369,6 +376,7 @@ export function resolveRelations(
|
||||
}
|
||||
|
||||
export async function readMicrosoftGraphOrg(
|
||||
logger: Logger,
|
||||
client: MicrosoftGraphClient,
|
||||
tenantId: string,
|
||||
options?: {
|
||||
@@ -377,7 +385,7 @@ export async function readMicrosoftGraphOrg(
|
||||
groupTransformer?: GroupTransformer;
|
||||
},
|
||||
): Promise<{ users: UserEntity[]; groups: GroupEntity[] }> {
|
||||
const { users } = await readMicrosoftGraphUsers(client, {
|
||||
const { users } = await readMicrosoftGraphUsers(logger, client, {
|
||||
userFilter: options?.userFilter,
|
||||
});
|
||||
const {
|
||||
|
||||
+1
@@ -84,6 +84,7 @@ export class MicrosoftGraphOrgReaderProcessor implements CatalogProcessor {
|
||||
// We create a client each time as we need one that matches the specific provider
|
||||
const client = MicrosoftGraphClient.create(provider);
|
||||
const { users, groups } = await readMicrosoftGraphOrg(
|
||||
this.logger,
|
||||
client,
|
||||
provider.tenantId,
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user