From 390af63a73b7d91c3c0b37089e88027b4f46a39f Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 15 May 2023 22:38:18 +0300 Subject: Add support for interactive parameter for task request --- mod/mod-build-task.cxx | 45 +++++++++++++++++++++++++++++++++++---------- mod/module.cli | 8 +++++++- mod/types-parsers.cxx | 24 ++++++++++++++++++++++++ mod/types-parsers.hxx | 8 ++++++++ 4 files changed, 74 insertions(+), 11 deletions(-) (limited to 'mod') diff --git a/mod/mod-build-task.cxx b/mod/mod-build-task.cxx index 4b0165f..19907ea 100644 --- a/mod/mod-build-task.cxx +++ b/mod/mod-build-task.cxx @@ -214,6 +214,40 @@ handle (request& rq, response& rs) task_response_manifest tsm; + auto serialize_task_response_manifest = [&tsm, &rs] () + { + // @@ Probably it would be a good idea to also send some cache control + // headers to avoid caching by HTTP proxies. That would require + // extension of the web::response interface. + // + + manifest_serializer s (rs.content (200, "text/manifest;charset=utf-8"), + "task_response_manifest"); + tsm.serialize (s); + }; + + interactive_mode imode (tqm.effective_interactive_mode ()); + + // Restict the interactive mode (specified by the task request manifest) if + // the interactive parameter is specified and is other than "both". If + // values specified by the parameter and manifest are incompatible (false vs + // true), then just bail out responding with the manifest with an empty + // session. + // + if (params.interactive () != interactive_mode::both) + { + if (imode != interactive_mode::both) + { + if (params.interactive () != imode) + { + serialize_task_response_manifest (); + return true; + } + } + else + imode = params.interactive (); // Can only change both to true or false. + } + // Map build target configurations to machines that are capable of building // them. The first matching machine is selected for each configuration. // @@ -604,7 +638,6 @@ handle (request& rq, response& rs) using pkg_query = query; using prep_pkg_query = prepared_query; - interactive_mode imode (tqm.effective_interactive_mode ()); pkg_query pq (package_query (params, imode)); // Transform (in-place) the interactive login information into the actual @@ -1495,14 +1528,6 @@ handle (request& rq, response& rs) } } - // @@ Probably it would be a good idea to also send some cache control - // headers to avoid caching by HTTP proxies. That would require extension - // of the web::response interface. - // - - manifest_serializer s (rs.content (200, "text/manifest;charset=utf-8"), - "task_response_manifest"); - tsm.serialize (s); - + serialize_task_response_manifest (); return true; } diff --git a/mod/module.cli b/mod/module.cli index 4c10826..ab72a9a 100644 --- a/mod/module.cli +++ b/mod/module.cli @@ -5,6 +5,7 @@ include ; include ; include ; // repository_location +include ; // interactive_mode include ; @@ -842,9 +843,14 @@ namespace brep class build_task { - // Package repository canonical name (note: including pkg: type). + // Only consider packages from repositories with these canonical names + // (note: including pkg: type). // vector repository | r; + + // Only consider tenants with this interactive build mode. + // + bbot::interactive_mode interactive = bbot::interactive_mode::both; }; class build_result diff --git a/mod/types-parsers.cxx b/mod/types-parsers.cxx index fd087bc..34a8bac 100644 --- a/mod/types-parsers.cxx +++ b/mod/types-parsers.cxx @@ -13,6 +13,7 @@ using namespace std; using namespace butl; using namespace bpkg; +using namespace bbot; using namespace web::xhtml; namespace brep @@ -114,6 +115,29 @@ namespace brep } } + // Parse interactive_mode. + // + void parser:: + parse (interactive_mode& x, bool& xs, scanner& s) + { + xs = true; + const char* o (s.next ()); + + if (!s.more ()) + throw missing_value (o); + + const string v (s.next ()); + + try + { + x = to_interactive_mode (v); + } + catch (const invalid_argument&) + { + throw invalid_value (o, v); + } + } + // Parse page_form. // void parser:: diff --git a/mod/types-parsers.hxx b/mod/types-parsers.hxx index c6da9f6..f10100c 100644 --- a/mod/types-parsers.hxx +++ b/mod/types-parsers.hxx @@ -10,6 +10,7 @@ #include #include // repository_location +#include // interactive_mode #include @@ -58,6 +59,13 @@ namespace brep }; template <> + struct parser + { + static void + parse (bbot::interactive_mode&, bool&, scanner&); + }; + + template <> struct parser { static void -- cgit v1.1