|
36 | 36 |
|
37 | 37 | app.url_map.strict_slashes = False |
38 | 38 |
|
39 | | -app.config['SECRET_KEY'] = 'secret-for-dev' |
40 | | -app.config['LOGGING_LEVEL'] = logging.INFO |
41 | | -app.config['API_KEY'] = os.getenv('API_KEY') |
42 | | -app.config['ERROR_404_HELP'] = False |
| 39 | +app.config["SECRET_KEY"] = "secret-for-dev" |
| 40 | +app.config["LOGGING_LEVEL"] = logging.INFO |
| 41 | +app.config["API_KEY"] = os.getenv("API_KEY") |
| 42 | +app.config["ERROR_404_HELP"] = False |
43 | 43 |
|
44 | 44 | # Document the type of authorization required |
45 | | -authorizations = { |
46 | | - 'apikey': { |
47 | | - 'type': 'apiKey', |
48 | | - 'in': 'header', |
49 | | - 'name': 'X-Api-Key' |
50 | | - } |
51 | | -} |
| 45 | +authorizations = {"apikey": {"type": "apiKey", "in": "header", "name": "X-Api-Key"}} |
52 | 46 |
|
53 | 47 | ###################################################################### |
54 | 48 | # Configure Swagger before initializing it |
55 | 49 | ###################################################################### |
56 | | -api = Api(app, |
57 | | - version='1.0.0', |
58 | | - title='Pet Demo REST API Service', |
59 | | - description='This is a sample server Pet store server.', |
60 | | - default='pets', |
61 | | - default_label='Pet shop operations', |
62 | | - doc='/apidocs', # default also could use doc='/apidocs/' |
63 | | - authorizations=authorizations, |
64 | | - prefix='/api' |
65 | | - ) |
| 50 | +api = Api( |
| 51 | + app, |
| 52 | + version="1.0.0", |
| 53 | + title="Pet Demo REST API Service", |
| 54 | + description="This is a sample server Pet store server.", |
| 55 | + default="pets", |
| 56 | + default_label="Pet shop operations", |
| 57 | + doc="/apidocs", # default also could use doc='/apidocs/' |
| 58 | + authorizations=authorizations, |
| 59 | + prefix="/api", |
| 60 | +) |
| 61 | + |
66 | 62 |
|
67 | 63 | # Import the routes After the Flask app is created |
68 | | -from service import routes, models |
| 64 | +# pylint: disable=wrong-import-position, wrong-import-order, cyclic-import |
| 65 | +from service import routes, models # noqa: F401, E402 |
| 66 | +from service.common import error_handlers |
69 | 67 |
|
70 | 68 | # Set up logging for production |
71 | 69 | log_handlers.init_logging(app, "gunicorn.error") |
72 | 70 |
|
73 | | -app.logger.info(70 * '*') |
74 | | -app.logger.info(' P E T S E R V I C E R U N N I N G '.center(70, '*')) |
75 | | -app.logger.info(70 * '*') |
| 71 | +app.logger.info(70 * "*") |
| 72 | +app.logger.info(" P E T S E R V I C E R U N N I N G ".center(70, "*")) |
| 73 | +app.logger.info(70 * "*") |
76 | 74 |
|
77 | | -app.logger.info('Service initialized!') |
| 75 | +app.logger.info("Service initialized!") |
78 | 76 |
|
79 | 77 | # If an API Key was not provided, autogenerate one |
80 | | -if not app.config['API_KEY']: |
81 | | - app.config['API_KEY'] = routes.generate_apikey() |
82 | | - app.logger.info('Missing API Key! Autogenerated: {}'.format(app.config['API_KEY'])) |
| 78 | +if not app.config["API_KEY"]: |
| 79 | + app.config["API_KEY"] = routes.generate_apikey() |
| 80 | + app.logger.info("Missing API Key! Autogenerated: %s", app.config["API_KEY"]) |
| 81 | + |
| 82 | +try: |
| 83 | + routes.init_db() |
| 84 | +except Exception as error: # pylint: disable=broad-except |
| 85 | + app.logger.critical("%s: Cannot continue", error) |
| 86 | + # gunicorn requires exit code 4 to stop spawning workers when they die |
| 87 | + sys.exit(4) |
0 commit comments