1 // SPDX-License-Identifier: Apache-2.0 2 // SPDX-FileCopyrightText: Copyright OpenBMC Authors 3 #pragma once 4 5 #include "async_resp.hpp" 6 #include "error_messages.hpp" 7 #include "persistent_data.hpp" 8 9 #include <nlohmann/json.hpp> 10 11 #include <memory> 12 #include <string_view> 13 14 namespace redfish 15 { 16 17 namespace manager_utils 18 { 19 20 inline void setServiceIdentification( 21 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 22 std::string_view serviceIdentification) 23 { 24 constexpr const size_t maxStrSize = 99; 25 constexpr const char* allowedChars = 26 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 _-"; 27 if (serviceIdentification.size() > maxStrSize) 28 { 29 messages::stringValueTooLong(asyncResp->res, "ServiceIdentification", 30 maxStrSize); 31 return; 32 } 33 if (serviceIdentification.find_first_not_of(allowedChars) != 34 std::string_view::npos) 35 { 36 messages::propertyValueError(asyncResp->res, "ServiceIdentification"); 37 return; 38 } 39 40 persistent_data::ConfigFile& config = persistent_data::getConfig(); 41 config.serviceIdentification = serviceIdentification; 42 config.writeData(); 43 messages::success(asyncResp->res); 44 } 45 46 inline void getServiceIdentification( 47 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 48 const bool isServiceRoot) 49 { 50 std::string_view serviceIdentification = 51 persistent_data::getConfig().serviceIdentification; 52 53 // This property shall not be present if its value is an empty string or 54 // null: Redfish Data Model Specification 6.125.3 55 if (isServiceRoot && serviceIdentification.empty()) 56 { 57 return; 58 } 59 asyncResp->res.jsonValue["ServiceIdentification"] = serviceIdentification; 60 } 61 62 } // namespace manager_utils 63 64 } // namespace redfish 65