Re-adding user namespacing

Signed-off-by: Gregory Yogan <gregory.yogan@unity3d.com>
This commit is contained in:
Gregory Yogan
2021-08-25 13:12:00 -07:00
parent 8b066c47d5
commit 977b1dfbea
6 changed files with 43 additions and 7 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-backend': minor
---
Adds optional namespacing for users in the GitHub Multi Org Plugin
+7
View File
@@ -163,6 +163,13 @@ export interface Config {
* Defaults to org name if omitted.
*/
groupNamespace?: string;
/**
* The namespace of the users created from this org.
*
* Defaults to empty string if omitted.
*/
userNamespace?: string;
}>;
};
@@ -111,6 +111,7 @@ export class GithubMultiOrgReaderProcessor implements CatalogProcessor {
client,
orgConfig.name,
tokenType,
orgConfig.userNamespace,
);
const { groups, groupMemberUsers } = await getOrganizationTeams(
client,
@@ -78,32 +78,48 @@ describe('config', () => {
});
describe('readGithubMultiOrgConfig', () => {
function config(orgs: { name: string; groupNamespace?: string }[]) {
function config(
orgs: { name: string; groupNamespace?: string; userNamespace?: string }[],
) {
return new ConfigReader({ orgs });
}
it('reads org configs', () => {
const output = readGithubMultiOrgConfig(
config([
{ name: 'foo', groupNamespace: 'apple' },
{ name: 'bar', groupNamespace: 'Orange' },
{ name: 'foo', groupNamespace: 'apple', userNamespace: 'red' },
{ name: 'bar', groupNamespace: 'Orange', userNamespace: 'blue' },
]),
);
expect(output).toEqual([
{ name: 'foo', groupNamespace: 'apple' },
{ name: 'bar', groupNamespace: 'orange' },
{ name: 'foo', groupNamespace: 'apple', userNamespace: 'red' },
{ name: 'bar', groupNamespace: 'orange', userNamespace: 'blue' },
]);
});
it('defaults groupNamespace to org name if undefined', () => {
const output = readGithubMultiOrgConfig(
config([
{ name: 'foo', userNamespace: 'red' },
{ name: 'bar', userNamespace: 'blue' },
]),
);
expect(output).toEqual([
{ name: 'foo', groupNamespace: 'foo', userNamespace: 'red' },
{ name: 'bar', groupNamespace: 'bar', userNamespace: 'blue' },
]);
});
it('defaults userNamespace to empty string if undefined', () => {
const output = readGithubMultiOrgConfig(
config([{ name: 'foo' }, { name: 'bar' }]),
);
expect(output).toEqual([
{ name: 'foo', groupNamespace: 'foo' },
{ name: 'bar', groupNamespace: 'bar' },
{ name: 'foo', groupNamespace: 'foo', userNamespace: '' },
{ name: 'bar', groupNamespace: 'bar', userNamespace: '' },
]);
});
});
@@ -95,6 +95,10 @@ export type GithubMultiOrgConfig = Array<{
* The namespace of the group created for this org.
*/
groupNamespace: string;
/**
* The namespace of the users created for this org.
*/
userNamespace: string;
}>;
export function readGithubMultiOrgConfig(config: Config): GithubMultiOrgConfig {
@@ -104,5 +108,6 @@ export function readGithubMultiOrgConfig(config: Config): GithubMultiOrgConfig {
groupNamespace: (
c.getOptionalString('groupNamespace') ?? c.getString('name')
).toLowerCase(),
userNamespace: c.getOptionalString('userNamespace') ?? '',
}));
}
@@ -82,6 +82,7 @@ export async function getOrganizationUsers(
client: typeof graphql,
org: string,
tokenType: GithubCredentialType,
userNamespace?: string,
): Promise<{ users: UserEntity[] }> {
const query = `
query users($org: String!, $email: Boolean!, $cursor: String) {
@@ -117,6 +118,7 @@ export async function getOrganizationUsers(
},
};
if (userNamespace) entity.metadata.namespace = userNamespace;
if (user.bio) entity.metadata.description = user.bio;
if (user.name) entity.spec.profile!.displayName = user.name;
if (user.email) entity.spec.profile!.email = user.email;