-
Notifications
You must be signed in to change notification settings - Fork 146
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
feat(parameters): ability to set maxAge
and decrypt
via environment variables
#1384
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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. Prior to this PR this method was used only in Logger. Now it's used also by Parameters so I am extracting it to the commons package to avoid duplication. |
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. See this comment. |
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. There was a lot of duplication with the |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
interface ConfigServiceInterface { | ||
|
||
get?(name: string): string | ||
|
||
getServiceName(): string | ||
|
||
getParametersMaxAge(): number | undefined | ||
|
||
getSSMDecrypt(): string | ||
|
||
} | ||
|
||
export { | ||
ConfigServiceInterface, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { ConfigServiceInterface } from './ConfigServiceInterface'; | ||
import { DEFAULT_MAX_AGE_SECS } from '../constants'; | ||
import { EnvironmentVariablesService as CommonEnvironmentVariablesService } from '@aws-lambda-powertools/commons'; | ||
|
||
class EnvironmentVariablesService extends CommonEnvironmentVariablesService implements ConfigServiceInterface { | ||
|
||
// Environment variables | ||
private parametersMaxAgeVariable = 'POWERTOOLS_PARAMETERS_MAX_AGE'; | ||
private ssmDecryptVariable = 'POWERTOOLS_PARAMETERS_SSM_DECRYPT'; | ||
|
||
public getParametersMaxAge(): number | undefined { | ||
const maxAge = this.get(this.parametersMaxAgeVariable); | ||
|
||
if (maxAge.length === 0) return undefined; | ||
|
||
const maxAgeAsNumber = parseInt(maxAge, 10); | ||
if (isNaN(maxAgeAsNumber)) { | ||
console.warn( | ||
`Invalid value for ${this.parametersMaxAgeVariable} environment variable: [${maxAge}], using default value of ${DEFAULT_MAX_AGE_SECS} seconds` | ||
); | ||
} else { | ||
return maxAgeAsNumber; | ||
} | ||
} | ||
|
||
public getSSMDecrypt(): string { | ||
return this.get(this.ssmDecryptVariable); | ||
} | ||
|
||
} | ||
|
||
export { | ||
EnvironmentVariablesService, | ||
}; |
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.
Housekeeping