diff options
Diffstat (limited to 'src/git')
| -rw-r--r-- | src/git/authorization.rs | 12 | ||||
| -rw-r--r-- | src/git/handlers.rs | 7 |
2 files changed, 9 insertions, 10 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}; | |||
| 31 | use nostr_relay_builder::prelude::*; | 31 | use nostr_relay_builder::prelude::*; |
| 32 | use nostr_sdk::{EventId, ToBech32}; | 32 | use nostr_sdk::{EventId, ToBech32}; |
| 33 | use std::collections::{HashMap, HashSet}; | 33 | use std::collections::{HashMap, HashSet}; |
| 34 | use std::sync::Arc; | ||
| 35 | use tracing::debug; | 34 | use tracing::debug; |
| 36 | 35 | ||
| 36 | use crate::nostr::builder::SharedDatabase; | ||
| 37 | use crate::nostr::events::{ | 37 | use 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. |
| 58 | pub async fn fetch_repository_data( | 58 | pub 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. |
| 286 | pub async fn get_authorization_from_db( | 286 | pub 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. |
| 342 | pub async fn get_authorization_for_owner( | 342 | pub 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 |
| 819 | pub async fn get_event_commit_tag( | 819 | pub 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 |
| 874 | pub async fn validate_nostr_ref_pushes( | 874 | pub 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 { |
diff --git a/src/git/handlers.rs b/src/git/handlers.rs index e84cabb..8e5f5e1 100644 --- a/src/git/handlers.rs +++ b/src/git/handlers.rs | |||
| @@ -4,9 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | use http_body_util::Full; | 5 | use http_body_util::Full; |
| 6 | use hyper::{body::Bytes, Response, StatusCode}; | 6 | use hyper::{body::Bytes, Response, StatusCode}; |
| 7 | use nostr_relay_builder::prelude::MemoryDatabase; | ||
| 8 | use std::path::PathBuf; | 7 | use std::path::PathBuf; |
| 9 | use std::sync::Arc; | ||
| 10 | use tokio::io::{AsyncReadExt, AsyncWriteExt}; | 8 | use tokio::io::{AsyncReadExt, AsyncWriteExt}; |
| 11 | use tracing::{debug, error, info, warn}; | 9 | use tracing::{debug, error, info, warn}; |
| 12 | 10 | ||
| @@ -18,6 +16,7 @@ use super::protocol::{GitService, PktLine}; | |||
| 18 | use super::subprocess::GitSubprocess; | 16 | use super::subprocess::GitSubprocess; |
| 19 | use super::try_set_head_if_available; | 17 | use super::try_set_head_if_available; |
| 20 | 18 | ||
| 19 | use crate::nostr::builder::SharedDatabase; | ||
| 21 | use crate::nostr::events::RepositoryState; | 20 | use crate::nostr::events::RepositoryState; |
| 22 | 21 | ||
| 23 | /// Handle GET /info/refs?service=git-{upload,receive}-pack | 22 | /// Handle GET /info/refs?service=git-{upload,receive}-pack |
| @@ -178,7 +177,7 @@ pub async fn handle_upload_pack( | |||
| 178 | pub async fn handle_receive_pack( | 177 | pub async fn handle_receive_pack( |
| 179 | repo_path: PathBuf, | 178 | repo_path: PathBuf, |
| 180 | request_body: Bytes, | 179 | request_body: Bytes, |
| 181 | database: Option<Arc<MemoryDatabase>>, | 180 | database: Option<SharedDatabase>, |
| 182 | identifier: &str, | 181 | identifier: &str, |
| 183 | owner_pubkey: &str, | 182 | owner_pubkey: &str, |
| 184 | ) -> Result<Response<Full<Bytes>>, GitError> { | 183 | ) -> Result<Response<Full<Bytes>>, GitError> { |
| @@ -310,7 +309,7 @@ pub async fn handle_receive_pack( | |||
| 310 | /// 5. Validates that pushed refs match the state | 309 | /// 5. Validates that pushed refs match the state |
| 311 | /// 6. Validates refs/nostr/<event-id> has valid event id and if event exists, `c` tag matches ref | 310 | /// 6. Validates refs/nostr/<event-id> has valid event id and if event exists, `c` tag matches ref |
| 312 | async fn authorize_push( | 311 | async fn authorize_push( |
| 313 | database: &Arc<MemoryDatabase>, | 312 | database: &SharedDatabase, |
| 314 | identifier: &str, | 313 | identifier: &str, |
| 315 | owner_pubkey: &str, | 314 | owner_pubkey: &str, |
| 316 | request_body: &Bytes, | 315 | request_body: &Bytes, |