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