Archived after platelet was moved to the Amplify platform.
This is the API for Platelet. It makes use of Flask, RESTx, SQLALchemy and Marshmallow along with other Flask plugins.
It is a REST API. Refer to api_routes.md or the generated Swagger documentation for more detailed documentation.
Run:
docker-compose up
to build and setup a docker instance.
To prepopulate the database with some data, put a sql file named platelet_init.sql in the root directory.
sudo apt install postgresql postgresql-server-dev-12 python3-venv python3-dev python3-wheel gcc
sudo apt install apt-transport-https
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
sudo add-apt-repository "deb https://artifacts.elastic.co/packages/7.x/apt stable main"
sudo apt update && sudo apt install elasticsearch
sudo apt install redis
sudo nano /etc/postgresql/12/main/pg_hba.conf
Edit the line:
# IPv4 local connections:
host all all 127.0.0.1/32 md5
to:
# IPv4 local connections:
host all all 127.0.0.1/32 trust
This will allow unauthenticated connections on localhost
sudo systemctl restart postgresql && sudo systemctl restart elasticsearch && sudo systemctl restart redis
./setup.sh
Optionally input a json file with premade data to insert into the database. You can also add a password to set for the admin user instead of setting it interactively.
./setup.sh dev_data.json somepass
sudo systemctl start postgresql && sudo systemctl start elasticsearch
source venv/bin/activate
URI string for the database you are connecting to. E.g.:
postgres://user:password@some-database-host/database_name
If no URI is specified it will attempt to connect to a localhost database named platelet_dev
Specify the cloud platform that should be used. Currently only aws
is available.
If specified, it will attempt to connect to another endpoint. This can be useful for mocking AWS for testing (e.g with moto).
The access key id for the AWS account you are connecting to.
The secret access key for the AWS account you are connecting to.
The name of the image store on the cloud provider. On AWS this is the name of the bucket that has been created.
A directory created locally that the flask process has write access to. Suggested /tmp/profile_pics
If a user has no profile picture set in the database, this URL will be returned for their picture instead.
Enable CORS. Defaults to False
.
When developing locally suggest setting this to True
so that processes running on another port can access the API (e.g. a React server running on port 3000).
The origin URL when CORS_ENABLED
is set to True
. Defaults to http://localhost:3000
. Does nothing if CORS_ENABLED
is set to False
.
The URL for the Redis server. Defaults connecting to localhost if none is specified.
The URL for the ElasticSearch server. Defaults to None
in which case no connection attempts will be made.
In a terminal, export your environment variables and run:
python app.py
For profile picture uploads, also run the redis worker. This must have the same environment variables as the Flask server.
python redis_worker.py
source venv/bin/activate
cd tests
pytest -v .
(Some fail at the moment when all tests are ran together, but won't fail when ran individually.)
To run individual tests use
pytest -v . -k "some pattern"
e.g.:
pytest -v . -k "users"
Will run all tests associated with users.
When you add a new library with pip install
run:
pip freeze > requirements.txt
When you make changes that require database migrations run:
flask db migrate -m "message"