Extract instanceUid from Location header, v1.0.9
This commit is contained in:
@@ -20,7 +20,13 @@ class HttpClient:
|
|||||||
kwargs.setdefault("timeout", 30)
|
kwargs.setdefault("timeout", 30)
|
||||||
r = self._session.post(f"{self._endpoint}{path}", json=data, **kwargs)
|
r = self._session.post(f"{self._endpoint}{path}", json=data, **kwargs)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
|
result = {}
|
||||||
try:
|
try:
|
||||||
return r.json()
|
result = r.json()
|
||||||
except Exception:
|
except Exception:
|
||||||
return {}
|
pass
|
||||||
|
# instanceUid приходит в Location (для create)
|
||||||
|
loc = r.headers.get("Location", "")
|
||||||
|
if loc:
|
||||||
|
result["_location"] = loc
|
||||||
|
return result
|
||||||
|
|||||||
+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 import bp as api_bp
|
||||||
from routes.api_test import bp as api_test_bp
|
from routes.api_test import bp as api_test_bp
|
||||||
|
|
||||||
VERSION = "1.0.8"
|
VERSION = "1.0.9"
|
||||||
|
|
||||||
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_ENDPOINT"] = os.getenv("NUBES_API_ENDPOINT", "https://lk-api-gateway-dev.ngcloud.ru/api/v1/svc")
|
||||||
|
|||||||
@@ -95,6 +95,11 @@ def api_test():
|
|||||||
payload["cfsParams"] = [{"svcOperationCfsParamId": int(k), "paramValue": str(v)} for k, v in params.items()]
|
payload["cfsParams"] = [{"svcOperationCfsParamId": int(k), "paramValue": str(v)} for k, v in params.items()]
|
||||||
resp = client.post("/instances", payload)
|
resp = client.post("/instances", payload)
|
||||||
instance_uid = resp.get("instanceUid") or _find_uid(resp)
|
instance_uid = resp.get("instanceUid") or _find_uid(resp)
|
||||||
|
# Location header: /instances/{uid}
|
||||||
|
loc = resp.get("_location", "")
|
||||||
|
if not instance_uid and loc:
|
||||||
|
parts = loc.rstrip("/").split("/")
|
||||||
|
instance_uid = parts[-1] if len(parts[-1]) == 36 else None
|
||||||
|
|
||||||
# wait
|
# wait
|
||||||
deadline = time.time() + 300
|
deadline = time.time() + 300
|
||||||
|
|||||||
Reference in New Issue
Block a user