Jayanth Othayoth | 0aa0d11 | 2018-09-03 03:47:27 -0500 | [diff] [blame] | 1 | /** |
| 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 Othayoth | cfbc8dc | 2018-09-03 07:22:27 -0500 | [diff] [blame] | 17 | #include "config.h" |
| 18 | |
Jayanth Othayoth | 0aa0d11 | 2018-09-03 03:47:27 -0500 | [diff] [blame] | 19 | #include "argument.hpp" |
Nan Zhou | cf06ccd | 2021-12-28 16:25:45 -0800 | [diff] [blame] | 20 | #include "certificate.hpp" |
Jayanth Othayoth | cfbc8dc | 2018-09-03 07:22:27 -0500 | [diff] [blame] | 21 | #include "certs_manager.hpp" |
Jayanth Othayoth | 0aa0d11 | 2018-09-03 03:47:27 -0500 | [diff] [blame] | 22 | |
Nan Zhou | 014be0b | 2021-12-28 18:00:14 -0800 | [diff] [blame] | 23 | #include <systemd/sd-event.h> |
| 24 | |
Nan Zhou | 014be0b | 2021-12-28 18:00:14 -0800 | [diff] [blame] | 25 | #include <sdbusplus/bus.hpp> |
| 26 | #include <sdbusplus/server/manager.hpp> |
Marri Devender Rao | f468271 | 2019-03-19 05:00:28 -0500 | [diff] [blame] | 27 | #include <sdeventplus/event.hpp> |
Patrick Williams | 223e460 | 2023-05-10 07:51:11 -0500 | [diff] [blame] | 28 | |
| 29 | #include <cctype> |
Jayanth Othayoth | 0aa0d11 | 2018-09-03 03:47:27 -0500 | [diff] [blame] | 30 | #include <string> |
Nan Zhou | 014be0b | 2021-12-28 18:00:14 -0800 | [diff] [blame] | 31 | #include <utility> |
Jayanth Othayoth | 0aa0d11 | 2018-09-03 03:47:27 -0500 | [diff] [blame] | 32 | |
Nan Zhou | cf06ccd | 2021-12-28 16:25:45 -0800 | [diff] [blame] | 33 | inline std::string capitalize(const std::string& s) |
Jayanth Othayoth | cfbc8dc | 2018-09-03 07:22:27 -0500 | [diff] [blame] | 34 | { |
Nan Zhou | cf06ccd | 2021-12-28 16:25:45 -0800 | [diff] [blame] | 35 | std::string res = s; |
| 36 | if (!res.empty()) |
| 37 | { |
Jayanth Othayoth | 1c1497a | 2024-11-24 22:35:15 -0600 | [diff] [blame^] | 38 | res[0] = static_cast<char>(std::toupper(res[0])); |
Nan Zhou | cf06ccd | 2021-12-28 16:25:45 -0800 | [diff] [blame] | 39 | } |
| 40 | return res; |
Jayanth Othayoth | cfbc8dc | 2018-09-03 07:22:27 -0500 | [diff] [blame] | 41 | } |
| 42 | |
Jayanth Othayoth | 0aa0d11 | 2018-09-03 03:47:27 -0500 | [diff] [blame] | 43 | int main(int argc, char** argv) |
| 44 | { |
Nan Zhou | 7047be6 | 2022-03-10 12:34:06 -0800 | [diff] [blame] | 45 | phosphor::certs::Arguments arguments; |
| 46 | if (phosphor::certs::processArguments(argc, argv, arguments) != 0) |
Jayanth Othayoth | 0aa0d11 | 2018-09-03 03:47:27 -0500 | [diff] [blame] | 47 | { |
Nan Zhou | 7047be6 | 2022-03-10 12:34:06 -0800 | [diff] [blame] | 48 | std::exit(EXIT_FAILURE); |
Jayanth Othayoth | 0aa0d11 | 2018-09-03 03:47:27 -0500 | [diff] [blame] | 49 | } |
| 50 | |
Jayanth Othayoth | cfbc8dc | 2018-09-03 07:22:27 -0500 | [diff] [blame] | 51 | auto bus = sdbusplus::bus::new_default(); |
Nan Zhou | 7047be6 | 2022-03-10 12:34:06 -0800 | [diff] [blame] | 52 | auto objPath = std::string(objectNamePrefix) + '/' + arguments.typeStr + |
| 53 | '/' + arguments.endpoint; |
Marri Devender Rao | 6ceec40 | 2019-02-01 03:15:19 -0600 | [diff] [blame] | 54 | // Add sdbusplus ObjectManager |
Patrick Williams | b3dbfb3 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 55 | sdbusplus::server::manager_t objManager(bus, objPath.c_str()); |
Marri Devender Rao | 6ceec40 | 2019-02-01 03:15:19 -0600 | [diff] [blame] | 56 | |
Marri Devender Rao | f468271 | 2019-03-19 05:00:28 -0500 | [diff] [blame] | 57 | // 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 Zhou | 7047be6 | 2022-03-10 12:34:06 -0800 | [diff] [blame] | 62 | phosphor::certs::Manager manager( |
| 63 | bus, event, objPath.c_str(), |
| 64 | phosphor::certs::stringToCertificateType(arguments.typeStr), |
| 65 | arguments.unit, arguments.path); |
Jayanth Othayoth | cfbc8dc | 2018-09-03 07:22:27 -0500 | [diff] [blame] | 66 | |
| 67 | // Adjusting Interface name as per std convention |
Nan Zhou | 7047be6 | 2022-03-10 12:34:06 -0800 | [diff] [blame] | 68 | auto busName = std::string(busNamePrefix) + '.' + |
| 69 | capitalize(arguments.typeStr) + '.' + |
| 70 | capitalize(arguments.endpoint); |
Jayanth Othayoth | cfbc8dc | 2018-09-03 07:22:27 -0500 | [diff] [blame] | 71 | bus.request_name(busName.c_str()); |
Marri Devender Rao | f468271 | 2019-03-19 05:00:28 -0500 | [diff] [blame] | 72 | event.loop(); |
Jayanth Othayoth | 0aa0d11 | 2018-09-03 03:47:27 -0500 | [diff] [blame] | 73 | return 0; |
| 74 | } |