╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ net.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1416 .id = std.fmt.bytesToHex(user_id, .lower), 1417 .author = .{ .name = "admin", .email = "admin@example.test" }, 1418 .event = .{ .user = .{ 1419 .name = "admin", 1420 .email = "admin@example.test", 1421 .password_hash = password_hash, 1422 .ssh_keys = admin_ssh_key, 1423 } }, 1424 }}); 1425 } 1426 1427 // resolve admin/<repo_name> to its on-disk directory under <data_dir>/repos via 1428 // the event store 1429 fn repoOnDiskPath( 1430 io: std.Io, 1431 allocator: std.mem.Allocator, 1432 data_dir_name: []const u8, 1433 repo_name: []const u8, 1434 create: bool, 1435 ) !?[]u8 { 1436 const cwd_path = try std.process.currentPathAlloc(io, allocator); 1437 defer allocator.free(cwd_path); 1438 1439 const admin_repo_path = try std.fs.path.join(allocator, &.{ cwd_path, data_dir_name, "admin" }); 1440 defer allocator.free(admin_repo_path); 1441 1442 const event_id_hex = (try evt.resolveOrCreateRepo(io, allocator, admin_repo_path, "admin", repo_name, create)) orelse return null; 1443 return try std.fs.path.join(allocator, &.{ cwd_path, data_dir_name, "repos", &event_id_hex }); 1444 } 1445 1446 // build the remote URL addressing admin/<repo_name> over the given transport 1447 fn remoteUrl( 1448 comptime transport_def: net.TransportDefinition, 1449 allocator: std.mem.Allocator, 1450 repo_name: []const u8, 1451 port: u16, 1452 ) ![]u8 { 1453 return switch (transport_def) { 1454 .file => unreachable, 1455 .wire => |wire_kind| switch (wire_kind) { 1456 .http => try std.fmt.allocPrint(allocator, "http://localhost:{}/admin/{s}", .{ port, repo_name }), 1457 .raw => try std.fmt.allocPrint(allocator, "git://localhost:{}/admin/{s}", .{ port, repo_name }), 1458 .ssh => try std.fmt.allocPrint(allocator, "git@localhost:admin/{s}", .{repo_name}), 1459 }, 1460 }; 1461 } 1462 1463 // the ssh command the haxy git client should invoke, or null when not using 1464 // ssh. haxy generates a fresh host key on every run, so accept the unknown host 1465 // and skip writing to known_hosts. 1466 fn sshCommand( 1467 is_ssh: bool, 1468 allocator: std.mem.Allocator, 1469 cwd_path: []const u8, 1470 temp_dir_name: []const u8, 1471 port: u16, 1472 ) !?[]u8 { 1473 if (!is_ssh) return null; 1474 1475 const priv_key_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "key" }); 1476 defer allocator.free(priv_key_path); 1477 1478 return try std.fmt.allocPrint(allocator, "ssh -p {} -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR -o IdentitiesOnly=yes -o IdentityFile=\"{s}\"", .{ port + 1, priv_key_path }); 1479 } 1480