Strip to minimal: single route, static HTML, no logic
This commit is contained in:
@@ -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
@@ -1,18 +1,14 @@
|
|||||||
"""Точка входа — запускается как python site/app.py."""
|
"""Точка входа — минимальное приложение."""
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
# site/ не может быть пакетом (конфликт с stdlib site.py)
|
|
||||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
from flask import Flask
|
from flask import Flask, render_template
|
||||||
|
|
||||||
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", "")
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
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")
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -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)
|
|
||||||
@@ -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
@@ -1,44 +1,16 @@
|
|||||||
{% extends "base.html" %}
|
<!DOCTYPE html>
|
||||||
{% block title %}Autotest Nubes{% endblock %}
|
<html lang="ru">
|
||||||
{% block content %}
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
<div class="card" style="max-width: 780px; margin: 32px auto;">
|
<title>Autotest</title>
|
||||||
<div class="card-header">
|
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}" />
|
||||||
<i data-lucide="cloud" style="width: 16px; height: 16px; margin-right: 6px;"></i>
|
</head>
|
||||||
Организация
|
<body>
|
||||||
</div>
|
<div class="card" style="max-width: 400px; margin: 48px auto;">
|
||||||
|
<div class="card-header">Autotest</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
{% if organization %}
|
<p>OK</p>
|
||||||
<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>
|
</div>
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</body>
|
||||||
|
</html>
|
||||||
{% endblock %}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user