Guilherme Silberfarb Costa commited on
Commit
8718a07
·
1 Parent(s): 3dc38bc

correcao de logs

Browse files
backend/app/services/audit_log_service.py CHANGED
@@ -3,7 +3,7 @@ from __future__ import annotations
3
  import json
4
  import os
5
  import uuid
6
- from datetime import datetime, timezone
7
  from io import BytesIO
8
  from pathlib import Path
9
  from threading import Lock
@@ -22,6 +22,7 @@ except Exception: # pragma: no cover
22
 
23
 
24
  LOGS_ROOT = "logs"
 
25
  _SCOPE_ALLOWED = {"auth", "repositorio", "elaboracao", "visualizacao", "geral"}
26
  _HF_LOCK = Lock()
27
  _HF_ROOT_READY: dict[str, bool] = {}
@@ -103,6 +104,10 @@ def _repo_path_for_event(scope: str, now: datetime) -> str:
103
  )
104
 
105
 
 
 
 
 
106
  def _build_record(
107
  scope: str,
108
  action: str,
@@ -113,7 +118,7 @@ def _build_record(
113
  details: dict[str, Any] | None,
114
  request: Request | None,
115
  ) -> dict[str, Any]:
116
- now = datetime.now(timezone.utc)
117
  return {
118
  "ts": now.isoformat(),
119
  "event_id": uuid.uuid4().hex,
@@ -222,7 +227,7 @@ def _append_record_remote(record: dict[str, Any], actor: str | None = None) -> N
222
  api, repo_id, revision, token = _hf_client_context()
223
  _ensure_logs_root_remote(api, repo_id, revision, token)
224
 
225
- timestamp = datetime.now(timezone.utc)
226
  scope = _sanitize_scope(str(record.get("scope") or "geral"))
227
  path_in_repo = _repo_path_for_event(scope, timestamp)
228
  line = json.dumps(sanitize_value(record), ensure_ascii=False)
 
3
  import json
4
  import os
5
  import uuid
6
+ from datetime import datetime, timedelta, timezone
7
  from io import BytesIO
8
  from pathlib import Path
9
  from threading import Lock
 
22
 
23
 
24
  LOGS_ROOT = "logs"
25
+ _TZ_GMT_MINUS_3 = timezone(timedelta(hours=-3), name="GMT-3")
26
  _SCOPE_ALLOWED = {"auth", "repositorio", "elaboracao", "visualizacao", "geral"}
27
  _HF_LOCK = Lock()
28
  _HF_ROOT_READY: dict[str, bool] = {}
 
104
  )
105
 
106
 
107
+ def _now_gmt_minus_3() -> datetime:
108
+ return datetime.now(_TZ_GMT_MINUS_3)
109
+
110
+
111
  def _build_record(
112
  scope: str,
113
  action: str,
 
118
  details: dict[str, Any] | None,
119
  request: Request | None,
120
  ) -> dict[str, Any]:
121
+ now = _now_gmt_minus_3()
122
  return {
123
  "ts": now.isoformat(),
124
  "event_id": uuid.uuid4().hex,
 
227
  api, repo_id, revision, token = _hf_client_context()
228
  _ensure_logs_root_remote(api, repo_id, revision, token)
229
 
230
+ timestamp = _now_gmt_minus_3()
231
  scope = _sanitize_scope(str(record.get("scope") or "geral"))
232
  path_in_repo = _repo_path_for_event(scope, timestamp)
233
  line = json.dumps(sanitize_value(record), ensure_ascii=False)