From 19727d19b1c6959b87dbdb35923aae18c8f77c3d Mon Sep 17 00:00:00 2001 From: Gregory Yogan Date: Fri, 27 Aug 2021 09:11:15 -0700 Subject: [PATCH] Adding undefined handling of usernamespace and namespaced user deduplicaiton Signed-off-by: Gregory Yogan --- .../processors/GithubMultiOrgReaderProcessor.ts | 9 ++++++--- .../src/ingestion/processors/github/config.test.ts | 7 +++---- .../src/ingestion/processors/github/config.ts | 6 +++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/plugins/catalog-backend/src/ingestion/processors/GithubMultiOrgReaderProcessor.ts b/plugins/catalog-backend/src/ingestion/processors/GithubMultiOrgReaderProcessor.ts index dfe48939bc..e09cff2f1e 100644 --- a/plugins/catalog-backend/src/ingestion/processors/GithubMultiOrgReaderProcessor.ts +++ b/plugins/catalog-backend/src/ingestion/processors/GithubMultiOrgReaderProcessor.ts @@ -124,15 +124,18 @@ export class GithubMultiOrgReaderProcessor implements CatalogProcessor { `Read ${users.length} GitHub users and ${groups.length} GitHub teams from ${orgConfig.name} in ${duration} seconds`, ); + var prefix:string = orgConfig.userNamespace ?? ''; + if (prefix.length > 0) prefix += '/'; + users.forEach(u => { - if (!allUsersMap.has(u.metadata.name)) { - allUsersMap.set(u.metadata.name, u); + if (!allUsersMap.has(prefix + u.metadata.name)) { + allUsersMap.set(prefix + u.metadata.name, u); } }); for (const [groupName, userNames] of groupMemberUsers.entries()) { for (const userName of userNames) { - const user = allUsersMap.get(userName); + const user = allUsersMap.get(prefix + userName); if (user && !user.spec.memberOf.includes(groupName)) { user.spec.memberOf.push(groupName); } diff --git a/plugins/catalog-backend/src/ingestion/processors/github/config.test.ts b/plugins/catalog-backend/src/ingestion/processors/github/config.test.ts index 9aa6ee41d7..4b834938a6 100644 --- a/plugins/catalog-backend/src/ingestion/processors/github/config.test.ts +++ b/plugins/catalog-backend/src/ingestion/processors/github/config.test.ts @@ -112,14 +112,13 @@ describe('config', () => { ]); }); - it('defaults userNamespace to empty string if undefined', () => { - const output = readGithubMultiOrgConfig( + it('defaults userNamespace to undefined if unspecified', () => { const output = readGithubMultiOrgConfig( config([{ name: 'foo' }, { name: 'bar' }]), ); expect(output).toEqual([ - { name: 'foo', groupNamespace: 'foo', userNamespace: '' }, - { name: 'bar', groupNamespace: 'bar', userNamespace: '' }, + { name: 'foo', groupNamespace: 'foo', userNamespace: undefined }, + { name: 'bar', groupNamespace: 'bar', userNamespace: undefined }, ]); }); }); diff --git a/plugins/catalog-backend/src/ingestion/processors/github/config.ts b/plugins/catalog-backend/src/ingestion/processors/github/config.ts index 440b0d7801..df9e19ff10 100644 --- a/plugins/catalog-backend/src/ingestion/processors/github/config.ts +++ b/plugins/catalog-backend/src/ingestion/processors/github/config.ts @@ -96,9 +96,9 @@ export type GithubMultiOrgConfig = Array<{ */ groupNamespace: string; /** - * The namespace of the users created for this org. + * The namespace of the users created for this org. If not specified defaults to undefined. */ - userNamespace: string; + userNamespace: string | undefined; }>; export function readGithubMultiOrgConfig(config: Config): GithubMultiOrgConfig { @@ -108,6 +108,6 @@ export function readGithubMultiOrgConfig(config: Config): GithubMultiOrgConfig { groupNamespace: ( c.getOptionalString('groupNamespace') ?? c.getString('name') ).toLowerCase(), - userNamespace: c.getOptionalString('userNamespace') ?? '', + userNamespace: c.getOptionalString('userNamespace') ?? undefined, })); }