Show More
@@ -1,69 +1,74 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2016-2016 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 logging |
|
22 | 22 | import os |
|
23 | 23 | |
|
24 | 24 | from rhodecode import events |
|
25 | 25 | from rhodecode.lib.utils2 import str2bool |
|
26 | 26 | from rhodecode.svn_support.subscribers import generate_mod_dav_svn_config |
|
27 | 27 | from rhodecode.svn_support import keys |
|
28 | 28 | |
|
29 | 29 | |
|
30 | 30 | log = logging.getLogger(__name__) |
|
31 | 31 | |
|
32 | 32 | |
|
33 | 33 | def includeme(config): |
|
34 | 34 | settings = config.registry.settings |
|
35 | 35 | _sanitize_settings_and_apply_defaults(settings) |
|
36 | 36 | |
|
37 | 37 | if settings[keys.generate_config]: |
|
38 | log.error('Add subscriber') | |
|
39 | 38 | config.add_subscriber( |
|
40 | 39 | generate_mod_dav_svn_config, events.RepoGroupEvent) |
|
41 | 40 | |
|
42 | 41 | |
|
43 | 42 | def _sanitize_settings_and_apply_defaults(settings): |
|
43 | """ | |
|
44 | Set defaults, convert to python types and validate settings. | |
|
45 | """ | |
|
44 | 46 | # Convert bool settings from string to bool. |
|
45 | 47 | settings[keys.generate_config] = str2bool( |
|
46 | 48 | settings.get(keys.generate_config, 'false')) |
|
47 | 49 | settings[keys.list_parent_path] = str2bool( |
|
48 | 50 | settings.get(keys.list_parent_path, 'true')) |
|
49 | 51 | |
|
50 | 52 | # Set defaults if key not present. |
|
51 | 53 | settings.setdefault(keys.config_file_path, None) |
|
52 | 54 | settings.setdefault(keys.location_root, '/') |
|
53 | 55 | settings.setdefault(keys.parent_path_root, None) |
|
54 | 56 | |
|
55 | 57 | # Append path separator to paths. |
|
56 |
settings[keys.location_root] = _append_ |
|
|
58 | settings[keys.location_root] = _append_path_sep( | |
|
57 | 59 | settings[keys.location_root]) |
|
58 |
settings[keys.parent_path_root] = _append_ |
|
|
60 | settings[keys.parent_path_root] = _append_path_sep( | |
|
59 | 61 | settings[keys.parent_path_root]) |
|
60 | 62 | |
|
61 | 63 | # Validate settings. |
|
62 | 64 | if settings[keys.generate_config]: |
|
63 | 65 | assert settings[keys.config_file_path] is not None |
|
64 | 66 | |
|
65 | 67 | |
|
66 |
def _append_ |
|
|
68 | def _append_path_sep(path): | |
|
69 | """ | |
|
70 | Append the path separator if missing. | |
|
71 | """ | |
|
67 | 72 | if isinstance(path, basestring) and not path.endswith(os.path.sep): |
|
68 | 73 | path += os.path.sep |
|
69 | 74 | return path |
@@ -1,27 +1,28 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2016-2016 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 | |
|
22 | # Settings keys used in the ini file. | |
|
22 | # Definition of setting keys used to configure this module. Defined here to | |
|
23 | # avoid repetition of keys throughout the module. | |
|
23 | 24 | config_file_path = 'svn.proxy.config_file_path' |
|
24 | 25 | generate_config = 'svn.proxy.generate_config' |
|
25 | 26 | list_parent_path = 'svn.proxy.list_parent_path' |
|
26 | 27 | location_root = 'svn.proxy.location_root' |
|
27 | 28 | parent_path_root = 'svn.proxy.parent_path_root' |
@@ -1,56 +1,70 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2016-2016 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 | |
|
22 | 22 | import logging |
|
23 | 23 | |
|
24 | 24 | from pyramid.renderers import render |
|
25 | 25 | |
|
26 | 26 | from rhodecode.model.db import RepoGroup |
|
27 | 27 | from rhodecode.svn_support import keys |
|
28 | 28 | |
|
29 | 29 | |
|
30 | 30 | log = logging.getLogger(__name__) |
|
31 | 31 | |
|
32 | 32 | |
|
33 | 33 | def generate_mod_dav_svn_config(event): |
|
34 | _generate(event.request) | |
|
34 | """ | |
|
35 | Subscriber to the `rhodcode.events.RepoGroupEvent`. This triggers the | |
|
36 | automatic generation of mod_dav_svn config file on repository group | |
|
37 | changes. | |
|
38 | """ | |
|
39 | _generate(event.request.registry.settings) | |
|
35 | 40 | |
|
36 | 41 | |
|
37 |
def _generate( |
|
|
38 | settings = request.registry.settings | |
|
42 | def _generate(settings): | |
|
43 | """ | |
|
44 | Generate the configuration file for use with subversion's mod_dav_svn | |
|
45 | module. The configuration has to contain a <Location> block for each | |
|
46 | available repository group because the mod_dav_svn module does not support | |
|
47 | repositories organized in sub folders. | |
|
48 | ||
|
49 | Currently this is only used by the subscriber above. If we extend this | |
|
50 | to include it as API method and in the web interface this should be moved | |
|
51 | to an appropriate place. | |
|
52 | """ | |
|
39 | 53 | filepath = settings[keys.config_file_path] |
|
40 | 54 | repository_root = settings[keys.parent_path_root] |
|
41 | 55 | list_parent_path = settings[keys.list_parent_path] |
|
42 | 56 | location_root = settings[keys.location_root] |
|
43 | 57 | |
|
44 | 58 | # Render the configuration to string. |
|
45 | 59 | template = 'rhodecode:svn_support/templates/mod-dav-svn.conf.mako' |
|
46 | 60 | context = { |
|
47 | 61 | 'location_root': location_root, |
|
48 | 62 | 'repository_root': repository_root, |
|
49 | 63 | 'repo_groups': RepoGroup.get_all_repo_groups(), |
|
50 | 64 | 'svn_list_parent_path': list_parent_path, |
|
51 | 65 | } |
|
52 | 66 | mod_dav_svn_config = render(template, context) |
|
53 | 67 | |
|
54 | 68 | # Write configuration to file. |
|
55 | 69 | with open(filepath, 'w') as file_: |
|
56 | 70 | file_.write(mod_dav_svn_config) |
@@ -1,20 +1,28 b'' | |||
|
1 | # This file is auto generated by RhodeCode. It contains the configuration for | |
|
2 | # use with mod_dav_svn. | |
|
1 | # Auto generated configuration for use with the Apache mod_dav_svn module. | |
|
2 | ||
|
3 | # The mod_dav_svn module does not support subversion repositories which are | |
|
4 | # organized in subfolders. To support the repository groups of RhodeCode it is | |
|
5 | # required to provide a <Location> block for each group pointing to the | |
|
6 | # repository group sub folder. | |
|
7 | ||
|
8 | # To ease the configuration RhodeCode auto generates this file whenever a | |
|
9 | # repository group is created/changed/deleted. Auto generation can be configured | |
|
10 | # in the ini file. | |
|
3 | 11 | |
|
4 | 12 | <Location ${location_root}> |
|
5 | 13 | DAV svn |
|
6 | 14 | SVNParentPath ${parent_path_root} |
|
7 | 15 | SVNListParentPath ${'On' if svn_list_parent_path else 'Off'} |
|
8 | 16 | Allow from all |
|
9 | 17 | Order allow,deny |
|
10 | 18 | </Location> |
|
11 | 19 | |
|
12 | 20 | % for repo_group in repo_groups: |
|
13 | 21 | <Location ${location_root}${repo_group.full_path}> |
|
14 | 22 | DAV svn |
|
15 | 23 | SVNParentPath ${parent_path_root}${repo_group.full_path} |
|
16 | 24 | SVNListParentPath ${'On' if svn_list_parent_path else 'Off'} |
|
17 | 25 | Allow from all |
|
18 | 26 | Order allow,deny |
|
19 | 27 | </Location> |
|
20 | 28 | % endfor |
General Comments 0
You need to be logged in to leave comments.
Login now