AccountService

Initial version moved to separate node.

Change-Id: I3fe4e2eb00bcb754ea81de0a0656f4de9eb9156c
Signed-off-by: Lewanczyk, Dawid <dawid.lewanczyk@intel.com>
diff --git a/include/redfish_v1.hpp b/include/redfish_v1.hpp
index e32be23..0c070ed 100644
--- a/include/redfish_v1.hpp
+++ b/include/redfish_v1.hpp
@@ -79,29 +79,6 @@
             res.end();
           });
 
-  CROW_ROUTE(app, "/redfish/v1/AccountService/")
-      .methods(
-          "GET"_method)([&](const crow::request& req, crow::response& res) {
-        res.json_value = {
-            {"@odata.context",
-             "/redfish/v1/$metadata#AccountService.AccountService"},
-            {"@odata.id", "/redfish/v1/AccountService"},
-            {"@odata.type", "#AccountService.v1_1_0.AccountService"},
-            {"Id", "AccountService"},
-            {"Name", "Account Service"},
-            {"Description", "BMC User Accounts"},
-            {"Status",
-             // TODO(ed) health rollup
-             {{"State", "Enabled"}, {"Health", "OK"}, {"HealthRollup", "OK"}}},
-            {"ServiceEnabled", true},
-            {"MinPasswordLength", 1},
-            {"MaxPasswordLength", 20},
-        };
-        get_redfish_sub_routes(app, "/redfish/v1/AccountService",
-                               res.json_value);
-        res.end();
-      });
-
   CROW_ROUTE(app, "/redfish/v1/AccountService/Accounts/")
       .methods(
           "GET"_method)([&](const crow::request& req, crow::response& res) {
diff --git a/redfish-core/include/redfish.hpp b/redfish-core/include/redfish.hpp
index b67c857..ad055f3 100644
--- a/redfish-core/include/redfish.hpp
+++ b/redfish-core/include/redfish.hpp
@@ -15,6 +15,7 @@
 */
 #pragma once
 
+#include "../lib/account_service.hpp"
 #include "../lib/redfish_sessions.hpp"
 #include "../lib/roles.hpp"
 #include "../lib/service_root.hpp"
@@ -38,6 +39,8 @@
         PrivilegeProvider("/etc/redfish.conf.d/privilege_registry.json");
 
     nodes.emplace_back(
+        std::make_unique<AccountService>(app, privilegeProvider));
+    nodes.emplace_back(
         std::make_unique<SessionCollection>(app, privilegeProvider));
     nodes.emplace_back(std::make_unique<Roles>(app, privilegeProvider));
     nodes.emplace_back(
diff --git a/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp
new file mode 100644
index 0000000..ceb5135
--- /dev/null
+++ b/redfish-core/lib/account_service.hpp
@@ -0,0 +1,55 @@
+/*
+// Copyright (c) 2018 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
+#pragma once
+
+#include "node.hpp"
+
+namespace redfish {
+
+class AccountService : public Node {
+ public:
+  template <typename CrowApp, typename PrivilegeProvider>
+  AccountService(CrowApp& app, PrivilegeProvider& provider)
+      : Node(app, provider, "#AccountService.v1_1_0.AccountService",
+             "/redfish/v1/AccountService/") {
+    nodeJson["@odata.id"] = "/redfish/v1/AccountService";
+    nodeJson["@odata.type"] = "#AccountService.v1_1_0.AccountService";
+    nodeJson["@odata.context"] =
+        "/redfish/v1/$metadata#AccountService.AccountService";
+    nodeJson["Id"] = "AccountService";
+    nodeJson["Description"] = "BMC User Accounts";
+    nodeJson["Name"] = "Account Service";
+    nodeJson["Status"]["State"] = "Enabled";
+    nodeJson["Status"]["Health"] = "OK";
+    nodeJson["Status"]["HealthRollup"] = "OK";
+    nodeJson["ServiceEnabled"] = true;
+    nodeJson["MinPasswordLength"] = 1;
+    nodeJson["MaxPasswordLength"] = 20;
+    nodeJson["Accounts"]["@odata.id"] = "/redfish/v1/AccountService/Accounts";
+    nodeJson["Roles"]["@odata.id"] = "/redfish/v1/AccountService/Roles";
+  }
+
+ private:
+  void doGet(crow::response& res, const crow::request& req,
+             const std::vector<std::string>& params) override {
+    res.json_value = nodeJson;
+    res.end();
+  }
+
+  nlohmann::json nodeJson;
+};
+
+}  // namespace redfish
diff --git a/redfish-core/lib/roles.hpp b/redfish-core/lib/roles.hpp
index bce4cce..d912e88 100644
--- a/redfish-core/lib/roles.hpp
+++ b/redfish-core/lib/roles.hpp
@@ -63,7 +63,7 @@
     nodeJson["Description"] = "BMC User Roles";
     nodeJson["Members@odata.count"] = 1;
     nodeJson["Members"] = {
-        {"@odata.id", "/redfish/v1/AccountService/Roles/Administrator"}};
+        {{"@odata.id", "/redfish/v1/AccountService/Roles/Administrator"}}};
   }
 
  private: