|
1
|
|
|
# Licensed to the StackStorm, Inc ('StackStorm') under one or more |
|
2
|
|
|
# contributor license agreements. See the NOTICE file distributed with |
|
3
|
|
|
# this work for additional information regarding copyright ownership. |
|
4
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0 |
|
5
|
|
|
# (the "License"); you may not use this file except in compliance with |
|
6
|
|
|
# the License. You may obtain a copy of the License at |
|
7
|
|
|
# |
|
8
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
|
9
|
|
|
# |
|
10
|
|
|
# Unless required by applicable law or agreed to in writing, software |
|
11
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
|
12
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13
|
|
|
# See the License for the specific language governing permissions and |
|
14
|
|
|
# limitations under the License. |
|
15
|
|
|
|
|
16
|
|
|
import pecan |
|
17
|
|
|
from oslo_config import cfg |
|
18
|
|
|
|
|
19
|
|
|
from st2auth import config as st2auth_config |
|
20
|
|
|
from st2common import hooks |
|
21
|
|
|
from st2common import log as logging |
|
22
|
|
|
from st2common.constants.system import VERSION_STRING |
|
23
|
|
|
from st2common.service_setup import setup as common_setup |
|
24
|
|
|
|
|
25
|
|
|
LOG = logging.getLogger(__name__) |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
def _get_pecan_config(): |
|
29
|
|
|
|
|
30
|
|
|
config = { |
|
31
|
|
|
'app': { |
|
32
|
|
|
'root': 'st2auth.controllers.root.RootController', |
|
33
|
|
|
'modules': ['st2auth'], |
|
34
|
|
|
'debug': cfg.CONF.auth.debug, |
|
35
|
|
|
'errors': {'__force_dict__': True} |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
return pecan.configuration.conf_from_dict(config) |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
def setup_app(config=None): |
|
43
|
|
|
LOG.info('Creating st2auth: %s as Pecan app.', VERSION_STRING) |
|
44
|
|
|
|
|
45
|
|
|
is_gunicorn = getattr(config, 'is_gunicorn', False) |
|
46
|
|
|
if is_gunicorn: |
|
47
|
|
|
# This should be called in gunicorn case because we only want |
|
48
|
|
|
# workers to connect to db, rabbbitmq etc. In standalone HTTP |
|
49
|
|
|
# server case, this setup would have already occurred. |
|
50
|
|
|
st2auth_config.register_opts() |
|
51
|
|
|
common_setup(service='auth', config=st2auth_config, setup_db=True, |
|
52
|
|
|
register_mq_exchanges=False, |
|
53
|
|
|
register_signal_handlers=True, |
|
54
|
|
|
register_internal_trigger_types=False, |
|
55
|
|
|
run_migrations=False, |
|
56
|
|
|
config_args=config.config_args) |
|
57
|
|
|
|
|
58
|
|
|
if not config: |
|
59
|
|
|
# standalone HTTP server case |
|
60
|
|
|
config = _get_pecan_config() |
|
61
|
|
|
else: |
|
62
|
|
|
# gunicorn case |
|
63
|
|
|
if is_gunicorn: |
|
64
|
|
|
config.app = _get_pecan_config().app |
|
65
|
|
|
|
|
66
|
|
|
app_conf = dict(config.app) |
|
67
|
|
|
|
|
68
|
|
|
app = pecan.make_app( |
|
69
|
|
|
app_conf.pop('root'), |
|
70
|
|
|
logging=getattr(config, 'logging', {}), |
|
71
|
|
|
hooks=[hooks.JSONErrorResponseHook(), hooks.CorsHook()], |
|
72
|
|
|
**app_conf |
|
73
|
|
|
) |
|
74
|
|
|
LOG.info('%s app created.' % __name__) |
|
75
|
|
|
|
|
76
|
|
|
return app |
|
77
|
|
|
|