Exemplo n.º 1
0
def set_export_ok(config):
    global_enable = util.getConfigDefaultBoolean(config, 'defaults', 'daemon', False)
    log.debug(
        'Global default is %r',
        {True: 'allow', False: 'deny'}.get(global_enable),
        )

    enable_if_all = util.getConfigDefaultBoolean(config, 'defaults', 'daemon-if-all', False)
    if enable_if_all:
        access_table = access.getAccessTable(config)
    log.debug(
        'If accessible to @all: %r',
        {True: 'allow', False: 'unchanged'}.get(enable_if_all),
        )

    for (dirpath, repo, name) in walk_repos(config):
        try:
            enable = config.getboolean('repo %s' % name, 'daemon')
        except (NoSectionError, NoOptionError):
            enable = global_enable
            if not enable and enable_if_all:
                (users,groups,all_refs) = access.getAllAccess(config,access_table,name)
                enable = ('@all' in all_refs)

        if enable:
            log.debug('Allow %r', name)
            allow_export(os.path.join(dirpath, repo))
        else:
            log.debug('Deny %r', name)
            deny_export(os.path.join(dirpath, repo))
Exemplo n.º 2
0
def gen_htaccess(config):
    table = access.getAccessTable(config)

    for (dirpath, repo, name) in gitdaemon.walk_repos(config):
        (users, groups, all_refs) = access.getAllAccess(config,table,name)

        if '@all' in all_refs:
            log.debug('Allow all for %r', name)
            remove_htaccess(os.path.join(dirpath, repo))
        else:
            write_htaccess(os.path.join(dirpath, repo), users, groups)
Exemplo n.º 3
0
def test_list_all():
    cfg = RawConfigParser()
    cfg.add_section('group fooers')
    cfg.set('group fooers', 'members', 'jdoe')
    cfg.set('group fooers', 'map writable foo/bar', 'baz/quux/thud')
    cfg.add_section('group mooers')
    cfg.set('group mooers', 'members', '@fooers')
    cfg.set('group mooers', 'readonly', 'baz/quux/thud')
    table = access.getAccessTable(cfg)
    (users, groups, all_refs) = access.getAllAccess(cfg,table,'baz/quux/thud',['readonly'])
    eq(sorted(users), [])
    eq(sorted(groups), ['mooers'])
    eq(sorted(all_refs), ['@fooers','@mooers','jdoe'])
Exemplo n.º 4
0
def test_list_map():
    cfg = RawConfigParser()
    cfg.add_section('group fooers')
    cfg.set('group fooers', 'members', 'jdoe')
    cfg.set('group fooers', 'map writable foo/bar', 'baz/quux/thud')
    cfg.add_section('group mooers')
    cfg.set('group mooers', 'readonly', 'baz/quux/thud')
    table = access.getAccessTable(cfg)
    users = set()
    groups = set()
    access.listAccess(cfg,table,'writable','baz/quux/thud',users,groups)
    eq(sorted(groups), ['fooers'])
    eq(sorted(users), [])
Exemplo n.º 5
0
def test_list_read():
    cfg = RawConfigParser()
    cfg.add_section('gitosis')
    cfg.set('gitosis', 'owner-readonly', 'yes')
    cfg.add_section('group fooers')
    cfg.set('group fooers', 'members', 'jdoe')
    cfg.set('group fooers', 'map writable foo/bar', 'baz/quux/thud')
    cfg.add_section('group mooers')
    cfg.set('group mooers', 'readonly', 'baz/quux/thud')
    cfg.add_section('user jdoe')
    cfg.set('user jdoe', 'readonly', 'baz/quux/thud')
    cfg.add_section('user master')
    cfg.add_section('user admin')
    cfg.set('user admin', 'allow-read-all', 'yes')
    cfg.add_section('repo baz/quux/thud')
    cfg.set('repo baz/quux/thud', 'owner', 'master')
    table = access.getAccessTable(cfg)
    users = set()
    groups = set()
    access.listAccess(cfg,table,'readonly','baz/quux/thud',users,groups)
    eq(sorted(groups), ['mooers'])
    eq(sorted(users), ['admin','jdoe','master'])