blob: 9c0bb9c197a77eb55cbd2ca8fa2329ba1b63768f [file] [log] [blame]
Jason Lingc893f432020-10-24 19:31:44 -07001/*
2 * Copyright 2019 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#include "buildjson.hpp"
17
18#include "file_handler.hpp"
Jason Lingc893f432020-10-24 19:31:44 -070019
20#include <nlohmann/json.hpp>
21#include <sdbusplus/bus.hpp>
22
23#include <algorithm>
24#include <cstdio>
25#include <exception>
26#include <fstream>
27#include <string>
28#include <vector>
29
30namespace ipmi_flash
31{
32
33std::unique_ptr<TriggerableActionInterface>
34 buildFileSystemd(const nlohmann::json& data)
35{
36 /* This type of action requires a path and unit, and optionally a mode. */
37 const auto& path = data.at("path");
38 const auto& unit = data.at("unit");
39
40 /* the mode parameter is optional. */
41 std::string systemdMode = "replace";
42 const auto& mode = data.find("mode");
43 if (mode != data.end())
44 {
45 systemdMode = data.at("mode").get<std::string>();
46 }
47
48 return SystemdWithStatusFile::CreateSystemdWithStatusFile(
49 sdbusplus::bus::new_default(), path, unit, systemdMode);
50}
51
52std::unique_ptr<TriggerableActionInterface>
53 buildSystemd(const nlohmann::json& data)
54{
55 /* This type of action requires a unit, and optionally a mode. */
56 const auto& unit = data.at("unit");
57
58 /* the mode parameter is optional. */
59 std::string systemdMode = "replace";
60 const auto& mode = data.find("mode");
61 if (mode != data.end())
62 {
63 systemdMode = data.at("mode").get<std::string>();
64 }
65
66 return SystemdNoFile::CreateSystemdNoFile(sdbusplus::bus::new_default(),
67 unit, systemdMode);
68}
69
Jason Lingc893f432020-10-24 19:31:44 -070070} // namespace ipmi_flash