mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-04-04 19:28:49 +08:00
Implement possibility to submit yaml files (See #310)
This commit is contained in:
@@ -418,13 +418,22 @@ def record_component_builds(scm, mmd, module, initial_batch = 1):
|
||||
|
||||
return batch
|
||||
|
||||
def submit_module_build(username, url, allow_local_url = False):
|
||||
|
||||
def submit_module_build_from_yaml(username, yaml):
|
||||
mmd = load_mmd(yaml)
|
||||
return submit_module_build(username, None, mmd, None, yaml)
|
||||
|
||||
|
||||
def submit_module_build_from_scm(username, url, allow_local_url=False):
|
||||
mmd, scm, yaml = _fetch_mmd(url, allow_local_url)
|
||||
return submit_module_build(username, url, mmd, scm, yaml)
|
||||
|
||||
|
||||
def submit_module_build(username, url, mmd, scm, yaml):
|
||||
# Import it here, because SCM uses utils methods
|
||||
# and fails to import them because of dep-chain.
|
||||
import module_build_service.scm
|
||||
|
||||
mmd, scm, yaml = _fetch_mmd(url, allow_local_url)
|
||||
|
||||
module = models.ModuleBuild.query.filter_by(
|
||||
name=mmd.name, stream=mmd.stream, version=str(mmd.version)).first()
|
||||
if module:
|
||||
|
||||
@@ -35,7 +35,8 @@ from flask.views import MethodView
|
||||
|
||||
from module_build_service import app, conf, log
|
||||
from module_build_service import models, db
|
||||
from module_build_service.utils import pagination_metadata, filter_module_builds, submit_module_build, scm_url_schemes
|
||||
from module_build_service.utils import pagination_metadata, filter_module_builds, submit_module_build_from_scm, \
|
||||
submit_module_build_from_yaml, scm_url_schemes
|
||||
from module_build_service.errors import (
|
||||
ValidationError, Unauthorized, NotFound)
|
||||
|
||||
@@ -97,6 +98,14 @@ class ModuleBuildAPI(MethodView):
|
||||
raise Unauthorized("%s is not in any of %r, only %r" % (
|
||||
username, conf.allowed_groups, groups))
|
||||
|
||||
if "multipart/form-data" in request.headers.get("Content-Type"):
|
||||
module = self.post_file(username)
|
||||
else:
|
||||
module = self.post_scm(username)
|
||||
|
||||
return jsonify(module.json()), 201
|
||||
|
||||
def post_scm(self, username):
|
||||
try:
|
||||
r = json.loads(request.get_data().decode("utf-8"))
|
||||
except:
|
||||
@@ -120,8 +129,16 @@ class ModuleBuildAPI(MethodView):
|
||||
log.error("The submitted scmurl %r is not valid" % url)
|
||||
raise Unauthorized("The submitted scmurl %s is not valid" % url)
|
||||
|
||||
module = submit_module_build(username, url, allow_local_url=False)
|
||||
return jsonify(module.json()), 201
|
||||
return submit_module_build_from_scm(username, url, allow_local_url=False)
|
||||
|
||||
def post_file(self, username):
|
||||
try:
|
||||
r = request.files["yaml"]
|
||||
except:
|
||||
log.error('Invalid file submitted')
|
||||
raise ValidationError('Invalid file submitted')
|
||||
|
||||
return submit_module_build_from_yaml(username, r.read())
|
||||
|
||||
def patch(self, id):
|
||||
username, groups = module_build_service.auth.get_user(request)
|
||||
|
||||
Reference in New Issue
Block a user