Show More
@@ -1,90 +1,96 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2010-2017 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | import os |
|
22 | 22 | |
|
23 | from pyramid.events import ApplicationCreated | |
|
23 | 24 | from pyramid.settings import asbool |
|
24 | 25 | |
|
25 | 26 | from rhodecode.config.routing import ADMIN_PREFIX |
|
26 | 27 | from rhodecode.lib.ext_json import json |
|
27 | 28 | |
|
28 | 29 | |
|
29 | 30 | def url_gen(request): |
|
30 | 31 | registry = request.registry |
|
31 | 32 | longpoll_url = registry.settings.get('channelstream.longpoll_url', '') |
|
32 | 33 | ws_url = registry.settings.get('channelstream.ws_url', '') |
|
33 | 34 | proxy_url = request.route_url('channelstream_proxy') |
|
34 | 35 | urls = { |
|
35 | 36 | 'connect': request.route_path('channelstream_connect'), |
|
36 | 37 | 'subscribe': request.route_path('channelstream_subscribe'), |
|
37 | 38 | 'longpoll': longpoll_url or proxy_url, |
|
38 | 39 | 'ws': ws_url or proxy_url.replace('http', 'ws') |
|
39 | 40 | } |
|
40 | 41 | return json.dumps(urls) |
|
41 | 42 | |
|
42 | 43 | |
|
43 | 44 | PLUGIN_DEFINITION = { |
|
44 | 45 | 'name': 'channelstream', |
|
45 | 46 | 'config': { |
|
46 | 47 | 'javascript': [], |
|
47 | 48 | 'css': [], |
|
48 | 49 | 'template_hooks': { |
|
49 | 50 | 'plugin_init_template': 'rhodecode:templates/channelstream/plugin_init.mako' |
|
50 | 51 | }, |
|
51 | 52 | 'url_gen': url_gen, |
|
52 | 53 | 'static': None, |
|
53 | 54 | 'enabled': False, |
|
54 | 55 | 'server': '', |
|
55 | 56 | 'secret': '' |
|
56 | 57 | } |
|
57 | 58 | } |
|
58 | 59 | |
|
59 | 60 | |
|
61 | def maybe_create_history_store(event): | |
|
62 | # create plugin history location | |
|
63 | settings = event.app.registry.settings | |
|
64 | history_dir = settings.get('channelstream.history.location', '') | |
|
65 | if history_dir and not os.path.exists(history_dir): | |
|
66 | os.makedirs(history_dir, 0750) | |
|
67 | ||
|
68 | ||
|
60 | 69 | def includeme(config): |
|
61 | 70 | settings = config.registry.settings |
|
62 | 71 | PLUGIN_DEFINITION['config']['enabled'] = asbool( |
|
63 | 72 | settings.get('channelstream.enabled')) |
|
64 | 73 | PLUGIN_DEFINITION['config']['server'] = settings.get( |
|
65 | 74 | 'channelstream.server', '') |
|
66 | 75 | PLUGIN_DEFINITION['config']['secret'] = settings.get( |
|
67 | 76 | 'channelstream.secret', '') |
|
68 | 77 | PLUGIN_DEFINITION['config']['history.location'] = settings.get( |
|
69 | 78 | 'channelstream.history.location', '') |
|
70 | 79 | config.register_rhodecode_plugin( |
|
71 | 80 | PLUGIN_DEFINITION['name'], |
|
72 | 81 | PLUGIN_DEFINITION['config'] |
|
73 | 82 | ) |
|
74 | # create plugin history location | |
|
75 | history_dir = PLUGIN_DEFINITION['config']['history.location'] | |
|
76 | if history_dir and not os.path.exists(history_dir): | |
|
77 | os.makedirs(history_dir, 0750) | |
|
83 | config.add_subscriber(maybe_create_history_store, ApplicationCreated) | |
|
78 | 84 | |
|
79 | 85 | config.add_route( |
|
80 | 86 | name='channelstream_connect', |
|
81 | 87 | pattern=ADMIN_PREFIX + '/channelstream/connect') |
|
82 | 88 | config.add_route( |
|
83 | 89 | name='channelstream_subscribe', |
|
84 | 90 | pattern=ADMIN_PREFIX + '/channelstream/subscribe') |
|
85 | 91 | config.add_route( |
|
86 | 92 | name='channelstream_proxy', |
|
87 | 93 | pattern=settings.get('channelstream.proxy_path') or '/_channelstream') |
|
88 | 94 | |
|
89 | 95 | # Scan module for configuration decorators. |
|
90 | 96 | config.scan('.views', ignore='.tests') |
General Comments 0
You need to be logged in to leave comments.
Login now