mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-08-27 20:40:13 +03:00
Fix review issues: key_prefix length, count validation, WAL log, timeout comment, pointless temp var
This commit is contained in:
parent
533d3d5b71
commit
59e5f8dd2f
@ -314,7 +314,7 @@ class Gns3Connector:
|
||||
"headers": headers,
|
||||
"params": params,
|
||||
"verify": verify,
|
||||
"timeout": 30.0,
|
||||
"timeout": 30.0, # Main request timeout (auth call uses 10s)
|
||||
}
|
||||
if data is not None:
|
||||
kwargs["data"] = data
|
||||
|
||||
@ -65,6 +65,10 @@ def batch_allocate_udp_ports(project_id: UUID, body: dict) -> dict:
|
||||
"""
|
||||
|
||||
count = body.get("count", 1)
|
||||
try:
|
||||
count = max(1, min(int(count), 10000))
|
||||
except (ValueError, TypeError):
|
||||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="count must be a positive integer")
|
||||
pm = ProjectManager.instance()
|
||||
project = pm.get_project(str(project_id))
|
||||
m = PortManager.instance()
|
||||
|
||||
@ -46,7 +46,7 @@ def _generate_api_key(api_key_id: UUID = None) -> tuple[str, str, str, UUID]:
|
||||
raw_key = f"gns3_{api_key_id}_{random_bytes}"
|
||||
# Only hash the random secret part, so auth can extract api_key_id and do O(1) lookup
|
||||
key_hash = bcrypt.hashpw(random_bytes.encode(), bcrypt.gensalt()).decode()
|
||||
key_prefix = raw_key[: len(API_KEY_PREFIX) + 8]
|
||||
key_prefix = raw_key[:8]
|
||||
return raw_key, key_hash, key_prefix, api_key_id
|
||||
|
||||
|
||||
|
||||
@ -618,6 +618,4 @@ async def create_node_from_template(
|
||||
node = await project.add_node_from_template(
|
||||
template, x=template_usage.x, y=template_usage.y, name=template_usage.name, compute_id=template_usage.compute_id
|
||||
)
|
||||
|
||||
result = node.asdict()
|
||||
return result
|
||||
return node.asdict()
|
||||
|
||||
@ -98,7 +98,9 @@ async def connect_to_db(app: FastAPI) -> None:
|
||||
cursor.close()
|
||||
return row[0] if row else "unknown"
|
||||
wal_mode = await _verify_conn.run_sync(_check_wal)
|
||||
log.info(f"SQLite journal mode: {wal_mode} {'✅' if wal_mode and wal_mode.upper() == 'WAL' else '❌ will cause database contention'}")
|
||||
log.info(f"SQLite journal mode: {wal_mode}")
|
||||
if wal_mode and wal_mode.upper() != "WAL":
|
||||
log.warning("WAL mode not active - concurrent writes may cause 'database is locked' errors")
|
||||
alembic_cfg = config.Config()
|
||||
alembic_cfg.set_main_option("script_location", "gns3server:db_migrations")
|
||||
#alembic_cfg.set_main_option('sqlalchemy.url', db_url)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user