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