From 577438d4e3f4f52818e70c8d2bc90efa47cbc890 Mon Sep 17 00:00:00 2001 From: "@permadeath.com" Date: Wed, 23 Sep 2026 12:31:56 -0400 Subject: [PATCH] refactor(onboarding): drop the operator a native environment never has Nothing set NativeEnvironment's operator, so the field and the operator_record override that read it could never run. Its type parameter, OperatorRepository and NoOperator existed only for it and go too. The environment still answers not checkable here for an operator session, as it always did. Co-Authored-By: Claude Opus 5.5 (1M context) Change-Id: Id96bf0ce1e455cace149979d4f2de38b73e8796e --- crates/didbot-onboarding/src/env.rs | 34 ----------------- crates/didbot-onboarding/src/lib.rs | 5 +-- crates/didbot-onboarding/src/native.rs | 53 +++++++------------------- 3 files changed, 15 insertions(+), 77 deletions(-) diff --git a/crates/didbot-onboarding/src/env.rs b/crates/didbot-onboarding/src/env.rs index 10c6e1ba..4719e8be 100644 --- a/crates/didbot-onboarding/src/env.rs +++ b/crates/didbot-onboarding/src/env.rs @@ -226,37 +226,3 @@ pub(crate) fn first_missing( .iter() .find_map(|capability| env.missing(*capability).map(|why| (*capability, why))) } - -/// Reads a record out of the operator's own repository. -/// -/// The one authenticated seam in this crate, and the seam a signed-in front -/// end fills. It is handed a collection and a record key, never a hostname, -/// because the repository it reads is the **operator's own** — on the -/// operator's own PDS — and never the server being checked. -// `async fn` in a public trait forgoes an auto `Send` bound on its future; -// see [`Environment`]'s own note. -#[allow(async_fn_in_trait)] -pub trait OperatorRepository { - /// The record at `collection`/`rkey`, or `None` when the repository - /// holds none. - async fn record( - &self, - collection: &str, - rkey: &str, - ) -> Result, String>; -} - -/// The absence of a signed-in operator, and what an environment is built -/// with until one arrives. -#[derive(Debug, Default, Clone, Copy)] -pub struct NoOperator; - -impl OperatorRepository for NoOperator { - async fn record( - &self, - _collection: &str, - _rkey: &str, - ) -> Result, String> { - Err("nobody is signed in".to_owned()) - } -} diff --git a/crates/didbot-onboarding/src/lib.rs b/crates/didbot-onboarding/src/lib.rs index e833f4d4..2953827c 100644 --- a/crates/didbot-onboarding/src/lib.rs +++ b/crates/didbot-onboarding/src/lib.rs @@ -43,10 +43,7 @@ pub mod verdict; #[cfg(not(target_arch = "wasm32"))] pub mod native; -pub use env::{ - Capability, Certificate, Environment, Fetched, NoOperator, OperatorRepository, RecordKind, - Unavailable, -}; +pub use env::{Capability, Certificate, Environment, Fetched, RecordKind, Unavailable}; pub use run::{run_steps, Target}; pub use step::{Check, Step}; pub use verdict::{CheckOutcome, Run, StepOutcome, StepState, Verdict}; diff --git a/crates/didbot-onboarding/src/native.rs b/crates/didbot-onboarding/src/native.rs index eb43479c..679e27de 100644 --- a/crates/didbot-onboarding/src/native.rs +++ b/crates/didbot-onboarding/src/native.rs @@ -1,15 +1,11 @@ //! The environment an operator's own machine offers. //! -//! Everything: HTTPS with no same-origin rule, the machine's own stub -//! resolver, DoH for the record types a stub resolver has no API for, and -//! the certificate the connection actually rests on. A signed-in operator is -//! the one thing a caller supplies. +//! Everything but a signed-in operator: HTTPS with no same-origin rule, the +//! machine's own stub resolver, DoH for the record types a stub resolver has +//! no API for, and the certificate the connection actually rests on. use crate::doh; -use crate::env::{ - Capability, Certificate, Environment, Fetched, NoOperator, OperatorRepository, RecordKind, - Unavailable, -}; +use crate::env::{Capability, Certificate, Environment, Fetched, RecordKind, Unavailable}; /// How long any one call waits before calling it a failure. /// @@ -21,38 +17,35 @@ use crate::env::{ pub const CHECK_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(10); /// The full environment: everything a command run by an operator can do. -pub struct NativeEnvironment { +pub struct NativeEnvironment { client: reqwest::Client, resolver: String, - operator: Option, } -impl NativeEnvironment { - /// An environment with nobody signed in, resolving through - /// [`doh::CLOUDFLARE`]. +impl NativeEnvironment { + /// An environment resolving through [`doh::CLOUDFLARE`]. #[must_use] pub fn new() -> Self { Self::with_resolver(doh::CLOUDFLARE) } - /// An environment with nobody signed in, resolving through `resolver`. + /// An environment resolving through `resolver`. #[must_use] pub fn with_resolver(resolver: impl Into) -> Self { Self { client: didbot_http::client(), resolver: resolver.into(), - operator: None, } } } -impl Default for NativeEnvironment { +impl Default for NativeEnvironment { fn default() -> Self { Self::new() } } -impl NativeEnvironment { +impl NativeEnvironment { /// One DoH query. The resolver is this machine's own choice, so it may /// be on a private address. async fn doh(&self, name: &str, record_type: (u16, &str)) -> Result, String> { @@ -85,14 +78,13 @@ impl NativeEnvironment { } } -impl Environment for NativeEnvironment { +impl Environment for NativeEnvironment { fn missing(&self, capability: Capability) -> Option { match capability { Capability::Fetch | Capability::Dns | Capability::Certificate => None, - Capability::OperatorSession => self - .operator - .is_none() - .then(|| "no operator account is signed in to this command".to_owned()), + Capability::OperatorSession => { + Some("no operator account is signed in to this command".to_owned()) + } } } @@ -131,23 +123,6 @@ impl Environment for NativeEnvironment { async fn certificate(&self, hostname: &str) -> Result { handshake(hostname).await.map_err(Unavailable::failed) } - - async fn operator_record( - &self, - collection: &str, - rkey: &str, - ) -> Result, Unavailable> { - match &self.operator { - Some(operator) => operator - .record(collection, rkey) - .await - .map_err(Unavailable::failed), - None => Err(Unavailable::not_here( - Capability::OperatorSession, - "no operator account is signed in to this command", - )), - } - } } /// Opens a TLS connection to `hostname` and reads the certificate it -- 2.51.2