2023-01-10 17:24:26 -05:00
|
|
|
"""
|
|
|
|
Main
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
|
|
Copyright © 2021 Project Author name guillermo.gutierrezmorote@concordia.ca
|
|
|
|
Project Collaborator name peteryefi@gmail.com
|
|
|
|
"""
|
|
|
|
|
2023-01-23 12:29:41 -05:00
|
|
|
import datetime
|
|
|
|
|
2023-01-10 17:24:26 -05:00
|
|
|
import flask
|
2023-01-16 15:31:02 -05:00
|
|
|
import yaml
|
2023-01-25 04:54:49 -05:00
|
|
|
from flasgger import LazyJSONEncoder, Swagger
|
|
|
|
from flask import Response
|
2023-01-10 17:24:26 -05:00
|
|
|
from flask_restful import Api
|
2023-01-23 12:29:41 -05:00
|
|
|
|
|
|
|
import hub_api.helpers.session_helper as sh
|
2023-02-14 04:32:04 -05:00
|
|
|
from hub_api.catalogs.construction_catalog import ConstructionCatalogEntry, ConstructionCatalogEntries, ConstructionCatalogNames
|
|
|
|
from hub_api.catalogs.greenery_catalog import GreeneryCatalogEntry, GreeneryCatalogEntries, GreeneryCatalogNames
|
|
|
|
from hub_api.catalogs.usage_catalog import UsageCatalogEntry, UsageCatalogEntries, UsageCatalogNames
|
2023-01-10 17:24:26 -05:00
|
|
|
from hub_api.session import SessionStart, SessionEnd, KeepSessionAlive
|
|
|
|
from hub_api.uptime import Uptime
|
2023-02-14 04:32:04 -05:00
|
|
|
|
2023-01-10 17:24:26 -05:00
|
|
|
|
2023-01-23 12:29:41 -05:00
|
|
|
sh.begin_time = datetime.datetime.now()
|
|
|
|
app = flask.Flask('cerc_api')
|
|
|
|
app.json_provider_class = LazyJSONEncoder
|
2023-01-10 17:24:26 -05:00
|
|
|
api = Api(app)
|
|
|
|
|
|
|
|
api.add_resource(Uptime, '/v1.4/uptime')
|
2023-01-23 12:29:41 -05:00
|
|
|
|
|
|
|
# Catalogs.
|
2023-01-10 17:24:26 -05:00
|
|
|
api.add_resource(GreeneryCatalogEntry, '/v1.4/greenery-catalog/entry')
|
|
|
|
api.add_resource(GreeneryCatalogEntries, '/v1.4/greenery-catalog/entries')
|
|
|
|
api.add_resource(GreeneryCatalogNames, '/v1.4/greenery-catalog/names')
|
|
|
|
api.add_resource(ConstructionCatalogEntry, '/v1.4/construction-catalog/entry')
|
|
|
|
api.add_resource(ConstructionCatalogEntries, '/v1.4/construction-catalog/entries')
|
|
|
|
api.add_resource(ConstructionCatalogNames, '/v1.4/construction-catalog/names')
|
|
|
|
api.add_resource(UsageCatalogEntry, '/v1.4/usage-catalog/entry')
|
|
|
|
api.add_resource(UsageCatalogEntries, '/v1.4/usage-catalog/entries')
|
|
|
|
api.add_resource(UsageCatalogNames, '/v1.4/usage-catalog/names')
|
2023-01-23 12:29:41 -05:00
|
|
|
|
|
|
|
# Session
|
2023-01-10 17:24:26 -05:00
|
|
|
api.add_resource(SessionStart, '/v1.4/session/start')
|
|
|
|
api.add_resource(SessionEnd, '/v1.4/session/end')
|
|
|
|
api.add_resource(KeepSessionAlive, '/v1.4/session/keep_alive')
|
2023-01-30 05:49:02 -05:00
|
|
|
|
|
|
|
with open("hub_api/docs/openapi-specs.yml", "r") as stream:
|
|
|
|
swagger_config = {
|
|
|
|
"headers": [],
|
|
|
|
"specs": [
|
|
|
|
{
|
|
|
|
"endpoint": 'apispec',
|
|
|
|
"route": '/apispec.json',
|
|
|
|
"rule_filter": lambda rule: True, # all in
|
|
|
|
"model_filter": lambda tag: True, # all in
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"static_url_path": "/flasgger_static",
|
|
|
|
"specs_route": "/v1.4/api-docs/",
|
|
|
|
"openapi": "3.0.0"
|
|
|
|
}
|
|
|
|
try:
|
|
|
|
Swagger(app, template=yaml.safe_load(stream), config=swagger_config)
|
|
|
|
except yaml.YAMLError as exc:
|
|
|
|
print(exc)
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/")
|
|
|
|
def home():
|
|
|
|
return Response(headers={'Access-Control-Allow-Origin': '*'})
|
|
|
|
|
|
|
|
app.run(port=15789, host="0.0.0.0", debug=True)
|