oncall-engine/tools/migrators/lib/session.py
Joey Orlando e4728ea69f
feat: add opsgenie to migrator script (#5495)
This PR adds support for migrating data from OpsGenie to Grafana IRM.

Closes https://github.com/grafana/irm/issues/1179
2025-04-07 08:47:27 -04:00

27 lines
724 B
Python

import os
import uuid
from pathlib import Path
# Use environment variable for session file location, with fallback
SESSION_FILE = Path(
os.environ.get("SESSION_FILE", str(Path(__file__).parent.parent / ".session"))
)
def get_or_create_session_id() -> str:
"""Get an existing session ID or create a new one if it doesn't exist."""
if os.path.exists(SESSION_FILE):
with open(SESSION_FILE, "r") as f:
return f.read().strip()
# Create new session ID
session_id = str(uuid.uuid4())
# Ensure directory exists
SESSION_FILE.parent.mkdir(parents=True, exist_ok=True)
# Save session ID
with open(SESSION_FILE, "w") as f:
f.write(session_id)
return session_id