blob: 4aae00d2987fed0ad70b683235cb07ade672bc84 [file] [log] [blame]
Jason Lingc893f432020-10-24 19:31:44 -07001#pragma once
2
3#include "general_systemd.hpp"
4#include "image_handler.hpp"
5
6#include <nlohmann/json.hpp>
7
8#include <memory>
9#include <string>
10#include <vector>
11
12namespace ipmi_flash
13{
14std::unique_ptr<TriggerableActionInterface>
15 buildFileSystemd(const nlohmann::json& data);
16
17std::unique_ptr<TriggerableActionInterface>
18 buildSystemd(const nlohmann::json& data);
19
20/**
21 * HandlerConfig associates a blobID with an ImageHandler and a set of
22 * supported actions of type T.
23 */
24template <typename T>
25class HandlerConfig
26{
27 public:
28 HandlerConfig() = default;
29 ~HandlerConfig() = default;
30 HandlerConfig(const HandlerConfig&) = delete;
31 HandlerConfig& operator=(const HandlerConfig&) = delete;
32 HandlerConfig(HandlerConfig&&) = default;
33 HandlerConfig& operator=(HandlerConfig&&) = default;
34
35 /* A string in the form: /flash/{unique}, s.t. unique is something like,
36 * flash, ubitar, statictar, or bios
37 */
38 std::string blobId;
39
40 /* This owns a handler interface, this is typically going to be a file
41 * writer object.
42 */
43 std::unique_ptr<ImageHandlerInterface> handler;
44
45 /* specifies actions to be taken in response to certain operations on a
46 * blob.
47 * Usually required but there are exceptions; the hashBlobId doesn't have
48 * an action pack.
49 */
50 std::unique_ptr<T> actions;
51};
52
53/* HandlersBuilderIfc is a helper class that builds Handlers from the json files
54 * found within a specified directory.
55 * The child class that inherits from HandlersBuilderIfc should implement
56 * buildHandlersConfigs to perform json validation and parsing.
57 *
58 */
59template <typename T>
60class HandlersBuilderIfc
61{
62 public:
63 HandlersBuilderIfc() = default;
64 ~HandlersBuilderIfc() = default;
65 HandlersBuilderIfc(const HandlersBuilderIfc&) = delete;
66 HandlersBuilderIfc& operator=(const HandlersBuilderIfc&) = delete;
67 HandlersBuilderIfc(HandlersBuilderIfc&&) = default;
68 HandlersBuilderIfc& operator=(HandlersBuilderIfc&&) = default;
69 /**
70 * Given a folder of json configs, build the configurations.
71 *
72 * @param[in] directory - the directory to search (recurisvely).
73 * @return list of HandlerConfig objects.
74 */
75 std::vector<HandlerConfig<T>>
76 buildHandlerConfigs(const std::string& directory);
77 /**
78 * Given a list of handlers as json data, construct the appropriate
79 * HandlerConfig objects. This method is meant to be called per json
80 * configuration file found.
81 *
82 * The list will only contain validly build HandlerConfig objects. Any
83 * invalid configuration is skipped. The hope is that the BMC firmware
84 * update configuration will never be invalid, but if another aspect is
85 * invalid, it can be fixed with a BMC firmware update once the bug is
86 * identified.
87 *
88 * This code does not validate that the blob specified is unique, that
89 * should be handled at a higher layer.
90 *
91 * @param[in] data - json data from a json file.
92 * @return list of HandlerConfig objects.
93 */
94 virtual std::vector<HandlerConfig<T>>
95 buildHandlerFromJson(const nlohmann::json& data) = 0;
96};
97} // namespace ipmi_flash