Add modules: api, operations, routes with org display

This commit is contained in:
2026-07-23 11:28:11 +04:00
parent 5c16e75b0a
commit 51f4508c1d
6 changed files with 86 additions and 9 deletions
View File
+17
View File
@@ -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()
+8 -6
View File
@@ -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__":
+13
View File
@@ -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
+21
View File
@@ -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)
+27 -3
View File
@@ -3,14 +3,38 @@
<head>
<meta charset="UTF-8" />
<title>Autotest</title>
<link rel="icon" type="image/svg+xml" href="{{ url_for('static', filename='favicon.svg') }}" />
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}" />
<script src="https://unpkg.com/lucide@latest"></script>
</head>
<body>
<div class="card" style="max-width: 400px; margin: 48px auto;">
<div class="card-header">Autotest</div>
<div class="card" style="max-width: 780px; margin: 32px auto;">
<div class="card-header">Организация</div>
<div class="card-body">
<p>OK</p>
{% if organization %}
<table>
<thead>
<tr>
<th>Имя</th>
<th>instanceUid</th>
<th>Сервис</th>
<th>Статус</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ organization.displayName }}</td>
<td style="font-family: monospace; font-size: 12px;">{{ organization.instanceUid }}</td>
<td>{{ organization.svc }}</td>
<td><span class="badge badge-success">{{ organization.explainedStatus or "OK" }}</span></td>
</tr>
</tbody>
</table>
{% else %}
<p style="color: var(--muted);">{% if error %}Ошибка: {{ error }}{% else %}Организация не найдена.{% endif %}</p>
{% endif %}
</div>
</div>
<script>lucide.createIcons();</script>
</body>
</html>