Skip to content

Commit

Permalink
Merge pull request #56 from ternaustralia/feature/allow_virtuoso_backend
Browse files Browse the repository at this point in the history
update app.py to use init_app from latest flask_tern version
  • Loading branch information
javiersan18 authored Oct 25, 2023
2 parents efc36ec + efb2053 commit 881e310
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 87 deletions.
6 changes: 1 addition & 5 deletions .flaskenv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FLASK_APP=linkeddata_api
FLASK_ENV=development
FLASK_DEBUG=true

LINKEDDATA_API_SETTINGS=development.cfg

Expand All @@ -9,7 +9,3 @@ LINKEDDATA_API_OIDC_DISCOVERY_URL='https://auth-test.tern.org.au/auth/realms/loc
LINKEDDATA_API_OIDC_CLIENT_ID=dst
LINKEDDATA_API_OIDC_CLIENT_SECRET=
LINKEDDATA_API_OIDC_USE_REFRESH_TOKEN=True

LINKEDDATA_API_ELASTICSEARCH_URL=https://es-test.tern.org.au
LINKEDDATA_API_ELASTICSEARCH_VERIFY_CERTS=
LINKEDDATA_API_ELASTICSEARCH_SSL_SHOW_WARN=
85 changes: 6 additions & 79 deletions src/linkeddata_api/app.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import os
import logging

from flask import Flask, redirect, url_for

from flask_cors import CORS

# from flask_migrate import Migrate
from flask_tern import logging as app_logging
from flask_tern import init_app
from flask_tern.utils.config import load_settings

# from flask_tern.utils.json import TernJSONEncoder
from werkzeug.middleware.proxy_fix import ProxyFix
from flask_tern.utils.json import TernJSONProvider

from linkeddata_api.version import version

Expand All @@ -28,7 +21,7 @@ def create_app(config=None) -> Flask:
###################################################
# custom json encoder
###################################################
# app.json_encoder = TernJSONEncoder
app.json = TernJSONProvider(app)

################################################################
# Configure application
Expand All @@ -39,73 +32,9 @@ def create_app(config=None) -> Flask:
load_settings(app, env_prefix="LINKEDDATA_API_", defaults=settings, config=config)

################################################################
# Configure logging
# Configure flask_tern extensions
################################################################
app_logging.init_app(app)

#################################################################
# Configure various Flask extensions used by this app
#################################################################
from flask_tern import cache

# Uses a local python dictionary for caching. This is not really thread safe.
# TODO: if other backends are available in the future, make it configurable via env vars.
app.config["CACHE_TYPE"] = "SimpleCache"
app.config["CACHE_DEFAULT_TIMEOUT"] = 60
cache.init_app(app)

#################################################################
# Configure sqlalchemy ad alembic
#################################################################
# Register extensions
# from flask_tern import db

# api.init_app(app)
# db.init_app(app)
# Migrate(app, db.db, directory=os.path.join(app.config.root_path, "migrations"))

###############################################
# Session setup
###############################################
if app.config.get("SESSION_TYPE"):
# only configure Flask-Session if requested, fall back to falsk Secure Cookie Session.
from flask_session import Session

Session(app)

#################################################################
# Configure elasticsearch
#################################################################
from flask_tern import elasticsearch

elasticsearch.init_app(app)

###############################################
# CORS
###############################################
CORS(app, resources={r"/api/*": {"origins": "*"}})

###############################################
# ProxyFix
###############################################
# x_for=1, x_proto=1, x_host=1, x_port=1, x_prefix=1
app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1, x_host=1)

###############################################
# Healthcheck
###############################################
from flask_tern import healthcheck

# TODO: add authorization to /metrics endpoint
healthcheck.init_app(app)
# app.extensions["healthcheck"].add_check(healthcheck.check_keycloak)

#############################################
# Setup OIDC
#############################################
from flask_tern import auth

auth.init_app(app)
init_app(app)

##############################################
# Register routes and views
Expand All @@ -124,7 +53,5 @@ def create_app(config=None) -> Flask:

# setup build_only route so that we can use url_for("root", _external=True) - "root" route required by oidc session login
# app.add_url_rule("/", "root", build_only=True)
app.add_url_rule(
"/", "root", view_func=lambda: redirect(url_for("home.home", _external=True))
)
app.add_url_rule("/", "root", view_func=lambda: redirect(url_for("home.home", _external=True)))
return app
3 changes: 0 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ def app():
"OIDC_DISCOVERY_URL": "https://auth.example.com/.well-known/openid-configuration",
"OIDC_CLIENT_ID": "oidc-test",
"SESSION_TYPE": "null",
"ELASTICSEARCH_URL": "https://es-test.tern.org.au",
"ELASTICSEARCH_VERIFY_CERTS": "",
"ELASTICSEARCH_SSL_SHOW_WARN": "",
}
)
# setup db
Expand Down

0 comments on commit 881e310

Please sign in to comment.