Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from Clinical-Genomics/refactor-load
Refactor server
- Loading branch information
Showing
38 changed files
with
649 additions
and
535 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from pydantic import BaseModel | ||
from typing import Optional, List | ||
from datetime import datetime | ||
|
||
class User(BaseModel): | ||
username: str | ||
email: Optional[str] = None | ||
disabled: Optional[bool] = None | ||
added: Optional[datetime] = None | ||
role: Optional[str]= None | ||
|
||
|
||
class UserInDB(User): | ||
hashed_password: str | ||
|
||
class Token(BaseModel): | ||
access_token: str | ||
token_type: str | ||
|
||
|
||
class TokenData(BaseModel): | ||
username: Optional[str] = None | ||
scopes: List[str] = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +0,0 @@ | ||
import logging | ||
|
||
from flask import Flask | ||
from pymongo import MongoClient | ||
import yaml | ||
|
||
from NIPTool.adapter.plugin import NiptAdapter | ||
from NIPTool.server.login import login_bp, login_manager | ||
from NIPTool.server.views import server_bp | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
def create_app(test=False): | ||
app = Flask(__name__) | ||
app.test = test | ||
if test: | ||
return app | ||
|
||
try: | ||
app.config.from_envvar('NIPT_CONFIG') | ||
configure_app(app) | ||
except: | ||
pass | ||
|
||
return app | ||
|
||
|
||
def configure_app(app, config=None): | ||
if config: | ||
app.config = {**app.config, **yaml.safe_load(config)} | ||
app.config['SECRET_KEY'] = app.config['SECRET_KEY'] | ||
client = MongoClient(app.config['DB_URI']) | ||
db_name = app.config['DB_NAME'] | ||
app.client = client | ||
app.db = client[db_name] | ||
app.adapter = NiptAdapter(client, db_name=db_name) | ||
app.register_blueprint(login_bp) | ||
app.register_blueprint(server_bp) | ||
login_manager.init_app(app) | ||
|
||
if app.config['DEBUG'] == 1: | ||
from flask_debugtoolbar import DebugToolbarExtension | ||
toolbar = DebugToolbarExtension(app) | ||
|
||
return app | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.