Created
February 6, 2022 01:53
-
-
Save zmallen/b8bd553dbd4b00bf98a31f9638085b5a to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
import os | |
import sys | |
import json | |
import argparse | |
import logging | |
import configparser | |
from flask import Flask | |
from flask_restx import Api | |
from libblapiserver.apis.binlex import api as api_binlex | |
from libblapiserver.apis.mongodb import api as api_mongodb | |
from libblapi.minio import MinIOHandler | |
from libblapi.mongodb import MongoDBHandler | |
from libblapi.amqp import AMQPHandler | |
logger = logging.getLogger(__name__) | |
__version__ = '1.1.1' | |
__author__ = '@c3rb3ru5d3d53c' | |
title = "Binlex HTTP API" | |
description = "A Binlex HTTP API Server" | |
app = Flask(__name__) | |
parser = argparse.ArgumentParser( | |
prog=f'blapi v{__version__}', | |
description=description, | |
epilog=f'Author: {__author__}' | |
) | |
parser.add_argument( | |
'--version', | |
action='version', | |
version=f'v{__version__}' | |
) | |
parser.add_argument( | |
'-c', | |
'--config', | |
default=None, | |
required=True, | |
help='Configuration File' | |
) | |
args = parser.parse_args() | |
config = configparser.ConfigParser() | |
config.read(args.config) | |
user_keys = open(config['blapi'].get('user_keys'), 'r').read().splitlines() | |
admin_keys = open(config['blapi'].get('admin_keys'), 'r').read().splitlines() | |
app.config['config'] = config['blapi'].get('host') | |
app.config['version'] = __version__ | |
app.config['debug'] = config['blapi'].getboolean('debug') | |
app.config['port'] = config['blapi'].getint('port') | |
app.config['amqp_queue_traits'] = config['amqp'].get('traits_queue') | |
app.config['amqp_queue_decomp'] = config['amqp'].get('decomp_queue') | |
app.config['user_keys'] = user_keys | |
app.config['admin_keys'] = admin_keys | |
app.config['mongodb'] = MongoDBHandler(config) | |
app.config['amqp'] = AMQPHandler(config) | |
app.config['minio'] = MinIOHandler(config) | |
with app.app_context(): | |
@app.errorhandler(404) | |
def page_not_found(e): | |
return {'error': 'not found'}, 404 | |
api = Api( | |
app, | |
version=__version__, | |
title=title, | |
description=description | |
) | |
api.add_namespace(api_binlex) | |
api.add_namespace(api_mongodb) | |
def run(): | |
app.run( | |
host=config['blapi'].get('host'), | |
port=config['blapi'].getint('port'), | |
debug=config['blapi'].getboolean('debug')) | |
if __name__ in '__main__': | |
run() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment