Adding undefined handling of usernamespace and namespaced user deduplicaiton

Signed-off-by: Gregory Yogan <gregory.yogan@unity3d.com>
This commit is contained in:
Gregory Yogan
2021-08-27 09:11:15 -07:00
parent 810c114644
commit 19727d19b1
3 changed files with 12 additions and 10 deletions
@@ -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);
}
@@ -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 },
]);
});
});
@@ -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,
}));
}