diff --git a/site/operations/get_services.py b/site/operations/get_services.py new file mode 100644 index 0000000..9eb8ce9 --- /dev/null +++ b/site/operations/get_services.py @@ -0,0 +1,11 @@ +from api.http_client import HttpClient + + +def get_services(client): + data = client.get("/services") + return data.get("results", []) + + +def get_service_detail(client, svc_id): + data = client.get(f"/services/{svc_id}") + return data.get("svc", {}) diff --git a/site/routes/main.py b/site/routes/main.py index 6404c25..486da4c 100644 --- a/site/routes/main.py +++ b/site/routes/main.py @@ -1,7 +1,8 @@ -from flask import Blueprint, current_app, render_template, request, make_response +from flask import Blueprint, current_app, render_template, request, make_response, jsonify from api.http_client import HttpClient from operations.get_instances import get_organization +from operations.get_services import get_services, get_service_detail bp = Blueprint("main", __name__) @@ -40,6 +41,7 @@ def index(): resp.status_code = 302 return resp + services = [] if active_token: try: client = HttpClient( @@ -47,10 +49,27 @@ def index(): active_token, ) org = get_organization(client) + raw = get_services(client) + services = sorted(raw, key=lambda s: (s.get("svcId", 0), s.get("svc", ""))) except Exception as e: error = str(e) return render_template("index.html", organization=org, error=error, env_token_masked=_mask(env_token), - has_user_token=bool(user_token)) + has_user_token=bool(user_token), + services=services) + + +@bp.route("/api/operations/") +def api_operations(svc_id): + env_token = current_app.config["NUBES_API_TOKEN"] + user_token = request.cookies.get("token") or "" + active_token = user_token or env_token + try: + client = HttpClient(current_app.config["NUBES_API_ENDPOINT"], active_token) + detail = get_service_detail(client, svc_id) + ops = detail.get("operations", []) + return jsonify({"svc": detail.get("svc", ""), "operations": ops}) + except Exception as e: + return jsonify({"error": str(e)}), 500 diff --git a/site/templates/index.html b/site/templates/index.html index 2bb97ad..074f2f7 100644 --- a/site/templates/index.html +++ b/site/templates/index.html @@ -20,30 +20,89 @@
- {% if organization %} - - - - - - - - - - - - - - - - - -
ИмяinstanceUidСервисСтатус
{{ organization.displayName }}{{ organization.instanceUid }}{{ organization.svc }}{{ organization.explainedStatus or "OK" }}
+ {% if error %} +

{{ error }}

+ {% elif organization %} +

{{ organization.displayName }} — {{ organization.explainedStatus or "OK" }}

{% else %} -

{% if error %}Ошибка: {{ error }}{% else %}Введите токен{% endif %}

+

Введите токен

{% endif %}
+ + {% if services %} +
+
Сервисы ({{ services|length }})
+
+ + + + + + + + + + {% for s in services %} + + + + + + {% endfor %} + +
#СервисОперации
{{ s.svcId }}{{ s.svc }}{% if s.svcExtendedName %} — {{ s.svcExtendedName }}{% endif %} + ? +
+
+
+ + + + + {% endif %} +