blob: 7430fe323edab916dca4b1dcb15fe3a8d3308844 (
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
|
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright OpenBMC Authors
#pragma once
#include "async_resp.hpp"
#include "error_messages.hpp"
#include "persistent_data.hpp"
#include <nlohmann/json.hpp>
#include <cstddef>
#include <memory>
#include <string_view>
namespace redfish
{
namespace manager_utils
{
inline void setServiceIdentification(
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
std::string_view serviceIdentification)
{
constexpr const size_t maxStrSize = 99;
constexpr const char* allowedChars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 _-";
if (serviceIdentification.size() > maxStrSize)
{
messages::stringValueTooLong(asyncResp->res, "ServiceIdentification",
maxStrSize);
return;
}
if (serviceIdentification.find_first_not_of(allowedChars) !=
std::string_view::npos)
{
messages::propertyValueError(asyncResp->res, "ServiceIdentification");
return;
}
persistent_data::ConfigFile& config = persistent_data::getConfig();
config.serviceIdentification = serviceIdentification;
config.writeData();
messages::success(asyncResp->res);
}
inline void getServiceIdentification(
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const bool isServiceRoot)
{
std::string_view serviceIdentification =
persistent_data::getConfig().serviceIdentification;
// This property shall not be present if its value is an empty string or
// null: Redfish Data Model Specification 6.125.3
if (isServiceRoot && serviceIdentification.empty())
{
return;
}
asyncResp->res.jsonValue["ServiceIdentification"] = serviceIdentification;
}
} // namespace manager_utils
} // namespace redfish
|