Add config option `repositories`, for giving a path prefix to repositories.

Both global and relative (to home directory) values work, can be given
in global section ``[gitosis]`` or in the ``[group FOO]`` section for
just that group.
This commit is contained in:
Tommi Virtanen 2007-06-04 14:22:54 +03:00
parent c578b212c0
commit 7b99ae7583
3 changed files with 88 additions and 18 deletions

View file

@ -1,5 +1,5 @@
# TODO commented sections not done yet [gitosis]
# [gitosis] repositories = repo
[group quux] [group quux]
members = jdoe wsmith @anothergroup members = jdoe wsmith @anothergroup

View file

@ -1,4 +1,4 @@
import logging import os, logging
from ConfigParser import NoSectionError, NoOptionError from ConfigParser import NoSectionError, NoOptionError
from gitosis import group from gitosis import group
@ -31,6 +31,8 @@ def haveAccess(config, user, mode, path):
else: else:
repos = repos.split() repos = repos.split()
mapping = None
if path in repos: if path in repos:
log.debug( log.debug(
'Access ok for %(user)r as %(mode)r on %(path)r' 'Access ok for %(user)r as %(mode)r on %(path)r'
@ -39,20 +41,45 @@ def haveAccess(config, user, mode, path):
mode=mode, mode=mode,
path=path, path=path,
)) ))
return path mapping = path
try:
mapping = config.get('group %s' % groupname,
'map %s %s' % (mode, path))
except (NoSectionError, NoOptionError):
pass
else: else:
log.debug( try:
'Access ok for %(user)r as %(mode)r on %(path)r=%(mapping)r' mapping = config.get('group %s' % groupname,
% dict( 'map %s %s' % (mode, path))
user=user, except (NoSectionError, NoOptionError):
mode=mode, pass
path=path, else:
mapping=mapping, log.debug(
)) 'Access ok for %(user)r as %(mode)r on %(path)r=%(mapping)r'
% dict(
user=user,
mode=mode,
path=path,
mapping=mapping,
))
if mapping is not None:
prefix = None
try:
prefix = config.get(
'group %s' % groupname, 'repositories')
except (NoSectionError, NoOptionError):
try:
prefix = config.get('gitosis', 'repositories')
except (NoSectionError, NoOptionError):
pass
if prefix is not None:
log.debug(
'Using prefix %(prefix)r for %(path)r'
% dict(
prefix=prefix,
path=mapping,
))
mapping = os.path.join(prefix, mapping)
log.debug(
'New path is %(path)r'
% dict(
path=mapping,
))
return mapping return mapping

View file

@ -77,3 +77,46 @@ def test_read_yes_map_wouldHaveWritable():
cfg.set('group fooers', 'map writable foo/bar', 'quux/thud') cfg.set('group fooers', 'map writable foo/bar', 'quux/thud')
eq(access.haveAccess(config=cfg, user='jdoe', mode='readonly', path='foo/bar'), eq(access.haveAccess(config=cfg, user='jdoe', mode='readonly', path='foo/bar'),
None) None)
def test_base_global_absolute():
cfg = RawConfigParser()
cfg.add_section('gitosis')
cfg.set('gitosis', 'repositories', '/a/leading/path')
cfg.add_section('group fooers')
cfg.set('group fooers', 'members', 'jdoe')
cfg.set('group fooers', 'map writable foo/bar', 'baz/quux/thud')
eq(access.haveAccess(
config=cfg, user='jdoe', mode='writable', path='foo/bar'),
'/a/leading/path/baz/quux/thud')
def test_base_global_relative():
cfg = RawConfigParser()
cfg.add_section('gitosis')
cfg.set('gitosis', 'repositories', 'some/relative/path')
cfg.add_section('group fooers')
cfg.set('group fooers', 'members', 'jdoe')
cfg.set('group fooers', 'map writable foo/bar', 'baz/quux/thud')
eq(access.haveAccess(
config=cfg, user='jdoe', mode='writable', path='foo/bar'),
'some/relative/path/baz/quux/thud')
def test_base_global_relative_simple():
cfg = RawConfigParser()
cfg.add_section('gitosis')
cfg.set('gitosis', 'repositories', 'some/relative/path')
cfg.add_section('group fooers')
cfg.set('group fooers', 'members', 'jdoe')
cfg.set('group fooers', 'readonly', 'foo xyzzy bar')
eq(access.haveAccess(
config=cfg, user='jdoe', mode='readonly', path='xyzzy'),
'some/relative/path/xyzzy')
def test_base_local():
cfg = RawConfigParser()
cfg.add_section('group fooers')
cfg.set('group fooers', 'repositories', 'some/relative/path')
cfg.set('group fooers', 'members', 'jdoe')
cfg.set('group fooers', 'map writable foo/bar', 'baz/quux/thud')
eq(access.haveAccess(
config=cfg, user='jdoe', mode='writable', path='foo/bar'),
'some/relative/path/baz/quux/thud')