Skip to content

Commit

Permalink
catalog-model: make User spec.memberOf theoretically - but not practi…
Browse files Browse the repository at this point in the history
…cally - optional

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
  • Loading branch information
freben committed Mar 15, 2022
1 parent 2d63d04 commit 132189e
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 7 deletions.
8 changes: 8 additions & 0 deletions .changeset/eighty-taxis-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@backstage/plugin-catalog-backend-module-github': patch
'@backstage/plugin-catalog-backend-module-ldap': patch
'@backstage/plugin-catalog-backend-module-msgraph': patch
'@backstage/plugin-org': patch
---

Updated the code to handle User kind `spec.memberOf` now being optional.
14 changes: 14 additions & 0 deletions .changeset/strong-dolphins-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@backstage/catalog-model': minor
---

**BREAKING**: The User kind has an updated TypeScript type where `spec.memberOf`
is optional.

**NOTE HOWEVER**, that this only applies to the TypeScript types `UserEntity`
and `UserEntityV1alpha1`. The catalog validation still requires the field to be
set, even if it's in the form of an empty array. If you try to ingest data that
stops producing this field, those entities _will be rejected_ by the catalog.
The reason for these choices is that consumers will get a long grace period
where old code still can rely on the underlying data being present, giving users
ample time to update before actual breakages could happen.
2 changes: 1 addition & 1 deletion packages/catalog-model/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ interface UserEntityV1alpha1 extends Entity {
email?: string;
picture?: string;
};
memberOf: string[];
memberOf?: string[];
};
}
export { UserEntityV1alpha1 as UserEntity };
Expand Down
2 changes: 1 addition & 1 deletion packages/catalog-model/src/kinds/UserEntityV1alpha1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface UserEntityV1alpha1 extends Entity {
email?: string;
picture?: string;
};
memberOf: string[];
memberOf?: string[];
};
}

Expand Down
7 changes: 5 additions & 2 deletions plugins/catalog-backend-module-github/src/lib/org.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ export function assignGroupsToUsers(
for (const [groupName, userNames] of groupMemberUsers.entries()) {
for (const userName of userNames) {
const user = usersByName.get(userName);
if (user && !user.spec.memberOf.includes(groupName)) {
if (user && !user.spec.memberOf?.includes(groupName)) {
if (!user.spec.memberOf) {
user.spec.memberOf = [];
}
user.spec.memberOf.push(groupName);
}
}
Expand All @@ -74,7 +77,7 @@ export function buildMemberOf(groups: GroupEntity[], users: UserEntity[]) {
const transitiveMemberOf = new Set<string>();

const todo = [
...user.spec.memberOf,
...(user.spec.memberOf ?? []),
...groups
.filter(g => g.spec.members?.includes(user.metadata.name))
.map(g => g.metadata.name),
Expand Down
2 changes: 1 addition & 1 deletion plugins/catalog-backend-module-ldap/src/ldap/org.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function buildMemberOf(groups: GroupEntity[], users: UserEntity[]) {
const transitiveMemberOf = new Set<string>();

const todo = [
...user.spec.memberOf,
...(user.spec.memberOf ?? []),
...groups
.filter(g => g.spec.members?.includes(user.metadata.name))
.map(g => g.metadata.name),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function buildMemberOf(groups: GroupEntity[], users: UserEntity[]) {
const transitiveMemberOf = new Set<string>();

const todo = [
...user.spec.memberOf,
...(user.spec.memberOf ?? []),
...groups
.filter(g => g.spec.members?.includes(user.metadata.name))
.map(g => g.metadata.name),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,9 @@ export function resolveRelations(
retrieveItems(groupMemberOf, id).forEach(p => {
const parentGroup = groupMap.get(p);
if (parentGroup) {
if (!user.spec.memberOf) {
user.spec.memberOf = [];
}
user.spec.memberOf.push(stringifyEntityRef(parentGroup));
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const getQueryParams = (
};
if (owner.kind === 'User') {
const user = owner as UserEntity;
filters.owners = [...filters.owners, ...user.spec.memberOf];
filters.owners = [...filters.owners, ...(user.spec.memberOf ?? [])];
}
const queryParams = qs.stringify(
{
Expand Down

0 comments on commit 132189e

Please sign in to comment.