Fix the schema / code mismatch in LDAP set config
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-backend': minor
|
||||
---
|
||||
|
||||
Fix the schema / code mismatch in LDAP `set` config
|
||||
@@ -88,7 +88,7 @@ describe('readLdapConfig', () => {
|
||||
filter: 'f',
|
||||
paged: true,
|
||||
},
|
||||
set: [{ path: 'p', value: 'v' }],
|
||||
set: { p: 'v' },
|
||||
map: {
|
||||
rdn: 'u',
|
||||
name: 'v',
|
||||
@@ -107,7 +107,7 @@ describe('readLdapConfig', () => {
|
||||
filter: 'f',
|
||||
paged: true,
|
||||
},
|
||||
set: [{ path: 'p', value: 'v' }],
|
||||
set: { p: 'v' },
|
||||
map: {
|
||||
rdn: 'u',
|
||||
name: 'v',
|
||||
@@ -136,7 +136,7 @@ describe('readLdapConfig', () => {
|
||||
filter: 'f',
|
||||
paged: true,
|
||||
},
|
||||
set: [{ path: 'p', value: 'v' }],
|
||||
set: { p: 'v' },
|
||||
map: {
|
||||
rdn: 'u',
|
||||
name: 'v',
|
||||
@@ -155,7 +155,7 @@ describe('readLdapConfig', () => {
|
||||
filter: 'f',
|
||||
paged: true,
|
||||
},
|
||||
set: [{ path: 'p', value: 'v' }],
|
||||
set: { p: 'v' },
|
||||
map: {
|
||||
rdn: 'u',
|
||||
name: 'v',
|
||||
@@ -182,9 +182,9 @@ describe('readLdapConfig', () => {
|
||||
dn: 'udn',
|
||||
options: {
|
||||
filter: `
|
||||
(|
|
||||
(cn=foo bar)
|
||||
(cn=bar)
|
||||
(|
|
||||
(cn=foo bar)
|
||||
(cn=bar)
|
||||
)
|
||||
`,
|
||||
},
|
||||
|
||||
@@ -57,7 +57,7 @@ export type UserConfig = {
|
||||
// default is scope "one" and attributes "*" and "+".
|
||||
options: SearchOptions;
|
||||
// JSON paths (on a.b.c form) and hard coded values to set on those paths
|
||||
set?: { path: string; value: JsonValue }[];
|
||||
set?: { [path: string]: JsonValue };
|
||||
// Mappings from well known entity fields, to LDAP attribute names
|
||||
map: {
|
||||
// The name of the attribute that holds the relative distinguished name of
|
||||
@@ -94,7 +94,7 @@ export type GroupConfig = {
|
||||
// Only the scope, filter, attributes, and paged fields are supported.
|
||||
options: SearchOptions;
|
||||
// JSON paths (on a.b.c form) and hard coded values to set on those paths
|
||||
set?: { path: string; value: JsonValue }[];
|
||||
set?: { [path: string]: JsonValue };
|
||||
// Mappings from well known entity fields, to LDAP attribute names
|
||||
map: {
|
||||
// The name of the attribute that holds the relative distinguished name of
|
||||
@@ -189,15 +189,12 @@ export function readLdapConfig(config: Config): LdapProviderConfig[] {
|
||||
}
|
||||
|
||||
function readSetConfig(
|
||||
c: Config[] | undefined,
|
||||
): { path: string; value: JsonValue }[] | undefined {
|
||||
c: Config | undefined,
|
||||
): { [path: string]: JsonValue } | undefined {
|
||||
if (!c) {
|
||||
return undefined;
|
||||
}
|
||||
return c.map(entry => ({
|
||||
path: entry.getString('path'),
|
||||
value: entry.get('value'),
|
||||
}));
|
||||
return Object.fromEntries(c.keys().map(path => [path, c.get(path)]));
|
||||
}
|
||||
|
||||
function readUserMapConfig(
|
||||
@@ -244,7 +241,7 @@ export function readLdapConfig(config: Config): LdapProviderConfig[] {
|
||||
return {
|
||||
dn: c.getString('dn'),
|
||||
options: readOptionsConfig(c.getOptionalConfig('options')),
|
||||
set: readSetConfig(c.getOptionalConfigArray('set')),
|
||||
set: readSetConfig(c.getOptionalConfig('set')),
|
||||
map: readUserMapConfig(c.getOptionalConfig('map')),
|
||||
};
|
||||
}
|
||||
@@ -255,7 +252,7 @@ export function readLdapConfig(config: Config): LdapProviderConfig[] {
|
||||
return {
|
||||
dn: c.getString('dn'),
|
||||
options: readOptionsConfig(c.getOptionalConfig('options')),
|
||||
set: readSetConfig(c.getOptionalConfigArray('set')),
|
||||
set: readSetConfig(c.getOptionalConfig('set')),
|
||||
map: readGroupMapConfig(c.getOptionalConfig('map')),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
import { GroupEntity, UserEntity } from '@backstage/catalog-model';
|
||||
import { SearchEntry } from 'ldapjs';
|
||||
import lodashSet from 'lodash/set';
|
||||
import { buildOrgHierarchy } from '../util/org';
|
||||
import { LdapClient } from './client';
|
||||
@@ -25,7 +26,6 @@ import {
|
||||
LDAP_UUID_ANNOTATION,
|
||||
} from './constants';
|
||||
import { LdapVendor } from './vendors';
|
||||
import { SearchEntry } from 'ldapjs';
|
||||
|
||||
/**
|
||||
* Reads users out of an LDAP provider.
|
||||
@@ -63,7 +63,7 @@ export async function readLdapUsers(
|
||||
};
|
||||
|
||||
if (set) {
|
||||
for (const { path, value } of set) {
|
||||
for (const [path, value] of Object.entries(set)) {
|
||||
lodashSet(entity, path, value);
|
||||
}
|
||||
}
|
||||
@@ -142,7 +142,7 @@ export async function readLdapGroups(
|
||||
};
|
||||
|
||||
if (set) {
|
||||
for (const { path, value } of set) {
|
||||
for (const [path, value] of Object.entries(set)) {
|
||||
lodashSet(entity, path, value);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user