blob: 3a882312596fa2092fc26fc3da683f50b118fc3a [file] [log] [blame]
Jayanth Othayoth0aa0d112018-09-03 03:47:27 -05001/**
2 * Copyright © 2018 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jayanth Othayothcfbc8dc2018-09-03 07:22:27 -050017#include "config.h"
18
Jayanth Othayoth0aa0d112018-09-03 03:47:27 -050019#include "argument.hpp"
Nan Zhoucf06ccd2021-12-28 16:25:45 -080020#include "certificate.hpp"
Jayanth Othayothcfbc8dc2018-09-03 07:22:27 -050021#include "certs_manager.hpp"
Jayanth Othayoth0aa0d112018-09-03 03:47:27 -050022
Nan Zhou014be0b2021-12-28 18:00:14 -080023#include <systemd/sd-event.h>
24
Nan Zhou014be0b2021-12-28 18:00:14 -080025#include <sdbusplus/bus.hpp>
26#include <sdbusplus/server/manager.hpp>
Marri Devender Raof4682712019-03-19 05:00:28 -050027#include <sdeventplus/event.hpp>
Patrick Williams223e4602023-05-10 07:51:11 -050028
29#include <cctype>
Jayanth Othayoth0aa0d112018-09-03 03:47:27 -050030#include <string>
Nan Zhou014be0b2021-12-28 18:00:14 -080031#include <utility>
Jayanth Othayoth0aa0d112018-09-03 03:47:27 -050032
Nan Zhoucf06ccd2021-12-28 16:25:45 -080033inline std::string capitalize(const std::string& s)
Jayanth Othayothcfbc8dc2018-09-03 07:22:27 -050034{
Nan Zhoucf06ccd2021-12-28 16:25:45 -080035 std::string res = s;
36 if (!res.empty())
37 {
Jayanth Othayoth1c1497a2024-11-24 22:35:15 -060038 res[0] = static_cast<char>(std::toupper(res[0]));
Nan Zhoucf06ccd2021-12-28 16:25:45 -080039 }
40 return res;
Jayanth Othayothcfbc8dc2018-09-03 07:22:27 -050041}
42
Jayanth Othayoth0aa0d112018-09-03 03:47:27 -050043int main(int argc, char** argv)
44{
Nan Zhou7047be62022-03-10 12:34:06 -080045 phosphor::certs::Arguments arguments;
46 if (phosphor::certs::processArguments(argc, argv, arguments) != 0)
Jayanth Othayoth0aa0d112018-09-03 03:47:27 -050047 {
Nan Zhou7047be62022-03-10 12:34:06 -080048 std::exit(EXIT_FAILURE);
Jayanth Othayoth0aa0d112018-09-03 03:47:27 -050049 }
50
Jayanth Othayothcfbc8dc2018-09-03 07:22:27 -050051 auto bus = sdbusplus::bus::new_default();
Nan Zhou7047be62022-03-10 12:34:06 -080052 auto objPath = std::string(objectNamePrefix) + '/' + arguments.typeStr +
53 '/' + arguments.endpoint;
Marri Devender Rao6ceec402019-02-01 03:15:19 -060054 // Add sdbusplus ObjectManager
Patrick Williamsb3dbfb32022-07-22 19:26:57 -050055 sdbusplus::server::manager_t objManager(bus, objPath.c_str());
Marri Devender Rao6ceec402019-02-01 03:15:19 -060056
Marri Devender Raof4682712019-03-19 05:00:28 -050057 // Get default event loop
58 auto event = sdeventplus::Event::get_default();
59
60 // Attach the bus to sd_event to service user requests
61 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
Nan Zhou7047be62022-03-10 12:34:06 -080062 phosphor::certs::Manager manager(
63 bus, event, objPath.c_str(),
64 phosphor::certs::stringToCertificateType(arguments.typeStr),
65 arguments.unit, arguments.path);
Jayanth Othayothcfbc8dc2018-09-03 07:22:27 -050066
67 // Adjusting Interface name as per std convention
Nan Zhou7047be62022-03-10 12:34:06 -080068 auto busName = std::string(busNamePrefix) + '.' +
69 capitalize(arguments.typeStr) + '.' +
70 capitalize(arguments.endpoint);
Jayanth Othayothcfbc8dc2018-09-03 07:22:27 -050071 bus.request_name(busName.c_str());
Marri Devender Raof4682712019-03-19 05:00:28 -050072 event.loop();
Jayanth Othayoth0aa0d112018-09-03 03:47:27 -050073 return 0;
74}