-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.py
More file actions
54 lines (38 loc) · 2.04 KB
/
setup.py
File metadata and controls
54 lines (38 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import environ
import logging
from flask import Blueprint
from flask_restx import Api
logger = logging.getLogger(__name__)
@environ.config()
class Settings:
"""App settings loaded from environment variables"""
version = "0.1"
title = environ.var("ESDL-Validator", name="ESDLVALIDATOR_TITLE")
description = environ.var("API for validating ESDL files", name="ESDLVALIDATOR_DESCRIPTION")
endpointPrefix = environ.var("", name="ESDLVALIDATOR_ENDPOINT_PREFIX")
useDefaultCors = environ.var(False, converter=bool, name="ESDLVALIDATOR_DEFAULT_CORS")
dbLocation = environ.var("schemas.db", name="ESDLVALIDATOR_DB_LOCATION")
logLevel = environ.var("INFO", name="ESDLVALIDATOR_LOG_LEVEL")
def setup_logger(logLevel: str):
"""Setup the logger"""
logLevel = logging.getLevelName(logLevel)
werkzeug = logging.getLogger('werkzeug')
waitress = logging.getLogger('waitress')
werkzeug.setLevel(logLevel)
waitress.setLevel(logLevel)
logging.basicConfig(level=logLevel, format="%(asctime)s | %(name)s | %(levelname)s | %(message)s", datefmt="%Y-%m-%dT%H:%M:%S%z")
class AppConfig:
"""Application config and initialization"""
def __init__(self):
# Load config
self.settings = Settings.from_environ()
# Setup the logger
setup_logger(self.settings.logLevel)
logger.info("Setting up app")
# Setup flask/restx, namespaces
self.apiBlueprint = Blueprint("api", __name__)
self.api = Api(self.apiBlueprint, version=self.settings.version, title=self.settings.title, description=self.settings.description)
self.ns_validation = self.api.namespace("validation", "ESDL validation endpoint")
self.ns_validation_to_notes = self.api.namespace("validationToNotes", "ESDL-aas validation endpoint")
self.ns_validation_to_msgs = self.api.namespace("validationToMessages", "ESDL-aas validation endpoint to return JSON")
self.ns_schema = self.api.namespace("schema", "Validation schema endpoint")