-
Notifications
You must be signed in to change notification settings - Fork 189
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
Fixes #396: add default values to environment variables #550
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These null
s are probably not a good idea.
Also, can you add some code to src/backend/lib/config.js
where we load the env
using dotenv
: we can check to see if it worked or not (i.e., if there is an .env
file): https://www.npmjs.com/package/dotenv#config
If we get back result.error
, we should probably either warn (like you did with redis) or perhaps throw and let the app crash now vs. fail later with random missing data. I think we should warn, so we don't have to mess with CI too much at this point.
@humphd How's this? telescope/src/backend/lib/config.js Lines 1 to 12 in 1074030
Because Also, it is worth mentioning that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
src/backend/login/usingPassport.js
Outdated
@@ -12,7 +12,8 @@ SAML2_REDIRECT_URI=http://localhost:3000/oauth/callback | |||
*/ | |||
let cert = null; | |||
|
|||
const { SAML2_BASE_URI, SAML2_REDIRECT_URI } = process.env; | |||
const SAML2_BASE_URI = process.env.SAML2_BASE_URI || ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is a good idea. Let's revert the changes in this file. We don't want to hide a missing value by having a proper but empty string get passed in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, done: e4c5a12
Currently, env.example
assigns an empty string to be the value of SAML2_BASE_URI
:
Lines 28 to 29 in 08c55d4
# SAML2 = BASE URL e.g. http://localhost:8080/simplesaml/saml2/idp/SSOService.php - This is pointing to the authentication service. e.g. What happens when you try to login to Seneca's site. | |
SAML2_BASE_URI="" |
Let me know if you'd like me to remove this value, as well.
src/backend/utils/logger.js
Outdated
@@ -9,7 +9,7 @@ require('../lib/config'); | |||
let logLevel = (process.env.LOG_LEVEL || 'info').toLowerCase(); | |||
if (!pino.levels.values[logLevel]) { | |||
// Use `debug` by default in development mode, `info` otherwise. | |||
logLevel = process.env.NODE_ENV === 'development' ? 'debug' : 'info'; | |||
logLevel = !process.env.NODE_ENV || process.env.NODE_ENV === 'development' ? 'debug' : 'info'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this change. We need to set one of debug
or info
. What is the first part of this doing? If process.env.NODE_ENV
is undefined
, the original code will return 'debug'
already. I think you can revert this unless I'm missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
process.env.NODE_ENV
isundefined
, the original code will return'debug'
already.
Sorry, Dave, but my understanding is that, since undefined === 'development'
evaluates to false, the enclosing ternary operation would return 'info'. However, I did also assume that CI would want to utilize a more verbose log level, and may be wrong about this. Let me know.
@@ -11,7 +11,9 @@ const { JSDOM } = jsdom; | |||
* That data is then returned as a Promise | |||
*/ | |||
module.exports.getData = function() { | |||
return fetch(process.env.FEED_URL) | |||
return fetch( | |||
process.env.FEED_URL || 'https://wiki.cdot.senecacollege.ca/wiki/Planet_CDOT_Feed_List' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably wise, since this URL doesn't change very often (if ever). But could you add a log that says we're doing this? Something like:
let ur = process.env.FEED_URL;
if(!url) {
url = 'https://wiki.cdot.senecacollege.ca/wiki/Planet_CDOT_Feed_List'
logger.debug('No value found for FEED_URL in env, using default ${url} instead');
}
This will help us debug things later, if we can't figure out why it's always loading a URL we don't intend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea! Done: e4c5a12
src/backend/web/routes/login.js
Outdated
@@ -13,7 +13,7 @@ router.use(cookieParser()); | |||
router.use(bodyParser.urlencoded({ extended: false })); | |||
router.use(bodyParser.json()); | |||
|
|||
const { SAML2_CLIENT_SECRET } = process.env; | |||
const SAML2_CLIENT_SECRET = process.env.SAML2_CLIENT_SECRET || 'secret'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a security issue. Let's not provide any default fallback if we're missing a secret. We should fail loudly if we are.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For sure... done: e4c5a12
Currently, env.example
mentions secret
to be the default value of SAML2_CLIENT_SECRET
:
Line 34 in 08c55d4
# SAML2_CLIENT_SECRET = CLIENT SECRET obtained from SAML Strategy, default : secret; |
Let me know if you'd like me to remove this piece of information, as well.
I'll also ask if you'd like me to do the same for SAML2_CLIENT_ID
—its default value is likewise mentioned:
Line 31 in 08c55d4
# SAML2_CLIENT_ID = CLIENT ID obtained from SAML Strategy default: saml-poc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a rebase, but looks good otherwise.
c8624da
to
2094902
Compare
Rebase completed and ready for final review; thank you everyone for your help! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally, works great. Well done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Issue This PR Addresses
Fixes #396
Type of Change
Description
Ensures that every
process.env
call within the code base is provided with a default value (as specified in #396) to ensure that they have some value on CI, and thus do not cause unwanted behaviour during CI testing.The default value provided to each
process.env
is either one specified withinenv.example
(if one exists), ornull
.Checklist