mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-06-27 23:46:33 +08:00
Allow submitting optional parameters such as copr_owner and copr_project
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
"""Add optional columns for copr
|
||||||
|
|
||||||
|
Revision ID: 474697622859
|
||||||
|
Revises: 0ef60c3ed440
|
||||||
|
Create Date: 2017-02-21 11:18:22.304038
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '474697622859'
|
||||||
|
down_revision = '0ef60c3ed440'
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.add_column('module_builds', sa.Column('copr_owner', sa.String(), nullable=True))
|
||||||
|
op.add_column('module_builds', sa.Column('copr_project', sa.String(), nullable=True))
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
op.drop_column('module_builds', 'copr_owner')
|
||||||
|
op.drop_column('module_builds', 'copr_project')
|
||||||
@@ -101,6 +101,8 @@ class ModuleBuild(RidaBase):
|
|||||||
state_reason = db.Column(db.String)
|
state_reason = db.Column(db.String)
|
||||||
modulemd = db.Column(db.String, nullable=False)
|
modulemd = db.Column(db.String, nullable=False)
|
||||||
koji_tag = db.Column(db.String) # This gets set after 'wait'
|
koji_tag = db.Column(db.String) # This gets set after 'wait'
|
||||||
|
copr_owner = db.Column(db.String)
|
||||||
|
copr_project = db.Column(db.String)
|
||||||
scmurl = db.Column(db.String)
|
scmurl = db.Column(db.String)
|
||||||
owner = db.Column(db.String, nullable=False)
|
owner = db.Column(db.String, nullable=False)
|
||||||
time_submitted = db.Column(db.DateTime, nullable=False)
|
time_submitted = db.Column(db.DateTime, nullable=False)
|
||||||
@@ -155,7 +157,8 @@ class ModuleBuild(RidaBase):
|
|||||||
% type(event).__name__)
|
% type(event).__name__)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, session, conf, name, stream, version, modulemd, scmurl, username):
|
def create(cls, session, conf, name, stream, version, modulemd, scmurl, username,
|
||||||
|
copr_owner=None, copr_project=None):
|
||||||
now = datetime.utcnow()
|
now = datetime.utcnow()
|
||||||
module = cls(
|
module = cls(
|
||||||
name=name,
|
name=name,
|
||||||
@@ -165,7 +168,9 @@ class ModuleBuild(RidaBase):
|
|||||||
modulemd=modulemd,
|
modulemd=modulemd,
|
||||||
scmurl=scmurl,
|
scmurl=scmurl,
|
||||||
owner=username,
|
owner=username,
|
||||||
time_submitted=now
|
time_submitted=now,
|
||||||
|
copr_owner=copr_owner,
|
||||||
|
copr_project=copr_project,
|
||||||
)
|
)
|
||||||
session.add(module)
|
session.add(module)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|||||||
@@ -526,17 +526,17 @@ def record_component_builds(scm, mmd, module, initial_batch = 1):
|
|||||||
return batch
|
return batch
|
||||||
|
|
||||||
|
|
||||||
def submit_module_build_from_yaml(username, yaml):
|
def submit_module_build_from_yaml(username, yaml, optional_params={}):
|
||||||
mmd = load_mmd(yaml)
|
mmd = load_mmd(yaml)
|
||||||
return submit_module_build(username, None, mmd, None, yaml)
|
return submit_module_build(username, None, mmd, None, yaml, optional_params)
|
||||||
|
|
||||||
|
|
||||||
def submit_module_build_from_scm(username, url, allow_local_url=False):
|
def submit_module_build_from_scm(username, url, allow_local_url=False, optional_params={}):
|
||||||
mmd, scm, yaml = _fetch_mmd(url, allow_local_url)
|
mmd, scm, yaml = _fetch_mmd(url, allow_local_url)
|
||||||
return submit_module_build(username, url, mmd, scm, yaml)
|
return submit_module_build(username, url, mmd, scm, yaml, optional_params)
|
||||||
|
|
||||||
|
|
||||||
def submit_module_build(username, url, mmd, scm, yaml):
|
def submit_module_build(username, url, mmd, scm, yaml, optional_params={}):
|
||||||
# Import it here, because SCM uses utils methods
|
# Import it here, because SCM uses utils methods
|
||||||
# and fails to import them because of dep-chain.
|
# and fails to import them because of dep-chain.
|
||||||
import module_build_service.scm
|
import module_build_service.scm
|
||||||
@@ -569,7 +569,8 @@ def submit_module_build(username, url, mmd, scm, yaml):
|
|||||||
version=str(mmd.version),
|
version=str(mmd.version),
|
||||||
modulemd=yaml,
|
modulemd=yaml,
|
||||||
scmurl=url,
|
scmurl=url,
|
||||||
username=username
|
username=username,
|
||||||
|
**optional_params
|
||||||
)
|
)
|
||||||
|
|
||||||
record_component_builds(scm, mmd, module)
|
record_component_builds(scm, mmd, module)
|
||||||
|
|||||||
@@ -124,18 +124,28 @@ class ModuleBuildAPI(MethodView):
|
|||||||
log.error("The submitted scmurl %r is not valid" % url)
|
log.error("The submitted scmurl %r is not valid" % url)
|
||||||
raise Unauthorized("The submitted scmurl %s is not valid" % url)
|
raise Unauthorized("The submitted scmurl %s is not valid" % url)
|
||||||
|
|
||||||
return submit_module_build_from_scm(username, url, allow_local_url=False)
|
forbidden_params = [k for k in r if not hasattr(models.ModuleBuild, k)]
|
||||||
|
if forbidden_params:
|
||||||
|
raise ValidationError('The request contains unspecified parameters: {}'.format(", ".join(forbidden_params)))
|
||||||
|
|
||||||
|
optional_params = {k: v for k, v in r.items() if k != "scmurl"}
|
||||||
|
return submit_module_build_from_scm(username, url, allow_local_url=False, optional_params=optional_params)
|
||||||
|
|
||||||
def post_file(self, username):
|
def post_file(self, username):
|
||||||
if not conf.yaml_submit_allowed:
|
if not conf.yaml_submit_allowed:
|
||||||
raise Unauthorized("YAML submission is not enabled")
|
raise Unauthorized("YAML submission is not enabled")
|
||||||
|
|
||||||
|
forbidden_params = [k for k in request.form if not hasattr(models.ModuleBuild, k)]
|
||||||
|
if forbidden_params:
|
||||||
|
raise ValidationError('The request contains unspecified parameters: {}'.format(", ".join(forbidden_params)))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r = request.files["yaml"]
|
r = request.files["yaml"]
|
||||||
except:
|
except:
|
||||||
log.error('Invalid file submitted')
|
log.error('Invalid file submitted')
|
||||||
raise ValidationError('Invalid file submitted')
|
raise ValidationError('Invalid file submitted')
|
||||||
|
|
||||||
return submit_module_build_from_yaml(username, r.read())
|
return submit_module_build_from_yaml(username, r.read(), optional_params=dict(request.form.items()))
|
||||||
|
|
||||||
def patch(self, id):
|
def patch(self, id):
|
||||||
username, groups = module_build_service.auth.get_user(request)
|
username, groups = module_build_service.auth.get_user(request)
|
||||||
|
|||||||
Reference in New Issue
Block a user