Enforce authenticated user and login validation in workspace operations, crashing program on failure instead of fallback defaults

This commit is contained in:
Michael Ingvarsson
2026-07-16 12:36:54 +02:00
parent c5dd178fd6
commit f08c7b64c1
2 changed files with 69 additions and 26 deletions
+25 -26
View File
@@ -22,11 +22,13 @@ class WorkspaceManager:
try:
client = GiteaClient()
user = client.get_authenticated_user()
username = user.login if user else "unknown-ai"
if not user or not user.login:
raise RuntimeError("No authenticated user found.")
username: str = user.login
auth_str = f"{username}:{GITEA_TOKEN}"
auth_bytes = auth_str.encode("utf-8")
auth_b64 = base64.b64encode(auth_bytes).decode("utf-8")
auth_str: str = f"{username}:{GITEA_TOKEN}"
auth_bytes: bytes = auth_str.encode("utf-8")
auth_b64: str = base64.b64encode(auth_bytes).decode("utf-8")
# Configure extraHeader locally for the repo
subprocess.run(
@@ -34,19 +36,19 @@ class WorkspaceManager:
check=True, capture_output=True
)
if user:
name = user.full_name or user.login or "unknown-ai"
email = user.email or f"{user.login or 'agent'}@noreply.gitea"
subprocess.run(
["git", "-C", str(repo_path), "config", "user.name", name],
check=True, capture_output=True
)
subprocess.run(
["git", "-C", str(repo_path), "config", "user.email", email],
check=True, capture_output=True
)
name: str = user.full_name or user.login
email: str = user.email or f"{user.login}@noreply.gitea"
subprocess.run(
["git", "-C", str(repo_path), "config", "user.name", name],
check=True, capture_output=True
)
subprocess.run(
["git", "-C", str(repo_path), "config", "user.email", email],
check=True, capture_output=True
)
except Exception as e:
logger.error(f"Error configuring local git user: {e}")
raise
def get_repo_path(self, repo_full_name: str) -> Path:
parts: list[str] = repo_full_name.split("/")
@@ -109,18 +111,15 @@ class WorkspaceManager:
logger.info(f"Cloning repository {repo_full_name} to {repo_path}...")
auth_url = self._get_authenticated_url(repo_full_name)
username = "unknown-ai"
try:
client = GiteaClient()
user = client.get_authenticated_user()
if user:
username = user.login
except Exception:
pass
client = GiteaClient()
user = client.get_authenticated_user()
if not user or not user.login:
raise RuntimeError("No authenticated user found.")
username: str = user.login
auth_str = f"{username}:{GITEA_TOKEN}"
auth_bytes = auth_str.encode("utf-8")
auth_b64 = base64.b64encode(auth_bytes).decode("utf-8")
auth_str: str = f"{username}:{GITEA_TOKEN}"
auth_bytes: bytes = auth_str.encode("utf-8")
auth_b64: str = base64.b64encode(auth_bytes).decode("utf-8")
subprocess.run(
["git", "clone", "-c", f"http.extraHeader=Authorization: Basic {auth_b64}", auth_url, str(repo_path)],
check=True, capture_output=True