##// END OF EJS Templates
svn: expose file path for generated config.
marcink -
r4337:8e74dd85 default
parent child Browse files
Show More
@@ -1,59 +1,59 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2016-2020 RhodeCode GmbH
3 # Copyright (C) 2016-2020 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 logging
21 import logging
22
22
23 from pyramid.view import view_config
23 from pyramid.view import view_config
24
24
25 from rhodecode.apps._base import BaseAppView
25 from rhodecode.apps._base import BaseAppView
26 from rhodecode.apps.svn_support.utils import generate_mod_dav_svn_config
26 from rhodecode.apps.svn_support.utils import generate_mod_dav_svn_config
27 from rhodecode.lib.auth import (
27 from rhodecode.lib.auth import (
28 LoginRequired, HasPermissionAllDecorator, CSRFRequired)
28 LoginRequired, HasPermissionAllDecorator, CSRFRequired)
29
29
30 log = logging.getLogger(__name__)
30 log = logging.getLogger(__name__)
31
31
32
32
33 class SvnConfigAdminSettingsView(BaseAppView):
33 class SvnConfigAdminSettingsView(BaseAppView):
34
34
35 @LoginRequired()
35 @LoginRequired()
36 @HasPermissionAllDecorator('hg.admin')
36 @HasPermissionAllDecorator('hg.admin')
37 @CSRFRequired()
37 @CSRFRequired()
38 @view_config(
38 @view_config(
39 route_name='admin_settings_vcs_svn_generate_cfg',
39 route_name='admin_settings_vcs_svn_generate_cfg',
40 request_method='POST', renderer='json')
40 request_method='POST', renderer='json')
41 def vcs_svn_generate_config(self):
41 def vcs_svn_generate_config(self):
42 _ = self.request.translate
42 _ = self.request.translate
43 try:
43 try:
44 generate_mod_dav_svn_config(self.request.registry)
44 file_path = generate_mod_dav_svn_config(self.request.registry)
45 msg = {
45 msg = {
46 'message': _('Apache configuration for Subversion generated.'),
46 'message': _('Apache configuration for Subversion generated at `{}`.').format(file_path),
47 'level': 'success',
47 'level': 'success',
48 }
48 }
49 except Exception:
49 except Exception:
50 log.exception(
50 log.exception(
51 'Exception while generating the Apache '
51 'Exception while generating the Apache '
52 'configuration for Subversion.')
52 'configuration for Subversion.')
53 msg = {
53 msg = {
54 'message': _('Failed to generate the Apache configuration for Subversion.'),
54 'message': _('Failed to generate the Apache configuration for Subversion.'),
55 'level': 'error',
55 'level': 'error',
56 }
56 }
57
57
58 data = {'message': msg}
58 data = {'message': msg}
59 return data
59 return data
@@ -1,97 +1,98 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2016-2020 RhodeCode GmbH
3 # Copyright (C) 2016-2020 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 codecs
21 import codecs
22 import logging
22 import logging
23 import os
23 import os
24 from pyramid.renderers import render
24 from pyramid.renderers import render
25
25
26 from rhodecode.events import trigger
26 from rhodecode.events import trigger
27 from rhodecode.lib.utils import get_rhodecode_realm, get_rhodecode_base_path
27 from rhodecode.lib.utils import get_rhodecode_realm, get_rhodecode_base_path
28 from rhodecode.lib.utils2 import str2bool
28 from rhodecode.lib.utils2 import str2bool
29 from rhodecode.model.db import RepoGroup
29 from rhodecode.model.db import RepoGroup
30
30
31 from . import config_keys
31 from . import config_keys
32 from .events import ModDavSvnConfigChange
32 from .events import ModDavSvnConfigChange
33
33
34
34
35 log = logging.getLogger(__name__)
35 log = logging.getLogger(__name__)
36
36
37
37
38 def write_mod_dav_svn_config(settings):
38 def write_mod_dav_svn_config(settings):
39 use_ssl = str2bool(settings['force_https'])
39 use_ssl = str2bool(settings['force_https'])
40
40 file_path = settings[config_keys.config_file_path]
41 config = _render_mod_dav_svn_config(
41 config = _render_mod_dav_svn_config(
42 use_ssl=use_ssl,
42 use_ssl=use_ssl,
43 parent_path_root=get_rhodecode_base_path(),
43 parent_path_root=get_rhodecode_base_path(),
44 list_parent_path=settings[config_keys.list_parent_path],
44 list_parent_path=settings[config_keys.list_parent_path],
45 location_root=settings[config_keys.location_root],
45 location_root=settings[config_keys.location_root],
46 repo_groups=RepoGroup.get_all_repo_groups(),
46 repo_groups=RepoGroup.get_all_repo_groups(),
47 realm=get_rhodecode_realm(), template=settings[config_keys.template])
47 realm=get_rhodecode_realm(), template=settings[config_keys.template])
48 _write_mod_dav_svn_config(config, settings[config_keys.config_file_path])
48 _write_mod_dav_svn_config(config, file_path)
49 return file_path
49
50
50
51
51 def generate_mod_dav_svn_config(registry):
52 def generate_mod_dav_svn_config(registry):
52 """
53 """
53 Generate the configuration file for use with subversion's mod_dav_svn
54 Generate the configuration file for use with subversion's mod_dav_svn
54 module. The configuration has to contain a <Location> block for each
55 module. The configuration has to contain a <Location> block for each
55 available repository group because the mod_dav_svn module does not support
56 available repository group because the mod_dav_svn module does not support
56 repositories organized in sub folders.
57 repositories organized in sub folders.
57 """
58 """
58 settings = registry.settings
59 settings = registry.settings
59 write_mod_dav_svn_config(settings)
60 file_path = write_mod_dav_svn_config(settings)
60
61
61 # Trigger an event on mod dav svn configuration change.
62 # Trigger an event on mod dav svn configuration change.
62 trigger(ModDavSvnConfigChange(), registry)
63 trigger(ModDavSvnConfigChange(), registry)
63
64 return file_path
64
65
65 def _render_mod_dav_svn_config(
66 def _render_mod_dav_svn_config(
66 parent_path_root, list_parent_path, location_root, repo_groups, realm,
67 parent_path_root, list_parent_path, location_root, repo_groups, realm,
67 use_ssl, template):
68 use_ssl, template):
68 """
69 """
69 Render mod_dav_svn configuration to string.
70 Render mod_dav_svn configuration to string.
70 """
71 """
71 repo_group_paths = []
72 repo_group_paths = []
72 for repo_group in repo_groups:
73 for repo_group in repo_groups:
73 group_path = repo_group.full_path_splitted
74 group_path = repo_group.full_path_splitted
74 location = os.path.join(location_root, *group_path)
75 location = os.path.join(location_root, *group_path)
75 parent_path = os.path.join(parent_path_root, *group_path)
76 parent_path = os.path.join(parent_path_root, *group_path)
76 repo_group_paths.append((location, parent_path))
77 repo_group_paths.append((location, parent_path))
77
78
78 context = {
79 context = {
79 'location_root': location_root,
80 'location_root': location_root,
80 'parent_path_root': parent_path_root,
81 'parent_path_root': parent_path_root,
81 'repo_group_paths': repo_group_paths,
82 'repo_group_paths': repo_group_paths,
82 'svn_list_parent_path': list_parent_path,
83 'svn_list_parent_path': list_parent_path,
83 'rhodecode_realm': realm,
84 'rhodecode_realm': realm,
84 'use_https': use_ssl,
85 'use_https': use_ssl,
85 }
86 }
86 template = template or \
87 template = template or \
87 'rhodecode:apps/svn_support/templates/mod-dav-svn.conf.mako'
88 'rhodecode:apps/svn_support/templates/mod-dav-svn.conf.mako'
88 # Render the configuration template to string.
89 # Render the configuration template to string.
89 return render(template, context)
90 return render(template, context)
90
91
91
92
92 def _write_mod_dav_svn_config(config, filepath):
93 def _write_mod_dav_svn_config(config, filepath):
93 """
94 """
94 Write mod_dav_svn config to file.
95 Write mod_dav_svn config to file.
95 """
96 """
96 with codecs.open(filepath, 'w', encoding='utf-8') as f:
97 with codecs.open(filepath, 'w', encoding='utf-8') as f:
97 f.write(config)
98 f.write(config)
General Comments 0
You need to be logged in to leave comments. Login now