diff --git a/app/api/__init__.py b/app/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/api/apache_restart.py b/app/api/apache_restart.py new file mode 100644 index 0000000..f2f2f1b --- /dev/null +++ b/app/api/apache_restart.py @@ -0,0 +1,29 @@ +import os + +from flask_restful import Resource, abort + +from app.glob import get_config + +apache_restart_flagfile = 'restart_apache' + + +class ApacheRestartFlag(Resource): + def get(self): + cfg = get_config() + flagfile = cfg.get('apache_restart_flagfile', apache_restart_flagfile) + if not os.path.isfile(flagfile): + abort(404, message='not found') + return { + 'message': 'found' + } + + def put(self): + cfg = get_config() + flagfile = cfg.get('apache_restart_flagfile', apache_restart_flagfile) + if os.path.isfile(flagfile): + return '', 304 + with open(flagfile, 'a'): + pass + return { + 'message': 'success' + } \ No newline at end of file diff --git a/app/api/index.py b/app/api/index.py new file mode 100644 index 0000000..f543624 --- /dev/null +++ b/app/api/index.py @@ -0,0 +1,7 @@ +from flask_restful import Resource + + +class APIIndex(Resource): + def get(self): + return ['infobases-available', 'infobases-all', 'publications', + 'module', 'config', 'config-test', 'apache-restart'] \ No newline at end of file diff --git a/pub1c-rest.py b/pub1c-rest.py index 389188b..c45c1ef 100644 --- a/pub1c-rest.py +++ b/pub1c-rest.py @@ -1,4 +1,3 @@ -import os from typing import List, Dict import traceback @@ -6,13 +5,13 @@ from flask import Flask, render_template from flask_restful import Resource, Api, reqparse, abort from flask_cors import CORS +from app.api.apache_restart import ApacheRestartFlag +from app.api.index import APIIndex from app.glob import get_config, get_manager from app.manager import infobase_data_blank from app.utils import validate_url from brackets import get_infobases as br_get_infobases -apache_restart_flagfile = 'restart_apache' - pub_parser = reqparse.RequestParser() pub_parser.add_argument('url', type=str) pub_parser.add_argument('file', type=str, default='') @@ -166,34 +165,6 @@ class EnterpriseModule(Resource): } -class ApacheRestartFlag(Resource): - def get(self): - cfg = get_config() - flagfile = cfg.get('apache_restart_flagfile', apache_restart_flagfile) - if not os.path.isfile(flagfile): - abort(404, message='not found') - return { - 'message': 'found' - } - - def put(self): - cfg = get_config() - flagfile = cfg.get('apache_restart_flagfile', apache_restart_flagfile) - if os.path.isfile(flagfile): - return '', 304 - with open(flagfile, 'a'): - pass - return { - 'message': 'success' - } - - -class APIIndex(Resource): - def get(self): - return ['infobases-available', 'infobases-all', 'publications', - 'module', 'config', 'config-test', 'apache-restart'] - - frontend_dir = 'frontend/dist' app = Flask(__name__, static_url_path='/', static_folder=frontend_dir, template_folder=frontend_dir) api = Api(app, '/api/v1/')