upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/nostr
diff options
context:
space:
mode:
Diffstat (limited to 'src/nostr')
-rw-r--r--src/nostr/builder.rs34
-rw-r--r--src/nostr/events.rs16
-rw-r--r--src/nostr/policy/state.rs9
3 files changed, 40 insertions, 19 deletions
diff --git a/src/nostr/builder.rs b/src/nostr/builder.rs
index 9211972..3baa2ff 100644
--- a/src/nostr/builder.rs
+++ b/src/nostr/builder.rs
@@ -185,7 +185,10 @@ impl Nip34WritePolicy {
185 WritePolicyResult::Accept 185 WritePolicyResult::Accept
186 } 186 }
187 Err(e) => { 187 Err(e) => {
188 let npub = event.pubkey.to_bech32().unwrap_or_else(|_| event.pubkey.to_hex()); 188 let npub = event
189 .pubkey
190 .to_bech32()
191 .unwrap_or_else(|_| event.pubkey.to_hex());
189 let event_id_short = &event.id.to_hex()[..12]; 192 let event_id_short = &event.id.to_hex()[..12];
190 // Try to extract repo identifier from 'd' tag even if parsing failed 193 // Try to extract repo identifier from 'd' tag even if parsing failed
191 let repo = Self::extract_identifier_from_event(event); 194 let repo = Self::extract_identifier_from_event(event);
@@ -221,7 +224,10 @@ impl Nip34WritePolicy {
221 WritePolicyResult::Accept 224 WritePolicyResult::Accept
222 } 225 }
223 Err(e) => { 226 Err(e) => {
224 let npub = event.pubkey.to_bech32().unwrap_or_else(|_| event.pubkey.to_hex()); 227 let npub = event
228 .pubkey
229 .to_bech32()
230 .unwrap_or_else(|_| event.pubkey.to_hex());
225 let event_id_short = &event.id.to_hex()[..12]; 231 let event_id_short = &event.id.to_hex()[..12];
226 // Try to extract repo identifier from 'd' tag even if parsing failed 232 // Try to extract repo identifier from 'd' tag even if parsing failed
227 let repo = Self::extract_identifier_from_event(event); 233 let repo = Self::extract_identifier_from_event(event);
@@ -265,7 +271,10 @@ impl Nip34WritePolicy {
265 { 271 {
266 Ok(poilicy_result) => poilicy_result, 272 Ok(poilicy_result) => poilicy_result,
267 Err(e) => { 273 Err(e) => {
268 let npub = event.pubkey.to_bech32().unwrap_or_else(|_| event.pubkey.to_hex()); 274 let npub = event
275 .pubkey
276 .to_bech32()
277 .unwrap_or_else(|_| event.pubkey.to_hex());
269 let event_id_short = &event.id.to_hex()[..12]; 278 let event_id_short = &event.id.to_hex()[..12];
270 // Try to extract repo identifier from 'd' tag even if parsing failed 279 // Try to extract repo identifier from 'd' tag even if parsing failed
271 let repo = Self::extract_identifier_from_event(event); 280 let repo = Self::extract_identifier_from_event(event);
@@ -287,7 +296,10 @@ impl Nip34WritePolicy {
287 } 296 }
288 } 297 }
289 StateResult::Reject(reason) => { 298 StateResult::Reject(reason) => {
290 let npub = event.pubkey.to_bech32().unwrap_or_else(|_| event.pubkey.to_hex()); 299 let npub = event
300 .pubkey
301 .to_bech32()
302 .unwrap_or_else(|_| event.pubkey.to_hex());
291 let event_id_short = &event.id.to_hex()[..12]; 303 let event_id_short = &event.id.to_hex()[..12];
292 // Try to extract repo identifier from 'd' tag even if parsing failed 304 // Try to extract repo identifier from 'd' tag even if parsing failed
293 let repo = Self::extract_identifier_from_event(event); 305 let repo = Self::extract_identifier_from_event(event);
@@ -397,9 +409,12 @@ impl Nip34WritePolicy {
397 ); 409 );
398 410
399 // Add to purgatory 411 // Add to purgatory
400 self.ctx 412 self.ctx.purgatory.add_pr(
401 .purgatory 413 event.clone(),
402 .add_pr(event.clone(), event.id.to_hex(), commit.clone(), is_synced); 414 event.id.to_hex(),
415 commit.clone(),
416 is_synced,
417 );
403 418
404 WritePolicyResult::Reject { 419 WritePolicyResult::Reject {
405 status: true, // Client sees OK 420 status: true, // Client sees OK
@@ -417,7 +432,10 @@ impl Nip34WritePolicy {
417 } 432 }
418 Err(e) => { 433 Err(e) => {
419 // Error checking git data - reject event 434 // Error checking git data - reject event
420 let npub = event.pubkey.to_bech32().unwrap_or_else(|_| event.pubkey.to_hex()); 435 let npub = event
436 .pubkey
437 .to_bech32()
438 .unwrap_or_else(|_| event.pubkey.to_hex());
421 let event_id_short = &event.id.to_hex()[..12]; 439 let event_id_short = &event.id.to_hex()[..12];
422 // Extract ALL repo identifiers from 'a' tags for PR events 440 // Extract ALL repo identifiers from 'a' tags for PR events
423 // (PR events can reference multiple repos when there are multiple maintainers) 441 // (PR events can reference multiple repos when there are multiple maintainers)
diff --git a/src/nostr/events.rs b/src/nostr/events.rs
index 718633e..a441742 100644
--- a/src/nostr/events.rs
+++ b/src/nostr/events.rs
@@ -419,14 +419,14 @@ pub fn validate_announcement(
419 // GRASP-01: Normal mode - accept if announcement lists our service AND matches repository whitelist (if enabled) 419 // GRASP-01: Normal mode - accept if announcement lists our service AND matches repository whitelist (if enabled)
420 if lists_service && !archive_config.read_only { 420 if lists_service && !archive_config.read_only {
421 // Check repository whitelist if enabled 421 // Check repository whitelist if enabled
422 if repository_config.enabled() { 422 if repository_config.enabled()
423 if !repository_config.matches(&npub, &announcement.identifier) { 423 && !repository_config.matches(&npub, &announcement.identifier)
424 return AnnouncementResult::Reject(format!( 424 {
425 "Announcement lists service but does not match repository whitelist. \ 425 return AnnouncementResult::Reject(format!(
426 Repository {}/{} not in whitelist", 426 "Announcement lists service but does not match repository whitelist. \
427 npub, announcement.identifier 427 Repository {}/{} not in whitelist",
428 )); 428 npub, announcement.identifier
429 } 429 ));
430 } 430 }
431 return AnnouncementResult::Accept; 431 return AnnouncementResult::Accept;
432 } 432 }
diff --git a/src/nostr/policy/state.rs b/src/nostr/policy/state.rs
index 52f0483..3411077 100644
--- a/src/nostr/policy/state.rs
+++ b/src/nostr/policy/state.rs
@@ -205,9 +205,12 @@ impl StatePolicy {
205 205
206 // If no git data - add to purgatory 206 // If no git data - add to purgatory
207 // (add_state automatically enqueues for background sync) 207 // (add_state automatically enqueues for background sync)
208 self.ctx 208 self.ctx.purgatory.add_state(
209 .purgatory 209 event.clone(),
210 .add_state(event.clone(), state.identifier.clone(), event.pubkey, is_synced); 210 state.identifier.clone(),
211 event.pubkey,
212 is_synced,
213 );
211 214
212 tracing::info!( 215 tracing::info!(
213 "state event added to purgatory: eventid: {}, identifier: {}", 216 "state event added to purgatory: eventid: {}, identifier: {}",