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

Remove require for conf in jwttokenmanager.js #50

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backend/server/lib/apiregistry_extensions/jwttokenmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function initSync() {

if (TOKENMANCONF.useGlobalMemory) TOKEN_MEMORY = _ => DISTRIBUTED_MEMORY; else TOKEN_MEMORY = _ => CLUSTER_MEMORY;

try {conf = require(TOKENMANCONF);} catch (err) {conf = {}}
try {conf = TOKENMANCONF;} catch (err) {conf = {}}
Copy link
Owner

Choose a reason for hiding this comment

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

Catch is redundant, secondly having 2 variables - conf and TOKENMANCONF is also wrong.

If you are submitting a fix - please fix correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Rohit,

It is better to remove the conf variable and directly use TOKENMANCONF and we can remove the try-catch block as the conf variable is not required. We can use the below code:

TOKENMANCONF.expiryInterval = TOKENMANCONF?.expiryInterval || DEFAULT_TOKEN_EXPIRY; 
    TOKENMANCONF.tokenGCInterval = TOKENMANCONF?.tokenGCInterval || DEFAULT_GC_INTERVAL;

    setInterval(_cleanTokens, TOKENMANCONF.tokenGCInterval);   
    ```
    
    Could you please review the above code?

Copy link
Owner

Choose a reason for hiding this comment

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

Yes that was my point!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, Rohit. Closing this PR and raising a new one.

// Default config if none was specified with 10 minute expiry and 30 min cleanups
conf.expiryInterval = conf.expiryInterval || DEFAULT_TOKEN_EXPIRY;
conf.tokenGCInterval = conf.tokenGCInterval || DEFAULT_GC_INTERVAL;
Expand Down Expand Up @@ -161,4 +161,4 @@ function _parseAddstokenString(addsTokenString, request, response) {

module.exports = { checkSecurity, injectResponseHeaders, injectResponseHeadersInternal, initSync, checkToken,
createSignedJWTToken, addListener, removeListener, checkHeaderToken, addToken: updateLastAccessOrAddToken,
releaseToken, getToken, getClaims };
releaseToken, getToken, getClaims };
Loading