v1.0.85: create_client(token) everywhere — single entry point stand detection; {{ stand }} in UI
This commit is contained in:
@@ -19,6 +19,22 @@ def detect_endpoint(token):
|
||||
return None
|
||||
|
||||
|
||||
def stand_name(endpoint):
|
||||
"""dev/test по URL стенда."""
|
||||
for name in ("dev", "test"):
|
||||
if name in (endpoint or ""):
|
||||
return name
|
||||
return "?"
|
||||
|
||||
|
||||
def create_client(token, fallback_endpoint=None):
|
||||
"""HttpClient с автоопределением стенда по токену."""
|
||||
ep = detect_endpoint(token) or fallback_endpoint
|
||||
if not ep:
|
||||
return None
|
||||
return HttpClient(ep, token), ep
|
||||
|
||||
|
||||
class HttpClient:
|
||||
def __init__(self, endpoint, token):
|
||||
self._endpoint = endpoint.rstrip("/")
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ from routes.main import bp as main_bp
|
||||
from routes.api import bp as api_bp
|
||||
from routes.api_test import bp as api_test_bp
|
||||
|
||||
VERSION = "1.0.84"
|
||||
VERSION = "1.0.85"
|
||||
|
||||
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")
|
||||
|
||||
+7
-1
@@ -2,6 +2,7 @@ import threading
|
||||
|
||||
from flask import Blueprint, current_app, jsonify, request
|
||||
|
||||
from api.http_client import create_client
|
||||
from runner import run_tests, get_status, load_config, save_config
|
||||
|
||||
bp = Blueprint("api", __name__)
|
||||
@@ -9,9 +10,14 @@ bp = Blueprint("api", __name__)
|
||||
|
||||
@bp.route("/api/run", methods=["POST"])
|
||||
def api_run():
|
||||
token = current_app.config["NUBES_API_TOKEN"]
|
||||
result = create_client(token, current_app.config["NUBES_API_ENDPOINT"])
|
||||
if not result:
|
||||
return jsonify({"error": "Не удалось определить стенд"}), 500
|
||||
client, endpoint = result
|
||||
t = threading.Thread(
|
||||
target=run_tests,
|
||||
args=(current_app.config["NUBES_API_ENDPOINT"], current_app.config["NUBES_API_TOKEN"]),
|
||||
args=(endpoint, token),
|
||||
daemon=True,
|
||||
)
|
||||
t.start()
|
||||
|
||||
+11
-5
@@ -1,6 +1,6 @@
|
||||
from flask import Blueprint, current_app, render_template, request, make_response, jsonify, redirect
|
||||
|
||||
from api.http_client import HttpClient, detect_endpoint
|
||||
from api.http_client import HttpClient, detect_endpoint, create_client, stand_name
|
||||
from operations.get_instances import get_organization, get_instances
|
||||
from operations.get_services import get_services, get_service_detail
|
||||
from operations.tracker import list_all as tracker_list
|
||||
@@ -84,6 +84,7 @@ def index():
|
||||
"client_id": _client_id(active_token),
|
||||
"token_info": _token_info(active_token),
|
||||
"config": config,
|
||||
"stand": stand,
|
||||
"services": services,
|
||||
"instances": instances,
|
||||
"instance_groups": instance_groups,
|
||||
@@ -110,11 +111,13 @@ def index():
|
||||
instances = []
|
||||
instance_groups = {}
|
||||
config = {}
|
||||
stand = "?"
|
||||
if active_token:
|
||||
endpoint = detect_endpoint(active_token)
|
||||
if endpoint:
|
||||
result = create_client(active_token, current_app.config["NUBES_API_ENDPOINT"])
|
||||
if result:
|
||||
client, endpoint = result
|
||||
stand = stand_name(endpoint)
|
||||
try:
|
||||
client = HttpClient(endpoint, active_token)
|
||||
org = get_organization(client)
|
||||
raw_svc = get_services(client)
|
||||
services = sorted(raw_svc, key=lambda s: (s.get("svcId", 0), s.get("svc", "")))
|
||||
@@ -149,7 +152,10 @@ def api_operations(svc_id):
|
||||
user_token = request.cookies.get("token") or ""
|
||||
active_token = user_token or env_token
|
||||
try:
|
||||
client = HttpClient(current_app.config["NUBES_API_ENDPOINT"], active_token)
|
||||
result = create_client(active_token, current_app.config["NUBES_API_ENDPOINT"])
|
||||
if not result:
|
||||
return jsonify({"error": "Не удалось определить стенд"}), 500
|
||||
client, _ = result
|
||||
detail = get_service_detail(client, svc_id)
|
||||
ops = detail.get("operations", [])
|
||||
tracked = tracker_list()
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
<div class="topbar">
|
||||
<img src="{{ url_for('static', filename='logo.svg') }}" alt="Nubes" style="height:22px;" />
|
||||
<span style="font-size:11px;color:var(--muted);">v{{ config.VERSION }}</span>
|
||||
{% if token_info.email %}<span style="font-size:11px;color:var(--muted);">{{ token_info.email }} | {{ token_info.company }} | test</span>{% endif %}
|
||||
{% if token_info.email %}<span style="font-size:11px;color:var(--muted);" title="{{ token_info.email }} · {{ token_info.company }} · стенд: {{ stand }}">{{ token_info.email }} | {{ token_info.company }} | {{ stand }}</span>{% endif %}
|
||||
<span style="flex:1;"></span>
|
||||
<form method="post" style="display:flex;align-items:center;gap:6px;">
|
||||
<input type="password" name="token" placeholder="env: {{ env_token_masked }}" value="{{ '' if not has_user_token else '••••••••' }}" style="height:28px;width:180px;font-size:12px;border:1px solid var(--brand-gray);border-radius:4px;padding:0 6px;" />
|
||||
|
||||
Reference in New Issue
Block a user