fabfire_adapter/fabapi/connect.py
Nadja Reitzenstein d8004c5b18 Initial commit
2021-09-19 20:39:06 +02:00

25 lines
761 B
Python

import capnp
capnp.remove_import_hook()
connection_capnp = capnp.load('schema/connection.capnp')
authenticationsystem_capnp = capnp.load('schema/authenticationsystem.capnp')
def connect(host, user, pw):
"""TODO: Docstring for connect.
:returns: TODO
"""
client = capnp.TwoPartyClient(host)
boot = client.bootstrap().cast_as(connection_capnp.Bootstrap)
auth = boot.authenticationSystem().authenticationSystem
req = auth.start_request()
req.request.mechanism = "PLAIN"
req.request.initialResponse.initial = "\0" + user + "\0" + pw
rep_prom = req.send()
response = rep_prom.wait()
if response.response.outcome.result == "successful":
return boot
else:
print("Auth failed")
return None