init commit
This commit is contained in:
@@ -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 }})
|
||||
@@ -0,0 +1,12 @@
|
||||
services:
|
||||
|
||||
{{ container_service_name }}:
|
||||
container_name: {{ container_name }}
|
||||
image: php:8.0-apache
|
||||
ports:
|
||||
- {{ container_http_port }}:80
|
||||
volumes:
|
||||
- ./html:/var/www/html/
|
||||
{{ extra_volumes }}
|
||||
network_mode: bridge
|
||||
restart: always
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
[Unit]
|
||||
Description={{ service_name }}
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
User=root
|
||||
Group=root
|
||||
WorkingDirectory={{ service_working_folder }}
|
||||
ExecStart={{ service_exe }}
|
||||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Reference in New Issue
Block a user