- move the allowed_scms validation into the assert_allowed() method of the SCM class
- make use_common an attribute of the SCM class instead of a method parameter
This commit is contained in:
parent
5bb48bb2bb
commit
68510f93fe
2 changed files with 35 additions and 23 deletions
|
|
@ -1842,23 +1842,7 @@ class BuildSRPMFromSCMTask(BaseTaskHandler):
|
||||||
def handler(self,url):
|
def handler(self,url):
|
||||||
# will throw a BuildError if the url is invalid
|
# will throw a BuildError if the url is invalid
|
||||||
scm = SCM(url)
|
scm = SCM(url)
|
||||||
|
scm.assert_allowed(options.allowed_scms)
|
||||||
use_common = True
|
|
||||||
|
|
||||||
for allowed_scm in options.allowed_scms.split():
|
|
||||||
scm_tuple = allowed_scm.split(':')
|
|
||||||
if len(scm_tuple) in (2, 3):
|
|
||||||
if fnmatch(scm.host, scm_tuple[0]) and fnmatch(scm.repository, scm_tuple[1]):
|
|
||||||
# SCM host:repository is in the allowed list
|
|
||||||
# check if we specify a value for use_common
|
|
||||||
if len(scm_tuple) == 3:
|
|
||||||
if scm_tuple[2].lower() in ('false', 'no', '0'):
|
|
||||||
use_common = False
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
self.logger.warn('Ignoring incorrectly formatted SCM host:repository: %s' % allowed_scm)
|
|
||||||
else:
|
|
||||||
raise koji.BuildError, '%s:%s is not in the list of allowed SCMs' % (scm.host, scm.repository)
|
|
||||||
|
|
||||||
# Setup files and directories for SRPM creation
|
# Setup files and directories for SRPM creation
|
||||||
scmdir = self.workdir + '/scmroot'
|
scmdir = self.workdir + '/scmroot'
|
||||||
|
|
@ -1868,7 +1852,7 @@ class BuildSRPMFromSCMTask(BaseTaskHandler):
|
||||||
uploadpath = self.getUploadDir()
|
uploadpath = self.getUploadDir()
|
||||||
|
|
||||||
# Check out spec file, etc. from SCM
|
# Check out spec file, etc. from SCM
|
||||||
sourcedir = scm.checkout(scmdir, uploadpath, logfile, use_common=use_common)
|
sourcedir = scm.checkout(scmdir, uploadpath, logfile)
|
||||||
|
|
||||||
# Find and verify that there is only one spec file.
|
# Find and verify that there is only one spec file.
|
||||||
spec_files = glob.glob("%s/*.spec" % sourcedir)
|
spec_files = glob.glob("%s/*.spec" % sourcedir)
|
||||||
|
|
@ -2370,6 +2354,8 @@ class SCM(object):
|
||||||
- repository
|
- repository
|
||||||
- module
|
- module
|
||||||
- revision
|
- revision
|
||||||
|
- use_common (defaults to True, may be set by assert_allowed())
|
||||||
|
- scmtype
|
||||||
|
|
||||||
The exact format of each attribute is SCM-specific, but the structure of the url
|
The exact format of each attribute is SCM-specific, but the structure of the url
|
||||||
must conform to the template above, or an error will be raised.
|
must conform to the template above, or an error will be raised.
|
||||||
|
|
@ -2386,6 +2372,7 @@ class SCM(object):
|
||||||
self.repository = path
|
self.repository = path
|
||||||
self.module = query
|
self.module = query
|
||||||
self.revision = fragment
|
self.revision = fragment
|
||||||
|
self.use_common = True
|
||||||
|
|
||||||
for scmtype, schemes in SCM.types.items():
|
for scmtype, schemes in SCM.types.items():
|
||||||
if self.scheme in schemes:
|
if self.scheme in schemes:
|
||||||
|
|
@ -2437,15 +2424,40 @@ class SCM(object):
|
||||||
# return parsed values
|
# return parsed values
|
||||||
return (scheme, user, netloc, path, query, fragment)
|
return (scheme, user, netloc, path, query, fragment)
|
||||||
|
|
||||||
def checkout(self, scmdir, uploadpath, logfile, use_common=False):
|
def assert_allowed(self, allowed):
|
||||||
|
"""
|
||||||
|
Verify that the host and repository of this SCM is in the provided list of
|
||||||
|
allowed repositories.
|
||||||
|
|
||||||
|
allowed is a space-separated list of host:repository[:use_common] tuples. Incorrectly-formatted
|
||||||
|
tuples will be ignored.
|
||||||
|
|
||||||
|
If use_common is not present, kojid will attempt to checkout a common/ directory from the
|
||||||
|
repository. If use_common is set to no, off, false, or 0, it will not attempt to checkout a common/
|
||||||
|
directory.
|
||||||
|
"""
|
||||||
|
for allowed_scm in options.allowed_scms.split():
|
||||||
|
scm_tuple = allowed_scm.split(':')
|
||||||
|
if len(scm_tuple) in (2, 3):
|
||||||
|
if fnmatch(self.host, scm_tuple[0]) and fnmatch(self.repository, scm_tuple[1]):
|
||||||
|
# SCM host:repository is in the allowed list
|
||||||
|
# check if we specify a value for use_common
|
||||||
|
if len(scm_tuple) == 3:
|
||||||
|
if scm_tuple[2].lower() in ('no', 'off', 'false', '0'):
|
||||||
|
self.use_common = False
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
self.logger.warn('Ignoring incorrectly formatted SCM host:repository: %s' % allowed_scm)
|
||||||
|
else:
|
||||||
|
raise koji.BuildError, '%s:%s is not in the list of allowed SCMs' % (self.host, self.repository)
|
||||||
|
|
||||||
|
def checkout(self, scmdir, uploadpath, logfile):
|
||||||
"""
|
"""
|
||||||
Checkout the module from SCM. Accepts the following parameters:
|
Checkout the module from SCM. Accepts the following parameters:
|
||||||
|
|
||||||
- scmdir: the working directory
|
- scmdir: the working directory
|
||||||
- uploadpath: the path on the server the logfile should be uploaded to
|
- uploadpath: the path on the server the logfile should be uploaded to
|
||||||
- logfile: the file used for logging command output
|
- logfile: the file used for logging command output
|
||||||
- use_common: if True, also checkout a "common" module from the top-level of the repository
|
|
||||||
and symlink it into the parent directory of the module checkout
|
|
||||||
|
|
||||||
Returns the directory that the module was checked-out into (a subdirectory of scmdir)
|
Returns the directory that the module was checked-out into (a subdirectory of scmdir)
|
||||||
"""
|
"""
|
||||||
|
|
@ -2546,7 +2558,7 @@ class SCM(object):
|
||||||
raise koji.BuildError, 'Error running %s update command "%s", see %s for details' % \
|
raise koji.BuildError, 'Error running %s update command "%s", see %s for details' % \
|
||||||
(self.scmtype, ' '.join(update_checkout_cmd), os.path.basename(logfile))
|
(self.scmtype, ' '.join(update_checkout_cmd), os.path.basename(logfile))
|
||||||
|
|
||||||
if use_common:
|
if self.use_common:
|
||||||
if log_output(common_checkout_cmd[0], common_checkout_cmd, logfile, uploadpath, cwd=scmdir, logerror=1, append=1, env=env):
|
if log_output(common_checkout_cmd[0], common_checkout_cmd, logfile, uploadpath, cwd=scmdir, logerror=1, append=1, env=env):
|
||||||
raise koji.BuildError, 'Error running %s checkout command "%s", see %s for details' % \
|
raise koji.BuildError, 'Error running %s checkout command "%s", see %s for details' % \
|
||||||
(self.scmtype, ' '.join(common_checkout_cmd), os.path.basename(logfile))
|
(self.scmtype, ' '.join(common_checkout_cmd), os.path.basename(logfile))
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ pkgurl=http://hub.example.com/packages
|
||||||
|
|
||||||
; A space-separated list of hostname:repository[:use_common] tuples that kojid is authorized to checkout from (no quotes).
|
; A space-separated list of hostname:repository[:use_common] tuples that kojid is authorized to checkout from (no quotes).
|
||||||
; Wildcards (as supported by fnmatch) are allowed.
|
; Wildcards (as supported by fnmatch) are allowed.
|
||||||
; If use_common is specified and is one of "false", "no", or "0" (without quotes), then kojid will not attempt to checkout
|
; If use_common is specified and is one of "false", "no", "off", or "0" (without quotes), then kojid will not attempt to checkout
|
||||||
; a common/ dir when checking out sources from the source control system. Otherwise, it will attempt to checkout a common/
|
; a common/ dir when checking out sources from the source control system. Otherwise, it will attempt to checkout a common/
|
||||||
; dir, and will raise an exception if it cannot.
|
; dir, and will raise an exception if it cannot.
|
||||||
allowed_scms=scm.example.com:/cvs/example git.example.org:/example svn.example.org:/users/*:no
|
allowed_scms=scm.example.com:/cvs/example git.example.org:/example svn.example.org:/users/*:no
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue