╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ User.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
288 _ = try kv_pair.key_cursor.readBytes(&user_id); 289 try user_ids.append(arena.allocator(), user_id); 290 } 291 return user_ids.items; 292 } 293 294 // whether the user holds the ssh key with this fingerprint 295 pub fn holdsKey( 296 comptime DB: type, 297 comptime hash_kind: hash.HashKind, 298 haxy_moment: DB.HashMap(.read_only), 299 arena: *std.heap.ArenaAllocator, 300 user_id: *const [evt.event_id_size]u8, 301 fingerprint: *const [ssh.fingerprint_len]u8, 302 ) !bool { 303 for (try readIdsByFingerprint(DB, hash_kind, haxy_moment, arena, fingerprint)) |holder_id| { 304 if (std.mem.eql(u8, &holder_id, user_id)) return true; 305 } 306 return false; 307 } 308 309 // a user's record map via the event-id->user index 310 fn userMap( 311 comptime DB: type, 312 comptime hash_kind: hash.HashKind, 313 haxy_moment: DB.HashMap(.read_only), 314 user_id: []const u8, 315 ) !?DB.HashMap(.read_only) { 316 const event_id_to_user_cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, "event-id->user")) orelse return null; 317 const event_id_to_user = try DB.HashMap(.read_only).init(event_id_to_user_cursor); 318 const user_cursor = try event_id_to_user.getCursor(hash.hashInt(hash_kind, user_id)) orelse return null; 319 return try DB.HashMap(.read_only).init(user_cursor); 320 } 321 322 // read a user by name from the admin event store, or null if the admin repo or 323 // the user doesn't exist. field byte slices are allocated in `arena`. 324 pub fn readByName( 325 io: std.Io, 326 allocator: std.mem.Allocator, 327 admin_repo_path: []const u8, 328 arena: *std.heap.ArenaAllocator, 329 name: []const u8, 330 ) !?Record { 331 var repo = rp.Repo(.xit, evt.admin_repo_opts).open(io, allocator, .{ .path = admin_repo_path }) catch |err| switch (err) { 332 error.RepoNotFound => return null, 333 else => |e| return e, 334 }; 335 defer repo.deinit(io, allocator); 336 337 const moment = try evt.currentMoment(evt.admin_repo_opts, &repo); 338 339 const user_id = try readIdByName(evt.AdminDB, evt.admin_repo_opts.hash, moment, name) orelse return null; 340 341 return try readById(evt.AdminDB, evt.admin_repo_opts.hash, moment, arena, &user_id); 342 } 343