webapp.py: improve parameter validation for /schedule
authorHelmut Grohne <helmut@subdivi.de>
Sat, 10 Oct 2020 07:32:27 +0000 (09:32 +0200)
committerHelmut Grohne <helmut@subdivi.de>
Sat, 10 Oct 2020 07:32:27 +0000 (09:32 +0200)
Allow scheduling any_arm64. Disallow scheduling garbage_any.

webapp.py

index 5d75ba6..f433ccf 100644 (file)
--- a/webapp.py
+++ b/webapp.py
@@ -426,20 +426,20 @@ def request_schedule():
         raise werkzeug.exceptions.BadRequest()
     if buildarch == "any":
         buildarch = None
+    if hostarch == "any":
+        hostarch = None
     with db.engine.connect() as conn:
         query = sqlalchemy.text("""
             SELECT 1 FROM depstate WHERE source = :source;""")
         if not conn.execute(query, source=source).first():
             raise werkzeug.exceptions.BadRequest()
-        if hostarch == "any":
-            hostarch = None
-        else:
-            query = sqlalchemy.text("""
-                SELECT 1 FROM depcheck
-                    WHERE buildarch = :buildarch AND hostarch = :hostarch;""")
-            if not conn.execute(query, buildarch=buildarch,
-                                hostarch=hostarch).first():
-                raise werkzeug.exceptions.BadRequest()
+        query = sqlalchemy.text("""
+            SELECT 1 FROM depcheck
+                WHERE buildarch = ifnull(:buildarch, buildarch)
+                    AND hostarch = ifnull(:hostarch, hostarch);""")
+        if not conn.execute(query, buildarch=buildarch,
+                            hostarch=hostarch).first():
+            raise werkzeug.exceptions.BadRequest()
         query = sqlalchemy.text("""
             INSERT INTO buildrequests (source, buildarch, hostarch,
                                        requesttime)