1
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
|
2
|
|
|
import json |
3
|
|
|
import time |
4
|
|
|
|
5
|
|
|
from pyramid.config import Configurator |
6
|
|
|
from pyramid.authentication import BasicAuthAuthenticationPolicy |
7
|
|
|
from hapic.ext.pyramid import PyramidContext |
8
|
|
|
|
9
|
|
|
from tracim.extensions import hapic |
10
|
|
|
from tracim.config import CFG |
11
|
|
|
from tracim.lib.utils.auth import basic_auth_check_credentials |
12
|
|
|
from tracim.lib.utils.request import TracimRequest |
13
|
|
|
from tracim.lib.utils.auth import AcceptAllAuthorizationPolicy |
14
|
|
|
from tracim.lib.utils.auth import BASIC_AUTH_WEBUI_REALM |
15
|
|
|
from tracim.lib.utils.auth import TRACIM_DEFAULT_PERM |
16
|
|
|
from tracim.views.example_api.example_api_controller import ExampleApiController |
17
|
|
|
from tracim.views.default.default_controller import DefaultController |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
def main(global_config, **settings): |
|
|
|
|
21
|
|
|
""" This function returns a Pyramid WSGI application. |
22
|
|
|
""" |
23
|
|
|
# set CFG object |
24
|
|
|
app_config = CFG(settings) |
25
|
|
|
app_config.configure_filedepot() |
26
|
|
|
settings['CFG'] = app_config |
27
|
|
|
configurator = Configurator(settings=settings, autocommit=True) |
28
|
|
|
# Add BasicAuthPolicy |
29
|
|
|
authn_policy = BasicAuthAuthenticationPolicy( |
30
|
|
|
basic_auth_check_credentials, |
31
|
|
|
realm=BASIC_AUTH_WEBUI_REALM, |
32
|
|
|
) |
33
|
|
|
# Default authorization : Accept anything. |
34
|
|
|
configurator.set_authorization_policy(AcceptAllAuthorizationPolicy()) |
35
|
|
|
configurator.set_authentication_policy(authn_policy) |
36
|
|
|
# INFO - GM - 11-04-2018 - set default perm |
37
|
|
|
# setting default perm is needed to force authentification |
38
|
|
|
# mecanism in all views. |
39
|
|
|
configurator.set_default_permission(TRACIM_DEFAULT_PERM) |
40
|
|
|
# Override default request |
41
|
|
|
configurator.set_request_factory(TracimRequest) |
42
|
|
|
# Pyramids "plugin" include. |
43
|
|
|
configurator.include('pyramid_jinja2') |
44
|
|
|
# Add SqlAlchemy DB |
45
|
|
|
configurator.include('.models') |
46
|
|
|
# set Hapic |
47
|
|
|
hapic.set_context(PyramidContext(configurator)) |
48
|
|
|
# Add controllers |
49
|
|
|
default_controllers = DefaultController() |
50
|
|
|
default_controllers.bind(configurator) |
51
|
|
|
example_api_controllers = ExampleApiController() |
52
|
|
|
example_api_controllers.bind(configurator) |
53
|
|
|
|
54
|
|
|
# TODO - G.M - 09-04-2018 - Enable swagger ui doc |
|
|
|
|
55
|
|
|
# time.sleep(1) |
56
|
|
|
# s = json.dumps( |
57
|
|
|
# hapic.generate_doc( |
58
|
|
|
# title='Fake API', |
59
|
|
|
# description='just an example of hapic API' |
60
|
|
|
# ) |
61
|
|
|
# ) |
62
|
|
|
# time.sleep(1) |
63
|
|
|
# # print swagger doc |
64
|
|
|
# print(s) |
65
|
|
|
# time.sleep(1) |
66
|
|
|
return configurator.make_wsgi_app() |
67
|
|
|
|
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.