blob: c6b9a7de419af4febf216d56f628ab925b077720 [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
25#include <cctype>
Nan Zhou014be0b2021-12-28 18:00:14 -080026#include <sdbusplus/bus.hpp>
27#include <sdbusplus/server/manager.hpp>
Marri Devender Raof4682712019-03-19 05:00:28 -050028#include <sdeventplus/event.hpp>
Jayanth Othayoth0aa0d112018-09-03 03:47:27 -050029#include <string>
Nan Zhou014be0b2021-12-28 18:00:14 -080030#include <utility>
Jayanth Othayoth0aa0d112018-09-03 03:47:27 -050031
Nan Zhoucf06ccd2021-12-28 16:25:45 -080032inline std::string capitalize(const std::string& s)
Jayanth Othayothcfbc8dc2018-09-03 07:22:27 -050033{
Nan Zhoucf06ccd2021-12-28 16:25:45 -080034 std::string res = s;
35 if (!res.empty())
36 {
37 res[0] = std::toupper(res[0]);
38 }
39 return res;
Jayanth Othayothcfbc8dc2018-09-03 07:22:27 -050040}
41
Jayanth Othayoth0aa0d112018-09-03 03:47:27 -050042int main(int argc, char** argv)
43{
Nan Zhou7047be62022-03-10 12:34:06 -080044 phosphor::certs::Arguments arguments;
45 if (phosphor::certs::processArguments(argc, argv, arguments) != 0)
Jayanth Othayoth0aa0d112018-09-03 03:47:27 -050046 {
Nan Zhou7047be62022-03-10 12:34:06 -080047 std::exit(EXIT_FAILURE);
Jayanth Othayoth0aa0d112018-09-03 03:47:27 -050048 }
49
Jayanth Othayothcfbc8dc2018-09-03 07:22:27 -050050 auto bus = sdbusplus::bus::new_default();
Nan Zhou7047be62022-03-10 12:34:06 -080051 auto objPath = std::string(objectNamePrefix) + '/' + arguments.typeStr +
52 '/' + arguments.endpoint;
Marri Devender Rao6ceec402019-02-01 03:15:19 -060053 // Add sdbusplus ObjectManager
54 sdbusplus::server::manager::manager objManager(bus, objPath.c_str());
55
Marri Devender Raof4682712019-03-19 05:00:28 -050056 // Get default event loop
57 auto event = sdeventplus::Event::get_default();
58
59 // Attach the bus to sd_event to service user requests
60 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
Nan Zhou7047be62022-03-10 12:34:06 -080061 phosphor::certs::Manager manager(
62 bus, event, objPath.c_str(),
63 phosphor::certs::stringToCertificateType(arguments.typeStr),
64 arguments.unit, arguments.path);
Jayanth Othayothcfbc8dc2018-09-03 07:22:27 -050065
66 // Adjusting Interface name as per std convention
Nan Zhou7047be62022-03-10 12:34:06 -080067 auto busName = std::string(busNamePrefix) + '.' +
68 capitalize(arguments.typeStr) + '.' +
69 capitalize(arguments.endpoint);
Jayanth Othayothcfbc8dc2018-09-03 07:22:27 -050070 bus.request_name(busName.c_str());
Marri Devender Raof4682712019-03-19 05:00:28 -050071 event.loop();
Jayanth Othayoth0aa0d112018-09-03 03:47:27 -050072 return 0;
73}