diff --git a/packages/server/src/integrations/adldap.ts b/packages/server/src/integrations/adldap.ts index 8eeec69e0..6cb93326a 100644 --- a/packages/server/src/integrations/adldap.ts +++ b/packages/server/src/integrations/adldap.ts @@ -1,4 +1,4 @@ -import { Integration, QueryType, IntegrationBase } from "@budibase/types" +import { Integration, QueryType, IntegrationBase, DatasourceFieldType } from "@budibase/types" import { IClientConfig, Client } from "ldap-ts-client"; @@ -16,8 +16,8 @@ module AdLdapModule { docs: "https://github.com/saostad/ldap-ts-client#readme", description: "LDAP Client to connect your Active Directory LDAP Server.", - friendlyName: "AD Ldap", - type: "Object store", + friendlyName: "AD Ldap", + type: "Non-relational", datasource: { url: { type: "string", @@ -39,21 +39,59 @@ module AdLdapModule { }, query: { + command: { + readable: true, + displayName: "Get Ldap users", + type: QueryType.JSON, + }, + create: { + type: QueryType.FIELDS, + fields: { + key: { + type: DatasourceFieldType.STRING, + required: true, + }, + value: { + type: DatasourceFieldType.STRING, + required: true, + } + }, + }, read: { + readable: true, type: QueryType.FIELDS, fields: { - bucket: { - type: "string", + key: { + type: DatasourceFieldType.STRING, required: true, }, }, }, + update: { + readable: true, + type: QueryType.FIELDS, + fields: { + key: { + type: DatasourceFieldType.STRING, + required: true, + }, + }, + }, + delete: { + type: QueryType.FIELDS, + fields: { + key: { + type: DatasourceFieldType.STRING, + required: true, + }, + }, + } }, } - class AdLdapIntegration implements IntegrationBase { + class AdLdapIntegration { private readonly config: AdLdapConfig - private client: any + private client; constructor(config: AdLdapConfig) { this.config = config @@ -62,20 +100,62 @@ module AdLdapModule { this.client = new Client(this.config) } - async read(query: { bucket: string }) { + + async ldapContext(query: Function) { + try { + return await query() + } catch (err) { + throw new Error(`Redis error: ${err}`) + } finally { + console.log("end") + } + } + + + async create(query: { key: string; value: string; ttl: number }) { + return this.ldapContext(async () => { + const response = null + return response + }) + } + + async read(query: { key: string }) { + return this.ldapContext(async () => { + const response = null + return response + }) + } + + async update(query: { key: string }) { + return this.ldapContext(async () => { + const response = null + return response + }) + } + + async delete(query: { key: string }) { + return this.ldapContext(async () => { + const response = null + return response + }) + } + async command(query: { bucket: string }) { + return this.ldapContext(async () => { const response = await this.client.queryAttributes({ - attributes: [query.bucket], + attributes: [`${query.bucket}`], options: { - filter: - "(&(|(objectClass=user)(objectClass=person))(!(objectClass=computer))(!(objectClass=group)))", + filter:"(&(|(objectClass=user)(objectClass=person))(!(objectClass=computer))(!(objectClass=group)))", scope: "sub", - paged: true, + paged: false }, + base:this.config.baseDN + }); - + console.log("Ldap users :",response) // always free-Up after you done the job! this.client.unbind(); return response + }) } }