upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/git/authorization.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-12-03 08:54:00 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-12-03 08:54:00 +0000
commit2f8ecd482077d82f2d1a937c7f979eaaa87a27b2 (patch)
treecd892cde6ef6fd7ff654377946cab5b95339276f /src/git/authorization.rs
parent62a3855cb96616caf704a0f112fb2ade99fb8b45 (diff)
feat: implement LMDB database backend
- Add nostr-lmdb dependency (v0.44) for persistent storage - Create SharedDatabase type alias for database abstraction - Update all database-related functions to use trait object - Support runtime selection via NGIT_DATABASE_BACKEND env var Database backends: - memory: In-memory (default, fastest, no persistence) - lmdb: LMDB backend (persistent, general purpose) All 34 tests pass with the new implementation.
Diffstat (limited to 'src/git/authorization.rs')
-rw-r--r--src/git/authorization.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/git/authorization.rs b/src/git/authorization.rs
index 3b0e759..4896fc0 100644
--- a/src/git/authorization.rs
+++ b/src/git/authorization.rs
@@ -31,9 +31,9 @@ use anyhow::{anyhow, Result};
31use nostr_relay_builder::prelude::*; 31use nostr_relay_builder::prelude::*;
32use nostr_sdk::{EventId, ToBech32}; 32use nostr_sdk::{EventId, ToBech32};
33use std::collections::{HashMap, HashSet}; 33use std::collections::{HashMap, HashSet};
34use std::sync::Arc;
35use tracing::debug; 34use tracing::debug;
36 35
36use crate::nostr::builder::SharedDatabase;
37use crate::nostr::events::{ 37use crate::nostr::events::{
38 RepositoryAnnouncement, RepositoryState, KIND_PR, KIND_PR_UPDATE, KIND_REPOSITORY_ANNOUNCEMENT, 38 RepositoryAnnouncement, RepositoryState, KIND_PR, KIND_PR_UPDATE, KIND_REPOSITORY_ANNOUNCEMENT,
39 KIND_REPOSITORY_STATE, 39 KIND_REPOSITORY_STATE,
@@ -56,7 +56,7 @@ pub struct RepositoryData {
56/// This performs a single database query to fetch both announcement and state events, 56/// This performs a single database query to fetch both announcement and state events,
57/// which is more efficient than separate queries. 57/// which is more efficient than separate queries.
58pub async fn fetch_repository_data( 58pub async fn fetch_repository_data(
59 database: &Arc<MemoryDatabase>, 59 database: &SharedDatabase,
60 identifier: &str, 60 identifier: &str,
61) -> Result<RepositoryData> { 61) -> Result<RepositoryData> {
62 let filter = Filter::new() 62 let filter = Filter::new()
@@ -284,7 +284,7 @@ pub fn is_latest_state(
284/// 284///
285/// Returns an `AuthorizationResult` that indicates whether a push is authorized. 285/// Returns an `AuthorizationResult` that indicates whether a push is authorized.
286pub async fn get_authorization_from_db( 286pub async fn get_authorization_from_db(
287 database: &Arc<MemoryDatabase>, 287 database: &SharedDatabase,
288 identifier: &str, 288 identifier: &str,
289) -> Result<AuthorizationResult> { 289) -> Result<AuthorizationResult> {
290 // Fetch all repository data with a single query 290 // Fetch all repository data with a single query
@@ -340,7 +340,7 @@ pub async fn get_authorization_from_db(
340/// 340///
341/// Returns an `AuthorizationResult` that indicates whether a push is authorized. 341/// Returns an `AuthorizationResult` that indicates whether a push is authorized.
342pub async fn get_authorization_for_owner( 342pub async fn get_authorization_for_owner(
343 database: &Arc<MemoryDatabase>, 343 database: &SharedDatabase,
344 identifier: &str, 344 identifier: &str,
345 owner_pubkey: &str, 345 owner_pubkey: &str,
346) -> Result<AuthorizationResult> { 346) -> Result<AuthorizationResult> {
@@ -817,7 +817,7 @@ pub fn npub_to_pubkey(npub: &str) -> Result<String> {
817/// - `Ok(None)` if the event doesn't exist (push should be allowed) 817/// - `Ok(None)` if the event doesn't exist (push should be allowed)
818/// - `Err(_)` on database errors 818/// - `Err(_)` on database errors
819pub async fn get_event_commit_tag( 819pub async fn get_event_commit_tag(
820 database: &Arc<MemoryDatabase>, 820 database: &SharedDatabase,
821 event_id: &EventId, 821 event_id: &EventId,
822) -> Result<Option<String>> { 822) -> Result<Option<String>> {
823 // Query for PR (1618) and PR Update (1619) events with this ID 823 // Query for PR (1618) and PR Update (1619) events with this ID
@@ -872,7 +872,7 @@ pub async fn get_event_commit_tag(
872/// * `Ok(())` if all refs/nostr/ pushes are valid 872/// * `Ok(())` if all refs/nostr/ pushes are valid
873/// * `Err(_)` if any ref has invalid event ID format or fails commit validation 873/// * `Err(_)` if any ref has invalid event ID format or fails commit validation
874pub async fn validate_nostr_ref_pushes( 874pub async fn validate_nostr_ref_pushes(
875 database: &Arc<MemoryDatabase>, 875 database: &SharedDatabase,
876 pushed_refs: &[(String, String, String)], 876 pushed_refs: &[(String, String, String)],
877) -> Result<()> { 877) -> Result<()> {
878 for (_, new_oid, ref_name) in pushed_refs { 878 for (_, new_oid, ref_name) in pushed_refs {