1.2.51 • Published 2 years ago

pharmos-app-service v1.2.51

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

PharmOS App Service

Documentation

Documentation site can be found here PharmOS App Documentation

Table of Contents

Development

This service is primarily written in Node using the Express framework and is a serverless application that is similar to the Scheduling Service.

Prerequisites

  • Docker >= 19.03.8
  • Docker Compose >= 1.25.4

Docker Desktop for Mac or Docker Desktop for Windows will install both of these for you. DO NOT try to install using brew install docker docker-compose - you will run into problems.

Setup

  1. Ensure docker and docker-compose are running and meet the version requirements above

    $ docker -v
    Docker version 19.03.8, build afacb8b
    $ docker-compose -v
    docker-compose version 1.25.4, build 8d51620a
    C:\>docker -v && docker-compose -v
    Docker version 19.03.8, build afacb8b
    docker-compose version 1.25.4, build 8d51620a
  2. Install AWS CLI

  3. Install AWS SAM

  4. Configure AWS - Manually or via SSO (instructions below))

  5. Run yarn install (see below to ensure that your NPM_TOKEN is set)

Manually configuring AWS credentials

  1. Run aws configure and input the following information when prompted. You can configure multiple accounts by setting the --profile flag (example: aws configure --profile uat). More info here
    region = us-east-1

    output = json
  1. You can follow the AWS Access and manually set the AWS credentials in ~/.aws/credentials. Run vi ~/.aws/credentials

    [default]
    aws_access_key_id = KEY_GOES_HERE
    aws_secret_access_key = KEY_GOES_HERE
    aws_session_token = TOKEN_GOES_HERE
    [dev]
    aws_access_key_id = KEY_GOES_HERE
    aws_secret_access_key = KEY_GOES_HERE
    aws_session_token = TOKEN_GOES_HERE

    You will be signed out from previous account if you log into another account from AWS SSO page

    Session time out is currently set to 8 hours for both console and CLI

Configuring AWS credentials with sso

  1. Configure SSO.

    Run aws configure sso.

    NOTE: ensure you set below values in ~/.aws/config.

    [default]
    sso_start_url = https://medly.awsapps.com/start
    sso_region = us-east-1
    sso_account_id = 592280881349
    sso_role_name = Developer
    region = us-east-1
    output = json
  2. Ensure ~/.aws/credentials file is deleted.

  3. Globally install jq Run brew install jq -g

  4. Script to rehydrate your AWS session
  • macOS

    1. Add this script to your ~/.bashrc or ~/.zshrc.

          function awscreds() {
            aws sts get-caller-identity --profile $1 || aws sso login --profile $1
            FILE=~/.aws/cli/cache/$(ls -t ~/.aws/cli/cache | head -n 1)
      
            export AWS_ACCESS_KEY_ID="$(jq -r '.Credentials.AccessKeyId' $FILE)" AWS_SECRET_ACCESS_KEY="$(jq -r '.Credentials.SecretAccessKey' $FILE)" AWS_SESSION_TOKEN="$(jq -r '.Credentials.SessionToken' $FILE)"
          }
    2. Anytime you want to rehydrate your AWS session in your terminal Run awscreds <profile> eg: awscreds default

  • Windows

    1. Make sure you have Python 3 installed, if not, install it here
    2. Download this file aws_creds_to_env.py
    3. Run this command. If you not set a profile name, it will take the default one:

      python aws_creds_to_env.py {your profile name}

Guides

To setup and run the project locally

These steps will run the project locally

  1. Configure your environment by adding an NPM_TOKEN environment variable:
    • If you're on a Mac
      • You can get the NPM_TOKEN from 1Password under 'Shared NPM Token' or you can generate one - (preferred). Set this token in your ~/.zshrc and add below to your .npmrc file.
      • Run echo "export NPM_TOKEN=${TOKEN_FROM_1PASS}" >> ~/.zshrc && source ~/.zshrc
    • If you're on Windows 10
      • Navigate to Control Panel\System and Security\System and select Advanced system settings
      • In the Advanced tab, click the Environment Variables... Button
      • Add new System variable Variable name: NPM_TOKEN Variable value: <TOKEN_FROM_1PASS>
      • Click OK and restart any vsCode and/or CMD instances
    • If on another system, set the NPM_TOKEN environment variable appropriately.
  2. Copy the contents of .env.example into a new file called .env
  3. Fill in the Okta env values
  4. Ensure that you have an Okta ID. Then update src/database/ops/users.csv with a new row for yourself (UUID, Okta ID, email address, first name, last name).
  5. Run yarn db:start-local to run a local PG database in Docker that mimics AWS Aurora
  6. Run yarn start:dev to expose local port 3000 to listen for invoked lambda functions and get nodemon-enabled hot reloading as you edit your code

Database scripts available

API/DB commands

  • yarn db:start-local will start the DB container
  • yarn db:stop-local will shut down the DB container

DB commands

  • yarn db:migrate Will run all migrations
  • yarn db:seed-run Will seed database tables
  • yarn db:refresh Will drop all tables in schema 'public'

If you need to access the database command line

Local DB access

  • Run yarn docker:exec
  • Run psql -U postgres -d placeholderdb
  • This will allow you to write inline SQL queries if needed
  • Alternatively, you can use a simple connection string like this (substitute the appropriate credentials): PAGER="less -S" PGPASSWORD=medly123 psql -h 0.0.0.0 -p 1002 -U postgres pharm-os -x

Running tests

Run yarn test ( Without the server already running )

Killing your process in development

Run yarn stop:dev

Viewing API Docs

Run yarn spec:start Will open Open API docs on http://127.0.0.1:5001/