Add modules: api, operations, routes with org display
This commit is contained in:
@@ -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
@@ -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 = Flask(__name__, template_folder="templates", static_folder="static")
|
||||||
|
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.route("/")
|
app.register_blueprint(main_bp)
|
||||||
def index():
|
|
||||||
return render_template("index.html")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -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)
|
||||||
@@ -3,14 +3,38 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<title>Autotest</title>
|
<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') }}" />
|
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}" />
|
||||||
|
<script src="https://unpkg.com/lucide@latest"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="card" style="max-width: 400px; margin: 48px auto;">
|
<div class="card" style="max-width: 780px; margin: 32px auto;">
|
||||||
<div class="card-header">Autotest</div>
|
<div class="card-header">Организация</div>
|
||||||
<div class="card-body">
|
<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>
|
||||||
</div>
|
</div>
|
||||||
|
<script>lucide.createIcons();</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user