diff --git a/docs/integrations/ldap/org.md b/docs/integrations/ldap/org.md index b9c09103b4..75e29687d7 100644 --- a/docs/integrations/ldap/org.md +++ b/docs/integrations/ldap/org.md @@ -314,3 +314,63 @@ builder.addProcessor( }), ); ``` + +## Using a Provider instead of a Processor + +An alternative to using the Processor for ingesting LDAP entries is to use a +Provider. Doing this can give you a little bit more freedom to handle the LDAP +ingestion more independently from the rest of the catalog ingestion. + +This can be useful if you have a lot of Users and Groups and hitting your LDAP +server is resource intensive but you still want your other catalog entries to be +updated frequently. + +> Note: When configuring to use a Provider instead of a Processor you do not +> need to add a _location_ pointing to your LDAP server + +```ts +// packages/backend/src/plugins/catalog.ts +import { CatalogBuilder } from '@backstage/plugin-catalog-backend'; +import { PluginEnvironment } from '../types'; + +import { Router } from 'express'; +import { LdapOrgEntityProvider } from '@backstage/plugin-catalog-backend-module-ldap'; + +import { Duration } from 'luxon'; + +export default async function createPlugin( + env: PluginEnvironment, +): Promise { + const ldapEntityProvider = LdapOrgEntityProvider.fromConfig(env.config, { + id: 'custom-ldap', + // target needs to match the catalog.processors.ldapOrg.providers.target specified in app-config + target: 'ldaps://ds.example.net', + logger: env.logger, + }); + + const builder = await CatalogBuilder.create(env); + builder.addEntityProvider(ldapEntityProvider); + + // You can change the refresh interval for the other catalog entries independently, or just leave the line below out to use the default refresh interval + builder.setRefreshIntervalSeconds(100); + + const { processingEngine, router } = await builder.build(); + await processingEngine.start(); + + await env.scheduler.scheduleTask({ + id: 'refresh_ldap', + // frequency sets how often you want to ingest users and groups from LDAP, in this case every 60 minutes + frequency: Duration.fromObject({ minutes: 60 }), + timeout: Duration.fromObject({ minutes: 15 }), + fn: async () => { + try { + await ldapEntityProvider.read(); + } catch (error) { + env.logger.error(error); + } + }, + }); + + return router; +} +```