Nothing to see here

refactor(knot): make `model::RepositoryManager` dyn-compatible

Re-write `can_push()` method as a boxed future.

Signed-off-by: tjh <did:plc:65gha4t3avpfpzmvpbwovss7>

tjh.dev b1f18b97 7bf5ec4a

verified
Changed files
+18 -10
crates
knot
src
+18 -10
crates/knot/src/model.rs
··· 14 http::request::Parts, 15 }; 16 use errors::RepoNotFound; 17 use gix::{Repository, open::Options}; 18 use identity::Resolver; 19 use jetstream::JetstreamClient; ··· 121 122 /// Determine whether the specified account has permission to push to the 123 /// specified repository. 124 - fn can_push(&self, repo: &RepoPath, did: &Did) -> impl Future<Output = bool>; 125 } 126 127 impl RepositoryManager for Knot { ··· 145 } 146 147 // Currently defers to the real knotserver's internal "/push-allowed" route. 148 - async fn can_push(&self, repo: &RepoPath, did: &Did) -> bool { 149 use reqwest::StatusCode; 150 151 - let url = format!("http://localhost:5444/push-allowed?user={did}&repo={repo}"); 152 - self.private_http() 153 - .get(url) 154 - .send() 155 - .await 156 - .inspect_err(|err| tracing::error!(?err, "failed to query push permission")) 157 - .map(|response| response.status() == StatusCode::NO_CONTENT) 158 - .unwrap_or_default() 159 } 160 } 161
··· 14 http::request::Parts, 15 }; 16 use errors::RepoNotFound; 17 + use futures_util::{FutureExt, future::BoxFuture}; 18 use gix::{Repository, open::Options}; 19 use identity::Resolver; 20 use jetstream::JetstreamClient; ··· 120 121 /// Determine whether the specified account has permission to push to the 122 /// specified repository. 123 + fn can_push(&self, repo: &RepoPath, did: &Did) -> BoxFuture<'_, bool>; 124 } 125 126 impl RepositoryManager for Knot { ··· 144 } 145 146 // Currently defers to the real knotserver's internal "/push-allowed" route. 147 + fn can_push(&self, repo: &RepoPath, did: &Did) -> BoxFuture<'_, bool> { 148 use reqwest::StatusCode; 149 150 + let request = self 151 + .private_http() 152 + .get(format!( 153 + "http://localhost:5444/push-allowed?user={did}&repo={repo}" 154 + )) 155 + .send(); 156 + 157 + async move { 158 + request 159 + .await 160 + .inspect_err(|error| tracing::error!(?error, "failed to query push permission")) 161 + .map(|response| response.status() == StatusCode::NO_CONTENT) 162 + .unwrap_or_default() 163 + } 164 + .boxed() 165 } 166 } 167