Show More
@@ -1,49 +1,49 b'' | |||
|
1 | 1 | repoze.sendmail==4.1 |
|
2 |
pyramid==1. |
|
|
2 | pyramid==1.10.2 | |
|
3 | 3 | pyramid_tm==0.12 |
|
4 | 4 | pyramid_debugtoolbar |
|
5 | 5 | pyramid_authstack==1.0.1 |
|
6 | 6 | SQLAlchemy==1.0.12 |
|
7 | 7 | alembic==1.0.8 |
|
8 | 8 | webhelpers2==2.0 |
|
9 | 9 | transaction==1.4.3 |
|
10 | 10 | zope.sqlalchemy==0.7.6 |
|
11 | 11 | pyramid_mailer==0.14.1 |
|
12 | 12 | redis==2.10.5 |
|
13 | 13 | redlock-py==1.0.8 |
|
14 | 14 | pyramid_jinja2==2.6.2 |
|
15 | 15 | psycopg2==2.7.7 |
|
16 | 16 | wtforms==2.1 |
|
17 | 17 | celery==3.1.23 |
|
18 | 18 | formencode==1.3.0 |
|
19 | 19 | psutil==2.1.2 |
|
20 | 20 | ziggurat_foundations==0.8.3 |
|
21 | 21 | bcrypt==3.1.6 |
|
22 | 22 | appenlight_client |
|
23 | 23 | markdown==2.5 |
|
24 | 24 | colander==1.7 |
|
25 | 25 | defusedxml==0.5.0 |
|
26 | 26 | dogpile.cache==0.5.7 |
|
27 | 27 | pyramid_redis_sessions==1.0.1 |
|
28 | 28 | simplejson==3.8.2 |
|
29 | 29 | waitress==1.0 |
|
30 | 30 | gunicorn==19.9.0 |
|
31 | 31 | requests==2.20.0 |
|
32 | 32 | requests_oauthlib==0.6.1 |
|
33 | 33 | gevent==1.1.1 |
|
34 | 34 | gevent-websocket==0.9.5 |
|
35 | 35 | pygments==2.1.3 |
|
36 | 36 | lxml==4.3.2 |
|
37 | 37 | paginate==0.5.4 |
|
38 | 38 | paginate-sqlalchemy==0.2.0 |
|
39 | 39 | pyelasticsearch==1.4 |
|
40 | 40 | six>=1.10.0 |
|
41 | 41 | mock==1.0.1 |
|
42 | 42 | itsdangerous==1.1.0 |
|
43 | 43 | camplight==0.9.6 |
|
44 | 44 | jira==1.0.7 |
|
45 | 45 | python-dateutil==2.5.3 |
|
46 | 46 | authomatic==0.1.0.post1 |
|
47 | 47 | cryptography==2.6.1 |
|
48 | 48 | webassets==0.11.1 |
|
49 | 49 |
@@ -1,225 +1,225 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright 2010 - 2017 RhodeCode GmbH and the AppEnlight project authors |
|
4 | 4 | # |
|
5 | 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
|
6 | 6 | # you may not use this file except in compliance with the License. |
|
7 | 7 | # You may obtain a copy of the License at |
|
8 | 8 | # |
|
9 | 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
|
10 | 10 | # |
|
11 | 11 | # Unless required by applicable law or agreed to in writing, software |
|
12 | 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
|
13 | 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 | 14 | # See the License for the specific language governing permissions and |
|
15 | 15 | # limitations under the License. |
|
16 | 16 | |
|
17 | 17 | import datetime |
|
18 | 18 | import logging |
|
19 | 19 | import pyelasticsearch |
|
20 | 20 | import redis |
|
21 | 21 | import os |
|
22 | 22 | import pkg_resources |
|
23 | 23 | from pkg_resources import iter_entry_points |
|
24 | 24 | |
|
25 | 25 | import appenlight.lib.jinja2_filters as jinja2_filters |
|
26 | 26 | import appenlight.lib.encryption as encryption |
|
27 | 27 | |
|
28 | 28 | from pyramid.config import PHASE3_CONFIG |
|
29 | 29 | from pyramid.authentication import AuthTktAuthenticationPolicy |
|
30 | 30 | from pyramid.authorization import ACLAuthorizationPolicy |
|
31 | 31 | from pyramid_mailer.interfaces import IMailer |
|
32 | 32 | from pyramid.renderers import JSON |
|
33 | 33 | from pyramid_redis_sessions import session_factory_from_settings |
|
34 | 34 | from pyramid.settings import asbool, aslist |
|
35 | 35 | from pyramid.security import AllPermissionsList |
|
36 | 36 | from pyramid_authstack import AuthenticationStackPolicy |
|
37 | 37 | from redlock import Redlock |
|
38 | 38 | from sqlalchemy import engine_from_config |
|
39 | 39 | |
|
40 | 40 | from appenlight.celery import configure_celery |
|
41 | 41 | from appenlight.lib.configurator import (CythonCompatConfigurator, |
|
42 | 42 | register_appenlight_plugin) |
|
43 | 43 | from appenlight.lib import cache_regions |
|
44 | 44 | from appenlight.lib.ext_json import json |
|
45 | 45 | from appenlight.security import groupfinder, AuthTokenAuthenticationPolicy |
|
46 | 46 | |
|
47 | 47 | __license__ = 'Apache 2.0' |
|
48 | 48 | __author__ = 'RhodeCode GmbH' |
|
49 | 49 | __url__ = 'http://rhodecode.com' |
|
50 | 50 | __version__ = pkg_resources.get_distribution("appenlight").parsed_version |
|
51 | 51 | |
|
52 | 52 | json_renderer = JSON(serializer=json.dumps, indent=4) |
|
53 | 53 | |
|
54 | 54 | log = logging.getLogger(__name__) |
|
55 | 55 | |
|
56 | 56 | |
|
57 | 57 | def datetime_adapter(obj, request): |
|
58 | 58 | return obj.isoformat() |
|
59 | 59 | |
|
60 | 60 | |
|
61 | 61 | def all_permissions_adapter(obj, request): |
|
62 | 62 | return '__all_permissions__' |
|
63 | 63 | |
|
64 | 64 | |
|
65 | 65 | json_renderer.add_adapter(datetime.datetime, datetime_adapter) |
|
66 | 66 | json_renderer.add_adapter(AllPermissionsList, all_permissions_adapter) |
|
67 | 67 | |
|
68 | 68 | |
|
69 | 69 | def main(global_config, **settings): |
|
70 | 70 | """ This function returns a Pyramid WSGI application. |
|
71 | 71 | """ |
|
72 | 72 | auth_tkt_policy = AuthTktAuthenticationPolicy( |
|
73 | 73 | settings['authtkt.secret'], |
|
74 | 74 | hashalg='sha512', |
|
75 | 75 | callback=groupfinder, |
|
76 | 76 | max_age=2592000, |
|
77 | 77 | secure=asbool(settings.get('authtkt.secure', 'false'))) |
|
78 | 78 | auth_token_policy = AuthTokenAuthenticationPolicy( |
|
79 | 79 | callback=groupfinder |
|
80 | 80 | ) |
|
81 | 81 | authorization_policy = ACLAuthorizationPolicy() |
|
82 | 82 | authentication_policy = AuthenticationStackPolicy() |
|
83 | 83 | authentication_policy.add_policy('auth_tkt', auth_tkt_policy) |
|
84 | 84 | authentication_policy.add_policy('auth_token', auth_token_policy) |
|
85 | 85 | # set crypto key |
|
86 | 86 | encryption.ENCRYPTION_SECRET = settings.get('encryption_secret') |
|
87 | 87 | # import this later so encyption key can be monkeypatched |
|
88 | 88 | from appenlight.models import DBSession, register_datastores |
|
89 | 89 | |
|
90 | 90 | # registration |
|
91 | 91 | settings['appenlight.disable_registration'] = asbool( |
|
92 | 92 | settings.get('appenlight.disable_registration')) |
|
93 | 93 | |
|
94 | 94 | # update config with cometd info |
|
95 | 95 | settings['cometd_servers'] = {'server': settings['cometd.server'], |
|
96 | 96 | 'secret': settings['cometd.secret']} |
|
97 | 97 | |
|
98 | 98 | # Create the Pyramid Configurator. |
|
99 | 99 | settings['_mail_url'] = settings['mailing.app_url'] |
|
100 | 100 | config = CythonCompatConfigurator( |
|
101 | 101 | settings=settings, |
|
102 | 102 | authentication_policy=authentication_policy, |
|
103 | 103 | authorization_policy=authorization_policy, |
|
104 | 104 | root_factory='appenlight.security.RootFactory', |
|
105 | 105 | default_permission='view') |
|
106 | 106 | # custom registry variables |
|
107 | 107 | |
|
108 | 108 | # resource type information |
|
109 | 109 | config.registry.resource_types = ['resource', 'application'] |
|
110 | 110 | # plugin information |
|
111 | 111 | config.registry.appenlight_plugins = {} |
|
112 | 112 | |
|
113 | 113 | config.set_default_csrf_options(require_csrf=True, header='X-XSRF-TOKEN') |
|
114 | 114 | config.add_view_deriver('appenlight.predicates.csrf_view', |
|
115 | 115 | name='csrf_view') |
|
116 | 116 | |
|
117 | 117 | # later, when config is available |
|
118 | 118 | dogpile_config = {'url': settings['redis.url'], |
|
119 | 119 | "redis_expiration_time": 86400, |
|
120 | 120 | "redis_distributed_lock": True} |
|
121 | 121 | cache_regions.regions = cache_regions.CacheRegions(dogpile_config) |
|
122 | 122 | config.registry.cache_regions = cache_regions.regions |
|
123 | 123 | engine = engine_from_config(settings, 'sqlalchemy.', |
|
124 | 124 | json_serializer=json.dumps) |
|
125 | 125 | DBSession.configure(bind=engine) |
|
126 | 126 | |
|
127 | 127 | # json rederer that serializes datetime |
|
128 | 128 | config.add_renderer('json', json_renderer) |
|
129 |
config. |
|
|
130 |
config. |
|
|
131 | reify=True) | |
|
132 |
config. |
|
|
133 | 'csrf_token', reify=True) | |
|
134 |
config. |
|
|
135 | 'safe_json_body', reify=True) | |
|
136 |
config. |
|
|
137 | 'unsafe_json_body', reify=True) | |
|
129 | config.add_request_method('appenlight.lib.request.es_conn', 'es_conn', property=True) | |
|
130 | config.add_request_method('appenlight.lib.request.get_user', 'user', | |
|
131 | reify=True, property=True) | |
|
132 | config.add_request_method('appenlight.lib.request.get_csrf_token', | |
|
133 | 'csrf_token', reify=True, property=True) | |
|
134 | config.add_request_method('appenlight.lib.request.safe_json_body', | |
|
135 | 'safe_json_body', reify=True, property=True) | |
|
136 | config.add_request_method('appenlight.lib.request.unsafe_json_body', | |
|
137 | 'unsafe_json_body', reify=True, property=True) | |
|
138 | 138 | config.add_request_method('appenlight.lib.request.add_flash_to_headers', |
|
139 | 139 | 'add_flash_to_headers') |
|
140 | 140 | config.add_request_method('appenlight.lib.request.get_authomatic', |
|
141 | 141 | 'authomatic', reify=True) |
|
142 | 142 | |
|
143 | 143 | config.include('pyramid_redis_sessions') |
|
144 | 144 | config.include('pyramid_tm') |
|
145 | 145 | config.include('pyramid_jinja2') |
|
146 | 146 | config.include('pyramid_mailer') |
|
147 | 147 | config.include('appenlight_client.ext.pyramid_tween') |
|
148 | 148 | config.include('ziggurat_foundations.ext.pyramid.sign_in') |
|
149 | 149 | es_server_list = aslist(settings['elasticsearch.nodes']) |
|
150 | 150 | redis_url = settings['redis.url'] |
|
151 | 151 | log.warning('Elasticsearch server list: {}'.format(es_server_list)) |
|
152 | 152 | log.warning('Redis server: {}'.format(redis_url)) |
|
153 | 153 | config.registry.es_conn = pyelasticsearch.ElasticSearch(es_server_list) |
|
154 | 154 | config.registry.redis_conn = redis.StrictRedis.from_url(redis_url) |
|
155 | 155 | |
|
156 | 156 | config.registry.redis_lockmgr = Redlock([settings['redis.redlock.url'], ], |
|
157 | 157 | retry_count=0, retry_delay=0) |
|
158 | 158 | # mailer bw compat |
|
159 | 159 | config.registry.mailer = config.registry.getUtility(IMailer) |
|
160 | 160 | |
|
161 | 161 | # Configure sessions |
|
162 | 162 | session_factory = session_factory_from_settings(settings) |
|
163 | 163 | config.set_session_factory(session_factory) |
|
164 | 164 | |
|
165 | 165 | # Configure renderers and event subscribers |
|
166 | 166 | config.add_jinja2_extension('jinja2.ext.loopcontrols') |
|
167 | 167 | config.add_jinja2_search_path('appenlight:templates') |
|
168 | 168 | # event subscribers |
|
169 | 169 | config.add_subscriber("appenlight.subscribers.application_created", |
|
170 | 170 | "pyramid.events.ApplicationCreated") |
|
171 | 171 | config.add_subscriber("appenlight.subscribers.add_renderer_globals", |
|
172 | 172 | "pyramid.events.BeforeRender") |
|
173 | 173 | config.add_subscriber('appenlight.subscribers.new_request', |
|
174 | 174 | 'pyramid.events.NewRequest') |
|
175 | 175 | config.add_view_predicate('context_type_class', |
|
176 | 176 | 'appenlight.predicates.contextTypeClass') |
|
177 | 177 | |
|
178 | 178 | register_datastores(es_conn=config.registry.es_conn, |
|
179 | 179 | redis_conn=config.registry.redis_conn, |
|
180 | 180 | redis_lockmgr=config.registry.redis_lockmgr) |
|
181 | 181 | |
|
182 | 182 | # base stuff and scan |
|
183 | 183 | |
|
184 | 184 | # need to ensure webassets exists otherwise config.override_asset() |
|
185 | 185 | # throws exception |
|
186 | 186 | if not os.path.exists(settings['webassets.dir']): |
|
187 | 187 | os.mkdir(settings['webassets.dir']) |
|
188 | 188 | config.add_static_view(path='appenlight:webassets', |
|
189 | 189 | name='static', cache_max_age=3600) |
|
190 | 190 | config.override_asset(to_override='appenlight:webassets/', |
|
191 | 191 | override_with=settings['webassets.dir']) |
|
192 | 192 | |
|
193 | 193 | config.include('appenlight.views') |
|
194 | 194 | config.include('appenlight.views.admin') |
|
195 | 195 | config.scan(ignore=['appenlight.migrations', 'appenlight.scripts', |
|
196 | 196 | 'appenlight.tests']) |
|
197 | 197 | |
|
198 | 198 | config.add_directive('register_appenlight_plugin', |
|
199 | 199 | register_appenlight_plugin) |
|
200 | 200 | |
|
201 | 201 | for entry_point in iter_entry_points(group='appenlight.plugins'): |
|
202 | 202 | plugin = entry_point.load() |
|
203 | 203 | plugin.includeme(config) |
|
204 | 204 | |
|
205 | 205 | # include other appenlight plugins explictly if needed |
|
206 | 206 | includes = aslist(settings.get('appenlight.includes', [])) |
|
207 | 207 | for inc in includes: |
|
208 | 208 | config.include(inc) |
|
209 | 209 | |
|
210 | 210 | # run this after everything registers in configurator |
|
211 | 211 | |
|
212 | 212 | def pre_commit(): |
|
213 | 213 | jinja_env = config.get_jinja2_environment() |
|
214 | 214 | jinja_env.filters['tojson'] = json.dumps |
|
215 | 215 | jinja_env.filters['toJSONUnsafe'] = jinja2_filters.toJSONUnsafe |
|
216 | 216 | |
|
217 | 217 | config.action(None, pre_commit, order=PHASE3_CONFIG + 999) |
|
218 | 218 | |
|
219 | 219 | def wrap_config_celery(): |
|
220 | 220 | configure_celery(config.registry) |
|
221 | 221 | |
|
222 | 222 | config.action(None, wrap_config_celery, order=PHASE3_CONFIG + 999) |
|
223 | 223 | |
|
224 | 224 | app = config.make_wsgi_app() |
|
225 | 225 | return app |
General Comments 0
You need to be logged in to leave comments.
Login now