This repository has been archived by the owner on Feb 16, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Grid Node to a different repository (#531)
* MOVE Grid Node Move Grid Node source code to another repository : https://github.com/OpenMined/GridNode * Update CI tests Comment Grid Nodes tests * FIX code style * Fix code style * Delete unused tests * Remove unused conftest settings * Move PyGrid app source files * Update requirements.txt - Add CI dependencies at requirements.txt file * Update requirements.txt * [REFACTORY] RENAME Rename app gateway -> grid * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md
- Loading branch information
1 parent
6bdbd27
commit efb8736
Showing
80 changed files
with
174 additions
and
3,255 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
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 was deleted.
Oops, something went wrong.
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,91 @@ | ||
import logging | ||
import os | ||
|
||
from flask import Flask | ||
from flask_cors import CORS | ||
from flask_sockets import Sockets | ||
from flask_sqlalchemy import SQLAlchemy | ||
from flask_migrate import Migrate | ||
from flask_executor import Executor | ||
|
||
# Default secret key used only for testing / development | ||
DEFAULT_SECRET_KEY = "justasecretkeythatishouldputhere" | ||
|
||
db = SQLAlchemy() | ||
executor = Executor() | ||
logging.getLogger().setLevel(logging.INFO) | ||
|
||
|
||
def set_database_config(app, test_config=None, verbose=False): | ||
""" Set configs to use SQL Alchemy library. | ||
Args: | ||
app: Flask application. | ||
test_config : Dictionary containing SQLAlchemy configs for test purposes. | ||
verbose : Level of flask application verbosity. | ||
Returns: | ||
app: Flask application. | ||
Raises: | ||
RuntimeError : If DATABASE_URL or test_config didn't initialized, RuntimeError exception will be raised. | ||
""" | ||
db_url = os.environ.get("DATABASE_URL") | ||
migrate = Migrate(app, db) | ||
if test_config is None: | ||
if db_url: | ||
app.config.from_mapping( | ||
SQLALCHEMY_DATABASE_URI=db_url, SQLALCHEMY_TRACK_MODIFICATIONS=False | ||
) | ||
else: | ||
raise RuntimeError( | ||
"Invalid database address : Set DATABASE_URL environment var or add test_config parameter at create_app method." | ||
) | ||
else: | ||
app.config["SQLALCHEMY_DATABASE_URI"] = test_config["SQLALCHEMY_DATABASE_URI"] | ||
app.config["TESTING"] = ( | ||
test_config["TESTING"] if test_config.get("TESTING") else True | ||
) | ||
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = ( | ||
test_config["SQLALCHEMY_TRACK_MODIFICATIONS"] | ||
if test_config.get("SQLALCHEMY_TRACK_MODIFICATIONS") | ||
else False | ||
) | ||
app.config["VERBOSE"] = verbose | ||
db.init_app(app) | ||
|
||
|
||
def create_app(debug=False, n_replica=None, test_config=None): | ||
"""Create flask application.""" | ||
app = Flask(__name__) | ||
app.debug = debug | ||
|
||
app.config["SECRET_KEY"] = os.environ.get("SECRET_KEY", None) | ||
|
||
if app.config["SECRET_KEY"] is None: | ||
app.config["SECRET_KEY"] = DEFAULT_SECRET_KEY | ||
logging.warn( | ||
"Using default secrect key, this is not safe and should be used only for testing and development. To define a secrete key please define the environment variable SECRET_KEY." | ||
) | ||
|
||
app.config["N_REPLICA"] = n_replica | ||
sockets = Sockets(app) | ||
|
||
# Register app blueprints | ||
from .main import main as main_blueprint, ws | ||
|
||
app.register_blueprint(main_blueprint) | ||
sockets.register_blueprint(ws, url_prefix=r"/") | ||
|
||
# Set SQLAlchemy configs | ||
set_database_config(app, test_config=test_config) | ||
s = app.app_context().push() | ||
db.create_all() | ||
db.session.commit() | ||
|
||
CORS(app) | ||
|
||
# Threads | ||
executor.init_app(app) | ||
app.config["EXECUTOR_PROPAGATE_EXCEPTIONS"] = True | ||
app.config["EXECUTOR_TYPE"] = "thread" | ||
|
||
return app |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.