fix api-report, move logger to options
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
@@ -103,10 +103,11 @@ export type OrganizationTransformer = (organization: MicrosoftGraph.Organization
|
||||
export function readMicrosoftGraphConfig(config: Config): MicrosoftGraphProviderConfig[];
|
||||
|
||||
// @public (undocumented)
|
||||
export function readMicrosoftGraphOrg(client: MicrosoftGraphClient, tenantId: string, options?: {
|
||||
export function readMicrosoftGraphOrg(client: MicrosoftGraphClient, tenantId: string, options: {
|
||||
userFilter?: string;
|
||||
groupFilter?: string;
|
||||
groupTransformer?: GroupTransformer;
|
||||
logger: Logger;
|
||||
}): Promise<{
|
||||
users: UserEntity[];
|
||||
groups: GroupEntity[];
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
},
|
||||
"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",
|
||||
@@ -41,6 +40,7 @@
|
||||
"qs": "^6.9.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@backstage/backend-common": "^0.8.3",
|
||||
"@backstage/cli": "^0.7.2",
|
||||
"@backstage/test-utils": "^0.1.14",
|
||||
"@types/lodash": "^4.14.151",
|
||||
|
||||
@@ -83,8 +83,9 @@ describe('read microsoft graph', () => {
|
||||
'data:image/jpeg;base64,...',
|
||||
);
|
||||
|
||||
const { users } = await readMicrosoftGraphUsers(getVoidLogger(), client, {
|
||||
const { users } = await readMicrosoftGraphUsers(client, {
|
||||
userFilter: 'accountEnabled eq true',
|
||||
logger: getVoidLogger(),
|
||||
});
|
||||
|
||||
expect(users).toEqual([
|
||||
|
||||
@@ -75,9 +75,12 @@ export async function defaultUserTransformer(
|
||||
}
|
||||
|
||||
export async function readMicrosoftGraphUsers(
|
||||
logger: Logger,
|
||||
client: MicrosoftGraphClient,
|
||||
options?: { userFilter?: string; transformer?: UserTransformer },
|
||||
options: {
|
||||
userFilter?: string;
|
||||
transformer?: UserTransformer;
|
||||
logger: Logger;
|
||||
},
|
||||
): Promise<{
|
||||
users: UserEntity[]; // With all relations empty
|
||||
}> {
|
||||
@@ -88,7 +91,7 @@ export async function readMicrosoftGraphUsers(
|
||||
const promises: Promise<void>[] = [];
|
||||
|
||||
for await (const user of client.getUsers({
|
||||
filter: options?.userFilter,
|
||||
filter: options.userFilter,
|
||||
})) {
|
||||
// Process all users in parallel, otherwise it can take quite some time
|
||||
promises.push(
|
||||
@@ -102,7 +105,7 @@ export async function readMicrosoftGraphUsers(
|
||||
120,
|
||||
);
|
||||
} catch (e) {
|
||||
logger.warn(`Unable to load photo for ${user.id}`);
|
||||
options.logger.warn(`Unable to load photo for ${user.id}`);
|
||||
}
|
||||
|
||||
const entity = await transformer(user, userPhoto);
|
||||
@@ -376,17 +379,18 @@ export function resolveRelations(
|
||||
}
|
||||
|
||||
export async function readMicrosoftGraphOrg(
|
||||
logger: Logger,
|
||||
client: MicrosoftGraphClient,
|
||||
tenantId: string,
|
||||
options?: {
|
||||
options: {
|
||||
userFilter?: string;
|
||||
groupFilter?: string;
|
||||
groupTransformer?: GroupTransformer;
|
||||
logger: Logger;
|
||||
},
|
||||
): Promise<{ users: UserEntity[]; groups: GroupEntity[] }> {
|
||||
const { users } = await readMicrosoftGraphUsers(logger, client, {
|
||||
userFilter: options?.userFilter,
|
||||
const { users } = await readMicrosoftGraphUsers(client, {
|
||||
userFilter: options.userFilter,
|
||||
logger: options.logger,
|
||||
});
|
||||
const {
|
||||
groups,
|
||||
|
||||
+1
-1
@@ -84,13 +84,13 @@ 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,
|
||||
{
|
||||
userFilter: provider.userFilter,
|
||||
groupFilter: provider.groupFilter,
|
||||
groupTransformer: this.groupTransformer,
|
||||
logger: this.logger,
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user