blob: 0af42418873bf9bba4300aa9f1bada55bc25a941 [file] [log] [blame]
Patrick Venture298930a2019-07-03 11:44:52 -07001#pragma once
2
3#include "firmware_handler.hpp"
4#include "image_handler.hpp"
5
Patrick Venture298930a2019-07-03 11:44:52 -07006#include <nlohmann/json.hpp>
Patrick Venture9b37b092020-05-28 20:58:57 -07007
8#include <memory>
Patrick Venture298930a2019-07-03 11:44:52 -07009#include <string>
10#include <vector>
11
12namespace ipmi_flash
13{
14
15class HandlerConfig
16{
17 public:
18 HandlerConfig() = default;
19 ~HandlerConfig() = default;
20 HandlerConfig(const HandlerConfig&) = delete;
21 HandlerConfig& operator=(const HandlerConfig&) = delete;
22 HandlerConfig(HandlerConfig&&) = default;
23 HandlerConfig& operator=(HandlerConfig&&) = default;
24
25 /* A string in the form: /flash/{unique}, s.t. unique is something like,
26 * flash, ubitar, statictar, or bios
27 */
28 std::string blobId;
29
30 /* This owns a handler interface, this is typically going to be a file
31 * writer object.
32 */
33 std::unique_ptr<ImageHandlerInterface> handler;
34
35 /* Only the hashBlobId doesn't have an action pack, otherwise it's required.
36 */
37 std::unique_ptr<ActionPack> actions;
38};
39
40/**
41 * Given a list of handlers as json data, construct the appropriate
42 * HandlerConfig objects. This method is meant to be called per json
43 * configuration file found.
44 *
45 * The list will only contain validly build HandlerConfig objects. Any invalid
46 * configuration is skipped. The hope is that the BMC firmware update
47 * configuration will never be invalid, but if another aspect is invalid, it can
48 * be fixed with a BMC firmware update once the bug is identified.
49 *
50 * This code does not validate that the blob specified is unique, that should
51 * be handled at a higher layer.
52 *
53 * @param[in] data - json data from a json file.
54 * @return list of HandlerConfig objects.
55 */
56std::vector<HandlerConfig> buildHandlerFromJson(const nlohmann::json& data);
57
Patrick Venturea6b4abd2019-07-19 10:58:55 -070058/**
59 * Given a folder of json configs, build the configurations.
60 *
61 * @param[in] directory - the directory to search (recurisvely).
62 * @return list of HandlerConfig objects.
63 */
64std::vector<HandlerConfig> BuildHandlerConfigs(const std::string& directory);
65
Patrick Venture298930a2019-07-03 11:44:52 -070066} // namespace ipmi_flash