python: support connecting with an interactive password prompt
That unique_ptr has to be hidden and not exported to Python because
pybind11 currently does not support "taking back" objects from Python's
ownership, and that's essentially what is needed for consuming a moved
unique_ptr. This means that we cannot really avoid that constructor
duplication in this context.
This patch comes with no test because so far, we have not used
password-based (well, kbdinteractive-based) authentication for NETCONF.
Here's how to use it, anyway:
def auth(auth_name, instruction, prompt, echo):
print(f'{auth_name}: {instruction}')
if echo:
return raw_input(prompt)
else:
return getpass.getpass(prompt)
conn = nc.NetconfAccess(server=..., username=..., interactive_auth=auth)
Change-Id: Iee3be17b024869f3cdebfd8ef876c20e177def74
diff --git a/src/python_netconf.cpp b/src/python_netconf.cpp
index 83964d6..eaa4349 100644
--- a/src/python_netconf.cpp
+++ b/src/python_netconf.cpp
@@ -5,9 +5,11 @@
*
*/
+#include <pybind11/functional.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include "netconf_access.hpp"
+#include "netconf-client.h"
using namespace std::literals;
using namespace pybind11::literals;
@@ -58,6 +60,12 @@
pybind11::class_<NetconfAccess>(m, "NetconfAccess")
.def(pybind11::init<const std::string&>(), "socketPath"_a)
+ .def(pybind11::init(
+ [](const std::string& host, const uint16_t port, const std::string& user, const libnetconf::client::KbdInteractiveCb interactiveAuth) {
+ auto session = libnetconf::client::Session::connectKbdInteractive(host, port, user, interactiveAuth);
+ return std::make_unique<NetconfAccess>(std::move(session));
+ }),
+ "server"_a, "port"_a=830, "username"_a, "interactive_auth"_a)
.def("getItems", &NetconfAccess::getItems, "xpath"_a)
.def("setLeaf", &NetconfAccess::setLeaf, "xpath"_a, "value"_a)
.def("commitChanges", &NetconfAccess::commitChanges)