instrumentation-api

command module
v1.3.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2022 License: MIT Imports: 13 Imported by: 0

README

Instrumentation API Build API and Lambda Package

An Application Programming Interface (API) to manage instrumentation data, built with Golang and Deployed on AWS Lambda.

How to Develop

Running a Database for Local Development

  1. Install, at a minimum, Docker Engine and Docker Compose. In place of these two, one can install Docker Desktop.

  2. Copy the .env.example file to .env (e.g., cp .env.example .env). This provides configuration options to Docker Compose.

  3. Change to the /database directory in this repository and type docker-compose up. This brings up two services on localhost

    1. A postgres database with postgis schema installed using the Docker image mdillon/postgis

    2. pgadmin4 (a user interface to interact with the database) using the Docker image dpage/pgadmin4

    To modify the database using pgadmin4, open a web browser and go to http://localhost:8080, or whichever port is set in .env.

    Login with Email:postgres@postgres.com and Password:postgres respectively.

    Create a database connection to the postgres database by right-clicking servers --> register --> server in the left menu tree. Enter the following information and click save.

    General Tab

    Field Value
    Name localhost (or other preferred name)

    Connection Tab

    Field Value
    Host name/address postgres
    Port 5432 (default)
    Username postgres
    Password postgres
  4. Initialize the database and seed it with some data (docker-compose runs this for you)

    Use the Query Tool in pgadmin4 and the .sql files in the database/ directory in this repository. You can find the query tool by expanding the left menu tree to Servers --> Databases --> postgres. Right click postgres --> Query Tool. From here, copy tables.sql into the Query Tool and run it by pressing f5. Note: to only run a portion of the SQL you've copied, you can highlight the section you want to run before hitting f5.

Running the GO API for Local Development

Either of these options starts the API at localhost:3030. The API uses JSON Web tokens (JWT) for authorization by default. To disable JWT for testing or development, you can set the environment variable JWT_DISABLED=TRUE.

With Visual Studio Code Debugger

You can use the launch.json file in this repository in lieu of go run main.go to run the API in the VSCode debugger. This takes care of the required environment variables to connect to the database.

Without Visual Studio Code Debugger

Set the following environment variables and type go run main.go from the top level of this repository.

* INSTRUMENTATION_DB_USER=postgres
* INSTRUMENTATION_DB_PASS=postgres
* INSTRUMENTATION_DB_NAME=postgres
* INSTRUMENTATION_DB_HOST=localhost
* INSTRUMENTATION_DB_SSLMODE=disable
* LAMBDA=FALSE
* JWT_DISABLED=FALSE

Note: When running the API locally, make sure environment variable LAMBDA is either not set or is set to LAMBDA=FALSE.

Running API Docs Locally

From the top level of this repository, type make docs. This starts a container that serves content based on "apidoc.yml" in this repository. Open a browser and navigate to https://localhost:4000 to view the content.

How To Deploy

Postgres Database on AWS Relational Database Service (RDS)

Database should be initialized with the following SQL files in the order listed:

  1. rds_init.sql (install PostGIS extensions)

  2. tables.sql (create tables for application)

  3. roles.sql (database roles, grants, etc.)

    Note: Change 'password' in roles.sql to a real password for the instrumentation_user account.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
api module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL