import { execSync } from 'child_process';
import { z } from 'zod';
export function authorizeSshCommand(keyId: string, originalCommand: string): boolean {
// Validate basic git SSH patterns: git-upload-pack 'owner/repo.git'
const commandMatch = originalCommand.match(/^(git-receive-pack|git-upload-pack|git-upload-archive)\s+'(.+)'$/);
if (!commandMatch) {
return false; // Reject interactive shell access or unknown commands
}
const [_, gitCommand, repository] = commandMatch;
const isPush = gitCommand === 'git-receive-pack';
// Here we would lookup the specific public key via Db or API to determine
// if user tied to keyId has WRITE or READ access to `repository`.
console.log(`Intercepted SSH command [${gitCommand}] for repo [${repository}] authenticated via key [${keyId}]`);
// E.g.
// const user = await db.query(Keys).where(eq(keyId)).first();
// const hasAccess = await checkPermissions(user, repository, isPush ? 'WRITE' : 'READ');
return true; // Simplified placeholder
}