Skip to content

refactor(NODE-5136): make authentication use async / await #3607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 24, 2023

Conversation

baileympearson
Copy link
Contributor

@baileympearson baileympearson commented Mar 22, 2023

Description

What is changing?

This PR cherry-picks unrelated refactors out of https://jira.mongodb.org/browse/NODE-3998. This is done to simplify review, as well as limit the surface area that I need to debug while looking for the issues in CI for https://jira.mongodb.org/browse/NODE-3998.

Is there new documentation needed for these changes?

No.

What is the motivation for this change?

Double check the following

  • Ran npm run check:lint script
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

@baileympearson baileympearson force-pushed the NODE-5136-misc-refactors branch from 550ea60 to 9138094 Compare March 22, 2023 17:10
@baileympearson baileympearson marked this pull request as ready for review March 22, 2023 17:40
@nbbeeken nbbeeken self-assigned this Mar 22, 2023
@nbbeeken nbbeeken changed the title refactor: make getWorkflow sync & throw refactor(NODE-5136): make getWorkflow sync & throw Mar 22, 2023
@nbbeeken nbbeeken added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Mar 22, 2023
spn = `${spn}@${mechanismProperties.SERVICE_REALM}`;
}

return initializeClient(spn, initOptions);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does initialize client return? you've removed the logic that checks for a null client after calling makeKerberosClient, which is only safe to do if initializeClient never resolves to null.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The null checks are all to make typescript happy, TS did not handle the mutual exclusion of the two arguments passed to the callback. this function will throw if it doesn't return a client

@@ -61,7 +60,16 @@ export function connect(options: ConnectionOptions, callback: Callback<Connectio
if (options.autoEncrypter) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just because we've come this far, do you want to refactor up one more function?

const makeConnectionAsync = promisify(makeConnection);

async function connectAsync(..) {


}
export const connect = callbackify(connectAsync);

I don't think it makes sense to make makeConnection async, because ideally we'll refactor it eventually so it's not performing io at all (purely synchronous). It also currently handles event listeners on the socket, so just wrapping it in a promisify seems more straightforward.

With this last refactor, the auth module is basically completely refactored.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into making this change but it would only be usable here, the socks5 logic would need to be untangled from callbacks as well. Or we leave socks5 unchanged and it still uses the callback form at which point we haven't got much value out of making a promisified version. Let's stick with what we got so far

Copy link
Contributor Author

@baileympearson baileympearson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verbal approval because Github won't let me approve my own PR

@nbbeeken nbbeeken changed the title refactor(NODE-5136): make getWorkflow sync & throw refactor(NODE-5136): make authentication use async / await Mar 24, 2023
@nbbeeken nbbeeken merged commit 6537e27 into main Mar 24, 2023
@nbbeeken nbbeeken deleted the NODE-5136-misc-refactors branch March 24, 2023 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Primary Review In Review with primary reviewer, not yet ready for team's eyes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants