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