use scm_ as the prefix instead of scm for scminfo

This commit is contained in:
Yu Ming Zhu 2021-08-11 17:23:00 +00:00
parent f1ba3b0ec0
commit 601cd33902
3 changed files with 35 additions and 36 deletions

View file

@ -526,9 +526,9 @@ _default_policies = {
''',
'build_from_scm': '''
has_perm admin :: allow
# match scmtype CVS CVS+SSH && match scmhost scm.example.com && match scmrepository /cvs/example :: allow
# match scmtype GIT GIT+SSH && match scmhost git.example.org && match scmrepository /example :: allow
# match scmtype SVN SVN+SSH && match scmhost svn.example.org && match scmrepository /users/* :: allow
# match scm_type CVS CVS+SSH && match scm_host scm.example.com && match scm_repository /cvs/example :: allow
# match scm_type GIT GIT+SSH && match scm_host git.example.org && match scm_repository /example :: allow
# match scm_type SVN SVN+SSH && match scm_host svn.example.org && match scm_repository /users/* :: allow
all :: deny
''', # noqa: E501
'package_list': '''

View file

@ -26,6 +26,7 @@ import errno
import hashlib
import logging
import os
import re
import signal
import subprocess
import sys
@ -429,17 +430,17 @@ class SCM(object):
"""
Check this scm against hub policy: build_from_scm and apply options
The policy data is the combination of scminfo with scm prefix and kwargs.
The policy data is the combination of scminfo with scm_ prefix and kwargs.
It should at least contain following keys:
- scmurl
- scmscheme
- scmuser
- scmhost
- scmrepository
- scmmodule
- scmrevision
- scmtype
- scm_url
- scm_scheme
- scm_user
- scm_host
- scm_repository
- scm_module
- scm_revision
- scm_type
More keys could be added as kwargs(extra_data). You can pass any reasonable data which
could be handled by policy tests, like:
@ -465,8 +466,8 @@ class SCM(object):
build_from_scm =
bool scratch :: allow none
match scmhost scm.example.com :: allow use_common make sources
match scmhost scm2.example.com :: allow
match scm_host scm.example.com :: allow use_common make sources
match scm_host scm2.example.com :: allow
all :: deny
@ -477,9 +478,7 @@ class SCM(object):
"""
policy_data = {}
for k, v in six.iteritems(self.get_info()):
if not k.startswith('scm'):
k = 'scm' + k
policy_data[k] = v
policy_data[re.sub(r'^(scm_?)?', 'scm_', k)] = v
policy_data.update(extra_data)
result = (session.host.evalPolicy('build_from_scm', policy_data) or '').split()
is_allowed = result and result[0].lower() in ('yes', 'true', 'allow', 'allowed')

View file

@ -14,22 +14,22 @@ from koji.daemon import SCM
policy = {
'one': '''
match scmhost goodserver :: allow none
match scmhost badserver :: deny
match scmhost maybeserver && match scmrepository /badpath/* :: deny
match scm_host goodserver :: allow none
match scm_host badserver :: deny
match scm_host maybeserver && match scm_repository /badpath/* :: deny
all :: allow
''',
'two': '''
match scmhost default :: allow
match scmhost nocommon :: allow
match scmhost common :: allow use_common
match scmhost srccmd :: allow fedpkg sources
match scmhost nosrc :: allow none
match scmhost mixed && match scmrepository /foo/* :: allow
match scmhost mixed && match scmrepository /bar/* :: allow use_common
match scmhost mixed && match scmrepository /baz/* :: allow fedpkg sources
match scmhost mixed && match scmrepository /foobar/* :: allow use_common fedpkg sources
match scmhost mixed && match scmrepository /foobaz/* :: allow use_common none
match scm_host default :: allow
match scm_host nocommon :: allow
match scm_host common :: allow use_common
match scm_host srccmd :: allow fedpkg sources
match scm_host nosrc :: allow none
match scm_host mixed && match scm_repository /foo/* :: allow
match scm_host mixed && match scm_repository /bar/* :: allow use_common
match scm_host mixed && match scm_repository /baz/* :: allow fedpkg sources
match scm_host mixed && match scm_repository /foobar/* :: allow use_common fedpkg sources
match scm_host mixed && match scm_repository /foobaz/* :: allow use_common none
'''
}
@ -376,42 +376,42 @@ class TestSCM(unittest.TestCase):
url = "git://default/koji.git#1234"
scm = SCM(url)
# match scmhost default :: allow
# match scm_host default :: allow
scm.assert_allowed(allowed=config, session=session, by_config=True, by_policy=True)
self.assertEqual(scm.use_common, False)
self.assertIsNone(scm.source_cmd)
url = "git://mixed/foo/koji.git#1234"
scm = SCM(url)
# match scmhost mixed && match scmrepository /foo/* :: allow
# match scm_host mixed && match scm_repository /foo/* :: allow
scm.assert_allowed(allowed=config, session=session, by_config=True, by_policy=True)
self.assertEqual(scm.use_common, False)
self.assertEqual(scm.source_cmd, ['make', 'sources'])
url = "git://mixed/bar/koji.git#1234"
scm = SCM(url)
# match scmhost mixed && match scmrepository /bar/* :: allow use_common
# match scm_host mixed && match scm_repository /bar/* :: allow use_common
scm.assert_allowed(allowed=config, session=session, by_config=True, by_policy=True)
self.assertEqual(scm.use_common, True)
self.assertEqual(scm.source_cmd, ['make', 'sources'])
url = "git://mixed/baz/koji.git#1234"
scm = SCM(url)
# match scmhost mixed && match scmrepository /baz/* :: allow fedpkg sources
# match scm_host mixed && match scm_repository /baz/* :: allow fedpkg sources
scm.assert_allowed(allowed=config, session=session, by_config=True, by_policy=True)
self.assertEqual(scm.use_common, False)
self.assertEqual(scm.source_cmd, ['fedpkg', 'sources'])
url = "git://mixed/foobar/koji.git#1234"
scm = SCM(url)
# match scmhost mixed && match scmrepository /foobar/* :: allow use_common fedpkg sources
# match scm_host mixed && match scm_repository /foobar/* :: allow use_common fedpkg sources
scm.assert_allowed(allowed=config, session=session, by_config=True, by_policy=True)
self.assertEqual(scm.use_common, True)
self.assertEqual(scm.source_cmd, ['fedpkg', 'sources'])
url = "git://mixed/foobaz/koji.git#1234"
scm = SCM(url)
# match scmhost mixed && match scmrepository /foobaz/* :: allow use_common none
# match scm_host mixed && match scm_repository /foobaz/* :: allow use_common none
scm.assert_allowed(allowed=config, session=session, by_config=True, by_policy=True)
self.assertEqual(scm.use_common, True)
self.assertIsNone(scm.source_cmd)