Skip to content
Snippets Groups Projects
Commit 87d31f99 authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

machines: exclude perso

parent 20c06109
No related branches found
No related tags found
No related merge requests found
...@@ -23,8 +23,9 @@ ATTRIBUTES = [ ...@@ -23,8 +23,9 @@ ATTRIBUTES = [
"roomNumber", "roomNumber",
] ]
FILTERS = { FILTERS = {
"laas-mach-group": "gepetto", "laas-mach-group": ["gepetto"],
"laas-mach-type": "PC", "laas-mach-type": ["PC"],
"laas-mach-origineAchat": ["LAAS", "autre"], # exclude perso
} }
...@@ -46,7 +47,11 @@ def parse(k, v): ...@@ -46,7 +47,11 @@ def parse(k, v):
def filter(**filters) -> str: def filter(**filters) -> str:
"""format some filters for LDAP query.""" """format some filters for LDAP query."""
return "".join(f"({k}={v})" for k, v in filters.items())
def filter_key(k, vs):
return "(|" + "".join(f"({k}={v})" for v in vs) + ")"
return "(&" + "".join(filter_key(k, vs) for k, vs in filters.items()) + ")"
def machines_ldap( def machines_ldap(
...@@ -65,7 +70,7 @@ def machines_ldap( ...@@ -65,7 +70,7 @@ def machines_ldap(
CONN.search( CONN.search(
"ou=machines,dc=laas,dc=fr", "ou=machines,dc=laas,dc=fr",
f"(&{filter(**filters)})", filter(**filters),
attributes=ATTRIBUTES, attributes=ATTRIBUTES,
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment