-
Notifications
You must be signed in to change notification settings - Fork 9
AutoMATES API (on carp)
The automates API is a web service that provides access to functionality from different parts of the AutoMATES code base. It is a python Flask web app that is located in the repository at automates/apps/automates (a very creative and descriptive path name :) ). Documentation for the api is located here.
To develop locally, do the following:
- Have your automates environment set up and activated.
- Set the FLASK_APP env variable to
automates.apps.automates.automates. On a linux system, runexport FLASK_APP=automates.apps.automates.automates - Run
python3 -m flask run
The web app should now be running locally!
To redeploy the AutoMATES API on carp:
- Log into carp
- Run
cd /usr/local/automates-app/automates/which will take you to a clone of the AutoMATES repo. - Pull the newest version.
- Rebuild the docker container via
docker build -t automates/local . - Change directory into the automates app via
cd automates/apps/automates - Run
docker-compose -f /usr/local/automates-app/automates/automates/apps/automates/docker-compose.yaml up --build -dand this will rebuild and deploy the app.
The AutoMATES API is run on our machine carp. This does not have access to external networks outside of UofA. To get external traffic to the carp machine, we have a proxy set up on the machine hopper (I think that's the correct machine?) that essentially forwards external traffic to the API on carp inside of the UofA network. Below details how the traffic forwarding and token authentication works on hopper using nginx.
sudo apt-get update
sudo apt-get install nginx
Disable the Default Virtual Host:
sudo unlink /etc/nginx/sites-enabled/default
Create the Nginx Reverse Proxy
sudo vi etc/nginx/sites-available/reverse-proxy.conf
bbasic conf file:
server {
listen 80;
location / {
proxy_pass http://<IP HERE>;
}
}Enable the virtual host
sudo ln -s /etc/nginx/sites-available/reverse-proxy.conf /etc/nginx/sites-enabled/reverse-proxy.conf
service nginx configtest
service nginx restart
from: https://www.nginx.com/blog/deploying-nginx-plus-as-an-api-gateway-part-1/
Auth map file in sites-available called auth-keys.config:
map $http_apikey $api_client_name {
default "";
"SOME API KEY" "Name of users of key (i.e. 'test', 'UA', 'GE', etc.";
}
update original reverse-proxy.conf to look like:
include /etc/nginx/sites-available/api-keys.conf;
server {
listen 80;
location / {
auth_request /_validate_apikey; # Calls out to a validate api key endpoint
proxy_pass http://10.128.255.11;
}
# Handle outgoing API key validation call. Could remove this and set up a different service to handle.
location = /_validate_apikey {
internal;
if ($http_apikey = "") {
return 401; # Unauthorized
}
if ($api_client_name = "") {
return 403; # Forbidden
}
return 204; # OK (no content)
}
}Restart the service
make sure world modelers app doesnt start