Skip to content

AutoMATES API (on carp)

Daniel Dicken edited this page Oct 18, 2021 · 9 revisions

Overview

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.

Example calls:

Developing locally

To develop locally, do the following:

  1. Have your automates environment set up and activated.
  2. Set the FLASK_APP env variable to automates.apps.automates.automates. On a linux system, run export FLASK_APP=automates.apps.automates.automates
  3. Run python3 -m flask run

The web app should now be running locally!

AutoMATES API deployment on carp

To redeploy the AutoMATES API on carp:

  1. Log into carp
  2. Run cd /usr/local/automates-app/automates/ which will take you to a clone of the AutoMATES repo.
  3. Pull the newest version.
  4. Rebuild the docker container via docker build -t automates/local .
  5. Change directory into the automates app via cd automates/apps/automates
  6. Run docker-compose -f /usr/local/automates-app/automates/automates/apps/automates/docker-compose.yaml up --build -d and this will rebuild and deploy the app.

Proxy setup on hopper

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.

Installation/running

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

Auth

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

Clone this wiki locally