Skip to content
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

Add checkToken back to addAppServicePath and ensure metrics doesn't require a token #435

Merged
merged 5 commits into from
Aug 12, 2022

Conversation

Half-Shot
Copy link
Contributor

This was broken in a previous release where we suddenly enabled authentication forcefully across all our endpoints, which broke bridges that used it for unauthenticated metrics access.

@Half-Shot Half-Shot requested a review from a team as a code owner August 12, 2022 11:21
src/bridge.ts Outdated
@@ -967,6 +967,7 @@ export class Bridge {
public addAppServicePath(opts: {
method: "GET"|"PUT"|"POST"|"DELETE",
path: string,
checkToken?: boolean,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
checkToken?: boolean,
checkToken: boolean = true,

Given the checkToken === false, this defaults to true.
Let's make that explicit in the signature.

I'm a fan of defaulting to false. Have you considered ignoreToken as a variable name?

Copy link
Contributor Author

@Half-Shot Half-Shot Aug 12, 2022

Choose a reason for hiding this comment

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

Hm, maybe we should just have authenticate to be properly explicit. checkToken was used as the legacy variable name, but since that was removed in 5.0.0 and we have typings, I don't think we need to follow it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I should have mentioned that I couldn't do a explicit signature value because it's an opts object type. I have however been explicit in the code below.

On the naming, on the whole I think that having a positive variable name like authenticate is probably a better look than ignoreToken because negative variable names are usually bad. I do concede that having default-to-true variables are a bit spooky, I hope people read the docstring :)

@Half-Shot Half-Shot requested a review from jaller94 August 12, 2022 11:42
handler: (req: ExRequest, respose: ExResponse, next: NextFunction) => void,
}): void {
if (!this.appservice) {
throw Error('Cannot call addAppServicePath before calling .run()');
}
const app: Application = this.appservice.expressApp;

const authenticate = opts.authenticate ?? true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const authenticate = opts.authenticate ?? true;
authenticate = opts.authenticate ?? true;

Is re-declaring a parameter on the top level of a function valid in JavaScript?
I'm getting SyntaxError: Identifier 'hi' has already been declared in a local test.

Is the linter dead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be fine? It's an opts object, not a parameter. (Which is why I can't do defaults)

Copy link
Contributor

@jaller94 jaller94 left a comment

Choose a reason for hiding this comment

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

Nevermind, the parameter is opts.authenticate not authenticate.

@Half-Shot Half-Shot merged commit 16df558 into develop Aug 12, 2022
@Half-Shot Half-Shot deleted the hs/fix-metrics branch May 2, 2023 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants