From a285eb398657d0ad9beb22baeb270725599c0a29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Wed, 16 Mar 2022 09:26:41 +0100 Subject: [PATCH] more forgiving init code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- plugins/catalog-backend-module-ldap/api-report.md | 2 +- .../src/processors/LdapOrgEntityProvider.ts | 10 ++-------- .../src/processors/LdapOrgReaderProcessor.ts | 10 ++-------- 3 files changed, 5 insertions(+), 17 deletions(-) diff --git a/plugins/catalog-backend-module-ldap/api-report.md b/plugins/catalog-backend-module-ldap/api-report.md index edeef4cb82..3c6cd4849b 100644 --- a/plugins/catalog-backend-module-ldap/api-report.md +++ b/plugins/catalog-backend-module-ldap/api-report.md @@ -134,7 +134,7 @@ export class LdapOrgReaderProcessor implements CatalogProcessor { }); // (undocumented) static fromConfig( - config: Config, + configRoot: Config, options: { logger: Logger; groupTransformer?: GroupTransformer; diff --git a/plugins/catalog-backend-module-ldap/src/processors/LdapOrgEntityProvider.ts b/plugins/catalog-backend-module-ldap/src/processors/LdapOrgEntityProvider.ts index bad3941767..b31b7ae266 100644 --- a/plugins/catalog-backend-module-ldap/src/processors/LdapOrgEntityProvider.ts +++ b/plugins/catalog-backend-module-ldap/src/processors/LdapOrgEntityProvider.ts @@ -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".`, ); } diff --git a/plugins/catalog-backend-module-ldap/src/processors/LdapOrgReaderProcessor.ts b/plugins/catalog-backend-module-ldap/src/processors/LdapOrgReaderProcessor.ts index 8cfc92eff1..74a7e153b9 100644 --- a/plugins/catalog-backend-module-ldap/src/processors/LdapOrgReaderProcessor.ts +++ b/plugins/catalog-backend-module-ldap/src/processors/LdapOrgReaderProcessor.ts @@ -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".`, ); }