summaryrefslogtreecommitdiffstats
path: root/bmc/buildjson.hpp
blob: 8e333f6a72ea3f8d1719711db8ac584833f8c264 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#pragma once

#include "firmware_handler.hpp"
#include "image_handler.hpp"

#include <memory>
#include <nlohmann/json.hpp>
#include <string>
#include <vector>

namespace ipmi_flash
{

class HandlerConfig
{
  public:
    HandlerConfig() = default;
    ~HandlerConfig() = default;
    HandlerConfig(const HandlerConfig&) = delete;
    HandlerConfig& operator=(const HandlerConfig&) = delete;
    HandlerConfig(HandlerConfig&&) = default;
    HandlerConfig& operator=(HandlerConfig&&) = default;

    /* A string in the form: /flash/{unique}, s.t. unique is something like,
     * flash, ubitar, statictar, or bios
     */
    std::string blobId;

    /* This owns a handler interface, this is typically going to be a file
     * writer object.
     */
    std::unique_ptr<ImageHandlerInterface> handler;

    /* Only the hashBlobId doesn't have an action pack, otherwise it's required.
     */
    std::unique_ptr<ActionPack> actions;
};

/**
 * Given a list of handlers as json data, construct the appropriate
 * HandlerConfig objects.  This method is meant to be called per json
 * configuration file found.
 *
 * The list will only contain validly build HandlerConfig objects.  Any invalid
 * configuration is skipped. The hope is that the BMC firmware update
 * configuration will never be invalid, but if another aspect is invalid, it can
 * be fixed with a BMC firmware update once the bug is identified.
 *
 * This code does not validate that the blob specified is unique, that should
 * be handled at a higher layer.
 *
 * @param[in] data - json data from a json file.
 * @return list of HandlerConfig objects.
 */
std::vector<HandlerConfig> buildHandlerFromJson(const nlohmann::json& data);

/**
 * Given a folder of json configs, build the configurations.
 *
 * @param[in] directory - the directory to search (recurisvely).
 * @return list of HandlerConfig objects.
 */
std::vector<HandlerConfig> BuildHandlerConfigs(const std::string& directory);

} // namespace ipmi_flash
OpenPOWER on IntegriCloud