init commit

This commit is contained in:
2025-11-07 09:40:06 -08:00
commit c0ad223ac5
10 changed files with 521 additions and 0 deletions
+65
View File
@@ -0,0 +1,65 @@
import yaml
from flask import Flask, request, jsonify
app = Flask(__name__)
# Load GPO data
with open('{{ gpo_yaml_path }}', 'r') as file:
data = yaml.safe_load(file)
# Debugging output to check the structure of loaded data
# print("Loaded YAML data:", data)
@app.route('/gpos', methods=['GET'])
def get_gpos():
group_name = request.args.get('group_name')
if not group_name:
return jsonify({"error": "Group name is required"}), 400
gpos = []
for gpo, links in data['configured_gpos'].items():
for link in links:
if link['ad_group'] == group_name or link['local_group'] == group_name:
gpos.append(gpo)
break
return jsonify({"group_name": group_name, "GPOs": gpos})
@app.route('/gpo', methods=['GET'])
def get_groups():
group_name = request.args.get('group')
print("Group specified:", group_name)
if not group_name:
return jsonify({"error": "Group parameter is required"}), 400
gpos = []
for entry in data:
configured_gpos = entry.get('configured_gpos', {})
for gpo, details in configured_gpos.items():
if details is None:
continue
for detail in details:
if detail['ad_group'] == group_name:
gpos.append({
"gpo": gpo,
"local_group": detail['local_group'],
"ad_group": detail['ad_group']
})
return jsonify(gpos)
# test route
@app.route('/test', methods=['GET'])
def test():
try:
root_ou = data[0]['root_ou']
except KeyError:
# Handle the case where 'root_ou' does not exist in the dictionary
return jsonify({"error": "KeyError: 'root_ou' not found in provided data"}), 400
except TypeError:
# Handle cases where data might be of a different type than expected
return jsonify({"error": "TypeError: Data is not a dictionary"}), 400
return jsonify({"result": "test", "OU_Root": root_ou})
if __name__ == '__main__':
app.run(debug=True, host='{{ api_service_bind_ip }}', port={{ api_service_port }})