-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
93 lines (73 loc) · 2.78 KB
/
app.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# coding=utf-8
import os
from flask import Flask
from flask_restful import Api
from flask_migrate import Migrate, MigrateCommand
from flask_cors import CORS
from flasgger import Swagger
from ressource.party import Party, PartyId
from ressource.health import Health
from extensions import db
import traceback
from sqlalchemy import create_engine
from conf import _init_logging
# get global Fehlerbildnummer Prefix as ENV Variable
FBNRPREFIX = os.environ.get('FBNRPREFIX', '99999999')
def create_app():
env = os.environ.get('ENV', 'Staging')
if env == "Production":
config_str = 'config.ProductionConfig'
elif env == "Staging":
config_str = 'config.StagingConfig'
elif env == "Development":
config_str = 'config.DevelopmentConfig'
logger.info("Running on Environment {}".format(env))
app = Flask(__name__)
app.config.from_object(config_str)
register_extensions(app)
register_resources(app)
return app
def register_extensions(app):
try:
db.init_app(app)
migrate = Migrate(app, db)
except:
FBNRPREFIX= FBNRPREFIX + '00000010'
logger.error('DB Init Error:' + traceback.print_exc(), extra={'fehlerbildnummer': FNummer, 'incomming_message': "",
'communication_pattern': '', 'service_domain': 'party',
'service_call': ""})
try:
dbUSER = os.environ.get('SPRING_DATASOURCE_USERNAME')
# Create schema
engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI'])
if not engine.dialect.has_schema(engine, dbUSER):
engine.execute('CREATE SCHEMA IF NOT EXISTS %s' % dbUSER)
db.create_all(app=app)
except:
FBNRPREFIX = FBNRPREFIX + '00000011'
logger.error('DB Create Error:' + traceback.print_exc(),
extra={'fehlerbildnummer': FNummer, 'incomming_message': "",
'communication_pattern': '', 'service_domain': 'party',
'service_call': ""})
app.config['SWAGGER'] = {
'title': 'Giga Party Individual',
'uiversion': 2
}
swag = Swagger(app, template_file='./conf/swagger/TMF632PartyIndiv_V1.yaml')
CORS(app)
def register_resources(app):
api = Api(app)
api.add_resource(Party, '/party/v1/individual')
api.add_resource(Health, '/actuator/health')
api.add_resource(PartyId, '/party/v1/individual/<int:id>')
@app.route("/")
def hello():
return "Hello here is Python based R.Schier Party-Individual APP"
if __name__ == "__main__":
# init logging
logger = _init_logging('main.app')
app = create_app()
env = os.environ.get('ENV', 'Staging')
if env == 'Staging':
print ("I am in Staging Mode")
app.run(debug=True, host='0.0.0.0', port=8080)