* Retrieve a configuration path based on a configuration name * * @param cmd std::string containing the command name to use in * case of errors * @param config_name std::string containing the configuration name to * look up * @param dbusconn (optional) DBus::Connection to reuse an existing * connection * * @return
| 244 | * paths were found. |
| 245 | */ |
| 246 | DBus::Object::Path retrieve_config_path(const std::string &cmd, |
| 247 | const std::string &config_name, |
| 248 | DBus::Connection::Ptr dbusconn) |
| 249 | { |
| 250 | auto conn = (dbusconn |
| 251 | ? dbusconn |
| 252 | : DBus::Connection::Create(DBus::BusType::SYSTEM)); |
| 253 | OpenVPN3ConfigurationProxy cfgmgr(conn, |
| 254 | Constants::GenPath("configuration")); |
| 255 | |
| 256 | auto paths = cfgmgr.LookupConfigName(config_name); |
| 257 | if (0 == paths.size()) |
| 258 | { |
| 259 | throw CommandException(cmd, |
| 260 | "No configuration profiles found"); |
| 261 | } |
| 262 | else if (1 < paths.size()) |
| 263 | { |
| 264 | throw CommandException(cmd, |
| 265 | "More than one configuration profile was " |
| 266 | "found with the given name"); |
| 267 | } |
| 268 | return paths.at(0); |
| 269 | } |
no test coverage detected