-
Notifications
You must be signed in to change notification settings - Fork 3
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
refactor: consume dynamic env vars from SSM rather than env vars [CHI-2897] #801
Open
GPaoloni
wants to merge
28
commits into
master
Choose a base branch
from
gian_CHI-2897
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
36331bc
refactor: consume dynamic env vars from SSM rather than env vars
GPaoloni 498fe9d
fix: lint
GPaoloni d5a82a6
fix: TS error in resources service
GPaoloni 38f60ce
fix: remove unnecessary TS dep
GPaoloni 31ada77
chore: add type option to lambdas tsconfig
GPaoloni 3d5a281
fix: TS errors in test
GPaoloni 59192c2
fix: added node types to job-complete
GPaoloni 6705de2
fix: tests types
GPaoloni 2b51e79
fix: mock types
GPaoloni e93a888
fix: docker file runs root npm ci to include common deps
GPaoloni b2e3ca0
fix: mock open rules
GPaoloni a06a3c3
fix: add ts as explicit dev dep
GPaoloni 641f4c9
chore: rollback deps
GPaoloni 55aaf15
Revert "chore: rollback deps"
GPaoloni d80b3fc
chore: revert all deps
GPaoloni d37dfee
chore: ssm cache defined within each module, removed extra package
GPaoloni f78d0ac
fix: test mocks type errors
GPaoloni e218024
fix: more ts errors in tests
GPaoloni a0e0f61
fix: ssm mocks
GPaoloni 7563f9a
fix: unit tests
GPaoloni ab41b26
refactor: twilio worker auth package expects lookup functions as para…
GPaoloni 8e8951c
refactor: hrm and resources service provide auth secrets lookup funct…
GPaoloni 36761fb
fix: unit test
GPaoloni 83166d0
fix: rollback unintended change
GPaoloni e0981a5
fix: service tests
GPaoloni da91db0
fix: missing lookup function in resources service
GPaoloni 7abede2
Merge remote-tracking branch 'origin/master' into gian_CHI-2897
GPaoloni 6707ee0
fix: missing lookup function in internal hrm service
GPaoloni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Copyright (C) 2021-2023 Technology Matters | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see https://www.gnu.org/licenses/. | ||
*/ | ||
|
||
import type { AuthSecretsLookup } from '@tech-matters/twilio-worker-auth'; | ||
import { getFromSSMCache } from './ssm-cache'; | ||
|
||
const authTokenLookup = async (accountSid: string) => { | ||
if (process.env[`TWILIO_AUTH_TOKEN_${accountSid}`]) { | ||
return process.env[`TWILIO_AUTH_TOKEN_${accountSid}`] || ''; | ||
} | ||
|
||
const { authToken } = await getFromSSMCache(accountSid); | ||
return authToken; | ||
}; | ||
|
||
const staticKeyLookup = async (keySuffix: string) => { | ||
const staticSecretKey = `STATIC_KEY_${keySuffix}`; | ||
if (process.env[staticSecretKey]) { | ||
return process.env[staticSecretKey] || ''; | ||
} | ||
|
||
const { staticKey } = await getFromSSMCache(keySuffix); | ||
return staticKey; | ||
}; | ||
|
||
export const defaultAuthSecretsLookup: AuthSecretsLookup = { | ||
authTokenLookup, | ||
staticKeyLookup, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* Copyright (C) 2021-2023 Technology Matters | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see https://www.gnu.org/licenses/. | ||
*/ | ||
|
||
import { loadSsmCache as loadSsmCacheRoot, ssmCache } from '@tech-matters/ssm-cache'; | ||
|
||
import env from 'dotenv'; | ||
|
||
env.config(); | ||
|
||
const ssmCacheConfigs = [ | ||
{ | ||
path: `/${process.env.NODE_ENV}/${ | ||
process.env.AWS_REGION ?? process.env.AWS_DEFAULT_REGION | ||
}/sqs/jobs/contact`, | ||
regex: /queue-url-*/, | ||
}, | ||
{ | ||
path: `/${process.env.NODE_ENV}/twilio`, | ||
regex: /\/.*\/static_key/, | ||
}, | ||
{ | ||
path: `/${process.env.NODE_ENV}/twilio`, | ||
regex: /\/.*\/auth_token/, | ||
}, | ||
{ | ||
path: `/${process.env.NODE_ENV}/config`, | ||
regex: /\/.*\/permission_config/, | ||
}, | ||
]; | ||
|
||
export const loadSsmCache = async () => { | ||
await loadSsmCacheRoot({ | ||
configs: ssmCacheConfigs, | ||
cacheDurationMilliseconds: 3600000 * 24, // cache for a day | ||
}); | ||
}; | ||
|
||
export const getFromSSMCache = async (accountSid: string) => { | ||
// does nothing if cache is still valid | ||
await loadSsmCache(); | ||
|
||
return { | ||
staticKey: | ||
ssmCache.values[`/${process.env.NODE_ENV}/twilio/${accountSid}/static_key`] | ||
?.value || '', | ||
authToken: | ||
ssmCache.values[`/${process.env.NODE_ENV}/twilio/${accountSid}/auth_token`] | ||
?.value || '', | ||
permissionConfig: | ||
ssmCache.values[`/${process.env.NODE_ENV}/config/${accountSid}/permission_config`] | ||
?.value || '', | ||
}; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can we revert this back to the correct file naming convention? i.e. camel case
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.
In fact, given it's specialised nature, perhaps we could call it something like ssmConfigurationCache?