v1.0.85: create_client(token) everywhere — single entry point stand detection; {{ stand }} in UI
This commit is contained in:
+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()
|
||||
|
||||
Reference in New Issue
Block a user