Skip to content

Commit

Permalink
Support profile of groups in LdapOrgReaderProcessor
Browse files Browse the repository at this point in the history
  • Loading branch information
Fox32 committed Dec 15, 2020
1 parent 8dd0a90 commit 7c3ffc0
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .changeset/dirty-wolves-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@backstage/plugin-catalog-backend': patch
---

Support `profile` of groups including `displayName`, `email`, and `picture` in
`LdapOrgReaderProcessor`. The source fields for them can be configured in the
`ldapOrg` provider.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ describe('readLdapConfig', () => {
name: 'cn',
description: 'description',
type: 'groupType',
displayName: 'cn',
memberOf: 'memberOf',
members: 'member',
},
Expand Down Expand Up @@ -114,6 +115,9 @@ describe('readLdapConfig', () => {
name: 'v',
description: 'd',
type: 't',
displayName: 'c',
email: 'm',
picture: 'p',
memberOf: 'm',
members: 'n',
},
Expand Down Expand Up @@ -161,6 +165,9 @@ describe('readLdapConfig', () => {
name: 'v',
description: 'd',
type: 't',
displayName: 'c',
email: 'm',
picture: 'p',
memberOf: 'm',
members: 'n',
},
Expand Down
13 changes: 13 additions & 0 deletions plugins/catalog-backend/src/ingestion/processors/ldap/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ export type GroupConfig = {
// The name of the attribute that shall be used for the value of the
// spec.type field of the entity. Defaults to "groupType".
type: string;
// The name of the attribute that shall be used for the value of the
// spec.profile.displayName field of the entity. Defaults to "cn".
displayName: string;
// The name of the attribute that shall be used for the value of the
// spec.profile.email field of the entity.
email?: string;
// The name of the attribute that shall be used for the value of the
// spec.profile.picture field of the entity.
picture?: string;
// The name of the attribute that shall be used for the values of the
// spec.parent field of the entity. Defaults to "memberOf".
memberOf: string;
Expand Down Expand Up @@ -141,6 +150,7 @@ const defaultConfig = {
rdn: 'cn',
name: 'cn',
description: 'description',
displayName: 'cn',
type: 'groupType',
memberOf: 'memberOf',
members: 'member',
Expand Down Expand Up @@ -220,6 +230,9 @@ export function readLdapConfig(config: Config): LdapProviderConfig[] {
name: c.getOptionalString('name'),
description: c.getOptionalString('description'),
type: c.getOptionalString('type'),
displayName: c.getOptionalString('displayName'),
email: c.getOptionalString('email'),
picture: c.getOptionalString('picture'),
memberOf: c.getOptionalString('memberOf'),
members: c.getOptionalString('members'),
};
Expand Down
10 changes: 10 additions & 0 deletions plugins/catalog-backend/src/ingestion/processors/ldap/read.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ describe('readLdapGroups', () => {
cn: ['cn-value'],
description: ['description-value'],
tt: ['type-value'],
mail: ['mail-value'],
avatarUrl: ['avatarUrl-value'],
memberOf: ['x', 'y', 'z'],
member: ['e', 'f', 'g'],
entryDN: ['dn-value'],
Expand All @@ -151,6 +153,9 @@ describe('readLdapGroups', () => {
rdn: 'cn',
name: 'cn',
description: 'description',
displayName: 'cn',
email: 'mail',
picture: 'avatarUrl',
type: 'tt',
memberOf: 'memberOf',
members: 'member',
Expand All @@ -173,6 +178,11 @@ describe('readLdapGroups', () => {
},
spec: {
type: 'type-value',
profile: {
displayName: 'cn-value',
email: 'mail-value',
picture: 'avatarUrl-value',
},
children: [],
},
}),
Expand Down
10 changes: 10 additions & 0 deletions plugins/catalog-backend/src/ingestion/processors/ldap/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export async function readLdapGroups(
},
spec: {
type: 'unknown',
profile: {},
children: [],
},
};
Expand Down Expand Up @@ -178,6 +179,15 @@ export async function readLdapGroups(
mapStringAttr(attributes, map.type, v => {
entity.spec.type = v;
});
mapStringAttr(attributes, map.displayName, v => {
entity.spec.profile!.displayName = v;
});
mapStringAttr(attributes, map.email, v => {
entity.spec.profile!.email = v;
});
mapStringAttr(attributes, map.picture, v => {
entity.spec.profile!.picture = v;
});

mapReferencesAttr(attributes, map.memberOf, (myDn, vs) => {
ensureItems(groupMemberOf, myDn, vs);
Expand Down

0 comments on commit 7c3ffc0

Please sign in to comment.