Remove the last instances of json pattern

In the past, we've tried to erradicate the use of
nlohmann::json(initiatlizer_list<...>) because it bloats binary sizes,
as every type is given a new nlohmann constructor.

This commit hunts down the last few places where we call this.  There is
still 2 remaining in openbmc_dbus_rest after this, but those are variant
accesses that are difficult to triage, and considering it's a less used
api, they're left as is.

Tested: WIP

Change-Id: Iaac24584bb78bb238da69010b511c1d598bd38bc
Signed-off-by: Ed Tanous <ed@tanous.net>
diff --git a/redfish-core/lib/roles.hpp b/redfish-core/lib/roles.hpp
index 7cd55b2..a0f4f34 100644
--- a/redfish-core/lib/roles.hpp
+++ b/redfish-core/lib/roles.hpp
@@ -21,8 +21,11 @@
 #include "registries/privilege_registry.hpp"
 
 #include <boost/url/format.hpp>
+#include <nlohmann/json.hpp>
 #include <sdbusplus/asio/property.hpp>
 
+#include <optional>
+#include <string_view>
 #include <variant>
 namespace redfish
 {
@@ -44,27 +47,34 @@
     return "";
 }
 
-inline bool getAssignedPrivFromRole(std::string_view role,
-                                    nlohmann::json& privArray)
+inline std::optional<nlohmann::json::array_t>
+    getAssignedPrivFromRole(std::string_view role)
 {
+    nlohmann::json::array_t privArray;
     if (role == "Administrator")
     {
-        privArray = {"Login", "ConfigureManager", "ConfigureUsers",
-                     "ConfigureSelf", "ConfigureComponents"};
+        privArray.emplace_back("Login");
+        privArray.emplace_back("ConfigureManager");
+        privArray.emplace_back("ConfigureUsers");
+        privArray.emplace_back("ConfigureSelf");
+        privArray.emplace_back("ConfigureComponents");
     }
     else if (role == "Operator")
     {
-        privArray = {"Login", "ConfigureSelf", "ConfigureComponents"};
+        privArray.emplace_back("Login");
+        privArray.emplace_back("ConfigureSelf");
+        privArray.emplace_back("ConfigureComponents");
     }
     else if (role == "ReadOnly")
     {
-        privArray = {"Login", "ConfigureSelf"};
+        privArray.emplace_back("Login");
+        privArray.emplace_back("ConfigureSelf");
     }
     else
     {
-        return false;
+        return std::nullopt;
     }
-    return true;
+    return privArray;
 }
 
 inline void requestRoutesRoles(App& app)
@@ -79,8 +89,10 @@
         {
             return;
         }
-        nlohmann::json privArray = nlohmann::json::array();
-        if (!getAssignedPrivFromRole(roleId, privArray))
+
+        std::optional<nlohmann::json::array_t> privArray =
+            getAssignedPrivFromRole(roleId);
+        if (!privArray)
         {
             messages::resourceNotFound(asyncResp->res, "Role", roleId);
 
@@ -96,7 +108,7 @@
         asyncResp->res.jsonValue["RoleId"] = roleId;
         asyncResp->res.jsonValue["@odata.id"] =
             boost::urls::format("/redfish/v1/AccountService/Roles/{}", roleId);
-        asyncResp->res.jsonValue["AssignedPrivileges"] = std::move(privArray);
+        asyncResp->res.jsonValue["AssignedPrivileges"] = std::move(*privArray);
     });
 }