Strip to minimal: single route, static HTML, no logic

This commit is contained in:
2026-07-23 11:10:33 +04:00
parent 420d09e6b5
commit 6cb8c05f05
9 changed files with 21 additions and 141 deletions
View File
-27
View File
@@ -1,27 +0,0 @@
"""HTTP-клиент Nubes API — только Bearer + User-Agent."""
import requests
class HttpClient:
"""Минимальная обёртка над requests для API облака."""
def __init__(self, endpoint: str, token: str):
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: str, **kwargs) -> dict:
kwargs.setdefault("timeout", 10)
r = self._session.get(f"{self._endpoint}{path}", **kwargs)
r.raise_for_status()
return r.json()
def post(self, path: str, data: dict, **kwargs) -> dict:
kwargs.setdefault("timeout", 30)
r = self._session.post(f"{self._endpoint}{path}", json=data, **kwargs)
r.raise_for_status()
return r.json()
+7 -11
View File
@@ -1,18 +1,14 @@
"""Точка входа — запускается как python site/app.py."""
"""Точка входа — минимальное приложение."""
import os
import sys
# site/ не может быть пакетом (конфликт с stdlib site.py)
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from flask import Flask
from routes.main import bp as main_bp
NUBES_API_ENDPOINT = os.getenv("NUBES_API_ENDPOINT", "https://lk-api-gateway-dev.ngcloud.ru/api/v1/svc")
NUBES_API_TOKEN = os.getenv("NUBES_API_TOKEN", "")
from flask import Flask, render_template
app = Flask(__name__)
app.config["NUBES_API_ENDPOINT"] = NUBES_API_ENDPOINT
app.config["NUBES_API_TOKEN"] = NUBES_API_TOKEN
app.register_blueprint(main_bp)
@app.route("/")
def index():
return render_template("index.html")
View File
-18
View File
@@ -1,18 +0,0 @@
"""GET /instances — получить список инстансов пользователя."""
from api.http_client import HttpClient
def get_instances(client: HttpClient) -> list[dict]:
"""Возвращает все инстансы текущего пользователя."""
data = client.get("/instances", params={"pageSize": 200})
return data.get("results", [])
def get_organization(client: HttpClient) -> dict | None:
"""Найти организацию среди инстансов (svcId=19)."""
instances = get_instances(client)
for inst in instances:
if inst.get("serviceId") == 19:
return inst
return None
View File
-23
View File
@@ -1,23 +0,0 @@
"""Главная страница — blueprint."""
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)
-20
View File
@@ -1,20 +0,0 @@
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{% block title %}Autotest Nubes{% endblock %}</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>
{% block head %}{% endblock %}
</head>
<body>
<div class="layout">
<main class="content">
{% block content %}{% endblock %}
</main>
</div>
<script>lucide.createIcons();</script>
</body>
</html>
+13 -41
View File
@@ -1,44 +1,16 @@
{% extends "base.html" %}
{% block title %}Autotest Nubes{% endblock %}
{% block content %}
<div class="card" style="max-width: 780px; margin: 32px auto;">
<div class="card-header">
<i data-lucide="cloud" style="width: 16px; height: 16px; margin-right: 6px;"></i>
Организация
</div>
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8" />
<title>Autotest</title>
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}" />
</head>
<body>
<div class="card" style="max-width: 400px; margin: 48px auto;">
<div class="card-header">Autotest</div>
<div class="card-body">
{% 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">
<i data-lucide="check" style="width: 12px; height: 12px;"></i>
{{ organization.state.explainedStatus or "OK" }}
</span>
</td>
</tr>
</tbody>
</table>
{% else %}
<div class="empty">
<i data-lucide="alert-circle" style="width: 24px; height: 24px; color: var(--muted);"></i>
<p>{% if error %}Ошибка: {{ error }}{% else %}Организация не найдена.{% endif %}</p>
</div>
{% endif %}
<p>OK</p>
</div>
</div>
{% endblock %}
</body>
</html>