more reasonable parameter name, and more doc strs
This commit is contained in:
parent
47c4b5d70b
commit
a3f19e0f12
3 changed files with 38 additions and 15 deletions
|
|
@ -1643,7 +1643,7 @@ class BuildMavenTask(BaseBuildTask):
|
|||
session=self.session,
|
||||
by_config=self.options.allowed_scms_use_config,
|
||||
by_policy=self.options.allowed_scms_use_policy,
|
||||
opts=scm_policy_opts)
|
||||
policy_data=scm_policy_opts)
|
||||
repo_id = opts.get('repo_id')
|
||||
if not repo_id:
|
||||
raise koji.BuildError('A repo_id must be provided')
|
||||
|
|
@ -1721,7 +1721,7 @@ class BuildMavenTask(BaseBuildTask):
|
|||
session=self.session,
|
||||
by_config=self.options.allowed_scms_use_config,
|
||||
by_policy=self.options.allowed_scms_use_policy,
|
||||
opts=scm_policy_opts)
|
||||
policy_data=scm_policy_opts)
|
||||
self.run_callbacks('preSCMCheckout', scminfo=patch_scm.get_info(),
|
||||
build_tag=build_tag, scratch=opts.get('scratch'),
|
||||
buildroot=buildroot)
|
||||
|
|
@ -2008,7 +2008,7 @@ class WrapperRPMTask(BaseBuildTask):
|
|||
session=self.session,
|
||||
by_config=self.options.allowed_scms_use_config,
|
||||
by_policy=self.options.allowed_scms_use_policy,
|
||||
opts={
|
||||
policy_data={
|
||||
'user_id': self.taskinfo['owner'],
|
||||
'channel': self.session.getChannel(self.taskinfo['channel_id'],
|
||||
strict=True)['name'],
|
||||
|
|
@ -3006,7 +3006,7 @@ class ImageTask(BaseTaskHandler):
|
|||
session=self.session,
|
||||
by_config=self.options.allowed_scms_use_config,
|
||||
by_policy=self.options.allowed_scms_use_policy,
|
||||
opts={
|
||||
policy_data={
|
||||
'user_id': self.taskinfo['owner'],
|
||||
'channel': self.session.getChannel(self.taskinfo['channel_id'],
|
||||
strict=True)['name'],
|
||||
|
|
@ -3489,7 +3489,7 @@ class LiveMediaTask(ImageTask):
|
|||
session=self.session,
|
||||
by_config=self.options.allowed_scms_use_config,
|
||||
by_policy=self.options.allowed_scms_use_policy,
|
||||
opts={
|
||||
policy_data={
|
||||
'user_id': self.taskinfo['owner'],
|
||||
'channel': self.session.getChannel(self.taskinfo['channel_id'],
|
||||
strict=True)['name'],
|
||||
|
|
@ -3745,7 +3745,7 @@ class OzImageTask(BaseTaskHandler):
|
|||
session=self.session,
|
||||
by_config=self.options.allowed_scms_use_config,
|
||||
by_policy=self.options.allowed_scms_use_policy,
|
||||
opts={
|
||||
policy_data={
|
||||
'user_id': self.taskinfo['owner'],
|
||||
'channel': self.session.getChannel(self.taskinfo['channel_id'],
|
||||
strict=True)['name'],
|
||||
|
|
@ -4581,7 +4581,7 @@ class BuildIndirectionImageTask(OzImageTask):
|
|||
session=self.session,
|
||||
by_config=self.options.allowed_scms_use_config,
|
||||
by_policy=self.options.allowed_scms_use_policy,
|
||||
opts={
|
||||
policy_data={
|
||||
'user_id': self.taskinfo['owner'],
|
||||
'channel': self.session.getChannel(self.taskinfo['channel_id'],
|
||||
strict=True)['name'],
|
||||
|
|
@ -5002,7 +5002,7 @@ class BuildSRPMFromSCMTask(BaseBuildTask):
|
|||
session=self.session,
|
||||
by_config=self.options.allowed_scms_use_config,
|
||||
by_policy=self.options.allowed_scms_use_policy,
|
||||
opts={
|
||||
policy_data={
|
||||
'user_id': self.taskinfo['owner'],
|
||||
'channel': self.session.getChannel(self.taskinfo['channel_id'],
|
||||
strict=True)['name'],
|
||||
|
|
|
|||
|
|
@ -327,14 +327,34 @@ class SCM(object):
|
|||
# return parsed values
|
||||
return (scheme, user, netloc, path, query, fragment)
|
||||
|
||||
def assert_allowed(self, allowed='', session=None, by_config=True, by_policy=False, opts=None):
|
||||
def assert_allowed(self, allowed='', session=None, by_config=True, by_policy=False,
|
||||
policy_data=None):
|
||||
"""
|
||||
Check whether this scm is allowed and apply options by either/both approach below:
|
||||
|
||||
- "allowed_scms" from config file, see
|
||||
:func:`~koji.daemon.SCM.assert_allowed_by_config`
|
||||
- "build_from_scm" hub policy, see :func:`~koji.daemon.SCM.assert_allowed_by_policy`
|
||||
|
||||
When both approaches are applied, the config one will be applied, then the policy one.
|
||||
|
||||
:param str allowed: The allowed_scms config content which is used for by-config approach
|
||||
:param koji.ClientSession session: The allowed_scms config content which is used for
|
||||
by-policy approach
|
||||
:param bool by_config: Using config or not, Default: True
|
||||
:param bool by_policy: Using policy or not, Default: False
|
||||
:param dict policy_data: The policy data which will be merged with the generated scm info,
|
||||
then will be passed to hub call for policy assertion when using
|
||||
policy.
|
||||
:raises koji.BuildError: if the scm is denied.
|
||||
"""
|
||||
if by_config:
|
||||
self.assert_allowed_by_config(allowed or '')
|
||||
if by_policy:
|
||||
if session is None:
|
||||
raise koji.ConfigurationError(
|
||||
'When allowed SCM assertion is by policy, session must be passed in.')
|
||||
self.assert_allowed_by_policy(session, **(opts or {}))
|
||||
self.assert_allowed_by_policy(session, **(policy_data or {}))
|
||||
|
||||
def assert_allowed_by_config(self, allowed):
|
||||
"""
|
||||
|
|
@ -405,7 +425,7 @@ class SCM(object):
|
|||
raise koji.BuildError(
|
||||
'%s:%s is not in the list of allowed SCMs' % (self.host, self.repository))
|
||||
|
||||
def assert_allowed_by_policy(self, session, **opts):
|
||||
def assert_allowed_by_policy(self, session, **extra_data):
|
||||
"""
|
||||
Check this scm against hub policy: build_from_scm and apply options
|
||||
|
||||
|
|
@ -421,13 +441,16 @@ class SCM(object):
|
|||
- scmrevision
|
||||
- scmtype
|
||||
|
||||
More keys could be added in opts. You can pass any reasonable data which could be handled
|
||||
by policy tests, like:
|
||||
More keys could be added as kwargs(extra_data). You can pass any reasonable data which
|
||||
could be handled by policy tests, like:
|
||||
|
||||
- scratch (if the task is scratch)
|
||||
- channel (which channel the task is assigned)
|
||||
- user_id (the task owner)
|
||||
|
||||
If the key in extra_data is one of scm_* listed above, it will override the one generated
|
||||
from scminfo.
|
||||
|
||||
The format of the action returned from build_from_scm could be one of following forms::
|
||||
|
||||
allow [use_common] [source_cmd]
|
||||
|
|
@ -457,7 +480,7 @@ class SCM(object):
|
|||
if not k.startswith('scm'):
|
||||
k = 'scm' + k
|
||||
policy_data[k] = v
|
||||
policy_data.update(opts)
|
||||
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')
|
||||
if not is_allowed:
|
||||
|
|
|
|||
|
|
@ -332,7 +332,7 @@ class WinBuildTask(MultiPlatformTask):
|
|||
session=self.session,
|
||||
by_config=self.options.allowed_scms_use_config,
|
||||
by_policy=self.options.allowed_scms_use_policy,
|
||||
opts={
|
||||
policy_data={
|
||||
'user_id': self.taskinfo['owner'],
|
||||
'channel': self.session.getChannel(self.taskinfo['channel_id'],
|
||||
strict=True)['name'],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue