Skip to content

Commit

Permalink
attempt fix:
Browse files Browse the repository at this point in the history
- more logging + changed timeouts
  • Loading branch information
Sampiiiii committed Apr 15, 2024
1 parent 8343576 commit 6e12340
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
23 changes: 8 additions & 15 deletions apps/anvil/src/ldap/ldap.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export class LdapService implements OnModuleInit {

this.client = ldap.createClient({
url: process.env.LDAP_HOST + ":" + process.env.LDAP_PORT,
connectTimeout: 1000, // Adjust this as per your needs
connectTimeout: 2_000,
timeout: 5000,
});

this.client.on("connect", () => {
Expand All @@ -33,9 +34,7 @@ export class LdapService implements OnModuleInit {
this.client = null; // Reset the client to reconnect later.
});
} else {
this.logger.warn(
"LDAP client already exists. Reusing existing connection.",
);
this.logger.warn("LDAP client already exists. Reusing existing connection.");
}
}

Expand All @@ -52,13 +51,8 @@ export class LdapService implements OnModuleInit {
});
}

private search(
base: string,
options: ldap.SearchOptions,
): Promise<ldap.SearchEntry[]> {
this.logger.debug(
`Performing search with base: ${base} and filter: ${options.filter}`,
);
private search(base: string, options: ldap.SearchOptions): Promise<ldap.SearchEntry[]> {
this.logger.debug(`Performing search with base: ${base} and filter: ${options.filter}`);
return new Promise((resolve, reject) => {
this.client!.search(base, options, (err, res) => {
if (err) {
Expand Down Expand Up @@ -104,10 +98,7 @@ export class LdapService implements OnModuleInit {
}

// query params can go by mail, uid
async lookup(
searchFilter: string,
attributes: string[] | undefined = undefined,
): Promise<ldap.SearchEntry[] | null> {
async lookup(searchFilter: string, attributes: string[] | undefined = undefined): Promise<ldap.SearchEntry[] | null> {
this.logger.debug(`Looking up entries with filter: ${searchFilter}`);
const searchBase = process.env.LDAP_BASE!;
const options: ldap.SearchOptions = {
Expand All @@ -126,7 +117,9 @@ export class LdapService implements OnModuleInit {
}

async lookupUsername(username: string): Promise<LdapUser | null> {
this.logger.debug(`Starting LDAP search for username: ${username}`);
const users = await this.lookup(`(&(objectclass=person)(uid=${username}))`);
this.logger.debug(`LDAP search completed for username: ${username}`);
if (!users) {
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions apps/anvil/src/sign-in/sign-in.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ export class SignInController {
@Get()
@IsRep()
async getList(@Param("location") location: Location) {
return await this.signInService.getList(location);
return this.signInService.getList(location);
}

@Throttle({ default: { limit: 1, ttl: 1000 } })
@IsRep()
@Post("register-user")
async registerUser(@Param("location") location: Location, @Body() registerUser: RegisterUserDto) {
// location here does nothing beyond just add extra analytics for us to track where people are registering
return await this.signInService.registerUser(location, registerUser);
return this.signInService.registerUser(location, registerUser);
}

@Get("sign-in/:ucard_number")
Expand Down

0 comments on commit 6e12340

Please sign in to comment.