From be498d22feb04cf97ed2a29c4a6a36eccfcd062d Mon Sep 17 00:00:00 2001 From: Oliver Sand Date: Wed, 18 Aug 2021 09:05:14 +0200 Subject: [PATCH] Pass along a `OrganizationTransformer` to the read step Follow up to #6855 Signed-off-by: Oliver Sand --- .changeset/violet-fishes-look.md | 5 +++++ .../api-report.md | 3 +++ .../src/microsoftGraph/read.ts | 18 +++++++++++++----- .../MicrosoftGraphOrgReaderProcessor.ts | 6 ++++++ 4 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 .changeset/violet-fishes-look.md diff --git a/.changeset/violet-fishes-look.md b/.changeset/violet-fishes-look.md new file mode 100644 index 0000000000..f526638a59 --- /dev/null +++ b/.changeset/violet-fishes-look.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend-module-msgraph': patch +--- + +Pass along a `OrganizationTransformer` to the read step diff --git a/plugins/catalog-backend-module-msgraph/api-report.md b/plugins/catalog-backend-module-msgraph/api-report.md index f614bdca36..7a10ad2995 100644 --- a/plugins/catalog-backend-module-msgraph/api-report.md +++ b/plugins/catalog-backend-module-msgraph/api-report.md @@ -113,6 +113,7 @@ export class MicrosoftGraphOrgReaderProcessor implements CatalogProcessor { logger: Logger_2; userTransformer?: UserTransformer; groupTransformer?: GroupTransformer; + organizationTransformer?: OrganizationTransformer; }); // (undocumented) static fromConfig( @@ -121,6 +122,7 @@ export class MicrosoftGraphOrgReaderProcessor implements CatalogProcessor { logger: Logger_2; userTransformer?: UserTransformer; groupTransformer?: GroupTransformer; + organizationTransformer?: OrganizationTransformer; }, ): MicrosoftGraphOrgReaderProcessor; // (undocumented) @@ -174,6 +176,7 @@ export function readMicrosoftGraphOrg( groupFilter?: string; userTransformer?: UserTransformer; groupTransformer?: GroupTransformer; + organizationTransformer?: OrganizationTransformer; logger: Logger_2; }, ): Promise<{ diff --git a/plugins/catalog-backend-module-msgraph/src/microsoftGraph/read.ts b/plugins/catalog-backend-module-msgraph/src/microsoftGraph/read.ts index 6fbd2cb0de..096cf8a479 100644 --- a/plugins/catalog-backend-module-msgraph/src/microsoftGraph/read.ts +++ b/plugins/catalog-backend-module-msgraph/src/microsoftGraph/read.ts @@ -20,6 +20,7 @@ import { } from '@backstage/catalog-model'; import * as MicrosoftGraph from '@microsoft/microsoft-graph-types'; import limiterFactory from 'p-limit'; +import { Logger } from 'winston'; import { MicrosoftGraphClient } from './client'; import { MICROSOFT_GRAPH_GROUP_ID_ANNOTATION, @@ -33,7 +34,6 @@ import { OrganizationTransformer, UserTransformer, } from './types'; -import { Logger } from 'winston'; export async function defaultUserTransformer( user: MicrosoftGraph.User, @@ -212,7 +212,11 @@ export async function defaultGroupTransformer( export async function readMicrosoftGraphGroups( client: MicrosoftGraphClient, tenantId: string, - options?: { groupFilter?: string; transformer?: GroupTransformer }, + options?: { + groupFilter?: string; + groupTransformer?: GroupTransformer; + organizationTransformer?: OrganizationTransformer; + }, ): Promise<{ groups: GroupEntity[]; // With all relations empty rootGroup: GroupEntity | undefined; // With all relations empty @@ -224,13 +228,15 @@ export async function readMicrosoftGraphGroups( const groupMemberOf: Map> = new Map(); const limiter = limiterFactory(10); - const { rootGroup } = await readMicrosoftGraphOrganization(client, tenantId); + const { rootGroup } = await readMicrosoftGraphOrganization(client, tenantId, { + transformer: options?.organizationTransformer, + }); if (rootGroup) { groupMember.set(rootGroup.metadata.name, new Set()); groups.push(rootGroup); } - const transformer = options?.transformer ?? defaultGroupTransformer; + const transformer = options?.groupTransformer ?? defaultGroupTransformer; const promises: Promise[] = []; for await (const group of client.getGroups({ @@ -384,6 +390,7 @@ export async function readMicrosoftGraphOrg( groupFilter?: string; userTransformer?: UserTransformer; groupTransformer?: GroupTransformer; + organizationTransformer?: OrganizationTransformer; logger: Logger; }, ): Promise<{ users: UserEntity[]; groups: GroupEntity[] }> { @@ -395,7 +402,8 @@ export async function readMicrosoftGraphOrg( const { groups, rootGroup, groupMember, groupMemberOf } = await readMicrosoftGraphGroups(client, tenantId, { groupFilter: options?.groupFilter, - transformer: options?.groupTransformer, + groupTransformer: options?.groupTransformer, + organizationTransformer: options?.organizationTransformer, }); resolveRelations(rootGroup, groups, users, groupMember, groupMemberOf); diff --git a/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgReaderProcessor.ts b/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgReaderProcessor.ts index 1495bce93c..161cc8799f 100644 --- a/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgReaderProcessor.ts +++ b/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgReaderProcessor.ts @@ -26,6 +26,7 @@ import { GroupTransformer, MicrosoftGraphClient, MicrosoftGraphProviderConfig, + OrganizationTransformer, readMicrosoftGraphConfig, readMicrosoftGraphOrg, UserTransformer, @@ -39,6 +40,7 @@ export class MicrosoftGraphOrgReaderProcessor implements CatalogProcessor { private readonly logger: Logger; private readonly userTransformer?: UserTransformer; private readonly groupTransformer?: GroupTransformer; + private readonly organizationTransformer?: OrganizationTransformer; static fromConfig( config: Config, @@ -46,6 +48,7 @@ export class MicrosoftGraphOrgReaderProcessor implements CatalogProcessor { logger: Logger; userTransformer?: UserTransformer; groupTransformer?: GroupTransformer; + organizationTransformer?: OrganizationTransformer; }, ) { const c = config.getOptionalConfig('catalog.processors.microsoftGraphOrg'); @@ -60,11 +63,13 @@ export class MicrosoftGraphOrgReaderProcessor implements CatalogProcessor { logger: Logger; userTransformer?: UserTransformer; groupTransformer?: GroupTransformer; + organizationTransformer?: OrganizationTransformer; }) { this.providers = options.providers; this.logger = options.logger; this.userTransformer = options.userTransformer; this.groupTransformer = options.groupTransformer; + this.organizationTransformer = options.organizationTransformer; } async readLocation( @@ -99,6 +104,7 @@ export class MicrosoftGraphOrgReaderProcessor implements CatalogProcessor { groupFilter: provider.groupFilter, userTransformer: this.userTransformer, groupTransformer: this.groupTransformer, + organizationTransformer: this.organizationTransformer, logger: this.logger, }, );