mirror of
https://gitlab.com/fabinfra/fabaccess/pyfabapi.git
synced 2025-03-12 06:41:42 +01:00
Update to new API
This commit is contained in:
parent
8189d04d0a
commit
47d22cf973
@ -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
|
||||
|
8
test.py
8
test.py
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user