Update Google v1

Adding setUpRedfishRoute for all handlers because this method is required
to return a gRPC response. In setUpRedfishRoute, the Odata version header
is set and this is required for gRPC to return a response

Tested:

ytbjs2-n1:~# /data/milotic_tool_cli --resource_url='/google/v1/' --uid=  \
 --host host-control-node.localproductionnode.goog --port 443 \
 --auth tls_not_verify_server --command get \
 --cert_chain /root/.zatar/cert.pem  --private_key /root/.zatar/key.pem
URL is /google/v1/
Response JSON is /google/v1/{
  "@odata.id": "/google/v1",
  "@odata.type": "#GoogleServiceRoot.v1_0_0.GoogleServiceRoot",
  "Id": "Google Rest RootService",
  "Name": "Google Service Root",
  "RootOfTrustCollection": {
    "@odata.id": "/google/v1/RootOfTrustCollection"
  },
  "Version": "1.0.0"
}

Google-Bug-Id: 272117695
Change-Id: I9349f53de881de74589c5084490a9721e59b95b4
Signed-off-by: Edward Lee <edwarddl@google.com>
(cherry picked from commit 148f3ff8fa6714f164fadb45a8c0330b483bc63f)
diff --git a/recipes-phosphor/interfaces/bmcweb/DOWNSTREAM_0001-google-v1-Add-setUpRedfishRoute-for-all-handlers.patch b/recipes-phosphor/interfaces/bmcweb/DOWNSTREAM_0001-google-v1-Add-setUpRedfishRoute-for-all-handlers.patch
new file mode 100644
index 0000000..e30a604
--- /dev/null
+++ b/recipes-phosphor/interfaces/bmcweb/DOWNSTREAM_0001-google-v1-Add-setUpRedfishRoute-for-all-handlers.patch
@@ -0,0 +1,174 @@
+From 50ba56d3bc01e7e436177edcfa29fad2b22f0e7c Mon Sep 17 00:00:00 2001
+From: Willy Tu <wltu@google.com>
+Date: Tue, 7 Mar 2023 10:59:58 -0800
+Subject: [PATCH] google/v1: Add setUpRedfishRoute for all handlers
+
+Adding setUpRedfishRoute for all handlers because this method is required
+to return a gRPC response. In setUpRedfishRoute, the Odata version header
+is set and this is required for gRPC to return a response
+
+Tested:
+
+ytbjs2-n1:~# /data/milotic_tool_cli --resource_url='/google/v1/' --uid=  \
+ --host host-control-node.localproductionnode.goog --port 443 \
+ --auth tls_not_verify_server --command get \
+ --cert_chain /root/.zatar/cert.pem  --private_key /root/.zatar/key.pem
+URL is /google/v1/
+Response JSON is /google/v1/{
+  "@odata.id": "/google/v1",
+  "@odata.type": "#GoogleServiceRoot.v1_0_0.GoogleServiceRoot",
+  "Id": "Google Rest RootService",
+  "Name": "Google Service Root",
+  "RootOfTrustCollection": {
+    "@odata.id": "/google/v1/RootOfTrustCollection"
+  },
+  "Version": "1.0.0"
+}
+
+Patch Tracking Bug: b/272117695
+Upstream info / review:
+Upstream-Status: Denied
+Justification:
+
+/google/v1 is not a redfish resource and should not even be in bmcweb.
+
+This will remain downstream only and is in the same place as the gRPC
+patch. When we create our own gRPC service, this patch will go along
+with it.
+
+Change-Id: I7f33cf4e46108cde8fb63caea5afe72a051a6c06
+Signed-off-by: Willy Tu <wltu@google.com>
+---
+ include/google/google_service_root.hpp        | 37 +++++++++++++++----
+ .../google/google_service_root_test.cpp       |  5 ++-
+ 2 files changed, 32 insertions(+), 10 deletions(-)
+ 
+diff --git a/include/google/google_service_root.hpp b/include/google/google_service_root.hpp
+index cbcf15d7..fb3c454d 100644
+--- a/include/google/google_service_root.hpp
++++ b/include/google/google_service_root.hpp
+@@ -4,6 +4,7 @@
+ #include <async_resp.hpp>
+ #include <dbus_utility.hpp>
+ #include <error_messages.hpp>
++#include <query.hpp>
+ #include <nlohmann/json.hpp>
+ #include <utils/collection.hpp>
+ #include <utils/hex_utils.hpp>
+@@ -21,9 +22,13 @@ namespace google_api
+ {
+ 
+ inline void
+-    handleGoogleV1Get(const crow::Request& /*req*/,
++    handleGoogleV1Get(App& app, const crow::Request& req,
+                       const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
+ {
++    if (!redfish::setUpRedfishRoute(app, req, asyncResp))
++    {
++        return;
++    }
+     asyncResp->res.jsonValue["@odata.type"] =
+         "#GoogleServiceRoot.v1_0_0.GoogleServiceRoot";
+     asyncResp->res.jsonValue["@odata.id"] = "/google/v1";
+@@ -35,9 +40,13 @@ inline void
+ }
+ 
+ inline void handleRootOfTrustCollectionGet(
+-    const crow::Request& /*req*/,
++    App& app, const crow::Request& req,
+     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
+ {
++    if (!redfish::setUpRedfishRoute(app, req, asyncResp))
++    {
++        return;
++    }
+     asyncResp->res.jsonValue["@odata.id"] = "/google/v1/RootOfTrustCollection";
+     asyncResp->res.jsonValue["@odata.type"] =
+         "#RootOfTrustCollection.RootOfTrustCollection";
+@@ -137,10 +146,14 @@ inline void populateRootOfTrustEntity(
+ }
+ 
+ inline void
+-    handleRootOfTrustGet(const crow::Request& /*req*/,
++    handleRootOfTrustGet(App& app, const crow::Request& req,
+                          const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+                          const std::string& param)
+ {
++    if (!redfish::setUpRedfishRoute(app, req, asyncResp))
++    {
++        return;
++    }
+     std::string emptyCommand;
+     resolveRoT(emptyCommand, asyncResp, param, populateRootOfTrustEntity);
+ }
+@@ -186,10 +199,14 @@ inline void
+ }
+ 
+ inline void handleRoTSendCommandPost(
+-    const crow::Request& request,
++    App& app, const crow::Request& request,
+     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+     const std::string& rotId)
+ {
++    if (!redfish::setUpRedfishRoute(app, request, asyncResp))
++    {
++        return;
++    }
+     std::string command;
+     if (!redfish::json_util::readJsonAction(request, asyncResp->res, "Command",
+                                             command))
+@@ -206,21 +223,25 @@ inline void handleRoTSendCommandPost(
+ inline void requestRoutes(App& app)
+ {
+     BMCWEB_ROUTE(app, "/google/v1/")
+-        .methods(boost::beast::http::verb::get)(handleGoogleV1Get);
++        .methods(boost::beast::http::verb::get)(
++            std::bind_front(handleGoogleV1Get, std::ref(app)));
+ 
+     BMCWEB_ROUTE(app, "/google/v1/RootOfTrustCollection")
+         .privileges({{"ConfigureManager"}})
+-        .methods(boost::beast::http::verb::get)(handleRootOfTrustCollectionGet);
++        .methods(boost::beast::http::verb::get)(
++            std::bind_front(handleRootOfTrustCollectionGet, std::ref(app)));
+ 
+     BMCWEB_ROUTE(app, "/google/v1/RootOfTrustCollection/<str>")
+         .privileges({{"ConfigureManager"}})
+-        .methods(boost::beast::http::verb::get)(handleRootOfTrustGet);
++        .methods(boost::beast::http::verb::get)(
++            std::bind_front(handleRootOfTrustGet, std::ref(app)));
+ 
+     BMCWEB_ROUTE(
+         app,
+         "/google/v1/RootOfTrustCollection/<str>/Actions/RootOfTrust.SendCommand")
+         .privileges({{"ConfigureManager"}})
+-        .methods(boost::beast::http::verb::post)(handleRoTSendCommandPost);
++        .methods(boost::beast::http::verb::post)(
++            std::bind_front(handleRoTSendCommandPost, std::ref(app)));
+ }
+ 
+ } // namespace google_api
+diff --git a/test/include/google/google_service_root_test.cpp b/test/include/google/google_service_root_test.cpp
+index 32d4e526..0e988335 100644
+--- a/test/include/google/google_service_root_test.cpp
++++ b/test/include/google/google_service_root_test.cpp
+@@ -26,14 +26,15 @@ void validateServiceRootGet(crow::Response& res)
+ 
+ TEST(HandleGoogleV1Get, OnSuccess)
+ {
++    App app;
+     std::error_code ec;
+     auto asyncResp = std::make_shared<bmcweb::AsyncResp>();
+ 
+     asyncResp->res.setCompleteRequestHandler(validateServiceRootGet);
+ 
+     crow::Request dummyRequest{{boost::beast::http::verb::get, "", 11}, ec};
+-    handleGoogleV1Get(dummyRequest, asyncResp);
++    handleGoogleV1Get(app, dummyRequest, asyncResp);
+ }
+ 
+ } // namespace
+-} // namespace crow::google_api
+\ No newline at end of file
++} // namespace crow::google_api
+-- 
+2.40.0.rc0.216.gc4246ad0f0-goog
\ No newline at end of file
diff --git a/recipes-phosphor/interfaces/bmcweb_%.bbappend b/recipes-phosphor/interfaces/bmcweb_%.bbappend
index b62e518..914d008 100644
--- a/recipes-phosphor/interfaces/bmcweb_%.bbappend
+++ b/recipes-phosphor/interfaces/bmcweb_%.bbappend
@@ -21,6 +21,7 @@
   file://service-override.conf \
   file://delay-reset@.service \
   file://0001-Add-chassis-reset-delay.patch \
+  file://DOWNSTREAM_0001-google-v1-Add-setUpRedfishRoute-for-all-handlers.patch \
 "
 
 # gBMC storage Support