svn: allow specifying alternative template file for mod_dav config.

This commit is contained in:
Marcin Kuzminski 2017-10-10 09:30:22 +02:00
parent c66d2e978e
commit cbcd579b02
7 changed files with 35 additions and 10 deletions

View file

@ -587,6 +587,8 @@ svn.proxy.generate_config = false
svn.proxy.list_parent_path = true
## Set location and file name of generated config file.
svn.proxy.config_file_path = %(here)s/mod_dav_svn.conf
## alternative mod_dav config template. This needs to be a mako template
#svn.proxy.config_template = ~/.rccontrol/enterprise-1/custom_svn_conf.mako
## Used as a prefix to the `Location` block in the generated config file.
## In most cases it should be set to `/`.
svn.proxy.location_root = /

View file

@ -556,6 +556,8 @@ svn.proxy.generate_config = false
svn.proxy.list_parent_path = true
## Set location and file name of generated config file.
svn.proxy.config_file_path = %(here)s/mod_dav_svn.conf
## alternative mod_dav config template. This needs to be a mako template
#svn.proxy.config_template = ~/.rccontrol/enterprise-1/custom_svn_conf.mako
## Used as a prefix to the `Location` block in the generated config file.
## In most cases it should be set to `/`.
svn.proxy.location_root = /

View file

@ -66,6 +66,7 @@ def _sanitize_settings_and_apply_defaults(settings):
_string_setting(settings, config_keys.config_file_path, '', lower=False)
_string_setting(settings, config_keys.location_root, '/', lower=False)
_string_setting(settings, config_keys.reload_command, '', lower=False)
_string_setting(settings, config_keys.template, '', lower=False)
# Convert negative timeout values to zero.
if settings[config_keys.reload_timeout] < 0:

View file

@ -27,3 +27,4 @@ list_parent_path = 'svn.proxy.list_parent_path'
location_root = 'svn.proxy.location_root'
reload_command = 'svn.proxy.reload_cmd'
reload_timeout = 'svn.proxy.reload_timeout'
template = 'svn.proxy.config_template'

View file

@ -28,7 +28,7 @@
# </VirtualHost>
#
# Depending on the apache configuration you may encounter the following error if
# you are using speecial characters in your repository or repository group
# you are using special characters in your repository or repository group
# names.
#
# ``Error converting entry in directory '/path/to/repo' to UTF-8``

View file

@ -18,10 +18,10 @@
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
import re
import os
import mock
import pytest
import re
from pyramid import testing
@ -69,7 +69,8 @@ class TestModDavSvnConfig(object):
location_root=self.location_root,
repo_groups=repo_groups,
realm=self.realm,
use_ssl=True
use_ssl=True,
template=''
)
# Assert that one location directive exists for each repository group.
for group in repo_groups:
@ -79,6 +80,23 @@ class TestModDavSvnConfig(object):
# Assert that the root location directive exists.
self.assert_root_location_directive(generated_config)
def test_render_mod_dav_svn_config_with_alternative_template(self, tmpdir):
repo_groups = self.get_repo_group_mocks(count=10)
test_file_path = os.path.join(str(tmpdir), 'example.mako')
with open(test_file_path, 'wb') as f:
f.write('TEST_EXAMPLE\n')
generated_config = utils._render_mod_dav_svn_config(
parent_path_root=self.parent_path_root,
list_parent_path=True,
location_root=self.location_root,
repo_groups=repo_groups,
realm=self.realm,
use_ssl=True,
template=test_file_path
)
assert 'TEST_EXAMPLE' in generated_config
@pytest.mark.parametrize('list_parent_path', [True, False])
@pytest.mark.parametrize('use_ssl', [True, False])
def test_list_parent_path(self, list_parent_path, use_ssl):
@ -88,7 +106,8 @@ class TestModDavSvnConfig(object):
location_root=self.location_root,
repo_groups=self.get_repo_group_mocks(count=10),
realm=self.realm,
use_ssl=use_ssl
use_ssl=use_ssl,
template=''
)
# Assert that correct configuration directive is present.

View file

@ -51,7 +51,7 @@ def generate_mod_dav_svn_config(registry):
list_parent_path=settings[config_keys.list_parent_path],
location_root=settings[config_keys.location_root],
repo_groups=RepoGroup.get_all_repo_groups(),
realm=get_rhodecode_realm())
realm=get_rhodecode_realm(), template=settings[config_keys.template])
_write_mod_dav_svn_config(config, settings[config_keys.config_file_path])
# Trigger an event on mod dav svn configuration change.
@ -60,7 +60,7 @@ def generate_mod_dav_svn_config(registry):
def _render_mod_dav_svn_config(
parent_path_root, list_parent_path, location_root, repo_groups, realm,
use_ssl):
use_ssl, template):
"""
Render mod_dav_svn configuration to string.
"""
@ -77,11 +77,11 @@ def _render_mod_dav_svn_config(
'repo_group_paths': repo_group_paths,
'svn_list_parent_path': list_parent_path,
'rhodecode_realm': realm,
'use_https': use_ssl
'use_https': use_ssl,
}
template = template or \
'rhodecode:apps/svn_support/templates/mod-dav-svn.conf.mako'
# Render the configuration template to string.
template = 'rhodecode:apps/svn_support/templates/mod-dav-svn.conf.mako'
return render(template, context)