╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ net.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1761 .ssh_keys = admin_ssh_key, 1762 } }, 1763 }}); 1764 } 1765 1766 // resolve admin/<repo_name> to its on-disk directory under <data_dir>/repos via 1767 // the event store 1768 fn repoOnDiskPath( 1769 io: std.Io, 1770 allocator: std.mem.Allocator, 1771 data_dir_name: []const u8, 1772 repo_name: []const u8, 1773 create: bool, 1774 ) !?[]u8 { 1775 const cwd_path = try std.process.currentPathAlloc(io, allocator); 1776 defer allocator.free(cwd_path); 1777 1778 const admin_repo_path = try std.fs.path.join(allocator, &.{ cwd_path, data_dir_name, "admin" }); 1779 defer allocator.free(admin_repo_path); 1780 1781 const event_id_hex = (try evt.resolveOrCreateRepo( 1782 io, 1783 allocator, 1784 admin_repo_path, 1785 "admin", 1786 repo_name, 1787 if (create) .{ .read_access = .public } else null, 1788 )) orelse return null; 1789 return try std.fs.path.join(allocator, &.{ cwd_path, data_dir_name, "repos", &event_id_hex }); 1790 } 1791 1792 // build the remote URL addressing admin/<repo_name> over the given transport 1793 fn remoteUrl( 1794 comptime transport_def: net.TransportDefinition, 1795 allocator: std.mem.Allocator, 1796 repo_name: []const u8, 1797 port: u16, 1798 ) ![]u8 { 1799 return switch (transport_def) { 1800 .file => unreachable, 1801 .wire => |wire_kind| switch (wire_kind) { 1802 .http => try std.fmt.allocPrint(allocator, "http://localhost:{}/admin/{s}", .{ port, repo_name }), 1803 .raw => try std.fmt.allocPrint(allocator, "git://localhost:{}/admin/{s}", .{ port, repo_name }), 1804 .ssh => try std.fmt.allocPrint(allocator, "git@localhost:admin/{s}", .{repo_name}), 1805 }, 1806 }; 1807 } 1808 1809 // the ssh command the haxy git client should invoke, or null when not using 1810 // ssh. haxy generates a fresh host key on every run, so accept the unknown host 1811 // and skip writing to known_hosts. 1812 fn sshCommand( 1813 is_ssh: bool, 1814 allocator: std.mem.Allocator, 1815 cwd_path: []const u8, 1816 temp_dir_name: []const u8, 1817 port: u16, 1818 ) !?[]u8 { 1819 if (!is_ssh) return null; 1820 1821 const priv_key_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "key" }); 1822 defer allocator.free(priv_key_path); 1823 1824 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 }); 1825 } 1826