From 51f4508c1dae749fc54db0ee71cfe9276774b32c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Thu, 23 Jul 2026 11:28:11 +0400 Subject: [PATCH] Add modules: api, operations, routes with org display --- site/__init__.py | 0 site/api/http_client.py | 17 +++++++++++++++++ site/app.py | 14 ++++++++------ site/operations/get_instances.py | 13 +++++++++++++ site/routes/main.py | 21 +++++++++++++++++++++ site/templates/index.html | 30 +++++++++++++++++++++++++++--- 6 files changed, 86 insertions(+), 9 deletions(-) delete mode 100644 site/__init__.py create mode 100644 site/api/http_client.py create mode 100644 site/operations/get_instances.py create mode 100644 site/routes/main.py diff --git a/site/__init__.py b/site/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/site/api/http_client.py b/site/api/http_client.py new file mode 100644 index 0000000..bc50fd8 --- /dev/null +++ b/site/api/http_client.py @@ -0,0 +1,17 @@ +import requests + + +class HttpClient: + def __init__(self, endpoint, token): + self._endpoint = endpoint.rstrip("/") + self._session = requests.Session() + self._session.headers.update({ + "Authorization": f"Bearer {token}", + "User-Agent": "Mozilla/5.0", + }) + + def get(self, path, **kwargs): + kwargs.setdefault("timeout", 10) + r = self._session.get(f"{self._endpoint}{path}", **kwargs) + r.raise_for_status() + return r.json() diff --git a/site/app.py b/site/app.py index 261cfa6..3ffdb6f 100644 --- a/site/app.py +++ b/site/app.py @@ -1,11 +1,13 @@ -from flask import Flask, render_template +import os + +from flask import Flask + +from routes.main import bp as main_bp app = Flask(__name__, template_folder="templates", static_folder="static") - - -@app.route("/") -def index(): - return render_template("index.html") +app.config["NUBES_API_ENDPOINT"] = os.getenv("NUBES_API_ENDPOINT", "https://lk-api-gateway-dev.ngcloud.ru/api/v1/svc") +app.config["NUBES_API_TOKEN"] = os.getenv("NUBES_API_TOKEN", "") +app.register_blueprint(main_bp) if __name__ == "__main__": diff --git a/site/operations/get_instances.py b/site/operations/get_instances.py new file mode 100644 index 0000000..7fc7636 --- /dev/null +++ b/site/operations/get_instances.py @@ -0,0 +1,13 @@ +from api.http_client import HttpClient + + +def get_instances(client): + data = client.get("/instances", params={"pageSize": 200}) + return data.get("results", []) + + +def get_organization(client): + for inst in get_instances(client): + if inst.get("serviceId") == 19: + return inst + return None diff --git a/site/routes/main.py b/site/routes/main.py new file mode 100644 index 0000000..82491ce --- /dev/null +++ b/site/routes/main.py @@ -0,0 +1,21 @@ +from flask import Blueprint, current_app, render_template + +from api.http_client import HttpClient +from operations.get_instances import get_organization + +bp = Blueprint("main", __name__) + + +@bp.route("/") +def index(): + org = None + error = None + try: + client = HttpClient( + current_app.config["NUBES_API_ENDPOINT"], + current_app.config["NUBES_API_TOKEN"], + ) + org = get_organization(client) + except Exception as e: + error = str(e) + return render_template("index.html", organization=org, error=error) diff --git a/site/templates/index.html b/site/templates/index.html index ee65470..34f461e 100644 --- a/site/templates/index.html +++ b/site/templates/index.html @@ -3,14 +3,38 @@ Autotest + + -
-
Autotest
+
+
Организация
-

OK

+ {% if organization %} + + + + + + + + + + + + + + + + + +
ИмяinstanceUidСервисСтатус
{{ organization.displayName }}{{ organization.instanceUid }}{{ organization.svc }}{{ organization.explainedStatus or "OK" }}
+ {% else %} +

{% if error %}Ошибка: {{ error }}{% else %}Организация не найдена.{% endif %}

+ {% endif %}
+