From a45f1888a826c0ceaf60047495cddcae324046a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0abata?= Date: Fri, 8 Jul 2016 14:11:39 +0200 Subject: [PATCH] Attempt to fetch the modulemd file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Petr Ĺ abata --- rida.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/rida.py b/rida.py index aa5efbc1..26419bc4 100755 --- a/rida.py +++ b/rida.py @@ -36,12 +36,15 @@ from flask import Flask, request import json import logging import modulemd +import os.path import rida.auth import rida.config import rida.database import rida.logger import rida.messaging +import rida.scm import ssl +import tempfile app = Flask(__name__) app.config.from_envvar("RIDA_SETTINGS", silent=True) @@ -75,10 +78,22 @@ def submit_build(): break if not urlallowed: return "The submitted scmurl isn't allowed", 403 - # FIXME: Use the scm class to obtain modulemd - # for the next step we're pretending "yaml" contains - # the contents of the modulemd yaml file yaml = str() + try: + scm = rida.scm.SCM(url, conf.scmurls) + td = tempfile.TemporaryDirectory() + cod = scm.checkout(td.name) + cofn = os.path.join(cod, (scm.name + ".yaml")) + with open(cofn, "r") as mmdfile: + yaml = mmdfile.read() + except Exception as e: + if "is not in the list of allowed SCMs" in str(e): + rc = 403 + elif "Invalid SCM URL" in str(e): + rc = 400 + else: + rc = 500 + return str(e), rc mmd = modulemd.ModuleMetadata() try: mmd.loads(yaml)