Show More
@@ -1,77 +1,81 b'' | |||
|
1 | 1 | import os |
|
2 | 2 | import sys |
|
3 | 3 | import re |
|
4 | 4 | |
|
5 | 5 | from setuptools import setup, find_packages |
|
6 | 6 | |
|
7 | 7 | here = os.path.abspath(os.path.dirname(__file__)) |
|
8 | 8 | README = open(os.path.join(here, '..', 'README.md')).read() |
|
9 | 9 | CHANGES = open(os.path.join(here, 'CHANGELOG.rst')).read() |
|
10 | 10 | |
|
11 | 11 | REQUIREMENTS = open(os.path.join(here, 'requirements.txt')).readlines() |
|
12 | 12 | |
|
13 | 13 | compiled = re.compile('([^=><]*).*') |
|
14 | 14 | |
|
15 | 15 | |
|
16 | 16 | def parse_req(req): |
|
17 | 17 | return compiled.search(req).group(1).strip() |
|
18 | 18 | |
|
19 | 19 | |
|
20 | 20 | requires = [_f for _f in map(parse_req, REQUIREMENTS) if _f] |
|
21 | 21 | |
|
22 | 22 | |
|
23 | 23 | def _get_meta_var(name, data, callback_handler=None): |
|
24 | 24 | import re |
|
25 | 25 | matches = re.compile(r'(?:%s)\s*=\s*(.*)' % name).search(data) |
|
26 | 26 | if matches: |
|
27 | 27 | if not callable(callback_handler): |
|
28 | 28 | callback_handler = lambda v: v |
|
29 | 29 | |
|
30 | 30 | return callback_handler(eval(matches.groups()[0])) |
|
31 | 31 | |
|
32 | 32 | with open(os.path.join(here, 'src', 'appenlight', '__init__.py'), 'r') as _meta: |
|
33 | 33 | _metadata = _meta.read() |
|
34 | 34 | |
|
35 | 35 | with open(os.path.join('src', 'appenlight', 'VERSION')) as _meta_version: |
|
36 | 36 | __version__ = _meta_version.read().strip() |
|
37 | 37 | |
|
38 | 38 | __license__ = _get_meta_var('__license__', _metadata) |
|
39 | 39 | __author__ = _get_meta_var('__author__', _metadata) |
|
40 | 40 | __url__ = _get_meta_var('__url__', _metadata) |
|
41 | 41 | |
|
42 | 42 | found_packages = find_packages('src') |
|
43 | 43 | found_packages.append('appenlight.migrations.versions') |
|
44 | 44 | setup(name='appenlight', |
|
45 | 45 | description='appenlight', |
|
46 | 46 | long_description=README + '\n\n' + CHANGES, |
|
47 | 47 | classifiers=[ |
|
48 | 48 | "Programming Language :: Python", |
|
49 | 49 | "Framework :: Pylons", |
|
50 | 50 | "Topic :: Internet :: WWW/HTTP", |
|
51 | 51 | "Topic :: Internet :: WWW/HTTP :: WSGI :: Application", |
|
52 | 52 | ], |
|
53 | 53 | version=__version__, |
|
54 | 54 | license=__license__, |
|
55 | 55 | author=__author__, |
|
56 | 56 | url=__url__, |
|
57 | 57 | keywords='web wsgi bfg pylons pyramid', |
|
58 | 58 | package_dir={'': 'src'}, |
|
59 | 59 | packages=found_packages, |
|
60 | 60 | include_package_data=True, |
|
61 | 61 | zip_safe=False, |
|
62 | 62 | test_suite='appenlight', |
|
63 | 63 | install_requires=requires, |
|
64 | extras_require={ | |
|
65 | "dev": ["coverage", "pytest", "pyramid", "tox", "mock", "webtest"], | |
|
66 | "lint": ["black"], | |
|
67 | }, | |
|
64 | 68 | entry_points={ |
|
65 | 69 | 'paste.app_factory': [ |
|
66 | 70 | 'main = appenlight:main' |
|
67 | 71 | ], |
|
68 | 72 | 'console_scripts': [ |
|
69 | 73 | 'appenlight-cleanup = appenlight.scripts.cleanup:main', |
|
70 | 74 | 'appenlight-initializedb = appenlight.scripts.initialize_db:main', |
|
71 | 75 | 'appenlight-migratedb = appenlight.scripts.migratedb:main', |
|
72 | 76 | 'appenlight-reindex-elasticsearch = appenlight.scripts.reindex_elasticsearch:main', |
|
73 | 77 | 'appenlight-static = appenlight.scripts.static:main', |
|
74 | 78 | 'appenlight-make-config = appenlight.scripts.make_config:main', |
|
75 | 79 | ] |
|
76 | 80 | } |
|
77 | 81 | ) |
@@ -1,222 +1,224 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 | import pkg_resources | |
|
22 | 23 | from pkg_resources import iter_entry_points |
|
23 | 24 | |
|
24 | 25 | import appenlight.lib.jinja2_filters as jinja2_filters |
|
25 | 26 | import appenlight.lib.encryption as encryption |
|
26 | 27 | |
|
27 | 28 | from pyramid.config import PHASE3_CONFIG |
|
28 | 29 | from pyramid.authentication import AuthTktAuthenticationPolicy |
|
29 | 30 | from pyramid.authorization import ACLAuthorizationPolicy |
|
30 | 31 | from pyramid_mailer.mailer import Mailer |
|
31 | 32 | from pyramid.renderers import JSON |
|
32 | 33 | from pyramid_redis_sessions import session_factory_from_settings |
|
33 | 34 | from pyramid.settings import asbool, aslist |
|
34 | 35 | from pyramid.security import AllPermissionsList |
|
35 | 36 | from pyramid_authstack import AuthenticationStackPolicy |
|
36 | 37 | from redlock import Redlock |
|
37 | 38 | from sqlalchemy import engine_from_config |
|
38 | 39 | |
|
39 | 40 | from appenlight.celery import configure_celery |
|
40 | 41 | from appenlight.lib.configurator import (CythonCompatConfigurator, |
|
41 | 42 | register_appenlight_plugin) |
|
42 | 43 | from appenlight.lib import cache_regions |
|
43 | 44 | from appenlight.lib.ext_json import json |
|
44 | 45 | from appenlight.security import groupfinder, AuthTokenAuthenticationPolicy |
|
45 | 46 | |
|
46 | 47 | __license__ = 'Apache 2.0' |
|
47 | 48 | __author__ = 'RhodeCode GmbH' |
|
48 | 49 | __url__ = 'http://rhodecode.com' |
|
50 | __version__ = pkg_resources.get_distribution("appenlight").parsed_version | |
|
49 | 51 | |
|
50 | 52 | json_renderer = JSON(serializer=json.dumps, indent=4) |
|
51 | 53 | |
|
52 | 54 | log = logging.getLogger(__name__) |
|
53 | 55 | |
|
54 | 56 | |
|
55 | 57 | def datetime_adapter(obj, request): |
|
56 | 58 | return obj.isoformat() |
|
57 | 59 | |
|
58 | 60 | |
|
59 | 61 | def all_permissions_adapter(obj, request): |
|
60 | 62 | return '__all_permissions__' |
|
61 | 63 | |
|
62 | 64 | |
|
63 | 65 | json_renderer.add_adapter(datetime.datetime, datetime_adapter) |
|
64 | 66 | json_renderer.add_adapter(AllPermissionsList, all_permissions_adapter) |
|
65 | 67 | |
|
66 | 68 | |
|
67 | 69 | def main(global_config, **settings): |
|
68 | 70 | """ This function returns a Pyramid WSGI application. |
|
69 | 71 | """ |
|
70 | 72 | auth_tkt_policy = AuthTktAuthenticationPolicy( |
|
71 | 73 | settings['authtkt.secret'], |
|
72 | 74 | hashalg='sha512', |
|
73 | 75 | callback=groupfinder, |
|
74 | 76 | max_age=2592000, |
|
75 | 77 | secure=asbool(settings.get('authtkt.secure', 'false'))) |
|
76 | 78 | auth_token_policy = AuthTokenAuthenticationPolicy( |
|
77 | 79 | callback=groupfinder |
|
78 | 80 | ) |
|
79 | 81 | authorization_policy = ACLAuthorizationPolicy() |
|
80 | 82 | authentication_policy = AuthenticationStackPolicy() |
|
81 | 83 | authentication_policy.add_policy('auth_tkt', auth_tkt_policy) |
|
82 | 84 | authentication_policy.add_policy('auth_token', auth_token_policy) |
|
83 | 85 | # set crypto key |
|
84 | 86 | encryption.ENCRYPTION_SECRET = settings.get('encryption_secret') |
|
85 | 87 | # import this later so encyption key can be monkeypatched |
|
86 | 88 | from appenlight.models import DBSession, register_datastores |
|
87 | 89 | |
|
88 | 90 | # registration |
|
89 | 91 | settings['appenlight.disable_registration'] = asbool( |
|
90 | 92 | settings.get('appenlight.disable_registration')) |
|
91 | 93 | |
|
92 | 94 | # update config with cometd info |
|
93 | 95 | settings['cometd_servers'] = {'server': settings['cometd.server'], |
|
94 | 96 | 'secret': settings['cometd.secret']} |
|
95 | 97 | |
|
96 | 98 | # Create the Pyramid Configurator. |
|
97 | 99 | settings['_mail_url'] = settings['mailing.app_url'] |
|
98 | 100 | config = CythonCompatConfigurator( |
|
99 | 101 | settings=settings, |
|
100 | 102 | authentication_policy=authentication_policy, |
|
101 | 103 | authorization_policy=authorization_policy, |
|
102 | 104 | root_factory='appenlight.security.RootFactory', |
|
103 | 105 | default_permission='view') |
|
104 | 106 | # custom registry variables |
|
105 | 107 | |
|
106 | 108 | # resource type information |
|
107 | 109 | config.registry.resource_types = ['resource', 'application'] |
|
108 | 110 | # plugin information |
|
109 | 111 | config.registry.appenlight_plugins = {} |
|
110 | 112 | |
|
111 | 113 | config.set_default_csrf_options(require_csrf=True, header='X-XSRF-TOKEN') |
|
112 | 114 | config.add_view_deriver('appenlight.predicates.csrf_view', |
|
113 | 115 | name='csrf_view') |
|
114 | 116 | |
|
115 | 117 | # later, when config is available |
|
116 | 118 | dogpile_config = {'url': settings['redis.url'], |
|
117 | 119 | "redis_expiration_time": 86400, |
|
118 | 120 | "redis_distributed_lock": True} |
|
119 | 121 | cache_regions.regions = cache_regions.CacheRegions(dogpile_config) |
|
120 | 122 | config.registry.cache_regions = cache_regions.regions |
|
121 | 123 | engine = engine_from_config(settings, 'sqlalchemy.', |
|
122 | 124 | json_serializer=json.dumps) |
|
123 | 125 | DBSession.configure(bind=engine) |
|
124 | 126 | |
|
125 | 127 | # json rederer that serializes datetime |
|
126 | 128 | config.add_renderer('json', json_renderer) |
|
127 | 129 | config.set_request_property('appenlight.lib.request.es_conn', 'es_conn') |
|
128 | 130 | config.set_request_property('appenlight.lib.request.get_user', 'user', |
|
129 | 131 | reify=True) |
|
130 | 132 | config.set_request_property('appenlight.lib.request.get_csrf_token', |
|
131 | 133 | 'csrf_token', reify=True) |
|
132 | 134 | config.set_request_property('appenlight.lib.request.safe_json_body', |
|
133 | 135 | 'safe_json_body', reify=True) |
|
134 | 136 | config.set_request_property('appenlight.lib.request.unsafe_json_body', |
|
135 | 137 | 'unsafe_json_body', reify=True) |
|
136 | 138 | config.add_request_method('appenlight.lib.request.add_flash_to_headers', |
|
137 | 139 | 'add_flash_to_headers') |
|
138 | 140 | config.add_request_method('appenlight.lib.request.get_authomatic', |
|
139 | 141 | 'authomatic', reify=True) |
|
140 | 142 | |
|
141 | 143 | config.include('pyramid_redis_sessions') |
|
142 | 144 | config.include('pyramid_tm') |
|
143 | 145 | config.include('pyramid_jinja2') |
|
144 | 146 | config.include('appenlight_client.ext.pyramid_tween') |
|
145 | 147 | config.include('ziggurat_foundations.ext.pyramid.sign_in') |
|
146 | 148 | es_server_list = aslist(settings['elasticsearch.nodes']) |
|
147 | 149 | redis_url = settings['redis.url'] |
|
148 | 150 | log.warning('Elasticsearch server list: {}'.format(es_server_list)) |
|
149 | 151 | log.warning('Redis server: {}'.format(redis_url)) |
|
150 | 152 | config.registry.es_conn = pyelasticsearch.ElasticSearch(es_server_list) |
|
151 | 153 | config.registry.redis_conn = redis.StrictRedis.from_url(redis_url) |
|
152 | 154 | |
|
153 | 155 | config.registry.redis_lockmgr = Redlock([settings['redis.redlock.url'], ], |
|
154 | 156 | retry_count=0, retry_delay=0) |
|
155 | 157 | # mailer |
|
156 | 158 | config.registry.mailer = Mailer.from_settings(settings) |
|
157 | 159 | |
|
158 | 160 | # Configure sessions |
|
159 | 161 | session_factory = session_factory_from_settings(settings) |
|
160 | 162 | config.set_session_factory(session_factory) |
|
161 | 163 | |
|
162 | 164 | # Configure renderers and event subscribers |
|
163 | 165 | config.add_jinja2_extension('jinja2.ext.loopcontrols') |
|
164 | 166 | config.add_jinja2_search_path('appenlight:templates') |
|
165 | 167 | # event subscribers |
|
166 | 168 | config.add_subscriber("appenlight.subscribers.application_created", |
|
167 | 169 | "pyramid.events.ApplicationCreated") |
|
168 | 170 | config.add_subscriber("appenlight.subscribers.add_renderer_globals", |
|
169 | 171 | "pyramid.events.BeforeRender") |
|
170 | 172 | config.add_subscriber('appenlight.subscribers.new_request', |
|
171 | 173 | 'pyramid.events.NewRequest') |
|
172 | 174 | config.add_view_predicate('context_type_class', |
|
173 | 175 | 'appenlight.predicates.contextTypeClass') |
|
174 | 176 | |
|
175 | 177 | register_datastores(es_conn=config.registry.es_conn, |
|
176 | 178 | redis_conn=config.registry.redis_conn, |
|
177 | 179 | redis_lockmgr=config.registry.redis_lockmgr) |
|
178 | 180 | |
|
179 | 181 | # base stuff and scan |
|
180 | 182 | |
|
181 | 183 | # need to ensure webassets exists otherwise config.override_asset() |
|
182 | 184 | # throws exception |
|
183 | 185 | if not os.path.exists(settings['webassets.dir']): |
|
184 | 186 | os.mkdir(settings['webassets.dir']) |
|
185 | 187 | config.add_static_view(path='appenlight:webassets', |
|
186 | 188 | name='static', cache_max_age=3600) |
|
187 | 189 | config.override_asset(to_override='appenlight:webassets/', |
|
188 | 190 | override_with=settings['webassets.dir']) |
|
189 | 191 | |
|
190 | 192 | config.include('appenlight.views') |
|
191 | 193 | config.include('appenlight.views.admin') |
|
192 | 194 | config.scan(ignore=['appenlight.migrations', 'appenlight.scripts', |
|
193 | 195 | 'appenlight.tests']) |
|
194 | 196 | |
|
195 | 197 | config.add_directive('register_appenlight_plugin', |
|
196 | 198 | register_appenlight_plugin) |
|
197 | 199 | |
|
198 | 200 | for entry_point in iter_entry_points(group='appenlight.plugins'): |
|
199 | 201 | plugin = entry_point.load() |
|
200 | 202 | plugin.includeme(config) |
|
201 | 203 | |
|
202 | 204 | # include other appenlight plugins explictly if needed |
|
203 | 205 | includes = aslist(settings.get('appenlight.includes', [])) |
|
204 | 206 | for inc in includes: |
|
205 | 207 | config.include(inc) |
|
206 | 208 | |
|
207 | 209 | # run this after everything registers in configurator |
|
208 | 210 | |
|
209 | 211 | def pre_commit(): |
|
210 | 212 | jinja_env = config.get_jinja2_environment() |
|
211 | 213 | jinja_env.filters['tojson'] = json.dumps |
|
212 | 214 | jinja_env.filters['toJSONUnsafe'] = jinja2_filters.toJSONUnsafe |
|
213 | 215 | |
|
214 | 216 | config.action(None, pre_commit, order=PHASE3_CONFIG + 999) |
|
215 | 217 | |
|
216 | 218 | def wrap_config_celery(): |
|
217 | 219 | configure_celery(config.registry) |
|
218 | 220 | |
|
219 | 221 | config.action(None, wrap_config_celery, order=PHASE3_CONFIG + 999) |
|
220 | 222 | |
|
221 | 223 | app = config.make_wsgi_app() |
|
222 | 224 | return app |
General Comments 0
You need to be logged in to leave comments.
Login now