Update to new API

This commit is contained in:
Nadja Reitzenstein 2022-03-14 00:04:28 +01:00
parent 8189d04d0a
commit 47d22cf973
2 changed files with 9 additions and 16 deletions

View File

@ -38,20 +38,17 @@ async def connect(host, port, user, pw):
# Start TwoPartyClient using TwoWayPipe (takes no arguments in this mode)
client = capnp.TwoPartyClient()
cap = client.bootstrap().cast_as(connection_capnp.Bootstrap)
# Assemble reader and writer tasks, run in the background
coroutines = [myreader(client, reader), mywriter(client, writer)]
asyncio.gather(*coroutines, return_exceptions=True)
auth = cap.authenticationSystem().authenticationSystem
req = auth.start_request()
req.request.mechanism = "PLAIN"
req.request.initialResponse.initial = "\0" + user + "\0" + pw
rep_prom = req.send()
response = await rep_prom.a_wait()
if response.response.outcome.result == "successful":
return cap
boot = client.bootstrap().cast_as(connection_capnp.Bootstrap)
auth = await boot.createSession("PLAIN").a_wait()
p = "\0" + user + "\0" + pw
response = await auth.authentication.step(p).a_wait()
if response.which() == 'successful':
return response.successful.session
else:
print("Auth failed")
print("Authentication failed!")
return None

View File

@ -3,12 +3,8 @@ import fabapi
async def main():
boot = await fabapi.connect("localhost", 59661, "Testuser", "secret")
if boot:
ms = await boot.machineSystem().a_wait()
info = await ms.machineSystem.info().a_wait()
ma = await info.info.getMachineURN("urn:fabaccess:resource:Another").a_wait()
print(ma.machine)
session = await fabapi.connect("localhost", 59661, "Testuser", "secret")
print(session)
if __name__ == "__main__":
loop = asyncio.get_event_loop()