add linked GPOs functionality

This commit is contained in:
2025-12-19 19:08:32 -08:00
parent 02120b78b2
commit 5327f865b9
3 changed files with 135 additions and 34 deletions
+36
View File
@@ -37,6 +37,42 @@ def get_groups():
})
return jsonify(gpos)
@app.route("/linked_ous", methods=["GET"])
def linked_ous():
gpo_name = request.args.get("gpo")
if not gpo_name:
return jsonify({"error": "Missing 'gpo' query parameter"}), 400
linked = []
# The YAML is a list of dictionaries iterate over them
for top in data or []:
cfg = top.get("configured_gpos", {})
if not isinstance(cfg, dict):
continue
# Grab the value for the requested GPO it can be a dict *or* a list
gpo_entry = cfg.get(gpo_name)
if gpo_entry is None:
continue
# Case 1: direct dict → look for Linked_OUs key
if isinstance(gpo_entry, dict):
if "Linked_OUs" in gpo_entry:
ous = gpo_entry["Linked_OUs"]
if isinstance(ous, list):
linked.extend(ous)
continue
# Case 2: list of dicts → find the dict that has the Linked_OUs key
if isinstance(gpo_entry, list):
for sub in gpo_entry:
if isinstance(sub, dict) and "Linked_OUs" in sub:
ous = sub["Linked_OUs"]
if isinstance(ous, list):
linked.extend(ous)
return jsonify(linked)
# test route
@app.route('/test', methods=['GET'])
def test():