-
Notifications
You must be signed in to change notification settings - Fork 161
refactor(parameters): replace EnvironmentVariablesService class with helper functions in Parameters #4168
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
base: main
Are you sure you want to change the base?
refactor(parameters): replace EnvironmentVariablesService class with helper functions in Parameters #4168
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { | ||
getNumberFromEnv, | ||
getStringFromEnv, | ||
} from '@aws-lambda-powertools/commons/utils/env'; | ||
|
||
/** | ||
* It returns the value of the POWERTOOLS_PARAMETERS_MAX_AGE environment variable. | ||
* | ||
* @returns {number|undefined} | ||
*/ | ||
const getParametersMaxAge = (): number | undefined => { | ||
try { | ||
return getNumberFromEnv({ | ||
key: 'POWERTOOLS_PARAMETERS_MAX_AGE', | ||
}); | ||
} catch (error) { | ||
return undefined; | ||
} | ||
Comment on lines
+16
to
+18
Check noticeCode scanning / SonarCloud Exceptions should not be ignored Low
Handle this exception or don't catch it at all. See more on SonarQube Cloud
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is correct, we probably just want this to fail if the environment variable is not read properly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need to catch it, since the When removing the try/catch block from Instead of setting the What do you think? Perhaps I could add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ah yes, that's a good point. Another possibility is to return the default value as defined in the constants file: import { DEFAULT_MAX_AGE_SECS } from '../constants.js';
// ...
} catch (error) {
return DEFAULT_MAX_AGE_SECS;
} I'd like to hear @dreamorosi thoughts first though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case, I think it'd be sufficient to do this: return getNumberFromEnv({
key: 'POWERTOOLS_PARAMETERS_MAX_AGE',
// will return `undefined` and not throw if the env var is not set or empty
defaultValue: undefined,
}) It's ok to return this.maxAge = getParametersMaxAge() ?? DEFAULT_MAX_AGE_SECS; Since this |
||
}; | ||
|
||
/** | ||
* It returns the value of the POWERTOOLS_PARAMETERS_SSM_DECRYPT environment variable. | ||
* | ||
* @returns {string} | ||
*/ | ||
const getSSMDecrypt = (): string => { | ||
return getStringFromEnv({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest replacing this This would change the return value to a Also like discussed in the other comment above, I'd consider/suggest moving the |
||
key: 'POWERTOOLS_PARAMETERS_SSM_DECRYPT', | ||
defaultValue: '', | ||
}); | ||
}; | ||
|
||
export { getParametersMaxAge, getSSMDecrypt }; |
This file was deleted.
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 we need to add this one, we can use the existing
getBooleanFromEnv
above withextendedParsing
set totrue