-
Notifications
You must be signed in to change notification settings - Fork 331
add readme more instructions and script to fill some resources after … #5278
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
Open
VladMstv
wants to merge
1
commit into
develop
Choose a base branch
from
update-deploy-readme-and-scripts
base: develop
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
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 hidden or 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 hidden or 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,106 @@ | ||
| import Oystehr from '@oystehr/sdk'; | ||
| import { Organization } from 'fhir/r4b'; | ||
| import * as fs from 'fs'; | ||
| import { fhirApiUrlFromAuth0Audience, projectApiUrlFromAuth0Audience } from '../packages/zambdas/src/scripts/helpers'; | ||
| import { getAuth0Token } from '../packages/zambdas/src/shared'; | ||
|
|
||
| async function main(): Promise<void> { | ||
| const env = process.argv[2]; | ||
|
|
||
| const envFilePath = `../packages/zambdas/.env/${env}.json`; | ||
| const secrets = JSON.parse(fs.readFileSync(envFilePath, 'utf8')); | ||
|
|
||
| const token = await getAuth0Token(secrets); | ||
| const oystehr = new Oystehr({ | ||
| accessToken: token, | ||
| fhirApiUrl: fhirApiUrlFromAuth0Audience(secrets.AUTH0_AUDIENCE), | ||
| projectApiUrl: projectApiUrlFromAuth0Audience(secrets.AUTH0_AUDIENCE), | ||
| }); | ||
|
|
||
| // get organization | ||
| const organizationName = `${secrets['project-name']} Organization`; | ||
| const organizationSearch = await oystehr.fhir.search<Organization>({ | ||
| resourceType: 'Organization', | ||
| params: [{ name: 'name', value: organizationName }], | ||
| }); | ||
| const organization = (await organizationSearch.unbundle())[0]; | ||
|
|
||
| if (!organization) { | ||
| throw new Error(`Organization ${organizationName} not found`); | ||
| } else { | ||
| secrets['ORGANIZATION_ID'] = organization.id; | ||
| fs.writeFileSync(envFilePath, JSON.stringify(secrets, null, 2)); | ||
| console.log(`Updated ORGANIZATION_ID=${organization.id} in ${envFilePath}`); | ||
| } | ||
|
|
||
| // get default billing resource | ||
| const defaultBillingResourceSearch = await oystehr.fhir.search<Organization>({ | ||
| resourceType: 'Organization', | ||
| params: [{ name: 'name', value: 'Default Billing Provider' }], | ||
| }); | ||
| const defaultBillingResource = (await defaultBillingResourceSearch.unbundle())[0]; | ||
| if (!defaultBillingResource) { | ||
| throw new Error('Default billing resource not found'); | ||
| } else { | ||
| secrets['DEFAULT_BILLING_RESOURCE'] = `${defaultBillingResource.resourceType}/${defaultBillingResource.id}`; | ||
| fs.writeFileSync(envFilePath, JSON.stringify(secrets, null, 2)); | ||
| console.log( | ||
| `Updated DEFAULT_BILLING_RESOURCE=${defaultBillingResource.resourceType}/${defaultBillingResource.id} in ${envFilePath}` | ||
| ); | ||
| } | ||
|
|
||
| // get sendgrid api key | ||
| const sendgridApiKey = secrets['SENDGRID_API_KEY']; | ||
| if (!sendgridApiKey) { | ||
| throw new Error('Sendgrid API key not found'); | ||
| } | ||
|
|
||
| const m2ms = await oystehr.m2m.list(); | ||
| const e2eM2M = m2ms.find((m2m) => m2m.name === 'E2E Tests M2M Client'); | ||
| if (!e2eM2M) { | ||
| throw new Error('E2E Tests M2M Client not found'); | ||
| } | ||
| const rotateResponse = await oystehr.m2m.rotateSecret({ id: e2eM2M.id }); | ||
| secrets['AUTH0_CLIENT_TESTS'] = e2eM2M.clientId; | ||
| secrets['AUTH0_SECRET_TESTS'] = rotateResponse.secret!; | ||
| fs.writeFileSync(envFilePath, JSON.stringify(secrets, null, 2)); | ||
| console.log(`Updated AUTH0_CLIENT_TESTS (${e2eM2M.clientId}) and AUTH0_SECRET_TESTS in ${envFilePath}`); | ||
|
|
||
| // create test environment files for apps with E2E M2M credentials | ||
|
Contributor
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. could these could be managed by terraform similar to how we now manage the app env files? |
||
| const appsToUpdate = ['ehr', 'intake']; | ||
| const testEnvData = { | ||
| AUTH0_CLIENT_TESTS: secrets['AUTH0_CLIENT_TESTS'], | ||
| AUTH0_SECRET_TESTS: secrets['AUTH0_SECRET_TESTS'], | ||
| TEXT_USERNAME: 'e2euser@masslight.com', | ||
| TEXT_PASSWORD: '', | ||
| }; | ||
|
|
||
| const testEnvDataIntake = { | ||
| ...testEnvData, | ||
| PHONE_NUMBER: '', | ||
| TEXT_USERNAME: '', | ||
| TEXT_PASSWORD: '', | ||
| }; | ||
|
|
||
| for (const app of appsToUpdate) { | ||
| const appTestEnvPath = `../apps/${app}/env/tests.${env}.json`; | ||
|
|
||
| // only create file if it doesn't exist | ||
| if (fs.existsSync(appTestEnvPath)) { | ||
| console.log(`Updating existing ${appTestEnvPath} with E2E M2M credentials`); | ||
| } | ||
| if (app === 'ehr') { | ||
| fs.writeFileSync(appTestEnvPath, JSON.stringify(testEnvData, null, 2)); | ||
| } else { | ||
| fs.writeFileSync(appTestEnvPath, JSON.stringify(testEnvDataIntake, null, 2)); | ||
| } | ||
| console.log(`Created ${appTestEnvPath} with E2E M2M credentials`); | ||
| } | ||
| } | ||
|
|
||
| main() | ||
| .then(() => console.log('Completed filling env with created resources data')) | ||
| .catch((error) => { | ||
| console.error(error); | ||
| throw error; | ||
| }); | ||
This file contains hidden or 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
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.
these two organization lookups could use the name as defined in config instead of hardcoded strings