Pass along a OrganizationTransformer to the read step

Follow up to #6855

Signed-off-by: Oliver Sand <oliver.sand@sda-se.com>
This commit is contained in:
Oliver Sand
2021-08-18 09:05:14 +02:00
parent 7c1e6deefe
commit be498d22fe
4 changed files with 27 additions and 5 deletions
@@ -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<{
@@ -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<string, Set<string>> = 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<string>());
groups.push(rootGroup);
}
const transformer = options?.transformer ?? defaultGroupTransformer;
const transformer = options?.groupTransformer ?? defaultGroupTransformer;
const promises: Promise<void>[] = [];
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);
@@ -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,
},
);