#2 Query PDC to get the supported branches for gitolite.
Merged 7 years ago by pingou. Opened 7 years ago by ralph.

file modified
+41 -4
@@ -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)

:thumbsup: we'll need this for stg :)

+     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:

file modified
+20 -3
@@ -1,16 +1,21 @@ 

  from __future__ import print_function

+ 

  import tempfile

  import os

  

+ import mock

+ 

  # These are the tests from the pagure/ git repo.

  # Run with PYTHONPATH=.:/path/to/pagure/checkout nosetests dist_git_auth_tests.py

  import tests

  

- from dist_git_auth import DistGitoliteAuth

+ import dist_git_auth

  

  expected = """

  repo test

    R   = @all

+   RWC master = pingou

+   RWC f9000 = pingou

    -    f[0-9][0-9] = @all

    -    epel[0-9] = @all

    -    epel[0-9][0-9] = @all
@@ -23,6 +28,8 @@ 

  

  repo test2

    R   = @all

+   RWC master = pingou

+   RWC f9000 = pingou

    -    f[0-9][0-9] = @all

    -    epel[0-9] = @all

    -    epel[0-9][0-9] = @all
@@ -35,6 +42,8 @@ 

  

  repo somenamespace/test3

    R   = @all

+   RWC master = pingou

+   RWC f9000 = pingou

    -    f[0-9][0-9] = @all

    -    epel[0-9] = @all

    -    epel[0-9][0-9] = @all
@@ -63,12 +72,20 @@ 

              pass

          super(DistGitoliteAuthTestCase, self).tearDown()

  

-     def test_write_gitolite_acls(self):

+     @mock.patch('dist_git_auth.get_supported_branches')

+     def test_write_gitolite_acls(self, get_supported_branches):

+         get_supported_branches.return_value = ['master', 'f9000']

          print("Initializing DB.")

          tests.create_projects(self.session)

          print("Generating %r" % self.configfile)

-         DistGitoliteAuth.write_gitolite_acls(self.session, self.configfile)

+         dist_git_auth.DistGitoliteAuth.write_gitolite_acls(

+             self.session, self.configfile)

          print("Checking the contents of %r" % self.configfile)

          with open(self.configfile, 'r') as f:

              contents = f.read()

          self.assertMultiLineEqual(contents.strip(), expected.strip())

+ 

+     def test_get_supported_branches(self):

+         expected = ['master', 'f26', 'f25', 'f24', 'el6']

+         actual = dist_git_auth.get_supported_branches('rpms', 'nethack')

+         self.assertEquals(set(actual), set(expected))

no initial comment

Nice, looking good! :)

:thumbsup: we'll need this for stg :)

Pull-Request has been merged by pingou

7 years ago