def test_getExplicitRepoNames(): cfg = RawConfigParser() cfg.add_section('gitosis') cfg.set('gitosis', 'foo', 'bar baz') repos = list(util.getExplicitRepositoryNames(cfg, ['@foo', 'foo'])) ok('bar' in repos) ok('baz' in repos) ok('foo' in repos) eq(3, len(repos))
def get_mirror_sections(config): """ Get the list of all mirror sections. Return a list of uri and repositories set in each section @param config: ConfigParser object @return generator """ log = logging.getLogger('gitosis.mirror.get_mirror_sections') mirror_sections = (s for s in config.sections() if s.startswith('mirror ')) for section in mirror_sections: try: uri = config.get(section, 'uri').strip() repos = config.get(section, 'repos').split() yield uri, util.getExplicitRepositoryNames(config, repos) except NoOptionError: log.error('%s section is lacking the "repos" or "uri" settings.', section)
def haveAccess(config, user, mode, path): """ Map request for write access to allowed path. Note for read-only access, the caller should check for write access too. Returns ``None`` for no access, or a tuple of toplevel directory containing repositories and a relative path to the physical repository. """ log = logging.getLogger('gitosis.access.haveAccess') log.debug( 'Access check for %(user)r as %(mode)r on %(path)r...' % dict( user=user, mode=mode, path=path, )) basename, ext = os.path.splitext(path) if ext == '.git': log.debug( 'Stripping .git suffix from %(path)r, new value %(basename)r' % dict( path=path, basename=basename, )) path = basename for groupname in group.getMembership(config=config, user=user): try: repos = config.get('group %s' % groupname, mode) except (NoSectionError, NoOptionError): repos = [] else: repos = util.getExplicitRepositoryNames(config, repos.split()) mapping = None if path in repos: log.debug( 'Access ok for %(user)r as %(mode)r on %(path)r' % dict( user=user, mode=mode, path=path, )) mapping = path else: try: mapping = config.get('group %s' % groupname, 'map %s %s' % (mode, path)) except (NoSectionError, NoOptionError): pass else: 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): prefix = 'repositories' log.debug( 'Using prefix %(prefix)r for %(path)r' % dict( prefix=prefix, path=mapping, )) return (prefix, mapping)