Spaces:
Building
Building
Update config_provider.py
Browse files- config_provider.py +42 -60
config_provider.py
CHANGED
@@ -10,6 +10,7 @@ from datetime import datetime
|
|
10 |
from pathlib import Path
|
11 |
import tempfile
|
12 |
import shutil
|
|
|
13 |
|
14 |
from config_models import (
|
15 |
ServiceConfig, GlobalConfig, ProjectConfig, VersionConfig,
|
@@ -168,7 +169,7 @@ class ConfigProvider:
|
|
168 |
)
|
169 |
|
170 |
# Update metadata
|
171 |
-
config.last_update_date =
|
172 |
config.last_update_user = username
|
173 |
|
174 |
# Convert to JSON
|
@@ -252,7 +253,7 @@ class ConfigProvider:
|
|
252 |
# Create project
|
253 |
project = ProjectConfig(
|
254 |
id=config.project_id_counter,
|
255 |
-
created_date=
|
256 |
created_by=username,
|
257 |
**project_data
|
258 |
)
|
@@ -291,31 +292,22 @@ class ConfigProvider:
|
|
291 |
|
292 |
# Check race condition
|
293 |
if expected_last_update is not None and expected_last_update != '':
|
294 |
-
if project.last_update_date:
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
log_info(f"🔍 Date mismatch - Expected: {expected_normalized}, Actual: {actual_normalized}")
|
304 |
-
raise RaceConditionError(
|
305 |
-
f"Project '{project.name}' was modified by another user",
|
306 |
-
current_user=username,
|
307 |
-
last_update_user=project.last_update_user,
|
308 |
-
last_update_date=project.last_update_date,
|
309 |
-
entity_type="project",
|
310 |
-
entity_id=project_id
|
311 |
-
)
|
312 |
|
313 |
# Update fields
|
314 |
for key, value in update_data.items():
|
315 |
if hasattr(project, key) and key not in ['id', 'created_date', 'created_by', 'last_update_date', 'last_update_user']:
|
316 |
setattr(project, key, value)
|
317 |
|
318 |
-
project.last_update_date =
|
319 |
project.last_update_user = username
|
320 |
|
321 |
# Log activity
|
@@ -346,7 +338,7 @@ class ConfigProvider:
|
|
346 |
raise ResourceNotFoundError("project", project_id)
|
347 |
|
348 |
project.deleted = True
|
349 |
-
project.last_update_date =
|
350 |
project.last_update_user = username
|
351 |
|
352 |
# Log activity
|
@@ -379,7 +371,7 @@ class ConfigProvider:
|
|
379 |
# Create version
|
380 |
version = VersionConfig(
|
381 |
no=project.version_id_counter,
|
382 |
-
created_date=
|
383 |
created_by=username,
|
384 |
**version_data
|
385 |
)
|
@@ -387,7 +379,7 @@ class ConfigProvider:
|
|
387 |
# Update project
|
388 |
project.versions.append(version)
|
389 |
project.version_id_counter += 1
|
390 |
-
project.last_update_date =
|
391 |
project.last_update_user = username
|
392 |
|
393 |
# Log activity
|
@@ -430,11 +422,11 @@ class ConfigProvider:
|
|
430 |
|
431 |
# Publish this version
|
432 |
version.published = True
|
433 |
-
version.publish_date =
|
434 |
version.published_by = username
|
435 |
|
436 |
# Update project
|
437 |
-
project.last_update_date =
|
438 |
project.last_update_user = username
|
439 |
|
440 |
# Log activity
|
@@ -476,31 +468,26 @@ class ConfigProvider:
|
|
476 |
|
477 |
# Check race condition
|
478 |
if expected_last_update is not None and expected_last_update != '':
|
479 |
-
if version.last_update_date:
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
last_update_user=version.last_update_user,
|
489 |
-
last_update_date=version.last_update_date,
|
490 |
-
entity_type="version",
|
491 |
-
entity_id=f"{project_id}:{version_no}"
|
492 |
-
)
|
493 |
|
494 |
# Update fields
|
495 |
for key, value in update_data.items():
|
496 |
if hasattr(version, key) and key not in ['no', 'created_date', 'created_by', 'published', 'last_update_date']:
|
497 |
setattr(version, key, value)
|
498 |
|
499 |
-
version.last_update_date =
|
500 |
version.last_update_user = username
|
501 |
|
502 |
# Update project last update
|
503 |
-
project.last_update_date =
|
504 |
project.last_update_user = username
|
505 |
|
506 |
# Log activity
|
@@ -535,7 +522,7 @@ class ConfigProvider:
|
|
535 |
|
536 |
# Create API
|
537 |
api = APIConfig(
|
538 |
-
created_date=
|
539 |
created_by=username,
|
540 |
**api_data
|
541 |
)
|
@@ -575,27 +562,22 @@ class ConfigProvider:
|
|
575 |
|
576 |
# Check race condition
|
577 |
if expected_last_update is not None and expected_last_update != '':
|
578 |
-
if api.last_update_date:
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
last_update_user=api.last_update_user,
|
588 |
-
last_update_date=api.last_update_date,
|
589 |
-
entity_type="api",
|
590 |
-
entity_id=api.name
|
591 |
-
)
|
592 |
|
593 |
# Update fields
|
594 |
for key, value in update_data.items():
|
595 |
if hasattr(api, key) and key not in ['name', 'created_date', 'created_by', 'last_update_date']:
|
596 |
setattr(api, key, value)
|
597 |
|
598 |
-
api.last_update_date =
|
599 |
api.last_update_user = username
|
600 |
|
601 |
# Rebuild index
|
@@ -629,7 +611,7 @@ class ConfigProvider:
|
|
629 |
raise ResourceNotFoundError("api", api_name)
|
630 |
|
631 |
api.deleted = True
|
632 |
-
api.last_update_date =
|
633 |
api.last_update_user = username
|
634 |
|
635 |
# Rebuild index
|
@@ -665,7 +647,7 @@ class ConfigProvider:
|
|
665 |
) -> None:
|
666 |
"""Add activity log entry"""
|
667 |
activity = ActivityLogEntry(
|
668 |
-
timestamp=
|
669 |
username=username,
|
670 |
action=action,
|
671 |
entity_type=entity_type,
|
|
|
10 |
from pathlib import Path
|
11 |
import tempfile
|
12 |
import shutil
|
13 |
+
from utils import get_current_timestamp, timestamps_equal
|
14 |
|
15 |
from config_models import (
|
16 |
ServiceConfig, GlobalConfig, ProjectConfig, VersionConfig,
|
|
|
169 |
)
|
170 |
|
171 |
# Update metadata
|
172 |
+
config.last_update_date = get_current_timestamp()
|
173 |
config.last_update_user = username
|
174 |
|
175 |
# Convert to JSON
|
|
|
253 |
# Create project
|
254 |
project = ProjectConfig(
|
255 |
id=config.project_id_counter,
|
256 |
+
created_date=get_current_timestamp(),
|
257 |
created_by=username,
|
258 |
**project_data
|
259 |
)
|
|
|
292 |
|
293 |
# Check race condition
|
294 |
if expected_last_update is not None and expected_last_update != '':
|
295 |
+
if project.last_update_date and not timestamps_equal(expected_last_update, project.last_update_date):
|
296 |
+
raise RaceConditionError(
|
297 |
+
f"Project '{project.name}' was modified by another user",
|
298 |
+
current_user=username,
|
299 |
+
last_update_user=project.last_update_user,
|
300 |
+
last_update_date=project.last_update_date,
|
301 |
+
entity_type="project",
|
302 |
+
entity_id=project_id
|
303 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
304 |
|
305 |
# Update fields
|
306 |
for key, value in update_data.items():
|
307 |
if hasattr(project, key) and key not in ['id', 'created_date', 'created_by', 'last_update_date', 'last_update_user']:
|
308 |
setattr(project, key, value)
|
309 |
|
310 |
+
project.last_update_date = get_current_timestamp()
|
311 |
project.last_update_user = username
|
312 |
|
313 |
# Log activity
|
|
|
338 |
raise ResourceNotFoundError("project", project_id)
|
339 |
|
340 |
project.deleted = True
|
341 |
+
project.last_update_date = get_current_timestamp()
|
342 |
project.last_update_user = username
|
343 |
|
344 |
# Log activity
|
|
|
371 |
# Create version
|
372 |
version = VersionConfig(
|
373 |
no=project.version_id_counter,
|
374 |
+
created_date=get_current_timestamp(),
|
375 |
created_by=username,
|
376 |
**version_data
|
377 |
)
|
|
|
379 |
# Update project
|
380 |
project.versions.append(version)
|
381 |
project.version_id_counter += 1
|
382 |
+
project.last_update_date = get_current_timestamp()
|
383 |
project.last_update_user = username
|
384 |
|
385 |
# Log activity
|
|
|
422 |
|
423 |
# Publish this version
|
424 |
version.published = True
|
425 |
+
version.publish_date = get_current_timestamp()
|
426 |
version.published_by = username
|
427 |
|
428 |
# Update project
|
429 |
+
project.last_update_date = get_current_timestamp()
|
430 |
project.last_update_user = username
|
431 |
|
432 |
# Log activity
|
|
|
468 |
|
469 |
# Check race condition
|
470 |
if expected_last_update is not None and expected_last_update != '':
|
471 |
+
if version.last_update_date and not timestamps_equal(expected_last_update, version.last_update_date):
|
472 |
+
raise RaceConditionError(
|
473 |
+
f"Version '{version.no}' was modified by another user",
|
474 |
+
current_user=username,
|
475 |
+
last_update_user=version.last_update_user,
|
476 |
+
last_update_date=version.last_update_date,
|
477 |
+
entity_type="version",
|
478 |
+
entity_id=f"{project_id}:{version_no}"
|
479 |
+
)
|
|
|
|
|
|
|
|
|
|
|
480 |
|
481 |
# Update fields
|
482 |
for key, value in update_data.items():
|
483 |
if hasattr(version, key) and key not in ['no', 'created_date', 'created_by', 'published', 'last_update_date']:
|
484 |
setattr(version, key, value)
|
485 |
|
486 |
+
version.last_update_date = get_current_timestamp()
|
487 |
version.last_update_user = username
|
488 |
|
489 |
# Update project last update
|
490 |
+
project.last_update_date = get_current_timestamp()
|
491 |
project.last_update_user = username
|
492 |
|
493 |
# Log activity
|
|
|
522 |
|
523 |
# Create API
|
524 |
api = APIConfig(
|
525 |
+
created_date=get_current_timestamp(),
|
526 |
created_by=username,
|
527 |
**api_data
|
528 |
)
|
|
|
562 |
|
563 |
# Check race condition
|
564 |
if expected_last_update is not None and expected_last_update != '':
|
565 |
+
if api.last_update_date and not timestamps_equal(expected_last_update, api.last_update_date):
|
566 |
+
raise RaceConditionError(
|
567 |
+
f"API '{api.name}' was modified by another user",
|
568 |
+
current_user=username,
|
569 |
+
last_update_user=api.last_update_user,
|
570 |
+
last_update_date=api.last_update_date,
|
571 |
+
entity_type="api",
|
572 |
+
entity_id=api.name
|
573 |
+
)
|
|
|
|
|
|
|
|
|
|
|
574 |
|
575 |
# Update fields
|
576 |
for key, value in update_data.items():
|
577 |
if hasattr(api, key) and key not in ['name', 'created_date', 'created_by', 'last_update_date']:
|
578 |
setattr(api, key, value)
|
579 |
|
580 |
+
api.last_update_date = get_current_timestamp()
|
581 |
api.last_update_user = username
|
582 |
|
583 |
# Rebuild index
|
|
|
611 |
raise ResourceNotFoundError("api", api_name)
|
612 |
|
613 |
api.deleted = True
|
614 |
+
api.last_update_date = get_current_timestamp()
|
615 |
api.last_update_user = username
|
616 |
|
617 |
# Rebuild index
|
|
|
647 |
) -> None:
|
648 |
"""Add activity log entry"""
|
649 |
activity = ActivityLogEntry(
|
650 |
+
timestamp=get_current_timestamp(),
|
651 |
username=username,
|
652 |
action=action,
|
653 |
entity_type=entity_type,
|