more forgiving init code

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2022-03-16 09:26:41 +01:00
parent e949d68059
commit a285eb3986
3 changed files with 5 additions and 17 deletions
@@ -134,7 +134,7 @@ export class LdapOrgReaderProcessor implements CatalogProcessor {
});
// (undocumented)
static fromConfig(
config: Config,
configRoot: Config,
options: {
logger: Logger;
groupTransformer?: GroupTransformer;
@@ -114,17 +114,11 @@ export class LdapOrgEntityProvider implements EntityProvider {
const config =
configRoot.getOptionalConfig('ldap') ||
configRoot.getOptionalConfig('catalog.processors.ldapOrg');
if (!config) {
throw new TypeError(
`There is no LDAP configuration. Please add it as "ldap.providers".`,
);
}
const providers = readLdapConfig(config);
const providers = config ? readLdapConfig(config) : [];
const provider = providers.find(p => options.target === p.target);
if (!provider) {
throw new TypeError(
`There is no LDAP configuration that matches ${options.target}. Please add a configuration entry for it under "ldap.providers".`,
`There is no LDAP configuration that matches "${options.target}". Please add a configuration entry for it under "ldap.providers".`,
);
}
@@ -54,15 +54,9 @@ export class LdapOrgReaderProcessor implements CatalogProcessor {
const config =
configRoot.getOptionalConfig('ldap') ||
configRoot.getOptionalConfig('catalog.processors.ldapOrg');
if (!config) {
throw new TypeError(
`There is no LDAP configuration. Please add it as "ldap.providers".`,
);
}
return new LdapOrgReaderProcessor({
...options,
providers: readLdapConfig(config),
providers: config ? readLdapConfig(config) : [],
});
}
@@ -94,7 +88,7 @@ export class LdapOrgReaderProcessor implements CatalogProcessor {
const provider = this.providers.find(p => location.target === p.target);
if (!provider) {
throw new Error(
`There is no LDAP Org provider that matches ${location.target}. Please add a configuration entry for it under catalog.processors.ldapOrg.providers.`,
`There is no LDAP configuration that matches "${location.target}". Please add a configuration entry for it under "ldap.providers".`,
);
}