Refactor and add debug prints
All checks were successful
ci/woodpecker/manual/woodpecker Pipeline was successful

This commit is contained in:
Madis Mägi 2023-08-02 02:57:42 +03:00
parent 7f321385f7
commit 5e7eae7c3a

View File

@ -44,15 +44,25 @@ def view_users():
@check_api_key
def get_group_cards():
groups = request.json.get("groups", False)
users = get_users()
print(groups)
print(users)
if not groups:
return "must specify groups in parameter", 400
gu = list(filter(lambda u: any(g["name"] in groups for g in u["status"]["groups"]), users))
print(gu)
print(f"groups requested are: {groups}")
users = get_users()
print(f"found users: {users}")
gu = []
for u in users:
for gr in u["status"]["groups"]:
group_name = f"{gr['prefix']}:{gr['name']}"
print(f"prefix is {gr['prefix']}")
print(f"name is {gr['name']}")
print(f"group name is {group_name}")
for group in groups:
print(f"checking {group}")
if group_name == group:
gu.append(u)
print(f"gu is: {gu}")
keys = list(map(lambda u: u["metadata"]["name"], gu))
print(keys)
print(f"keys are {keys}")
flt = {
"token.uid_hash": {"$exists": True},
"inventory.owner.username": {"$in": keys}
@ -68,6 +78,6 @@ def get_group_cards():
del obj["inventory"]
found.append(obj)
fl = list(found)
print(fl)
print(f"found tokens are: {fl}")
return jsonify(fl)