Refactor helper script
This commit is contained in:
parent
67c83975d1
commit
b7316ff513
|
@ -1,35 +1,61 @@
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from pprint import pprint as pp
|
||||||
|
|
||||||
from phi.ldap.async_model import (
|
from phi.async_ldap.model import (
|
||||||
Hackers,
|
# Hackers,
|
||||||
|
# User,
|
||||||
Robots,
|
Robots,
|
||||||
Congregations,
|
|
||||||
User,
|
|
||||||
Service,
|
Service,
|
||||||
|
Congregations,
|
||||||
|
Group,
|
||||||
build_heritage,
|
build_heritage,
|
||||||
iter_children,
|
iter_children,
|
||||||
)
|
)
|
||||||
from phi.ldap.async_client import AsyncClient
|
|
||||||
|
from phi.async_ldap.new_model import Hackers, User
|
||||||
|
from phi.async_ldap.client import AsyncClient
|
||||||
|
|
||||||
|
|
||||||
async def dlv(h):
|
async def dlv(h, cls):
|
||||||
return [el async for el in build_heritage(h, User)]
|
return [el async for el in build_heritage(h, cls)]
|
||||||
|
|
||||||
|
|
||||||
cl = AsyncClient(
|
cl = AsyncClient(
|
||||||
"ldap://localhost",
|
"ldap://localhost",
|
||||||
port=389,
|
port=389,
|
||||||
encryption=True,
|
encryption=True,
|
||||||
validate=True,
|
# validate=True,
|
||||||
ca_cert="openldap/cert.pem",
|
ca_cert="/home/leo/Documents/coding/phi/openldap/cert.pem",
|
||||||
username="root",
|
username="root",
|
||||||
password="root",
|
password="root",
|
||||||
base_dn="dc=unit,dc=macaomilano,dc=org",
|
base_dn="dc=unit,dc=macaomilano,dc=org",
|
||||||
attribute_id="cn",
|
attribute_id="cn",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def get_all_children():
|
||||||
h = Hackers(cl)
|
h = Hackers(cl)
|
||||||
r = Robots(cl)
|
r = Robots(cl)
|
||||||
g = Congregations(cl)
|
g = Congregations(cl)
|
||||||
# asyncio.run(dlv(h))
|
|
||||||
|
hackers = await dlv(h, User)
|
||||||
|
robots = await dlv(r, Service)
|
||||||
|
groups = await dlv(g, Group)
|
||||||
|
|
||||||
|
return (hackers, robots, groups)
|
||||||
|
|
||||||
|
|
||||||
|
async def print_async(awaitable):
|
||||||
|
result = await awaitable
|
||||||
|
pp(result)
|
||||||
|
|
||||||
|
|
||||||
|
async def describe(obj):
|
||||||
|
results = await obj.describe()
|
||||||
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
asyncio.run(print_async(describe(Hackers(cl))))
|
||||||
|
asyncio.run(print_async(describe(User(cl, "conte_mascetti"))))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user