# Admin API

Endpoints that only exist on the protected API server.  These APIs are only used internal in the following areas:
- Arda, Rohan, and Fabricator webapps.
- Various fabricator tools and programs.
- Integration tests within this project.

All of these APIs requires account access with a specific access policy (e.g. Moderator, Admin, or Fabricator), or a SuperUser account.


# Looper

A command line node-js program that remotely calls various checklist functions on the admin api.  It uses an account that has
"readonly" access to various apis.

The program is intended to run on the jenkins build server.  Jenkins has internal cronjobs that run the program periodically with
various different command line arguments.


# Database Setup

For local dev, install Postgres15 on a WSL server running Ubuntu 22.04 (installing on windows directly may work too, but these instructions apply to Ubuntu 22.04 on WSL):
```
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo tee /etc/apt/trusted.gpg.d/pgdg.asc &>/dev/null
sudo apt-get update
sudo apt install -y postgresql postgresql-contrib postgresql-client
sudo service postgresql start
sudo -i -u postgres
psql
```
You should see a prompt:
```
psql (15.4 (Ubuntu 15.4-1.pgdg22.04+1))
Type "help" for help.

postgres=#
```

Now we need to run some postgres commands to set up the database:

1. Create a database:
```
postgres=# CREATE DATABASE devlocalfabricatorv1;
CREATE DATABASE
```
2. Create a new user:
```
postgres=# CREATE USER admin WITH PASSWORD 'admin';
CREATE ROLE
```
3. Grant privileges to the user for the database:
```
postgres=# GRANT ALL PRIVILEGES ON DATABASE devlocalfabricatorv1 TO admin;
GRANT
```
4. Postgres 15 bullshit for public schema:
```
postgres=# GRANT USAGE, CREATE ON SCHEMA public TO admin;
```


Set the values in the local .env files:
```
# Postgres Connection
FABRICATOR_DB_POSTGRES_HOST="127.0.0.1"
FABRICATOR_DB_POSTGRES_DATABASE="devlocalfabricatorv1"
FABRICATOR_DB_POSTGRES_USER="admin"
FABRICATOR_DB_POSTGRES_PASSWORD="admin"
```

Run db_setup.ts:
```
cd apps/admin_api
ts-node db_setup.ts
```

# Note on the .pem file in this folder

The .pem file is a publicly available certificate bundle provided by AWS here: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL.html