e-mission / op-admin-dashboard

An admin/deployer dashboard for the NREL OpenPATH platform
0 stars 8 forks source link

Dockerized Dash App Template

https://towardsdatascience.com/dockerize-your-dash-app-1e155dd1cea3

How to run it: Docker Compose (recommended)

docker compose -f docker-compose-dev.yml build

docker compose -f docker-compose-dev.yml up

You must use this method. Do not try to directly by setting up a virtualenv with the requirements.txt This uses components of the e-mission-server core, so it must have the e-mission-server modules in the PYTHONPATH The easiest method to accomplish this is to use the docker container, which is built on top of the e-mission-server base docker container.

Test with a reverse proxy

docker-compose -f docker-compose-prod-nginx.yml build
docker-compose -f docker-compose-prod-nginx.yml up -d

The dash component assumes that it is running from the host root, and will barf if you try to run it behind a reverse proxy with a different file prefix. This setting tests that configuration using an embedded reverse proxy in the docker container.

Dynamic Config

Set Variables

CONFIG_PATH

The CONFIG_PATH environment variable is used to specify the location of the configuration files that are required for a Docker container to run properly. This means that the Docker container will attempt to download the configuration files from the specified URL. The current path to the raw format of nrel configs is:

https://raw.githubusercontent.com/e-mission/nrel-openpath-deploy-configs/main/configs/

STUDY_CONFIG

The STUDY_CONFIG environment variable is used to specify the name of the study or program that is being run inside the Docker container. This variable is typically used by the application running inside the container to differentiate between different studies or programs.

Note that the STUDY_CONFIG variable can be set to any string value, and should be set to a unique value for each separate study or program.

User Permissions

The following document outlines the permissions that a user can have within the dashboard application. The permission is specified as a key-value pair, where the key is the name of the permission and the value is either true or false. If the value is true, the user has access to the corresponding feature or data, and if the value is false, the user does not have access. You need to place these key-value pairs within the admin_dashboard key in one of the configs of the emission.

These are all the permissions that you can specify:

Overview Page

Data Page

Token Page

Map Page

Segment Trip Time Page

Push Notification Page

Dropdown Options

Stage_uuids

This document represents a single row in a MongoDB collection. The document contains a single object of a uuid with the following fields that you can provide in data_uuids_columns_exlude:

valid_uuids_columns = [
    'user_token',
    'user_id',
    'update_ts',
]

Stage_analysis_timeseries

It contains information about a segmentation trip. It has the following fields that you can provide in data_trips_columns_exclude.

valid_trip_columns = [
    "data.source",
    "data.start_ts",
    "data.start_local_dt",
    "data.start_fmt_tm",
    "data.start_place",
    "data.start_loc",
    "data.end_ts",
    "data.end_local_dt",
    "data.end_fmt_time",
    "data.end_place",
    "data.end_loc",
    "data.duration",
    "data.distance",
    "metadata.key",
    "metadata.platform",
    "metadata.write_ts",
    "metadata.time_zone",
    "metadata.write_local_dt",
    "metadata.write_fmt_time",
    "user_id",
]

Authentication

Specify Authentication Type

The AUTH_TYPE environment variable is used to specify the authentication type for the dashboard, and it is defined in the Docker Compose file. It has two possible values: "basic" and "cognito". The "basic" option refers to basic authentication, which is a simple way to authenticate users using a username and password. The "cognito" option refers to Amazon Cognito, which is a user authentication service that can be used with AWS services.

config.py

The config.py file is a Python module that contains configuration settings for an application that uses authentication. To use this file, first make a copy of the provided config-fake.py file and rename it to config.py. Then, fill in the necessary variables with your own valid data.

CognitoConfig Class

The CognitoConfig class contains variables used for authentication when using AWS Cognito. To use this authentication method, fill in the following variables with your credential data from your AWS Cognito panel in config.py:

VALID_USERNAME_PASSWORD_PAIRS

The VALID_USERNAME_PASSWORD_PAIRS dictionary contains all the valid usernames and passwords that users can authenticate with when using basic authentication. To use this authentication method, fill in the dictionary with your own valid usernames and passwords in config.py.

Usage

To use the configuration settings defined in config.py, import the module at the beginning of your Python script, and access the variables using dot notation. For example:


from config import CognitoConfig, VALID_USERNAME_PASSWORD_PAIRS

# Access the CLIENT_ID variable in CognitoConfig
client_id = CognitoConfig.CLIENT_ID

# Access the valid username and password pairs
valid_pairs = VALID_USERNAME_PASSWORD_PAIRS