Skip to content

Commit

Permalink
Merge latest to main (#5)
Browse files Browse the repository at this point in the history
* Add tapis token retrieval and usage of the token in the api request (#4)

* initial rough draft commit
* Added auth_check to subjects data pull and wrote the function to return a boolean so that it's more modular.
* Passed coresessionid correctly and tried to remove an overlyverbose debug statement
* Correcting headers to be passed according to requests library, not flask
* Requiring tapis token to get data through APIs, still need to add requirement for local data
* Making flask more verbose
* Setup github actions for latest

---------

Co-authored-by: Frank Netscher <[email protected]>
  • Loading branch information
chandra-tacc and fnets authored Jul 26, 2023
1 parent c3c47ed commit 3ce12ef
Show file tree
Hide file tree
Showing 3 changed files with 215 additions and 147 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/build-latest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build on push to latest
on:
push:
branches: [ latest ]

jobs:
build_commit:
runs-on: ubuntu-latest
environment: docker
steps:
- uses: actions/checkout@v2
- name: Get shortsha
id: vars
run: |
if [ -z "$EVENT_SHA" ]; then SHORT_SHA=${GITHUB_SHA::8}; else SHORT_SHA=${EVENT_SHA::8}; fi
echo ::set-output name=sha_short::${SHORT_SHA}
env:
EVENT_SHA: ${{ github.event.client_payload.sha }}
- name: Print shortsha
run: |
echo $SHORTSHA
env:
SHORTSHA: ${{ steps.vars.outputs.sha_short }}
- uses: mr-smithers-excellent/docker-build-push@v3
name: Build & push commit tagged Docker image
with:
image: ${{ secrets.DOCKERHUB_REPO }}
tag: ${{ steps.vars.outputs.sha_short }}
registry: docker.io
dockerfile: Dockerfile
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: mr-smithers-excellent/docker-build-push@v3
name: Build & push commit tagged Docker image
with:
image: ${{ secrets.DOCKERHUB_REPO }}
tag: latest
registry: docker.io
dockerfile: Dockerfile
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
24 changes: 6 additions & 18 deletions src/app.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
from flask import Flask, jsonify
from os import environ
from flask import Flask, jsonify, request
import os
import pandas as pd
import json
import csv

# from data_processing import *
from data_loading import *

## Demonstrate that app is accessing the env variables properly
SECRET_KEY = environ.get("SECRET_KEY")
print("SECRET KEY", SECRET_KEY)

# ----------------------------------------------------------------------------
# DATA PARAMETERS
# ----------------------------------------------------------------------------
current_folder = os.path.dirname(__file__)
DATA_PATH = os.path.join(current_folder,'data')
ASSETS_PATH = os.path.join(current_folder,'assets')


# Path to Report files at TACC
api_root = environ.get("API_ROOT") #'https://api.a2cps.org/files/v2/download/public/system/a2cps.storage.community/reports'

# ----------------------------------------------------------------------------
# LOAD ASSETS FILES
# ----------------------------------------------------------------------------
Expand Down Expand Up @@ -127,11 +117,11 @@
}

app = Flask(__name__)
app.debug = True

# APIS: try to load new data, if doesn't work, get most recent
@app.route("/api/apis")
def api_apis():
print(api_data_index)
return jsonify(api_data_index)

@app.route("/api/imaging")
Expand All @@ -142,7 +132,7 @@ def api_imaging():
try:
if not api_data_index['imaging'] or not check_data_current(datetime.strptime(api_data_index['imaging'], datetime_format)):
api_date = datetime.now().strftime(datetime_format)
imaging_data = get_api_imaging_data()
imaging_data = get_api_imaging_data(request)
if imaging_data:
api_data_cache['imaging'] = imaging_data
api_data_index['imaging'] = api_date
Expand All @@ -159,7 +149,7 @@ def api_consort():
# try:
if not api_data_index['consort'] or not check_data_current(datetime.strptime(api_data_index['consort'], datetime_format)):
api_date = datetime.now().strftime(datetime_format)
consort_data_json = get_api_consort_data()
consort_data_json = get_api_consort_data(request)
if consort_data_json:
api_data_cache['consort'] = consort_data_json
api_data_index['consort'] = api_date
Expand All @@ -177,7 +167,7 @@ def api_blood():
try:
if not api_data_index['blood'] or not check_data_current(datetime.strptime(api_data_index['blood'], datetime_format)):
api_date = datetime.now().strftime(datetime_format)
blood_data, blood_data_request_status = get_api_blood_data()
blood_data, blood_data_request_status = get_api_blood_data(request)
if blood_data:
api_data_index['blood'] = api_date
api_data_cache['blood'] = blood_data
Expand All @@ -204,7 +194,7 @@ def api_subjects():
try:
if not api_data_index['subjects'] or not check_data_current(datetime.strptime(api_data_index['subjects'], datetime_format)):
api_date = datetime.now().strftime(datetime_format)
latest_subjects_json = get_api_subjects_json()
latest_subjects_json = get_api_subjects_json(request)
if latest_subjects_json:
# latest_data = create_clean_subjects(latest_subjects_json, screening_sites, display_terms_dict, display_terms_dict_multi)
latest_data = process_subjects_data(latest_subjects_json,subjects_raw_cols_for_reports,screening_sites, display_terms_dict, display_terms_dict_multi)
Expand Down Expand Up @@ -247,7 +237,5 @@ def api_simple():
return jsonify('not found')




if __name__ == "__main__":
app.run(host='0.0.0.0')
Loading

0 comments on commit 3ce12ef

Please sign in to comment.