move api index and apache_restart

This commit is contained in:
Dmitry Belyaev 2021-10-07 13:54:49 +03:00
parent 8eef627c2e
commit f5680564d2
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3
4 changed files with 38 additions and 31 deletions

0
app/api/__init__.py Normal file
View File

29
app/api/apache_restart.py Normal file
View File

@ -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'
}

7
app/api/index.py Normal file
View File

@ -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']

View File

@ -1,4 +1,3 @@
import os
from typing import List, Dict from typing import List, Dict
import traceback import traceback
@ -6,13 +5,13 @@ from flask import Flask, render_template
from flask_restful import Resource, Api, reqparse, abort from flask_restful import Resource, Api, reqparse, abort
from flask_cors import CORS 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.glob import get_config, get_manager
from app.manager import infobase_data_blank from app.manager import infobase_data_blank
from app.utils import validate_url from app.utils import validate_url
from brackets import get_infobases as br_get_infobases from brackets import get_infobases as br_get_infobases
apache_restart_flagfile = 'restart_apache'
pub_parser = reqparse.RequestParser() pub_parser = reqparse.RequestParser()
pub_parser.add_argument('url', type=str) pub_parser.add_argument('url', type=str)
pub_parser.add_argument('file', type=str, default='') 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' frontend_dir = 'frontend/dist'
app = Flask(__name__, static_url_path='/', static_folder=frontend_dir, template_folder=frontend_dir) app = Flask(__name__, static_url_path='/', static_folder=frontend_dir, template_folder=frontend_dir)
api = Api(app, '/api/v1/') api = Api(app, '/api/v1/')