| |
@@ -13,13 +13,14 @@
|
| |
import logging
|
| |
import os
|
| |
|
| |
+ import dogpile.cache
|
| |
+ import pdc_client
|
| |
import werkzeug
|
| |
|
| |
if 'PAGURE_CONFIG' not in os.environ \
|
| |
and os.path.exists('/etc/pagure/pagure.cfg'):
|
| |
os.environ['PAGURE_CONFIG'] = '/etc/pagure/pagure.cfg'
|
| |
|
| |
-
|
| |
import pagure # noqa: E402
|
| |
from pagure import APP # noqa: E402
|
| |
from pagure.lib import model # noqa: E402
|
| |
@@ -28,12 +29,38 @@
|
| |
logging.config.dictConfig(APP.config.get('LOGGING') or {'version': 1})
|
| |
_log = logging.getLogger(__name__)
|
| |
|
| |
+ cache = dogpile.cache.make_region().configure(
|
| |
+ 'dogpile.cache.memory',
|
| |
+ expiration_time=600,
|
| |
+ )
|
| |
+
|
| |
+
|
| |
_blacklist = ''' - f[0-9][0-9] = @all
|
| |
- epel[0-9] = @all
|
| |
- epel[0-9][0-9] = @all
|
| |
- el[0-9] = @all
|
| |
- olpc[0-9] = @all'''
|
| |
|
| |
+ namespace2pdctype = {
|
| |
+ 'rpms': 'rpm',
|
| |
+ 'modules': 'module',
|
| |
+ 'container': 'container',
|
| |
+ }
|
| |
+
|
| |
+ @cache.cache_on_arguments()
|
| |
+ def get_supported_branches(namespace, package):
|
| |
+ default_url = 'https://pdc.fedoraproject.org/rest_api/v1/'
|
| |
+ url = pagure.APP.config.get('PDC_URL', default_url)
|
| |
+ pdc = pdc_client.PDCClient(url, develop=True)
|
| |
+ kwargs = dict(
|
| |
+ global_component=package,
|
| |
+ type=namespace2pdctype[namespace],
|
| |
+ active=True, # Not EOL.
|
| |
+ )
|
| |
+ branches = pdc.get_paged(pdc['component-branches'], **kwargs)
|
| |
+ return [branch['name'] for branch in branches]
|
| |
+
|
| |
+
|
| |
class DistGitoliteAuth(Gitolite3Auth):
|
| |
""" A dist-git's gitolite authentication module. """
|
| |
|
| |
@@ -83,12 +110,21 @@
|
| |
if repos not in ['tickets/', 'requests/']:
|
| |
config.append(' R = @all')
|
| |
|
| |
- if repos == '':
|
| |
- config.append(_blacklist)
|
| |
-
|
| |
access = 'RWC'
|
| |
if project.is_fork:
|
| |
access = 'RW+'
|
| |
+
|
| |
+ if repos == '':
|
| |
+ # First, whitelist the supported branches from PDC
|
| |
+ for branch in get_supported_branches(project.namespace, project.name):
|
| |
+ config.append(' %s %s = %s' % (access, branch, project.user.user))
|
| |
+ for user in project.committers:
|
| |
+ if user != project.user:
|
| |
+ config.append(' %s = %s' % (access, branch, user.user))
|
| |
+
|
| |
+ # Then, blacklist a pattern over that (after).
|
| |
+ config.append(_blacklist)
|
| |
+
|
| |
if project.committer_groups:
|
| |
config.append(' %s+ = @%s' % (access, ' @'.join(
|
| |
[
|
| |
@@ -101,6 +137,7 @@
|
| |
for user in project.committers:
|
| |
if user != project.user:
|
| |
config.append(' %s = %s' % (access, user.user))
|
| |
+
|
| |
for deploykey in project.deploykeys:
|
| |
access = 'R'
|
| |
if deploykey.pushaccess:
|
| |
:thumbsup: we'll need this for stg :)