salt-account-service

0.1.0 • Public • Published

Account Service

Build Setup

UPDATE CONFIG DEFAULTS, TYPES, AND TEMPLATE when making config changes

Local App Setup

  1. cp ./config/config-defaults.ts ./config/config.ts
  2. cp ./config/certificates/private-key-test.pem ./config/certificates/private-key.pem
  3. cp -r ./config/certificates/public-keys-test/ ./config/certificates/public-keys/
  4. cp ./config/certificates/public-keys-test/borrower-api.pem ./config/certificates/googleSheets.pem
  5. Create the local database: in the command line enter the psql console (psql ) and create the database (CREATE DATABASE <db name>;) and quit (\q)
  6. Run npm install || npm i, which will acquire all the dependencies specified in package.json
  7. Run tsc to compile your files into typescript
  8. npm run compile runs tsc and excludes node_module errors
  9. Start redis server in background: redis-server
  10. To start the server in dev mode: npm run dev
  11. To start the api server in prod mode: npm start
  12. To run internal tests: npm test || npm t
  13. To run external tests: npm run extTest
  14. To find TODO items: npm run todo
  15. To reset the database: npm run reset
  16. To populate a user in the database: npm run populate
  17. To gen a token, console.log the response from getToken in ./test/helpers/util.ts and pass as Bearer Token in postman. Parameter claims = { iss: 'microservice' }

Profiling

  1. Run npm run inspect
  2. Open about:inspect in Chrome
  3. Click Open dedicated DevTools for Node - a new window that looks like DevTools will pop up
  4. Navigate to the Profiler tab and start recording
  5. Make API requests that require profiling
  6. View the new profile created under CPU Profiles on left sidebar
  7. Another option is to run a memory profile under the Memory tab (eg. record allication, heap snapshot) while running tests

Other Options (still need GUI analysis) WIP (do not use yet)

  • Start server with additional profiling and garbage collecting data node --prof --track_gc_object_stats --trace_gc_verbose --log_timer_events scripts/api
  • Create profiling log node --prof scripts/api
  • Get analysis on profile lognode --prof-process isolate-0x102801e00-v8.log

Generating Database Migrations

  • Restore a fresh db from ./src/models/entities/migrations/last-schema.sql
    • psql -d [db_name] < ./src/models/entities/migrations/last-schema.sql
  • Ensure you have the same version of typeorm as listed in package.json installed globally
  • Create or edit ormconfig.json:
    • Make sure the migrations cli points to path/to/models/entities/migrations
    • Make sure db connection options match the fresh db you just created
  • npm run compile
  • typeorm migration:generate -n [MigrationName]
  • Edit ./src/models/entities/migrations/[timestamp]-[MigrationName].ts to make sure the querys are correct and not dropping columns that should be renamed etc.
  • npm run compile
  • typeorm migration:run
  • Ensure this is successful
  • pg_dump -d [db_name] -oO > ./src/models/entities/migrations/last-schema.sql

Application Startup Flow

This blurb attempts to walk through the application startup in fargate.

  • The run time docker holds the initial start up command. CMD pm2-runtime ecosystem.config.js --env $Environment
  • ecosystem.config.js in this repo has this line script: './scripts/api.js',
  • api.ts has this line (the .ts is made into a .js at compile time?) import { runApplication } from '../src/api-setup'
  • api-setup.ts has the application listening on http.
  • deployImageBG lambda kicks off this chain of events by running boto3 ecs.update_service and when it redeploys it picks up the new container in ecr with the tag.
  • Images are created in the Build-Image step of CodePipeline
  • deployImageDevlopment step of CodePipeline then kicks off deployImageBG

Integration Test setup (Local)

  • Clone the salt-sts repo and follow the setup steps https://github.com/SALTLending/salt-sts
  • When logging into aws-cli via salt-sts, select SaltDevAWSDevOps_profile. You will need write access to our dev environment.
  • Update the config/config.ts file to point to development for both aws cognito and postgres
  • Run npm run test:integration
  • You can pass TEST_ENV=stage npm run test:integration to run the framework against stage. Note that your config.ts file will need to be updated to point to the stage aws/db instances. If no TEST_ENV param is passed, we default to dev.

Test user creation script

  • Follow steps to setup integration tests
  • Run npm run create -- --help to show cli options
  • TEST_ENV=stage npm run create -- -a personal -l -w doge would create a personal user, with a loan request and a doge wallet on stage.
  • npm run create -- -i 10 would create 10 users with personal accounts and output a csv file of the accounts to test/integration/scripts

Updating and generating new JWT key pairs

To simply update if new keys were committed to ./config.certificates/public-keys-test

  • rm ./config/certificates/private-key.pem
  • rm ./config/certificates/public-keys/*.pem
  • run through steps 2 and 3 in local app setup section above

To generate a new pair and update:

  • rm ./config/certificates/private-key.pem
  • rm ./config/certificates/public-keys/*.pem
openssl ecparam -name prime256v1 -genkey -noout -out ./config/certificates/private-key-test.pem

openssl ec -in ./config/certificates/private-key-test.pem -pubout -out ./config/certificates/public-keys-test/microservice.pem
  • copy microservice.peminto other key files in ./config/certificates/public-keys-test ie. cp ./config/certificates/public-keys-test/microservice.pem ./config/certificates/public-keys-test/borrower-api.pem
  • run through steps 2 and 3 in local app setup section above
  • connecting microservice keys should be updated with same set

Readme

Keywords

Package Sidebar

Install

npm i salt-account-service

Weekly Downloads

1

Version

0.1.0

License

none

Unpacked Size

1.91 MB

Total Files

326

Last publish

Collaborators

  • sloperations