Resolve all ambient configuration only at the trusted local boundary.
(
&self,
repository: &crate::atomic::RepositoryRef,
remote: &str,
identity: Option<String>,
push: bool,
)
| 363 | |
| 364 | /// Resolve all ambient configuration only at the trusted local boundary. |
| 365 | async fn sync_credentials( |
| 366 | &self, |
| 367 | repository: &crate::atomic::RepositoryRef, |
| 368 | remote: &str, |
| 369 | identity: Option<String>, |
| 370 | push: bool, |
| 371 | ) -> Result<(String, String, HttpRemoteConfig), Status> { |
| 372 | let handle = self.state.resolve(repository)?; |
| 373 | let remote = (!remote.is_empty()).then(|| remote.to_owned()); |
| 374 | let runtime = tokio::runtime::Handle::current(); |
| 375 | tokio::task::spawn_blocking(move || { |
| 376 | let repo = handle.repository_readonly()?; |
| 377 | let name = remote.unwrap_or_else(|| { |
| 378 | repo.get_default_remote() |
| 379 | .map(|(name, _)| name) |
| 380 | .unwrap_or_else(|_| "origin".to_owned()) |
| 381 | }); |
| 382 | let url = if name.contains("://") { |
| 383 | name.clone() |
| 384 | } else { |
| 385 | repo.get_remote(&name) |
| 386 | .map_err(|error| match error { |
| 387 | atomic_repository::RepositoryError::RemoteNotFound { .. } => { |
| 388 | crate::daemon::state::domain_status( |
| 389 | crate::atomic::ErrorCode::NotFound, |
| 390 | format!("remote '{name}' not found"), |
| 391 | ) |
| 392 | } |
| 393 | other => repository_error(other), |
| 394 | })? |
| 395 | .url |
| 396 | }; |
| 397 | if push { |
| 398 | auth::check_push_credentials(&url, identity.as_deref()).map_err(auth_status)?; |
| 399 | } |
| 400 | drop(repo); |
| 401 | let config = runtime.block_on(auth::attach_identity( |
| 402 | HttpRemoteConfig::new(), |
| 403 | &url, |
| 404 | identity.as_deref(), |
| 405 | )); |
| 406 | Ok::<_, Status>((name, url, config)) |
| 407 | }) |
| 408 | .await |
| 409 | .map_err(|e| Status::internal(format!("credentials task failed: {e}")))? |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | fn reject_transport_credentials( |
no test coverage detected