This commit is contained in:
Nadja Reitzenstein 2022-09-27 15:56:00 +02:00
parent 286aca0472
commit acdd150079
2 changed files with 45 additions and 0 deletions

23
add_del_user.py Normal file
View File

@ -0,0 +1,23 @@
import asyncio
import fabapi
import fabapi.user_system
async def main():
session = await fabapi.connect("localhost", 59661, "Testuser", "secret")
# Add an user with the given roles
roles = [
"somerole", "testrole"
]
user = await fabapi.user_system.add_user(session.userSystem, "ANewUser", "ANewSecret", roles=roles)
print("ANewUser obj: ", user)
# As you can see, Roles were attached
r = await user.info.listRoles().a_wait()
print("ANewUser roles: ", r)
# Delete the same user again
await fabapi.user_system.del_user(session.userSystem, "ANewUser")
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())

22
use_giveback_machine.py Normal file
View File

@ -0,0 +1,22 @@
import asyncio
import fabapi
import fabapi.user_system
async def main():
session = await fabapi.connect("localhost", 59661, "Testuser", "secret")
info = session.machineSystem.info
ma = await info.getMachineURN("urn:fabaccess:resource:Another").a_wait()
# ma.just isn't set if the above selected resource doesn't exist
if ma.just:
await ma.just.use.use().a_wait()
# Do whatever
# To give the resource back we have to re-query the changed state
ma = await info.getMachineURN("urn:fabaccess:resource:Another").a_wait()
await ma.just.inuse.giveBack().a_wait()
else:
print("No such resource!")
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())