Completed
Push — master ( 68bc61...042191 )
by
unknown
02:38
created

tracim.main()   A

Complexity

Conditions 1

Size

Total Lines 47
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 47
rs 9.0303
c 0
b 0
f 0
cc 1
nop 2
1
# -*- coding: utf-8 -*-
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
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):
0 ignored issues
show
Unused Code introduced by
The argument global_config seems to be unused.
Loading history...
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
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
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